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()));
51 // iTimer and other widgets are automatically deleted by their parent
54 void dimmer::paintEvent(QPaintEvent *)
56 QPainter painter(this);
60 painter.setBrush(dim);
61 painter.drawRect(rect());
63 painter.setBrush( QApplication::palette().color(QPalette::Highlight) );
68 if( iProgress == -1 ) {
69 painter.drawEllipse(QPoint(rect().left()+(rect().width()/2-(animMax*step)/2)+iAnim*step,
81 if( iProgress >= 0 ) {
85 painter.setBrush( QApplication::palette().color(QPalette::Window) );
86 painter.setPen( dim );
87 painter.drawRect(rect().left()+30, rect().bottom()-30, rect().right()-rect().left()-60, 10 );
88 painter.setBrush( QApplication::palette().color(QPalette::Highlight) );
89 painter.setPen( QApplication::palette().color(QPalette::Highlight) );
90 int pw = ( rect().right()-rect().left()-60 ) * iProgress / 100;
91 painter.drawRect(rect().left()+30, rect().bottom()-30, pw, 10 );
93 if( iDownloadSpeed >= 0 ) {
94 painter.setBrush( QApplication::palette().color(QPalette::BrightText) );
95 painter.setPen( QApplication::palette().color(QPalette::BrightText) );
96 QRect textrect(rect().left(),rect().bottom()-70,rect().width(),30);
97 painter.drawText(textrect,QString("%1 kB/s").arg(iDownloadSpeed),Qt::AlignHCenter|Qt::AlignVCenter);
102 void dimmer::timerEvent()
105 repaint(0,iAnimY-10,rect().width(),22);
109 void dimmer::resizeEvent(QResizeEvent *)
111 this->resize(iParent->size());
112 iLayout->setGeometry(iParent->rect());
113 iLayout->setSizeConstraint(QLayout::SetMaximumSize);
114 iAnimY = this->rect().height()-this->rect().height()/4;
117 void dimmer::orientationChanged()
122 void dimmer::dim(QString title, QString message)
124 QString colorname = QApplication::palette().color(QPalette::BrightText).name();
127 iLabel->setText("<font color=\"" + colorname + "\"><b><u>" + iTitle + "</u></b><br><br>" + message + "</font>");
137 void dimmer::updateText(QString message)
139 QString colorname = QApplication::palette().color(QPalette::BrightText).name();
140 iLabel->setText("<font color=\"" + colorname + "\"><b><u>" + iTitle + "</u></b><br><br>" + message + "</font>");
143 void dimmer::setProgress(int p_)
148 repaint(0,rect().bottom()-30,rect().width(),20);
151 void dimmer::setDownloadSpeed(int kbps_)
153 iDownloadSpeed = kbps_;
154 repaint(QRect(rect().left(),rect().bottom()-70,rect().width(),30));