• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kstars

timedialog.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           timedialog.cpp  -  K Desktop Planetarium
00003                              -------------------
00004     begin                : Sun Feb 11 2001
00005     copyright            : (C) 2001 by Jason Harris
00006     email                : jharris@30doradus.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 
00019 #include <klocale.h>
00020 
00021 #include <qlabel.h>
00022 #include <qpushbutton.h>
00023 #include <qspinbox.h>
00024 #include <qlayout.h>
00025 
00026 #include "timedialog.h"
00027 #include "kstars.h"
00028 #include "kstarsdata.h"
00029 #include "simclock.h"
00030 #include "libkdeedu/extdate/extdatepicker.h"
00031 
00032 TimeDialog::TimeDialog( const KStarsDateTime &now, QWidget* parent )
00033     : KDialogBase( KDialogBase::Plain, i18n( "set clock to a new time", "Set Time" ), Ok|Cancel, Ok, parent )
00034 {
00035     ksw = (KStars*) parent;
00036     QFrame *page = plainPage();
00037 
00038     vlay = new QVBoxLayout( page, 2, 2 );
00039     hlay = new QHBoxLayout( 2 ); //this layout will be added to the VLayout
00040     dPicker = new ExtDatePicker( page );
00041     dPicker->setDate( now.date() );
00042 
00043     HourBox = new QSpinBox( page, "HourBox" );
00044     QFont Box_font(  HourBox->font() );
00045     Box_font.setBold( TRUE );
00046     HourBox->setFont( Box_font );
00047     HourBox->setWrapping( TRUE );
00048     HourBox->setMaxValue( 23 );
00049     HourBox->setButtonSymbols( QSpinBox::PlusMinus );
00050     HourBox->setValue( now.time().hour() );
00051 
00052     TextLabel1 = new QLabel( page, "TextLabel1" );
00053     TextLabel1->setText( " :" );
00054     TextLabel1->setFont( Box_font );
00055     
00056     MinuteBox = new QSpinBox( page, "MinuteBox" );
00057     QFont MinuteBox_font(  MinuteBox->font() );
00058     MinuteBox->setFont( Box_font );
00059     MinuteBox->setWrapping( TRUE );
00060     MinuteBox->setMaxValue( 59 );
00061     MinuteBox->setButtonSymbols( QSpinBox::PlusMinus );
00062     MinuteBox->setValue( now.time().minute() );
00063     
00064     TextLabel1_2 = new QLabel( page, "TextLabel1_2" );
00065     TextLabel1_2->setFont( Box_font );
00066     
00067     SecondBox = new QSpinBox( page, "SecondBox" );
00068     SecondBox->setFont( Box_font );
00069     SecondBox->setMaxValue( 59 );
00070     SecondBox->setWrapping( TRUE );
00071     SecondBox->setButtonSymbols( QSpinBox::PlusMinus );
00072     SecondBox->setValue( now.time().second() );
00073     
00074     NowButton = new QPushButton( page, "NowButton" );
00075     NowButton->setText( i18n( "Now"  ) );
00076     NowButton->setFont( Box_font );
00077     
00078     vlay->addWidget( dPicker, 0, 0 );
00079     vlay->addLayout( hlay, 0 );
00080     
00081     hlay->addWidget( HourBox, 0, 0 );
00082     hlay->addWidget( TextLabel1, 0, 0 );
00083     hlay->addWidget( MinuteBox, 0, 0 );
00084     hlay->addWidget( TextLabel1_2, 0, 0 );
00085     hlay->addWidget( SecondBox, 0, 0 );
00086     hlay->addWidget( NowButton );
00087     
00088     vlay->activate();
00089     
00090     QObject::connect( this, SIGNAL( okClicked() ), this, SLOT( accept() ));
00091     QObject::connect( this, SIGNAL( cancelClicked() ), this, SLOT( reject() ));
00092     QObject::connect( NowButton, SIGNAL( clicked() ), this, SLOT( setNow() ));
00093     QObject::connect( HourBox, SIGNAL( valueChanged( int ) ), this, SLOT( HourPrefix( int ) ));
00094     QObject::connect( MinuteBox, SIGNAL( valueChanged( int ) ), this, SLOT( MinutePrefix( int ) ));
00095     QObject::connect( SecondBox, SIGNAL( valueChanged( int ) ), this, SLOT( SecondPrefix( int ) ));
00096 }
00097 
00098 //Add handler for Escape key to close window
00099 //Use keyReleaseEvent because keyPressEvents are already consumed
00100 //by the ExtDatePicker.
00101 void TimeDialog::keyReleaseEvent( QKeyEvent *kev ) {
00102     switch( kev->key() ) {
00103         case Key_Escape:
00104         {
00105             close();
00106             break;
00107         }
00108 
00109         default: { kev->ignore(); break; }
00110     }
00111 }
00112 
00113 void TimeDialog::setNow( void )
00114 {
00115   KStarsDateTime dt( KStarsDateTime::currentDateTime() );
00116 
00117   dPicker->setDate( dt.date() );
00118   QTime t = dt.time();
00119 
00120   HourBox->setValue( t.hour() );
00121   MinuteBox->setValue( t.minute() );
00122   SecondBox->setValue( t.second() );
00123 }
00124 
00125 void TimeDialog::HourPrefix( int value ) {
00126     HourBox->setPrefix( "" );
00127     if ( value < 10 ) HourBox->setPrefix( "0" );
00128 }
00129 
00130 void TimeDialog::MinutePrefix( int value ) {
00131     MinuteBox->setPrefix( "" );
00132     if ( value < 10 ) MinuteBox->setPrefix( "0" );
00133 }
00134 
00135 void TimeDialog::SecondPrefix( int value ) {
00136     SecondBox->setPrefix( "" );
00137     if ( value < 10 ) SecondBox->setPrefix( "0" );
00138 }
00139 
00140 QTime TimeDialog::selectedTime( void ) {
00141     QTime t( HourBox->value(), MinuteBox->value(), SecondBox->value() );
00142     return t;
00143 }
00144 
00145 ExtDate TimeDialog::selectedDate( void ) {
00146     ExtDate d( dPicker->date() );
00147     return d;
00148 }
00149 
00150 KStarsDateTime TimeDialog::selectedDateTime( void ) {
00151     return KStarsDateTime( selectedDate(), selectedTime() );
00152 }
00153 
00154 #include "timedialog.moc"

kstars

Skip menu "kstars"
  • Main Page
  • Modules
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • keduca
  • kstars
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal