26 #include <tqprogressbar.h>
30 #include <kiconloader.h>
35 #include "ktimerdialog.h"
36 #include "ktimerdialog.moc"
39 const char *name,
bool modal,
40 const TQString &caption,
41 int buttonMask, ButtonCode defaultButton,
43 const KGuiItem &user1,
44 const KGuiItem &user2,
45 const KGuiItem &user3 )
46 : KDialogBase(parent, name, modal, caption, buttonMask, defaultButton,
47 separator, user1, user2, user3 )
49 totalTimer =
new TQTimer(
this );
50 updateTimer =
new TQTimer(
this );
51 msecTotal = msecRemaining = msec;
52 updateInterval = 1000;
54 KWin::setIcons( winId(), DesktopIcon(
"randr"), SmallIcon(
"randr") );
56 if ( buttonMask & Cancel )
57 buttonOnTimeout = Cancel;
59 connect( totalTimer, TQT_SIGNAL( timeout() ), TQT_SLOT( slotInternalTimeout() ) );
60 connect( updateTimer, TQT_SIGNAL( timeout() ), TQT_SLOT( slotUpdateTime() ) );
63 mainWidget =
new TQVBox(
this,
"mainWidget" );
64 timerWidget =
new TQHBox( mainWidget,
"timerWidget" );
65 timerLabel =
new TQLabel( timerWidget );
66 timerProgress =
new TQProgressBar( timerWidget );
67 timerProgress->setTotalSteps( msecTotal );
68 timerProgress->setPercentageVisible(
false );
70 KDialogBase::setMainWidget( mainWidget );
72 slotUpdateTime(
false );
82 totalTimer->start( msecTotal,
true );
83 updateTimer->start( updateInterval,
false );
88 totalTimer->start( msecTotal,
true );
89 updateTimer->start( updateInterval,
false );
90 return KDialogBase::exec();
96 TQVBox *newWidget =
new TQVBox(
this );
98 if ( widget->parentWidget() != mainWidget ) {
99 widget->reparent( newWidget, 0, TQPoint(0,0) );
101 newWidget->insertChild( TQT_TQOBJECT(widget) );
104 timerWidget->reparent( newWidget, 0, TQPoint(0, 0) );
107 mainWidget = newWidget;
108 KDialogBase::setMainWidget( mainWidget );
113 updateInterval = msec;
114 if ( updateTimer->isActive() )
115 updateTimer->changeInterval( updateInterval );
120 return buttonOnTimeout;
125 buttonOnTimeout = newButton;
138 void KTimerDialog::slotUpdateTime(
bool update )
143 msecRemaining -= updateInterval;
146 msecRemaining += updateInterval;
152 timerProgress->setProgress( msecRemaining );
154 timerLabel->setText( i18n(
"1 second remaining:",
"%n seconds remaining:",msecRemaining/1000) );
157 void KTimerDialog::slotInternalTimeout()
160 switch ( buttonOnTimeout ) {
202 kdDebug() <<
"Cannot execute button code " << buttonOnTimeout <<
endl;
int timerStyle() const
Retrieves the current TimerStyle.
void setTimerStyle(TimerStyle newStyle)
Sets the TimerStyle.
void setMainWidget(TQWidget *widget)
Overridden function which is used to set the main widget of the dialog.
kdbgstream kdDebug(int area=0)
void timerTimeout()
Signal which is emitted once the timer has timed out.
~KTimerDialog()
Destructor.
int exec()
Execute the dialog modally - see.
void setTimeoutButton(ButtonCode newButton)
Sets the ButtonCode to determine which button will be activated once the timer times out...
virtual void show()
Execute the dialog modelessly - see.
void setRefreshInterval(int msec)
Set the refresh interval for the timer progress.
int timeoutButton() const
Retrieves the ButtonCode which will be activated once the timer times out.
kndbgstream & endl(kndbgstream &s)
KTimerDialog(int msec, TimerStyle style=CountDown, TQWidget *parent=0, const char *name=0, bool modal=true, const TQString &caption=TQString::null, int buttonMask=Ok|Apply|Cancel, ButtonCode defaultButton=Ok, bool separator=false, const KGuiItem &user1=KGuiItem(), const KGuiItem &user2=KGuiItem(), const KGuiItem &user3=KGuiItem())
Constructor for the standard mode where you must specify the main widget with setMainWidget() ...
static void setIcons(WId win, const TQPixmap &icon, const TQPixmap &miniIcon)