1*bb02e0acSNicolas Bonnefon /*
2*bb02e0acSNicolas Bonnefon * Copyright (C) 2009, 2010 Nicolas Bonnefon and other contributors
3*bb02e0acSNicolas Bonnefon *
4*bb02e0acSNicolas Bonnefon * This file is part of glogg.
5*bb02e0acSNicolas Bonnefon *
6*bb02e0acSNicolas Bonnefon * glogg is free software: you can redistribute it and/or modify
7*bb02e0acSNicolas Bonnefon * it under the terms of the GNU General Public License as published by
8*bb02e0acSNicolas Bonnefon * the Free Software Foundation, either version 3 of the License, or
9*bb02e0acSNicolas Bonnefon * (at your option) any later version.
10*bb02e0acSNicolas Bonnefon *
11*bb02e0acSNicolas Bonnefon * glogg is distributed in the hope that it will be useful,
12*bb02e0acSNicolas Bonnefon * but WITHOUT ANY WARRANTY; without even the implied warranty of
13*bb02e0acSNicolas Bonnefon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14*bb02e0acSNicolas Bonnefon * GNU General Public License for more details.
15*bb02e0acSNicolas Bonnefon *
16*bb02e0acSNicolas Bonnefon * You should have received a copy of the GNU General Public License
17*bb02e0acSNicolas Bonnefon * along with glogg. If not, see <http://www.gnu.org/licenses/>.
18*bb02e0acSNicolas Bonnefon */
19*bb02e0acSNicolas Bonnefon
20*bb02e0acSNicolas Bonnefon #include "log.h"
21*bb02e0acSNicolas Bonnefon
22*bb02e0acSNicolas Bonnefon #include "infoline.h"
23*bb02e0acSNicolas Bonnefon
24*bb02e0acSNicolas Bonnefon #include <QPainter>
25*bb02e0acSNicolas Bonnefon
26*bb02e0acSNicolas Bonnefon // This file implements InfoLine. It is responsible for decorating the
27*bb02e0acSNicolas Bonnefon // widget and managing the completion gauge.
28*bb02e0acSNicolas Bonnefon
InfoLine()29*bb02e0acSNicolas Bonnefon InfoLine::InfoLine() :
30*bb02e0acSNicolas Bonnefon QLabel(), origPalette_( palette() ),
31*bb02e0acSNicolas Bonnefon backgroundColor_( origPalette_.color( QPalette::Button ) ),
32*bb02e0acSNicolas Bonnefon darkBackgroundColor_( origPalette_.color( QPalette::Dark ) )
33*bb02e0acSNicolas Bonnefon {
34*bb02e0acSNicolas Bonnefon setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
35*bb02e0acSNicolas Bonnefon }
36*bb02e0acSNicolas Bonnefon
displayGauge(int completion)37*bb02e0acSNicolas Bonnefon void InfoLine::displayGauge( int completion )
38*bb02e0acSNicolas Bonnefon {
39*bb02e0acSNicolas Bonnefon int changeoverX = width() * completion / 100;
40*bb02e0acSNicolas Bonnefon
41*bb02e0acSNicolas Bonnefon // Create a gradient for the progress bar
42*bb02e0acSNicolas Bonnefon QLinearGradient linearGrad( changeoverX - 1, 0, changeoverX + 1, 0 );
43*bb02e0acSNicolas Bonnefon linearGrad.setColorAt( 0, darkBackgroundColor_ );
44*bb02e0acSNicolas Bonnefon linearGrad.setColorAt( 1, backgroundColor_ );
45*bb02e0acSNicolas Bonnefon
46*bb02e0acSNicolas Bonnefon // Apply the gradient to the current palette (background)
47*bb02e0acSNicolas Bonnefon QPalette newPalette = origPalette_;
48*bb02e0acSNicolas Bonnefon newPalette.setBrush( backgroundRole(), QBrush( linearGrad ) );
49*bb02e0acSNicolas Bonnefon setPalette( newPalette );
50*bb02e0acSNicolas Bonnefon }
51*bb02e0acSNicolas Bonnefon
hideGauge()52*bb02e0acSNicolas Bonnefon void InfoLine::hideGauge()
53*bb02e0acSNicolas Bonnefon {
54*bb02e0acSNicolas Bonnefon setPalette( origPalette_ );
55*bb02e0acSNicolas Bonnefon }
56*bb02e0acSNicolas Bonnefon
57*bb02e0acSNicolas Bonnefon // Custom painter: draw the background then call QLabel's painter
paintEvent(QPaintEvent * paintEvent)58*bb02e0acSNicolas Bonnefon void InfoLine::paintEvent( QPaintEvent* paintEvent )
59*bb02e0acSNicolas Bonnefon {
60*bb02e0acSNicolas Bonnefon // Fill the widget background
61*bb02e0acSNicolas Bonnefon {
62*bb02e0acSNicolas Bonnefon QPainter painter( this );
63*bb02e0acSNicolas Bonnefon painter.fillRect( 0, 0, this->width(), this->height(),
64*bb02e0acSNicolas Bonnefon palette().brush( backgroundRole() ) );
65*bb02e0acSNicolas Bonnefon }
66*bb02e0acSNicolas Bonnefon
67*bb02e0acSNicolas Bonnefon // Call the parent's painter
68*bb02e0acSNicolas Bonnefon QLabel::paintEvent( paintEvent );
69*bb02e0acSNicolas Bonnefon }
70