23 #include <tqbuttongroup.h>
24 #include <tqcombobox.h>
25 #include <tqgroupbox.h>
29 #include <tqlineedit.h>
30 #include <tqradiobutton.h>
31 #include <tqsizepolicy.h>
34 #include <tqwhatsthis.h>
36 #include <tdelocale.h>
37 #include <twinmodule.h>
39 #include "edittaskdialog.h"
40 #include "ktimewidget.h"
43 EditTaskDialog::EditTaskDialog( TQString caption,
bool editDlg,
44 DesktopList* desktopList)
45 : KDialogBase(0,
"EditTaskDialog", true, caption, Ok|Cancel, Ok, true ),
46 origTime( 0 ), origSession( 0 )
48 TQWidget *page =
new TQWidget(
this );
50 KWinModule twinmodule(0, KWinModule::INFO_DESKTOP);
52 TQVBoxLayout *lay1 =
new TQVBoxLayout(page);
54 TQHBoxLayout *lay2 =
new TQHBoxLayout();
55 lay1->addLayout(lay2);
58 TQLabel *label =
new TQLabel( i18n(
"Task &name:"), page,
"name" );
59 lay2->addWidget( label );
63 _name =
new TQLineEdit( page,
"lineedit" );
65 _name->setMinimumWidth(fontMetrics().maxWidth()*15);
66 lay2->addWidget( _name );
67 label->setBuddy( _name );
71 lay1->addSpacing(10);lay1->addStretch(1);
72 _absoluteRB =
new TQRadioButton( i18n(
"Edit &absolute" ), page,
74 lay1->addWidget( _absoluteRB );
75 connect( _absoluteRB, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( slotAbsolutePressed() ) );
79 TQHBoxLayout *lay5 =
new TQHBoxLayout();
80 lay1->addLayout(lay5);
82 TQGridLayout *lay3 =
new TQGridLayout( 2, 2, -1,
"lay3" );
83 lay5->addLayout(lay3);
85 _sessionLA =
new TQLabel( i18n(
"&Session time: "), page,
"session time" );
88 _timeLA =
new TQLabel( i18n(
"&Time:"), page,
"time" );
89 lay3->addWidget( _timeLA, 0, 0 );
90 _timeLA->setSizePolicy( TQSizePolicy( (TQSizePolicy::SizeType)1,
91 (TQSizePolicy::SizeType)0,
94 _timeLA->sizePolicy().hasHeightForWidth()) );
100 _timeLA->setMinimumWidth( fontMetrics().width( _sessionLA->text() ) );
103 lay3->addWidget( _timeTW, 0, 1 );
104 _timeLA->setBuddy( _timeTW );
108 lay3->addWidget( _sessionLA, 1, 0 );
111 lay3->addWidget( _sessionTW, 1, 1 );
112 _sessionLA->setBuddy( _sessionTW );
113 _sessionLA->setSizePolicy( TQSizePolicy( (TQSizePolicy::SizeType)1,
114 (TQSizePolicy::SizeType)0,
117 _sessionLA->sizePolicy().hasHeightForWidth()) );
118 _sessionLA->setMinimumWidth( fontMetrics().width( _sessionLA->text() ) );
122 lay1->addSpacing(10);
124 _relativeRB =
new TQRadioButton( i18n(
"Edit &relative (apply to both time and"
125 " session time)" ), page,
"_relativeRB" );
126 lay1->addWidget( _relativeRB );
127 connect( _relativeRB, TQ_SIGNAL( clicked() ),
this, TQ_SLOT(slotRelativePressed()) );
130 TQHBoxLayout *lay4 =
new TQHBoxLayout();
131 lay1->addLayout( lay4 );
132 lay4->addSpacing(20);
134 _operator =
new TQComboBox(page);
135 _operator->insertItem( TQString::fromLatin1(
"+" ) );
136 _operator->insertItem( TQString::fromLatin1(
"-" ) );
137 _operator->setSizePolicy( TQSizePolicy( (TQSizePolicy::SizeType)1,
138 (TQSizePolicy::SizeType)0,
141 _operator->sizePolicy().hasHeightForWidth()) );
143 _operator->setMinimumWidth( fontMetrics().width( _sessionLA->text() ) );
144 lay4->addWidget( _operator );
147 lay4->addWidget( _diffTW );
149 desktopCount = twinmodule.numberOfDesktops();
154 if ( (desktopList != 0) && (desktopList->size() > 0) )
156 DesktopList::iterator rit = desktopList->begin();
157 while (*rit < desktopCount && rit!=desktopList->end())
161 desktopList->erase(rit, desktopList->end());
165 lay1->addSpacing(10);
168 _desktopCB =
new TQCheckBox(i18n(
"A&uto tracking"), page);
169 _desktopCB->setEnabled(
true);
170 lay1->addWidget(_desktopCB);
172 TQGroupBox* groupBox;
174 int lines = (int)(desktopCount/2);
175 if (lines*2 != desktopCount) lines++;
176 groupBox =
new TQButtonGroup( lines, TQt::Horizontal,
177 i18n(
"In Desktop"), page,
"_desktopsGB");
179 lay1->addWidget(groupBox);
181 TQHBoxLayout *lay6 =
new TQHBoxLayout();
183 lay1->addLayout(lay6);
184 for (
int i=0; i<desktopCount; i++) {
185 _deskBox.push_back(
new TQCheckBox(groupBox,TQString::number(i).latin1()));
186 _deskBox[i]->setText(twinmodule.desktopName(i+1));
187 _deskBox[i]->setChecked(
false);
189 lay6->addWidget(_deskBox[i]);
192 bool enableDesktops =
false;
194 if ( (desktopList != 0) && (desktopList->size() > 0) )
196 DesktopList::iterator it = desktopList->begin();
197 while (it != desktopList->end())
199 _deskBox[*it]->setChecked(
true);
202 enableDesktops =
true;
205 _desktopCB->setChecked(enableDesktops);
207 for (
int i=0; i<desktopCount; i++)
208 _deskBox[i]->setEnabled(enableDesktops);
210 connect(_desktopCB, TQ_SIGNAL(clicked()),
this, TQ_SLOT(slotAutoTrackingPressed()));
217 _operator->setFocus();
224 slotRelativePressed();
227 TQWhatsThis::add( _name,
228 i18n(
"Enter the name of the task here. "
229 "This name is for your eyes only."));
230 TQWhatsThis::add( _absoluteRB,
231 i18n(
"Use this option to set the time spent on this task "
232 "to an absolute value.\n\nFor example, if you have "
233 "worked exactly four hours on this task during the current "
234 "session, you would set the Session time to 4 hr." ) );
235 TQWhatsThis::add( _relativeRB,
236 i18n(
"Use this option to change the time spent on this task "
237 "relative to its current value.\n\nFor example, if you worked "
238 "on this task for one hour without the timer running, you "
239 "would add 1 hr." ) );
240 TQWhatsThis::add( _timeTW,
241 i18n(
"This is the time the task has been "
242 "running since all times were reset."));
243 TQWhatsThis::add( _sessionTW,
244 i18n(
"This is the time the task has been running this "
246 TQWhatsThis::add( _diffTW, i18n(
"Specify how much time to add or subtract "
247 "to the overall and session time"));
249 TQWhatsThis::add( _desktopCB,
250 i18n(
"Use this option to automatically start the timer "
251 "on this task when you switch to the specified desktop(s)." ) );
252 TQWhatsThis::add( groupBox,
253 i18n(
"Select the desktop(s) that will automatically start the "
254 "timer on this task." ) );
258 void EditTaskDialog::slotAbsolutePressed()
260 _relativeRB->setChecked(
false );
261 _absoluteRB->setChecked(
true );
263 _operator->setEnabled(
false );
264 _diffTW->setEnabled(
false );
266 _timeLA->setEnabled(
true );
267 _sessionLA->setEnabled(
true );
268 _timeTW->setEnabled(
true );
269 _sessionTW->setEnabled(
true );
272 void EditTaskDialog::slotRelativePressed()
274 _relativeRB->setChecked(
true );
275 _absoluteRB->setChecked(
false );
277 _operator->setEnabled(
true );
278 _diffTW->setEnabled(
true );
280 _timeLA->setEnabled(
false );
281 _sessionLA->setEnabled(
false );
282 _timeTW->setEnabled(
false );
283 _sessionTW->setEnabled(
false );
286 void EditTaskDialog::slotAutoTrackingPressed()
288 bool checked = _desktopCB->isChecked();
289 for (
unsigned int i=0; i<_deskBox.size(); i++)
290 _deskBox[i]->setEnabled(checked);
293 for (
int i=0; i<desktopCount; i++)
294 _deskBox[i]->setChecked(
false);
297 void EditTaskDialog::setTask(
const TQString &name,
long time,
long session )
299 _name->setText( name );
301 _timeTW->setTime( time );
302 _sessionTW->setTime( session );
304 origSession = session;
308 TQString EditTaskDialog::taskName()
const
310 return( _name->text() );
314 void EditTaskDialog::status(
long *time,
long *timeDiff,
long *session,
315 long *sessionDiff, DesktopList *desktopList)
const
317 if ( _absoluteRB->isChecked() ) {
318 *time = _timeTW->time();
319 *session = _sessionTW->time();
322 int diff = _diffTW->time();
323 if ( _operator->currentItem() == 1) {
326 *time = origTime + diff;
327 *session = origSession + diff;
330 *timeDiff = *time - origTime;
331 *sessionDiff = *session - origSession;
333 for (
unsigned int i=0; i<_deskBox.size(); i++) {
334 if (_deskBox[i]->isChecked())
335 desktopList->push_back(i);
339 #include "edittaskdialog.moc"