Statistics
| Revision:

root / trunk / client / gui_qt / ProgressBarDelegateDownloadQueue.cpp @ 1777

History | View | Annotate | Download (1.8 KB)

1
#include "ProgressBarDelegateDownloadQueue.h"
2
#include "WidgetDownloadQueue.h"
3

                
4
#include 
5
#include 
6
#include 
7
#include 
8

                
9
#ifdef Q_OS_MACX
10
#include 
11
#endif
12

                
13
ProgressBarDelegateDownloadQueue::ProgressBarDelegateDownloadQueue(QObject *parent)
14
        : QItemDelegate(parent)
15
{
16

                
17
}
18

                
19
ProgressBarDelegateDownloadQueue::~ProgressBarDelegateDownloadQueue()
20
{
21

                
22
}
23

                
24
QSize ProgressBarDelegateDownloadQueue::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
25
{
26
    Q_UNUSED(option);
27

                
28
    QString txt = index.model()->data(index, Qt::DisplayRole).toString();
29

                
30
    if (txt.isEmpty()) {
31
        return QSize(60,16);
32
    } else {
33
        return QSize(100,16);
34
    }
35
}
36

                
37
void ProgressBarDelegateDownloadQueue::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
38
{
39
    QStyleOptionProgressBarV2 opts;
40
    int value = index.model()->data(index.sibling(index.row(), DownloadQueueItem::FIELD_PROGRESS), Qt::DisplayRole).toInt();
41
    QString txt = index.model()->data(index, Qt::DisplayRole).toString();
42

                
43
    if (txt.isEmpty()) {
44
        txt = QString ("%1%").arg(value);
45
    }
46

                
47
    opts.state = QStyle::State_Active | QStyle::State_Enabled;
48
    opts.text = txt;
49
    opts.maximum = 100;
50
    opts.minimum =   0;
51
    opts.progress = value;
52
    opts.rect = option.rect;
53
    opts.rect.setRight(option.rect.right()-1);
54
    opts.rect.setHeight(option.rect.height()-1);
55
    opts.textVisible = true;
56
    opts.textAlignment = Qt::AlignCenter;
57
#ifdef Q_OS_MACX
58
    QCleanlooksStyle s;
59
    s.drawControl(QCleanlooksStyle::CE_ProgressBar, &opts, painter, 0);
60
#else
61
    QApplication::style()->drawControl(QStyle::CE_ProgressBar, &opts, painter);
62
#endif
63
}