karm Library API Documentation

edittaskdialog.cpp

00001 /* 00002 * karm 00003 * This file only: Copyright (C) 1999 Espen Sand, espensa@online.no 00004 * Modifications (see CVS log) Copyright (C) 2000 Klarälvdalens 00005 * Datakonsult AB <kalle@dalheimer.de>, Jesper Pedersen <blackie@kde.org> 00006 * 00007 * 00008 * This program is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00021 * 00022 */ 00023 #include <qbuttongroup.h> 00024 #include <qcombobox.h> 00025 #include <qgroupbox.h> 00026 #include <qhbox.h> 00027 #include <qlabel.h> 00028 #include <qlayout.h> 00029 #include <qlineedit.h> 00030 #include <qpixmap.h> 00031 #include <qpushbutton.h> 00032 #include <qradiobutton.h> 00033 #include <qstring.h> 00034 #include <qwidget.h> 00035 #include <qwhatsthis.h> 00036 00037 #include <kiconloader.h> 00038 #include <klocale.h> // i18n 00039 #include <kwinmodule.h> 00040 00041 #include "edittaskdialog.h" 00042 #include "ktimewidget.h" 00043 #include "kdebug.h" 00044 00045 EditTaskDialog::EditTaskDialog( QString caption, bool editDlg, 00046 DesktopList* desktopList) 00047 : KDialogBase(0, "EditTaskDialog", true, caption, Ok|Cancel, Ok, true ), 00048 origTime( 0 ), origSession( 0 ) 00049 { 00050 QWidget *page = new QWidget( this ); 00051 setMainWidget(page); 00052 00053 QVBoxLayout *lay1 = new QVBoxLayout(page); 00054 00055 QHBoxLayout *lay2 = new QHBoxLayout(); 00056 lay1->addLayout(lay2); 00057 00058 // The name of the widget 00059 QLabel *label = new QLabel( i18n("Task &name:"), page, "name" ); 00060 lay2->addWidget( label ); 00061 lay2->addSpacing(5); 00062 00063 00064 _name = new QLineEdit( page, "lineedit" ); 00065 00066 _name->setMinimumWidth(fontMetrics().maxWidth()*15); 00067 lay2->addWidget( _name ); 00068 label->setBuddy( _name ); 00069 00070 00071 // The "Edit Absolut" radio button 00072 lay1->addSpacing(10);lay1->addStretch(1); 00073 _absoluteRB = new QRadioButton( i18n( "Edit &absolute" ), page, 00074 "_absoluteRB" ); 00075 lay1->addWidget( _absoluteRB ); 00076 connect( _absoluteRB, SIGNAL( clicked() ), this, SLOT( slotAbsolutePressed() ) ); 00077 00078 00079 // Absolute times 00080 QHBoxLayout *lay5 = new QHBoxLayout(); 00081 lay1->addLayout(lay5); 00082 lay5->addSpacing(20); 00083 QGridLayout *lay3 = new QGridLayout( 2, 2, -1, "lay3" ); 00084 lay5->addLayout(lay3); 00085 00086 // Time 00087 _timeLA = new QLabel( i18n("&Time:"), page, "time" ); 00088 lay3->addWidget( _timeLA, 0, 0 ); 00089 00090 _timeTW = new KArmTimeWidget( page, "_timeTW" ); 00091 lay3->addWidget( _timeTW, 0, 1 ); 00092 _timeLA->setBuddy( _timeTW ); 00093 00094 00095 // Session 00096 _sessionLA = new QLabel( i18n("&Session time:"), page, "session time" ); 00097 lay3->addWidget( _sessionLA, 1, 0 ); 00098 00099 _sessionTW = new KArmTimeWidget( page, "_sessionTW" ); 00100 lay3->addWidget( _sessionTW, 1, 1 ); 00101 _sessionLA->setBuddy( _sessionTW ); 00102 00103 00104 // The "Edit relative" radio button 00105 lay1->addSpacing(10);lay1->addStretch(1); 00106 _relativeRB = new QRadioButton( i18n( "Edit &relative (apply to both time and" 00107 " session time)" ), page, "_relativeRB" ); 00108 lay1->addWidget( _relativeRB ); 00109 connect( _relativeRB, SIGNAL( clicked() ), this, SLOT(slotRelativePressed()) ); 00110 00111 // The relative times 00112 QHBoxLayout *lay4 = new QHBoxLayout(); 00113 lay1->addLayout( lay4 ); 00114 lay4->addSpacing(20); 00115 00116 _operator = new QComboBox(page); 00117 _operator->insertItem( QString::fromLatin1( "+" ) ); 00118 _operator->insertItem( QString::fromLatin1( "-" ) ); 00119 lay4->addWidget( _operator ); 00120 00121 lay4->addSpacing(5); 00122 00123 _diffTW = new KArmTimeWidget( page, "_sessionAddTW" ); 00124 lay4->addWidget( _diffTW ); 00125 00126 desktopCount = getDesktopCount(); 00127 00128 // If desktopList contains higher numbered desktops than desktopCount then 00129 // delete those from desktopList. This may be the case if the user has 00130 // configured virtual desktops. The values in desktopList are sorted. 00131 if ( (desktopList != 0) && (desktopList->size() > 0) ) 00132 { 00133 DesktopList::iterator rit = desktopList->begin(); 00134 while (*rit < desktopCount && rit!=desktopList->end()) 00135 { 00136 ++rit; 00137 } 00138 desktopList->erase(rit, desktopList->end()); 00139 } 00140 00141 // The "Choose Desktop" checkbox 00142 lay1->addSpacing(10); 00143 lay1->addStretch(1); 00144 00145 _desktopCB = new QCheckBox(i18n("A&uto tracking"), page); 00146 _desktopCB->setEnabled(true); 00147 lay1->addWidget(_desktopCB); 00148 00149 QGroupBox* groupBox; 00150 { 00151 int lines = (int)(desktopCount/2); 00152 if (lines*2 != desktopCount) lines++; 00153 groupBox = new QButtonGroup( lines, QGroupBox::Horizontal, 00154 i18n("In Desktop"), page, "_desktopsGB"); 00155 } 00156 lay1->addWidget(groupBox); 00157 00158 QHBoxLayout *lay6 = new QHBoxLayout(); 00159 00160 lay1->addLayout(lay6); 00161 for (int i=0; i<desktopCount; i++) { 00162 _deskBox.push_back(new QCheckBox(groupBox,QString::number(i).latin1())); 00163 _deskBox[i]->setText(QString::number(i+1)); 00164 _deskBox[i]->setChecked(false); 00165 00166 lay6->addWidget(_deskBox[i]); 00167 } 00168 // check specified Desktop Check Boxes 00169 bool enableDesktops = false; 00170 00171 if ( (desktopList != 0) && (desktopList->size() > 0) ) 00172 { 00173 DesktopList::iterator it = desktopList->begin(); 00174 while (it != desktopList->end()) 00175 { 00176 _deskBox[*it]->setChecked(true); 00177 it++; 00178 } 00179 enableDesktops = true; 00180 } 00181 // if some desktops were specified, then enable the parent box 00182 _desktopCB->setChecked(enableDesktops); 00183 00184 for (int i=0; i<desktopCount; i++) 00185 _deskBox[i]->setEnabled(enableDesktops); 00186 00187 connect(_desktopCB, SIGNAL(clicked()), this, SLOT(slotAutoTrackingPressed())); 00188 00189 KIconLoader loader; 00190 00191 QPixmap whatsThisIM = loader.loadIcon( QString::fromLatin1("contexthelp"), 00192 KIcon::Toolbar); 00193 QPushButton* whatsThisBU = new QPushButton(page, "whatsThisLA"); 00194 whatsThisBU->setFocusPolicy(NoFocus); 00195 00196 connect(whatsThisBU, SIGNAL(clicked()), this, SLOT(enterWhatsThis())); 00197 whatsThisBU->setPixmap( whatsThisIM ); 00198 lay4->addWidget(whatsThisBU); 00199 00200 lay1->addStretch(1); 00201 00202 00203 if ( editDlg ) { 00204 // This is an edit dialog. 00205 _operator->setFocus(); 00206 } 00207 else { 00208 // This is an initial dialog 00209 _name->setFocus(); 00210 } 00211 00212 slotRelativePressed(); 00213 00214 // Whats this help. 00215 QWhatsThis::add( _name, 00216 i18n( "Enter the name of the task here. " 00217 "This name is for your eyes only.")); 00218 QWhatsThis::add( _absoluteRB, 00219 i18n( "If you select this radio button, you specify that " 00220 "you want to enter the time as absolute values. For " 00221 "example: the time for this task is 20 hours and 15 " 00222 "minutes.\n\n" 00223 "The time is specified for the cumulated time and " 00224 "the session time separately.")); 00225 QWhatsThis::add( _relativeRB, 00226 i18n( "If you select this radio button, you specify that " 00227 "you want to add or subtract time for the task. For " 00228 "example: I've worked 2 hours and 20 minutes more on " 00229 "this task (without having the timer running.)\n\n" 00230 "This time will be added or subtracted for both the " 00231 "session time and the cumulated time.")); 00232 QWhatsThis::add( _timeTW, 00233 i18n( "This is the overall time this task has been " 00234 "running.")); 00235 QWhatsThis::add( _sessionTW, 00236 i18n( "This is the time the task has been running this " 00237 "session.")); 00238 QWhatsThis::add( _diffTW, i18n( "Specify how much time to add or subtract " 00239 "to the overall and session time")); 00240 } 00241 00242 int EditTaskDialog::getDesktopCount() 00243 { 00244 KWinModule k(0, KWinModule::INFO_DESKTOP); 00245 return k.numberOfDesktops(); 00246 } 00247 00248 void EditTaskDialog::enterWhatsThis() 00249 { 00250 QWhatsThis::enterWhatsThisMode (); 00251 } 00252 00253 00254 void EditTaskDialog::slotAbsolutePressed() 00255 { 00256 _relativeRB->setChecked( false ); 00257 _absoluteRB->setChecked( true ); 00258 00259 _operator->setEnabled( false ); 00260 _diffTW->setEnabled( false ); 00261 00262 _timeLA->setEnabled( true ); 00263 _sessionLA->setEnabled( true ); 00264 _timeTW->setEnabled( true ); 00265 _sessionTW->setEnabled( true ); 00266 } 00267 00268 void EditTaskDialog::slotRelativePressed() 00269 { 00270 _relativeRB->setChecked( true ); 00271 _absoluteRB->setChecked( false ); 00272 00273 _operator->setEnabled( true ); 00274 _diffTW->setEnabled( true ); 00275 00276 _timeLA->setEnabled( false ); 00277 _sessionLA->setEnabled( false ); 00278 _timeTW->setEnabled( false ); 00279 _sessionTW->setEnabled( false ); 00280 } 00281 00282 void EditTaskDialog::slotAutoTrackingPressed() 00283 { 00284 bool checked = _desktopCB->isChecked(); 00285 for (unsigned int i=0; i<_deskBox.size(); i++) 00286 _deskBox[i]->setEnabled(checked); 00287 00288 if (!checked) // uncheck all desktop boxes 00289 for (int i=0; i<desktopCount; i++) 00290 _deskBox[i]->setChecked(false); 00291 } 00292 00293 void EditTaskDialog::setTask( const QString &name, long time, long session ) 00294 { 00295 _name->setText( name ); 00296 00297 _timeTW->setTime( time / 60, time % 60 ); 00298 _sessionTW->setTime( session / 60, session % 60 ); 00299 origTime = time; 00300 origSession = session; 00301 } 00302 00303 00304 QString EditTaskDialog::taskName() const 00305 { 00306 return( _name->text() ); 00307 } 00308 00309 00310 void EditTaskDialog::status(long *time, long *timeDiff, long *session, 00311 long *sessionDiff, DesktopList *desktopList) const 00312 { 00313 if ( _absoluteRB->isChecked() ) { 00314 *time = _timeTW->time(); 00315 *session = _sessionTW->time(); 00316 } 00317 else { 00318 int diff = _diffTW->time(); 00319 if ( _operator->currentItem() == 1) { 00320 diff = -diff; 00321 } 00322 *time = origTime + diff; 00323 *session = origSession + diff; 00324 } 00325 00326 *timeDiff = *time - origTime; 00327 *sessionDiff = *session - origSession; 00328 00329 for (unsigned int i=0; i<_deskBox.size(); i++) { 00330 if (_deskBox[i]->isChecked()) 00331 desktopList->push_back(i); 00332 } 00333 } 00334 00335 #include "edittaskdialog.moc"
KDE Logo
This file is part of the documentation for karm Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:05 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003