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

ktimetracker

edittaskdialog.cpp

Go to the documentation of this file.
00001 /*
00002  *     Copyright (C) 1999 by Espen Sand <espensa@online.no>
00003  *                   2000 by Klarälvdalens Datakonsult AB <kalle@dalheimer.de>
00004  *                   2000 by Jesper Pedersen <blackie@kde.org>
00005  *                   2007 the ktimetracker developers
00006  *
00007  *   This program is free software; you can redistribute it and/or modify
00008  *   it under the terms of the GNU General Public License as published by
00009  *   the Free Software Foundation; either version 2 of the License, or
00010  *   (at your option) any later version.
00011  *
00012  *   This program is distributed in the hope that it will be useful,
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *   GNU General Public License for more details.
00016  *
00017  *   You should have received a copy of the GNU General Public License along
00018  *   with this program; if not, write to the
00019  *      Free Software Foundation, Inc.
00020  *      51 Franklin Street, Fifth Floor
00021  *      Boston, MA  02110-1301  USA.
00022  *
00023  */
00024 
00025 #include "edittaskdialog.h"
00026 
00027 #include <QCheckBox>
00028 #include <QGridLayout>
00029 #include <QGroupBox>
00030 #include <QHBoxLayout>
00031 #include <QLabel>
00032 #include <QRadioButton>
00033 #include <QString>
00034 #include <QVBoxLayout>
00035 #include <QWidget>
00036 
00037 #include <KComboBox>
00038 #include <KDebug>
00039 #include <KLineEdit>
00040 #include <KLocale>            // i18n
00041 #include <KWindowSystem>
00042 
00043 #include "ktimewidget.h"
00044 
00045 EditTaskDialog::EditTaskDialog( QWidget *parent, const QString &caption, 
00046                                 bool editDlg, DesktopList* desktopList)
00047   : KDialog( parent ),
00048     origTime( 0 ), origSession( 0 )
00049 {
00050   setWindowTitle( caption );
00051   setObjectName( "EditTaskDialog" );
00052   QWidget *page = new QWidget( this ); 
00053   setMainWidget( page );
00054 
00055   QVBoxLayout *mainLayout = new QVBoxLayout;
00056   mainLayout->setMargin( 0 );
00057   mainLayout->setSpacing( KDialog::spacingHint() );
00058 
00059   /* Task name */
00060   QWidget *taskNameWidget = new QWidget( page );
00061   QHBoxLayout *layout = new QHBoxLayout;
00062   layout->setMargin( 0 );
00063   layout->setSpacing( KDialog::spacingHint() );
00064   QLabel *label = new QLabel( i18n( "Task &name:" ), taskNameWidget );
00065   _name = new KLineEdit( taskNameWidget );
00066   label->setBuddy( _name );
00067   layout->addWidget( label );
00068   layout->addWidget( _name );
00069   taskNameWidget->setLayout( layout );
00070 
00071   /* The "Edit Absolut" radio button */
00072   QWidget *timeWidget = new QWidget( page );
00073   QGridLayout *gridLayout = new QGridLayout;
00074   gridLayout->setMargin( 0 );
00075   gridLayout->setSpacing( 0 );
00076   gridLayout->setColumnMinimumWidth( 0, 20 );
00077   gridLayout->setColumnMinimumWidth( 2, KDialog::spacingHint() );
00078   _absoluteRB = new QRadioButton( i18n( "Edit &absolute" ), timeWidget );
00079   connect( _absoluteRB, SIGNAL( clicked() ),
00080            this, SLOT( slotAbsolutePressed() ) );
00081   _timeLA = new QLabel( i18n( "&Time:" ), timeWidget );
00082   _timeTW = new KArmTimeWidget( timeWidget );
00083   _timeLA->setBuddy( _timeTW );
00084   _sessionLA = new QLabel( i18n( "&Session time:" ), timeWidget );
00085   _sessionTW = new KArmTimeWidget( timeWidget );
00086   _sessionLA->setBuddy( _sessionTW );
00087 
00088   /* The "Edit relative" radio button */
00089   _relativeRB = new QRadioButton( i18n( "Edit &relative (apply to both time and"
00090       " session time)" ), timeWidget );
00091   connect( _relativeRB, SIGNAL( clicked() ), 
00092            this, SLOT( slotRelativePressed() ) );
00093   _operator = new KComboBox( timeWidget );
00094   _operator->addItem( QString::fromLatin1( "+" ) );
00095   _operator->addItem( QString::fromLatin1( "-" ) );
00096 
00097   _diffTW = new KArmTimeWidget( timeWidget );
00098   gridLayout->addWidget(_absoluteRB, 0, 0, 1, 4 );
00099   gridLayout->addWidget( _timeLA, 1, 1 );
00100   gridLayout->addWidget( _timeTW, 1, 3 );
00101   gridLayout->addWidget( _sessionLA, 2, 1 );
00102   gridLayout->addWidget( _sessionTW, 2, 3 );
00103   gridLayout->addWidget( _relativeRB, 3, 0, 1, 4 );
00104   gridLayout->addWidget( _operator, 4, 1, 1, 2 );
00105   gridLayout->addWidget( _diffTW, 4, 3 );
00106   timeWidget->setLayout( gridLayout );
00107 
00108   /* Auto Tracking */
00109 #ifdef Q_WS_X11
00110   desktopCount = KWindowSystem::numberOfDesktops();
00111 #else
00112 #ifdef __GNUC__
00113 #warning non-X11 support missing
00114 #endif
00115   desktopCount = 1;
00116 #endif
00117 
00118   if ( desktopList && (desktopList->size() > 0) ) {
00119     DesktopList::iterator rit = desktopList->begin();
00120     while ( *rit < desktopCount && rit!=desktopList->end() ) {
00121       ++rit;
00122     }
00123     desktopList->erase( rit, desktopList->end() );
00124   }
00125 
00126   int lines = (int)(desktopCount/2);
00127   if (lines*2 != desktopCount) lines++; 
00128 
00129   QGroupBox *groupBox = new QGroupBox( i18n( "A&uto Tracking" ), page );
00130   groupBox->setCheckable( true );
00131   groupBox->setChecked( false );
00132   gridLayout = new QGridLayout;
00133   gridLayout->setMargin( KDialog::marginHint() );
00134   gridLayout->setSpacing( KDialog::spacingHint() );
00135   label = new QLabel( i18n( "In Desktop" ) );
00136   gridLayout->addWidget( label, 0, 0, 1, lines );
00137 
00138   for ( int i = 0; i < desktopCount; ++i ) {
00139     QCheckBox *tmpBx = new QCheckBox( groupBox );
00140     tmpBx->setObjectName( QString::number( i ).toLatin1() );
00141     _deskBox.append( tmpBx );
00142 #ifdef Q_WS_X11
00143     tmpBx->setText( KWindowSystem::desktopName( i + 1 ) );
00144 #endif
00145     tmpBx->setChecked( false );
00146 
00147     gridLayout->addWidget( tmpBx, i / lines + 1, i % lines );
00148   }
00149 
00150   groupBox->setLayout( gridLayout );
00151 
00152   // check specified Desktop Check Boxes
00153   bool enableDesktops = false;
00154 
00155   if ( desktopList && ( desktopList->size() > 0 ) ) {
00156     DesktopList::iterator it = desktopList->begin();
00157     while ( it != desktopList->end() ) {
00158       _deskBox[*it]->setChecked( true );
00159       ++it;
00160     }
00161     enableDesktops = true;
00162   }
00163   // if some desktops were specified, then enable the parent box
00164   groupBox->setChecked( enableDesktops );
00165 
00166   connect(groupBox, SIGNAL( clicked( bool ) ),
00167           this, SLOT( slotAutoTrackingPressed( bool ) ) );
00168 
00169   mainLayout->addWidget( taskNameWidget );
00170   mainLayout->addWidget( timeWidget );
00171   mainLayout->addWidget( groupBox );
00172   page->setLayout( mainLayout );
00173 
00174   if ( editDlg ) {
00175     // This is an edit dialog.
00176     _operator->setFocus();
00177   }
00178   else {
00179     // This is an initial dialog
00180     _name->setFocus();
00181   }
00182 
00183   slotRelativePressed();
00184 
00185   // Whats this help.
00186   _name->setWhatsThis(
00187                    i18n( "Enter the name of the task here. "
00188                          "This name is for your eyes only."));
00189   _absoluteRB->setWhatsThis(
00190                    i18n( "Use this option to set the time spent on this task "
00191                          "to an absolute value.\n\nFor example, if you have "
00192                          "worked exactly four hours on this task during the current "
00193                          "session, you would set the Session time to 4 hr." ) );
00194   _relativeRB->setWhatsThis(
00195                    i18n( "Use this option to change the time spent on this task "
00196                          "relative to its current value.\n\nFor example, if you worked "
00197                          "on this task for one hour without the timer running, you "
00198                          "would add 1 hr." ) );
00199   _timeTW->setWhatsThis(
00200                    i18n( "This is the time the task has been "
00201                          "running since all times were reset."));
00202   _sessionTW->setWhatsThis(
00203                    i18n( "This is the time the task has been running this "
00204                          "session."));
00205   _diffTW->setWhatsThis( 
00206                    i18n( "Specify how much time to add or subtract "
00207                          "to the overall and session time"));
00208   groupBox->setWhatsThis( 
00209                    i18n( "Use this option to automatically start the timer "
00210                          "on this task when you switch to the specified desktop(s). "
00211                          "Select the desktop(s) that will automatically start the "
00212                          "timer on this task." ) );
00213 }
00214 
00215 void EditTaskDialog::slotAbsolutePressed()
00216 {
00217   _relativeRB->setChecked( false );
00218   _absoluteRB->setChecked( true );
00219 
00220   _operator->setEnabled( false );
00221   _diffTW->setEnabled( false );
00222 
00223   _timeLA->setEnabled( true );
00224   _sessionLA->setEnabled( true );
00225   _timeTW->setEnabled( true );
00226   _sessionTW->setEnabled( true );
00227 }
00228 
00229 void EditTaskDialog::slotRelativePressed()
00230 {
00231   _relativeRB->setChecked( true );
00232   _absoluteRB->setChecked( false );
00233 
00234   _operator->setEnabled( true );
00235   _diffTW->setEnabled( true );
00236 
00237   _timeLA->setEnabled( false );
00238   _sessionLA->setEnabled( false );
00239   _timeTW->setEnabled( false );
00240   _sessionTW->setEnabled( false );
00241 }
00242 
00243 void EditTaskDialog::slotAutoTrackingPressed( bool checked ) 
00244 {
00245   if (!checked)  // uncheck all desktop boxes
00246     for ( int i = 0; i < desktopCount; ++i ) 
00247       _deskBox[i]->setChecked( false );
00248 }
00249 
00250 void EditTaskDialog::setTask( const QString &name, long time, long session )
00251 {
00252   _name->setText( name );
00253 
00254   _timeTW->setTime( time / 60, time % 60 );
00255   _sessionTW->setTime( session / 60, session % 60 );
00256   origTime = time;
00257   origSession = session;
00258 }
00259 
00260 QString EditTaskDialog::taskName() const
00261 {
00262   return( _name->text() );
00263 }
00264 
00265 void EditTaskDialog::status(long *time, long *timeDiff, long *session,
00266                             long *sessionDiff, DesktopList *desktopList) const
00267 {
00268   if ( _absoluteRB->isChecked() ) {
00269     *time = _timeTW->time();
00270     *session = _sessionTW->time();
00271   } else {
00272     int diff = _diffTW->time();
00273     if ( _operator->currentIndex() == 1) {
00274       diff = -diff;
00275     }
00276     *time = origTime + diff;
00277     *session = origSession + diff;
00278   }
00279 
00280   *timeDiff = *time - origTime;
00281   *sessionDiff = *session - origSession;
00282 
00283   for ( int i = 0; i < _deskBox.count(); i++ ) {
00284     if ( _deskBox[i]->isChecked() )
00285       desktopList->append( i );
00286   }
00287 }
00288 
00289 #include "edittaskdialog.moc"

ktimetracker

Skip menu "ktimetracker"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
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