summaryrefslogtreecommitdiff
path: root/test/progressbardark/ProgressBarDark.cpp
blob: a03167e531832a70400b09d8f181666ba1ef2f28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "ProgressBarDark.h"
#include <QPainter>

ProgressBarDark::ProgressBarDark(QWidget *parent) :
    QProgressBar(parent)
{
    setMinimumHeight(22);
    setMaximumHeight(22);
}

void ProgressBarDark::paintEvent(QPaintEvent *)
{
    if(backgroundLeft.isNull() || backgroundLeft.height()!=height())
    {
        QPixmap background(":/progressBarout.png");
        QPixmap bar(":/progressBarin.png");
        if(height()==background.height())
        {
            backgroundLeft=background.copy(0,0,24,55);
            backgroundMiddle=background.copy(24,0,701,55);
            backgroundRight=background.copy(725,0,24,55);
            barLeft=bar.copy(0,0,24,55);
            barMiddle=bar.copy(24,0,701,55);
            barRight=bar.copy(725,0,24,55);
        }
        else
        {
            backgroundLeft=background.copy(0,0,24,55).scaledToHeight(height(),Qt::SmoothTransformation);
            backgroundMiddle=background.copy(24,0,701,55).scaledToHeight(height(),Qt::SmoothTransformation);
            backgroundRight=background.copy(725,0,24,55).scaledToHeight(height(),Qt::SmoothTransformation);
            barLeft=bar.copy(0,0,24,55).scaledToHeight(height(),Qt::SmoothTransformation);
            barMiddle=bar.copy(24,0,701,55).scaledToHeight(height(),Qt::SmoothTransformation);
            barRight=bar.copy(725,0,24,55).scaledToHeight(height(),Qt::SmoothTransformation);
        }
    }
    int size=width()-barLeft.width()-barRight.width();
    int inpixel=value()*size/maximum();
    QPainter paint;
    paint.begin(this);
    paint.drawPixmap(0,0,backgroundLeft.width(),    backgroundLeft.height(),    backgroundLeft);
    paint.drawPixmap(0,0,barLeft.width(),           barLeft.height(),           barLeft);

    paint.drawPixmap(backgroundLeft.width(),        0,
                     width()-backgroundLeft.width()-backgroundRight.width(),    backgroundLeft.height(),backgroundMiddle);
    paint.drawPixmap(barLeft.width(),               0,
                     inpixel,                  barLeft.height(),barMiddle);

    paint.drawPixmap(width()-backgroundRight.width(),0,                         backgroundRight.width(),    backgroundRight.height(),backgroundRight);
    paint.drawPixmap(barLeft.width()+inpixel,          0,                          barRight.width(),           barRight.height(),barRight);
}