mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 02:42:48 +00:00
kdeui: move private KTimerDialog members to private data pointer
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
e0d476372c
commit
437a488d1a
2 changed files with 63 additions and 61 deletions
|
@ -27,11 +27,29 @@
|
|||
#include <QTimer>
|
||||
#include <QProgressBar>
|
||||
|
||||
#include <kvbox.h>
|
||||
#include <khbox.h>
|
||||
#include <kwindowsystem.h>
|
||||
#include <kiconloader.h>
|
||||
#include <klocale.h>
|
||||
#include <kdebug.h>
|
||||
|
||||
class KTimerDialogPrivate
|
||||
{
|
||||
public:
|
||||
QTimer *totalTimer;
|
||||
QTimer *updateTimer;
|
||||
int msecRemaining, updateInterval, msecTotal;
|
||||
|
||||
KDialog::ButtonCode buttonOnTimeout;
|
||||
KTimerDialog::TimerStyle tStyle;
|
||||
|
||||
KHBox *timerWidget;
|
||||
QProgressBar *timerProgress;
|
||||
QLabel *timerLabel;
|
||||
KVBox *mainWidget;
|
||||
};
|
||||
|
||||
KTimerDialog::KTimerDialog(int msec, TimerStyle style, QWidget *parent,
|
||||
const QString &caption,
|
||||
int buttonMask, ButtonCode defaultButton,
|
||||
|
@ -39,7 +57,8 @@ KTimerDialog::KTimerDialog(int msec, TimerStyle style, QWidget *parent,
|
|||
const KGuiItem &user1,
|
||||
const KGuiItem &user2,
|
||||
const KGuiItem &user3)
|
||||
: KDialog(parent)
|
||||
: KDialog(parent),
|
||||
d(new KTimerDialogPrivate())
|
||||
{
|
||||
setCaption(caption);
|
||||
setButtons((ButtonCodes)buttonMask);
|
||||
|
@ -50,38 +69,39 @@ KTimerDialog::KTimerDialog(int msec, TimerStyle style, QWidget *parent,
|
|||
setButtonGuiItem(User2, user2);
|
||||
setButtonGuiItem(User3, user3);
|
||||
|
||||
totalTimer = new QTimer(this);
|
||||
totalTimer->setSingleShot(true);
|
||||
updateTimer = new QTimer(this);
|
||||
updateTimer->setSingleShot(false);
|
||||
msecTotal = msecRemaining = msec;
|
||||
updateInterval = 1000;
|
||||
tStyle = style;
|
||||
d->totalTimer = new QTimer(this);
|
||||
d->totalTimer->setSingleShot(true);
|
||||
d->updateTimer = new QTimer(this);
|
||||
d->updateTimer->setSingleShot(false);
|
||||
d->msecTotal = d->msecRemaining = msec;
|
||||
d->updateInterval = 1000;
|
||||
d->tStyle = style;
|
||||
KWindowSystem::setIcons(winId(), DesktopIcon("randr"), SmallIcon("randr"));
|
||||
// default to canceling the dialog on timeout
|
||||
if (buttonMask & Cancel) {
|
||||
buttonOnTimeout = Cancel;
|
||||
if (buttonMask & KDialog::Cancel) {
|
||||
d->buttonOnTimeout = KDialog::Cancel;
|
||||
}
|
||||
|
||||
connect(totalTimer, SIGNAL(timeout()), SLOT(slotInternalTimeout()));
|
||||
connect(updateTimer, SIGNAL(timeout()), SLOT(slotUpdateTime()));
|
||||
connect(d->totalTimer, SIGNAL(timeout()), SLOT(slotInternalTimeout()));
|
||||
connect(d->updateTimer, SIGNAL(timeout()), SLOT(slotUpdateTime()));
|
||||
|
||||
// create the widgets
|
||||
mainWidget = new KVBox(this);
|
||||
timerWidget = new KHBox(mainWidget);
|
||||
timerWidget->setSpacing(-1);
|
||||
timerLabel = new QLabel(timerWidget);
|
||||
timerProgress = new QProgressBar(timerWidget);
|
||||
timerProgress->setRange(0, msecTotal);
|
||||
timerProgress->setTextVisible(false);
|
||||
d->mainWidget = new KVBox(this);
|
||||
d->timerWidget = new KHBox(d->mainWidget);
|
||||
d->timerWidget->setSpacing(-1);
|
||||
d->timerLabel = new QLabel(d->timerWidget);
|
||||
d->timerProgress = new QProgressBar(d->timerWidget);
|
||||
d->timerProgress->setRange(0, d->msecTotal);
|
||||
d->timerProgress->setTextVisible(false);
|
||||
|
||||
KDialog::setMainWidget(mainWidget);
|
||||
KDialog::setMainWidget(d->mainWidget);
|
||||
|
||||
slotUpdateTime(false);
|
||||
}
|
||||
|
||||
KTimerDialog::~KTimerDialog()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
void KTimerDialog::setVisible(bool visible)
|
||||
|
@ -89,15 +109,15 @@ void KTimerDialog::setVisible(bool visible)
|
|||
KDialog::setVisible(visible);
|
||||
|
||||
if (visible) {
|
||||
totalTimer->start(msecTotal);
|
||||
updateTimer->start(updateInterval);
|
||||
d->totalTimer->start(d->msecTotal);
|
||||
d->updateTimer->start(d->updateInterval);
|
||||
}
|
||||
}
|
||||
|
||||
int KTimerDialog::exec()
|
||||
{
|
||||
totalTimer->start(msecTotal);
|
||||
updateTimer->start(updateInterval);
|
||||
d->totalTimer->start(d->msecTotal);
|
||||
d->updateTimer->start(d->updateInterval);
|
||||
return KDialog::exec();
|
||||
}
|
||||
|
||||
|
@ -107,67 +127,67 @@ void KTimerDialog::setMainWidget(QWidget *widget)
|
|||
KVBox *newWidget = new KVBox(this);
|
||||
newWidget->setSpacing(-1);
|
||||
|
||||
if (widget->parentWidget() != mainWidget) {
|
||||
if (widget->parentWidget() != d->mainWidget) {
|
||||
widget->setParent(newWidget);
|
||||
}
|
||||
timerWidget->setParent(newWidget);
|
||||
d->timerWidget->setParent(newWidget);
|
||||
|
||||
delete mainWidget;
|
||||
mainWidget = newWidget;
|
||||
KDialog::setMainWidget(mainWidget);
|
||||
delete d->mainWidget;
|
||||
d->mainWidget = newWidget;
|
||||
KDialog::setMainWidget(d->mainWidget);
|
||||
}
|
||||
|
||||
void KTimerDialog::setRefreshInterval(int msec)
|
||||
{
|
||||
updateInterval = msec;
|
||||
if (updateTimer->isActive()) {
|
||||
updateTimer->start(updateInterval);
|
||||
d->updateInterval = msec;
|
||||
if (d->updateTimer->isActive()) {
|
||||
d->updateTimer->start(d->updateInterval);
|
||||
}
|
||||
}
|
||||
|
||||
int KTimerDialog::timeoutButton() const
|
||||
{
|
||||
return buttonOnTimeout;
|
||||
return d->buttonOnTimeout;
|
||||
}
|
||||
|
||||
void KTimerDialog::setTimeoutButton(const ButtonCode newButton)
|
||||
{
|
||||
buttonOnTimeout = newButton;
|
||||
d->buttonOnTimeout = newButton;
|
||||
}
|
||||
|
||||
int KTimerDialog::timerStyle() const
|
||||
{
|
||||
return tStyle;
|
||||
return d->tStyle;
|
||||
}
|
||||
|
||||
void KTimerDialog::setTimerStyle(const TimerStyle newStyle)
|
||||
{
|
||||
tStyle = newStyle;
|
||||
d->tStyle = newStyle;
|
||||
}
|
||||
|
||||
void KTimerDialog::slotUpdateTime(bool update)
|
||||
{
|
||||
if (update)
|
||||
switch(tStyle) {
|
||||
switch(d->tStyle) {
|
||||
case CountDown:
|
||||
msecRemaining -= updateInterval;
|
||||
d->msecRemaining -= d->updateInterval;
|
||||
break;
|
||||
case CountUp:
|
||||
msecRemaining += updateInterval;
|
||||
d->msecRemaining += d->updateInterval;
|
||||
break;
|
||||
case Manual:
|
||||
break;
|
||||
}
|
||||
|
||||
timerProgress->setValue(msecRemaining);
|
||||
d->timerProgress->setValue(d->msecRemaining);
|
||||
|
||||
timerLabel->setText(i18np("1 second remaining:", "%1 seconds remaining:", msecRemaining / 1000));
|
||||
d->timerLabel->setText(i18np("1 second remaining:", "%1 seconds remaining:", d->msecRemaining / 1000));
|
||||
}
|
||||
|
||||
void KTimerDialog::slotInternalTimeout()
|
||||
{
|
||||
emit timerTimeout();
|
||||
slotButtonClicked(buttonOnTimeout);
|
||||
slotButtonClicked(d->buttonOnTimeout);
|
||||
}
|
||||
|
||||
#include "moc_ktimerdialog.cpp"
|
||||
|
|
|
@ -21,14 +21,7 @@
|
|||
#ifndef KTIMERDIALOG_H
|
||||
#define KTIMERDIALOG_H
|
||||
|
||||
#include <QLabel>
|
||||
#include <QTimer>
|
||||
#include <QProgressBar>
|
||||
#include <QLabel>
|
||||
|
||||
#include <kdialog.h>
|
||||
#include <kvbox.h>
|
||||
#include <khbox.h>
|
||||
|
||||
class KTimerDialogPrivate;
|
||||
|
||||
|
@ -150,18 +143,7 @@ private:
|
|||
*/
|
||||
void setupLayout();
|
||||
|
||||
QTimer *totalTimer;
|
||||
QTimer *updateTimer;
|
||||
int msecRemaining, updateInterval, msecTotal;
|
||||
|
||||
ButtonCode buttonOnTimeout;
|
||||
TimerStyle tStyle;
|
||||
|
||||
KHBox *timerWidget;
|
||||
QProgressBar *timerProgress;
|
||||
QLabel *timerLabel;
|
||||
KVBox *mainWidget;
|
||||
|
||||
Q_DISABLE_COPY(KTimerDialog);
|
||||
KTimerDialogPrivate *d;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue