Falkon Develop
Cross-platform Qt-based web browser
progressbar.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2010-2016 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "progressbar.h"
19
20#include <QStylePainter>
21#include <QStyleOptionProgressBar>
22
24 : QWidget(parent)
25 , m_value(0)
26 , m_lastPaintedValue(-1)
27{
28 setMinimumSize(130, 16);
29 setMaximumSize(150, 16);
30}
31
33{
34 m_value = value;
35 if (m_lastPaintedValue != m_value) {
36 update();
37 }
38}
39
40void ProgressBar::initStyleOption(QStyleOptionProgressBar* option)
41{
42 if (!option) {
43 return;
44 }
45
46 option->initFrom(this);
47 option->minimum = 0;
48 option->maximum = 100;
49 option->progress = m_value;
50 option->textAlignment = Qt::AlignLeft;
51 option->textVisible = false;
52}
53
54void ProgressBar::paintEvent(QPaintEvent*)
55{
56 QStylePainter paint(this);
57
58 QStyleOptionProgressBar opt;
59 initStyleOption(&opt);
60
61 paint.drawControl(QStyle::CE_ProgressBar, opt);
62
63 m_lastPaintedValue = m_value;
64}
void paintEvent(QPaintEvent *e) override
Definition: progressbar.cpp:54
ProgressBar(QWidget *parent=nullptr)
Definition: progressbar.cpp:23
void setValue(int value)
Definition: progressbar.cpp:32
void initStyleOption(QStyleOptionProgressBar *option)
Definition: progressbar.cpp:40
int value(const QColor &c)
Definition: colors.cpp:238