2 This file is part of Faster Application Manager.
4 Faster Application Manager is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 Faster Application Manager is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with Faster Application Manager. If not, see <http://www.gnu.org/licenses/>.
17 (C) Heikki Holstila 2010
23 dimmer::dimmer(QWidget *parent) :
28 iLayout = new QVBoxLayout(this);
29 iLabel = new QLabel(this);
30 iLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
31 iLabel->setAlignment(Qt::AlignCenter);
32 iLayout->addWidget(iLabel);
36 iAnimY = this->rect().height()-this->rect().height()/4;
41 iTimer = new QTimer(this);
42 connect(iTimer,SIGNAL(timeout()),this,SLOT(timerEvent()));
44 connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(orientationChanged()));
49 void dimmer::paintEvent(QPaintEvent *)
51 QPainter painter(this);
55 painter.setBrush(dim);
56 painter.drawRect(rect());
58 painter.setBrush( QApplication::palette().color(QPalette::Highlight) );
63 if( iProgress == -1 ) {
64 painter.drawEllipse(QPoint(rect().left()+(rect().width()/2-(animMax*step)/2)+iAnim*step,
76 if( iProgress >= 0 ) {
80 painter.setBrush( QApplication::palette().color(QPalette::Window) );
81 painter.setPen( dim );
82 painter.drawRect(rect().left()+30, rect().bottom()-30, rect().right()-rect().left()-60, 10 );
83 painter.setBrush( QApplication::palette().color(QPalette::Highlight) );
84 painter.setPen( QApplication::palette().color(QPalette::Highlight) );
85 int pw = ( rect().right()-rect().left()-60 ) * iProgress / 100;
86 painter.drawRect(rect().left()+30, rect().bottom()-30, pw, 10 );
88 if( iDownloadSpeed >= 0 ) {
89 painter.setBrush( QApplication::palette().color(QPalette::BrightText) );
90 painter.setPen( QApplication::palette().color(QPalette::BrightText) );
91 QRect textrect(rect().left(),rect().bottom()-70,rect().width(),30);
92 painter.drawText(textrect,QString("%1 kB/s").arg(iDownloadSpeed),Qt::AlignHCenter|Qt::AlignVCenter);
97 void dimmer::timerEvent()
100 repaint(0,iAnimY-10,rect().width(),22);
104 void dimmer::resizeEvent(QResizeEvent *)
106 this->resize(iParent->size());
107 iLayout->setGeometry(iParent->rect());
108 iLayout->setSizeConstraint(QLayout::SetMaximumSize);
109 iAnimY = this->rect().height()-this->rect().height()/4;
112 void dimmer::orientationChanged()
117 void dimmer::dim(QString title, QString message)
119 QString colorname = QApplication::palette().color(QPalette::BrightText).name();
122 iLabel->setText("<font color=\"" + colorname + "\"><b><u>" + iTitle + "</u></b><br><br>" + message + "</font>");
132 void dimmer::updateText(QString message)
134 QString colorname = QApplication::palette().color(QPalette::BrightText).name();
135 iLabel->setText("<font color=\"" + colorname + "\"><b><u>" + iTitle + "</u></b><br><br>" + message + "</font>");
138 void dimmer::setProgress(int p_)
143 repaint(0,rect().bottom()-30,rect().width(),20);
146 void dimmer::setDownloadSpeed(int kbps_)
148 iDownloadSpeed = kbps_;
149 repaint(QRect(rect().left(),rect().bottom()-70,rect().width(),30));