diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-03 02:15:56 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-03 02:15:56 +0000 |
commit | 50b48aec6ddd451a6d1709c0942477b503457663 (patch) | |
tree | a9ece53ec06fd0a2819de7a2a6de997193566626 /src/k3btimeoutwidget.cpp | |
download | k3b-50b48aec6ddd451a6d1709c0942477b503457663.tar.gz k3b-50b48aec6ddd451a6d1709c0942477b503457663.zip |
Added abandoned KDE3 version of K3B
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/k3b@1084400 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/k3btimeoutwidget.cpp')
-rw-r--r-- | src/k3btimeoutwidget.cpp | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/src/k3btimeoutwidget.cpp b/src/k3btimeoutwidget.cpp new file mode 100644 index 0000000..156963f --- /dev/null +++ b/src/k3btimeoutwidget.cpp @@ -0,0 +1,149 @@ +/* + * + * $Id: sourceheader 511311 2006-02-19 14:51:05Z trueg $ + * Copyright (C) 2006 Sebastian Trueg <[email protected]> + * + * This file is part of the K3b project. + * Copyright (C) 1998-2007 Sebastian Trueg <[email protected]> + * + * 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 <qpainter.h> +#include <qtimer.h> +#include <qbitmap.h> + + +class K3bTimeoutWidget::Private +{ +public: + int timeout; + int margin; + + QTimer timer; + int currentTime; +}; + + +K3bTimeoutWidget::K3bTimeoutWidget( QWidget* parent ) + : QWidget( parent ) +{ + d = new Private; + d->timeout = 10000; + d->margin = 4; + connect( &d->timer, SIGNAL(timeout()), this, 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(); + } +} + + +QSize K3bTimeoutWidget::sizeHint() const +{ + return minimumSizeHint(); +} + + +QSize K3bTimeoutWidget::minimumSizeHint() const +{ + int fw = fontMetrics().width( QString::number( d->timeout/1000 ) ); + int fh = fontMetrics().height(); + + int diam = QMAX( fw, fh ) + 2*d->margin; + + return QSize( diam, diam ); +} + + +void K3bTimeoutWidget::setTimeout( int msecs ) +{ + d->timeout = msecs; +} + + +void K3bTimeoutWidget::startTimer() +{ + d->timer.start( 100 ); +} + + +void K3bTimeoutWidget::paintEvent( QPaintEvent* ) +{ + if( d->timer.isActive() ) { + QPainter p(this); + + if( K3bTheme* theme = k3bappcore->themeManager()->currentTheme() ) { + p.setBrush( theme->backgroundColor() ); + p.setPen( theme->backgroundColor() ); + } + + QRect 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( Qt::black ); + p.drawText( rect(), Qt::AlignCenter, QString::number( (d->timeout - d->currentTime + 500)/1000 ) ); + } +} + + +void K3bTimeoutWidget::resizeEvent( QResizeEvent* e ) +{ + QWidget::resizeEvent( e ); +} + + +#include "k3btimeoutwidget.moc" |