1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
/*
*
* $Id: sourceheader 511311 2006-02-19 14:51:05Z trueg $
* Copyright (C) 2006 Sebastian Trueg <trueg@k3b.org>
*
* This file is part of the K3b project.
* Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* See the file "COPYING" for the exact licensing terms.
*/
#include "k3btimeoutwidget.h"
#include "k3bthememanager.h"
#include "k3bapplication.h"
#include <kiconloader.h>
#include <tqpainter.h>
#include <tqtimer.h>
#include <tqbitmap.h>
class K3bTimeoutWidget::Private
{
public:
int timeout;
int margin;
TQTimer timer;
int currentTime;
};
K3bTimeoutWidget::K3bTimeoutWidget( TQWidget* parent )
: TQWidget( parent )
{
d = new Private;
d->timeout = 10000;
d->margin = 4;
connect( &d->timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(timeStep()) );
}
K3bTimeoutWidget::~K3bTimeoutWidget()
{
delete d;
}
void K3bTimeoutWidget::start()
{
d->currentTime = 0;
startTimer();
}
void K3bTimeoutWidget::stop()
{
d->timer.stop();
d->currentTime = 0;
}
void K3bTimeoutWidget::pause()
{
d->timer.stop();
}
void K3bTimeoutWidget::resume()
{
startTimer();
}
void K3bTimeoutWidget::timeStep()
{
d->currentTime += 100;
update();
if( d->currentTime >= d->timeout ) {
stop();
emit timeout();
}
}
TQSize K3bTimeoutWidget::sizeHint() const
{
return minimumSizeHint();
}
TQSize K3bTimeoutWidget::minimumSizeHint() const
{
int fw = fontMetrics().width( TQString::number( d->timeout/1000 ) );
int fh = fontMetrics().height();
int diam = TQMAX( fw, fh ) + 2*d->margin;
return TQSize( diam, diam );
}
void K3bTimeoutWidget::setTimeout( int msecs )
{
d->timeout = msecs;
}
void K3bTimeoutWidget::startTimer()
{
d->timer.start( 100 );
}
void K3bTimeoutWidget::paintEvent( TQPaintEvent* )
{
if( d->timer.isActive() ) {
TQPainter p(this);
if( K3bTheme* theme = k3bappcore->themeManager()->currentTheme() ) {
p.setBrush( theme->backgroundColor() );
p.setPen( theme->backgroundColor() );
}
TQRect r;
r.setSize( minimumSizeHint() );
r.moveCenter( rect().center() );
p.drawArc( r, 0, 360*16 );
p.drawPie( r, 90*16, 360*16*d->currentTime/d->timeout );
p.setPen( TQt::black );
p.drawText( rect(), TQt::AlignCenter, TQString::number( (d->timeout - d->currentTime + 500)/1000 ) );
}
}
void K3bTimeoutWidget::resizeEvent( TQResizeEvent* e )
{
TQWidget::resizeEvent( e );
}
#include "k3btimeoutwidget.moc"
|