File: DirectoryDelegate.cpp

package info (click to toggle)
wsjtx 2.3.0%2Brepack-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 63,524 kB
  • sloc: cpp: 59,051; f90: 34,130; python: 27,241; ansic: 11,205; fortran: 2,051; sh: 132; makefile: 109
file content (44 lines) | stat: -rw-r--r-- 1,492 bytes parent folder | download | duplicates (3)
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
#include "DirectoryDelegate.hpp"

#include <QApplication>
#include <QVariant>
#include <QString>
#include <QStyle>
#include <QModelIndex>
#include <QPainter>
#include <QStyleOptionViewItem>
#include <QStyleOptionProgressBar>

void DirectoryDelegate::paint (QPainter * painter, QStyleOptionViewItem const& option
                               , QModelIndex const& index) const
{
  if (1 == index.column ())
    {
      QStyleOptionProgressBar progress_bar_option;
      progress_bar_option.rect = option.rect;
      progress_bar_option.state = QStyle::State_Enabled;
      progress_bar_option.direction = QApplication::layoutDirection ();
      progress_bar_option.fontMetrics = QApplication::fontMetrics ();
      progress_bar_option.minimum = 0;
      progress_bar_option.maximum = 100;
      auto progress = index.data ().toLongLong ();
      if (progress > 0)
        {
          auto percent = int (progress * 100 / index.data (Qt::UserRole).toLongLong ());
          progress_bar_option.progress = percent;
          progress_bar_option.text = QString::number (percent) + '%';
          progress_bar_option.textVisible = true;
          progress_bar_option.textAlignment = Qt::AlignCenter;
        }
      else
        {
          // not started
          progress_bar_option.progress = -1;
        }
      QApplication::style ()->drawControl (QStyle::CE_ProgressBar, &progress_bar_option, painter);
    }
  else
    {
      QStyledItemDelegate::paint (painter, option, index);
    }
}