• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tderandr
 

tderandr

  • tderandr
ktimerdialog.cpp
1 /*
2  * This file is part of the KDE Libraries
3  * Copyright (C) 2002 Hamish Rodda <rodda@kde.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  *
20  */
21 
22 #include <tqhbox.h>
23 #include <tqlayout.h>
24 #include <tqvbox.h>
25 #include <tqtimer.h>
26 #include <tqprogressbar.h>
27 #include <tqlabel.h>
28 
29 #include <twin.h>
30 #include <kiconloader.h>
31 
32 #include <tdelocale.h>
33 #include <kdebug.h>
34 
35 #include "ktimerdialog.h"
36 #include "ktimerdialog.moc"
37 
38 KTimerDialog::KTimerDialog( int msec, TimerStyle style, TQWidget *parent,
39  const char *name, bool modal,
40  const TQString &caption,
41  int buttonMask, ButtonCode defaultButton,
42  bool separator,
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 )
48 {
49  totalTimer = new TQTimer( this );
50  updateTimer = new TQTimer( this );
51  msecTotal = msecRemaining = msec;
52  updateInterval = 1000;
53  tStyle = style;
54  KWin::setIcons( winId(), DesktopIcon("randr"), SmallIcon("randr") );
55  // default to cancelling the dialog on timeout
56  if ( buttonMask & Cancel )
57  buttonOnTimeout = Cancel;
58 
59  connect( totalTimer, TQ_SIGNAL( timeout() ), TQ_SLOT( slotInternalTimeout() ) );
60  connect( updateTimer, TQ_SIGNAL( timeout() ), TQ_SLOT( slotUpdateTime() ) );
61 
62  // create the widgets
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 );
69 
70  KDialogBase::setMainWidget( mainWidget );
71 
72  slotUpdateTime( false );
73 }
74 
75 KTimerDialog::~KTimerDialog()
76 {
77 }
78 
79 void KTimerDialog::show()
80 {
81  KDialogBase::show();
82  totalTimer->start( msecTotal, true );
83  updateTimer->start( updateInterval, false );
84 }
85 
86 int KTimerDialog::exec()
87 {
88  totalTimer->start( msecTotal, true );
89  updateTimer->start( updateInterval, false );
90  return KDialogBase::exec();
91 }
92 
93 void KTimerDialog::setMainWidget( TQWidget *widget )
94 {
95  // yuck, here goes.
96  TQVBox *newWidget = new TQVBox( this );
97 
98  if ( widget->parentWidget() != mainWidget ) {
99  widget->reparent( newWidget, 0, TQPoint(0,0) );
100  } else {
101  newWidget->insertChild( widget );
102  }
103 
104  timerWidget->reparent( newWidget, 0, TQPoint(0, 0) );
105 
106  delete mainWidget;
107  mainWidget = newWidget;
108  KDialogBase::setMainWidget( mainWidget );
109 }
110 
111 void KTimerDialog::setRefreshInterval( int msec )
112 {
113  updateInterval = msec;
114  if ( updateTimer->isActive() )
115  updateTimer->changeInterval( updateInterval );
116 }
117 
118 int KTimerDialog::timeoutButton() const
119 {
120  return buttonOnTimeout;
121 }
122 
123 void KTimerDialog::setTimeoutButton( const ButtonCode newButton )
124 {
125  buttonOnTimeout = newButton;
126 }
127 
128 int KTimerDialog::timerStyle() const
129 {
130  return tStyle;
131 }
132 
133 void KTimerDialog::setTimerStyle( const TimerStyle newStyle )
134 {
135  tStyle = newStyle;
136 }
137 
138 void KTimerDialog::slotUpdateTime( bool update )
139 {
140  if ( update )
141  switch ( tStyle ) {
142  case CountDown:
143  msecRemaining -= updateInterval;
144  break;
145  case CountUp:
146  msecRemaining += updateInterval;
147  break;
148  case Manual:
149  break;
150  }
151 
152  timerProgress->setProgress( msecRemaining );
153 
154  timerLabel->setText( i18n("1 second remaining:","%n seconds remaining:",msecRemaining/1000) );
155 }
156 
157 void KTimerDialog::slotInternalTimeout()
158 {
159  emit timerTimeout();
160  switch ( buttonOnTimeout ) {
161  case Help:
162  slotHelp();
163  break;
164  case Default:
165  slotDefault();
166  break;
167  case Ok:
168  slotOk();
169  break;
170  case Apply:
171  applyPressed();
172  break;
173  case Try:
174  slotTry();
175  break;
176  case Cancel:
177  slotCancel();
178  break;
179  case Close:
180  slotClose();
181  break;
182  /*case User1:
183  slotUser1();
184  break;
185  case User2:
186  slotUser2();
187  break;*/
188  case User3:
189  slotUser3();
190  break;
191  case No:
192  slotNo();
193  break;
194  case Yes:
195  slotCancel();
196  break;
197  case Details:
198  slotDetails();
199  break;
200  case Filler:
201  case Stretch:
202  kdDebug() << "Cannot execute button code " << buttonOnTimeout << endl;
203  break;
204  }
205 }
KTimerDialog::~KTimerDialog
~KTimerDialog()
Destructor.
Definition: ktimerdialog.cpp:75
KTimerDialog::exec
int exec()
Execute the dialog modally - see.
Definition: ktimerdialog.cpp:86
KTimerDialog::setTimeoutButton
void setTimeoutButton(ButtonCode newButton)
Sets the ButtonCode to determine which button will be activated once the timer times out.
Definition: ktimerdialog.cpp:123
KTimerDialog::TimerStyle
TimerStyle
Definition: ktimerdialog.h:58
KTimerDialog::KTimerDialog
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() .
Definition: ktimerdialog.cpp:38
KTimerDialog::show
virtual void show()
Execute the dialog modelessly - see.
Definition: ktimerdialog.cpp:79
KTimerDialog::setMainWidget
void setMainWidget(TQWidget *widget)
Overridden function which is used to set the main widget of the dialog.
Definition: ktimerdialog.cpp:93
KTimerDialog::timerStyle
int timerStyle() const
Retrieves the current TimerStyle.
Definition: ktimerdialog.cpp:128
KTimerDialog::timerTimeout
void timerTimeout()
Signal which is emitted once the timer has timed out.
KTimerDialog::setRefreshInterval
void setRefreshInterval(int msec)
Set the refresh interval for the timer progress.
Definition: ktimerdialog.cpp:111
KTimerDialog::setTimerStyle
void setTimerStyle(TimerStyle newStyle)
Sets the TimerStyle.
Definition: ktimerdialog.cpp:133
KTimerDialog::timeoutButton
int timeoutButton() const
Retrieves the ButtonCode which will be activated once the timer times out.
Definition: ktimerdialog.cpp:118
KWin::setIcons
static void setIcons(WId win, const TQPixmap &icon, const TQPixmap &miniIcon)
endl
kndbgstream & endl(kndbgstream &s)
kdDebug
kdbgstream kdDebug(int area=0)
tdelocale.h

tderandr

Skip menu "tderandr"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tderandr

Skip menu "tderandr"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tderandr by doxygen 1.9.1
This website is maintained by Timothy Pearson.