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);
33 iLayout->setSizeConstraint(QLayout::SetMaximumSize);
39 iAnimY = this->rect().height()-this->rect().height()/4;
45 iTimer = new QTimer(this);
46 connect(iTimer,SIGNAL(timeout()),this,SLOT(timerEvent()));
48 connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(orientationChanged()));
55 // iTimer and other widgets are automatically deleted by their parent
58 void dimmer::paintEvent(QPaintEvent *)
60 QPainter painter(this);
64 painter.setBrush(dim);
65 painter.drawRect(rect());
67 painter.setBrush( QApplication::palette().color(QPalette::Highlight) );
72 if( iProgress == -1 ) {
73 painter.drawEllipse(QPoint(rect().left()+(rect().width()/2-(animMax*step)/2)+iAnim*step,
85 if( iProgress >= 0 ) {
89 painter.setBrush( QApplication::palette().color(QPalette::Window) );
90 painter.setPen( dim );
91 painter.drawRect(rect().left()+30, rect().bottom()-30, rect().right()-rect().left()-60, 10 );
92 painter.setBrush( QApplication::palette().color(QPalette::Highlight) );
93 painter.setPen( QApplication::palette().color(QPalette::Highlight) );
94 int pw = ( rect().right()-rect().left()-60 ) * iProgress / 100;
95 painter.drawRect(rect().left()+30, rect().bottom()-30, pw, 10 );
97 if( iDownloadSpeed >= 0 ) {
98 painter.setBrush( QApplication::palette().color(QPalette::BrightText) );
99 painter.setPen( QApplication::palette().color(QPalette::BrightText) );
100 QRect textrect(rect().left(),rect().bottom()-70,rect().width(),30);
101 painter.drawText(textrect,QString("%1 kB/s").arg(iDownloadSpeed),Qt::AlignHCenter|Qt::AlignVCenter);
106 void dimmer::timerEvent()
109 repaint(0,iAnimY-10,rect().width(),22);
113 void dimmer::resizeEvent(QResizeEvent* event)
115 iAnimY = this->rect().height() - this->rect().height() / 4;
116 QWidget::resizeEvent(event);
119 void dimmer::orientationChanged()
121 //resize( iParent->size() );
124 void dimmer::dim(QString title, QString message)
126 QString colorname = QApplication::palette().color(QPalette::BrightText).name();
129 iLabel->setText("<font color=\"" + colorname + "\"><b><u>" + iTitle + "</u></b><br><br>" + message + "</font>");
137 resize(iParent->size());
142 void dimmer::updateText(QString message)
144 QString colorname = QApplication::palette().color(QPalette::BrightText).name();
145 iLabel->setText("<font color=\"" + colorname + "\"><b><u>" + iTitle + "</u></b><br><br>" + message + "</font>");
148 void dimmer::setProgress(int p_)
153 repaint(0,rect().bottom()-30,rect().width(),20);
156 void dimmer::setDownloadSpeed(int kbps_)
158 iDownloadSpeed = kbps_;
159 repaint(QRect(rect().left(),rect().bottom()-70,rect().width(),30));