You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
2.7 KiB
115 lines
2.7 KiB
#include <tqpushbutton.h> |
|
#include <tqlistbox.h> |
|
#include <tqlayout.h> |
|
#include <tqtimer.h> |
|
|
|
#include <tdeapplication.h> |
|
#include <tdemessagebox.h> |
|
#include <kiconloader.h> |
|
#include <ktimewidget.h> |
|
#include <tdelocale.h> |
|
|
|
#include "tdestopwatch.h" |
|
|
|
TDEStopWatch::TDEStopWatch() |
|
{ |
|
TDEIconLoader *il = kapp->iconLoader(); |
|
TQVBoxLayout *vlayout = new TQVBoxLayout(this); |
|
TQHBoxLayout *hlayout = new TQHBoxLayout(this); |
|
vlayout->addLayout(hlayout); |
|
|
|
time = new KTimeWidget(this); |
|
connect( time, SIGNAL(valueChanged(const TQTime&)), this, SLOT(slotSetTime(const TQTime&)) ); |
|
hlayout->addWidget(time); |
|
|
|
start = new TQPushButton(this, "start"); |
|
start->setPixmap(il->loadIcon("media-playback-start", TDEIcon::Toolbar)); |
|
start->setToggleButton(true); |
|
start->setFocus(); |
|
hlayout->addWidget(start); |
|
|
|
reset = new TQPushButton(this, "reset"); |
|
reset->setPixmap(il->loadIcon("reload", TDEIcon::Toolbar)); |
|
hlayout->addWidget(reset); |
|
|
|
connect( start, SIGNAL(clicked()), this, SLOT(slotStartStop()) ); |
|
connect( reset, SIGNAL(clicked()), this, SLOT(slotReset()) ); |
|
|
|
step = new TQPushButton(this, "step"); |
|
step->setPixmap(il->loadIcon("bookmark", TDEIcon::Toolbar)); |
|
hlayout->addWidget(step); |
|
|
|
stepl = new TQListBox(this, "steplist"); |
|
vlayout->addWidget(stepl); |
|
connect( step, SIGNAL(clicked()), this, SLOT(slotStep()) ); |
|
connect( stepl, SIGNAL(doubleClicked(TQListBoxItem*)), this, SLOT(slotSetFromStep(TQListBoxItem*)) ); |
|
|
|
TQTime timer; |
|
pulse = new TQTimer(this); |
|
connect( pulse, SIGNAL(timeout()), this, SLOT(slotTimeout()) ); |
|
|
|
setCaption( i18n("TDE Stopwatch") ); |
|
|
|
show(); |
|
} |
|
|
|
TDEStopWatch::~TDEStopWatch() |
|
{} |
|
|
|
void TDEStopWatch::slotStartStop() |
|
{ |
|
if( pulse->isActive() ) |
|
pulse->stop(); |
|
else |
|
pulse->start(1000); |
|
} |
|
|
|
void TDEStopWatch::slotReset() |
|
{ |
|
int result = KMessageBox::warningYesNo( |
|
this, |
|
i18n("Are you sure you want to reset the stopwatch and steps?"), |
|
i18n("Confirm Reset") |
|
); |
|
|
|
if( result != KMessageBox::Yes ) return; |
|
|
|
if( start->isOn() ) |
|
start->setOn(false); |
|
pulse->stop(); |
|
stepl->clear(); |
|
timer.setHMS(0, 0, 0); |
|
time->setTime(timer); |
|
} |
|
|
|
void TDEStopWatch::slotSetTime(const TQTime& t) |
|
{ |
|
timer = t; |
|
} |
|
|
|
void TDEStopWatch::slotSetFromStep(TQListBoxItem* step) |
|
{ |
|
int h, m, s; |
|
TQStringList step_time = TQStringList::split(":", step->text()); |
|
h = TQString(step_time[0]).toInt(); |
|
m = TQString(step_time[1]).toInt(); |
|
s = TQString(step_time[2]).toInt(); |
|
|
|
timer.setHMS(h, m, s); |
|
time->setTime(timer); |
|
} |
|
|
|
void TDEStopWatch::slotTimeout() |
|
{ |
|
timer = timer.addSecs(1); |
|
time->setTime(timer); |
|
} |
|
|
|
void TDEStopWatch::slotStep() |
|
{ |
|
TQString time_str = timer.toString("hh:mm:ss"); |
|
if( stepl->findItem(time_str) == 0 ) |
|
stepl->insertItem(time_str); |
|
} |
|
|
|
#include "tdestopwatch.moc"
|
|
|