File: DirectoryDelegate.cpp

package info (click to toggle)
wsjtx 2.7.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 70,440 kB
  • sloc: cpp: 75,379; f90: 46,460; python: 27,241; ansic: 13,367; fortran: 2,382; makefile: 197; sh: 133
file content (58 lines) | stat: -rwxr-xr-x 1,927 bytes parent folder | download
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
51
52
53
54
55
56
57
58
#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 ())
    {
      auto progress = index.data ().toLongLong ();
      qint64 percent;
      if (progress > 0)
        {
          percent = int (progress * 100 / index.data (Qt::UserRole).toLongLong ());
        }
#if !defined (Q_OS_DARWIN)
      QStyleOptionProgressBar progress_option;
      auto control_element = QStyle::CE_ProgressBar;
      progress_option.minimum = 0;
      progress_option.maximum = 100;
      progress_option.textAlignment = Qt::AlignCenter;
      if (progress > 0)
        {
          progress_option.progress = percent;
          progress_option.textVisible = true;
        }
      else
        {
          // not started
          progress_option.progress = -1;
        }
#else
      // workaround for broken QProgressBar item delegates on macOS
      QStyleOptionViewItem progress_option;
      auto control_element = QStyle::CE_ItemViewItem;
      progress_option.displayAlignment = Qt::AlignHCenter;
      progress_option.index = index;
      progress_option.features = QStyleOptionViewItem::HasDisplay;
#endif
      progress_option.rect = option.rect;
      progress_option.state = QStyle::State_Enabled;
      progress_option.direction = QApplication::layoutDirection ();
      progress_option.fontMetrics = QApplication::fontMetrics ();
      progress_option.text = QString::number (progress > 0 ? percent : 0) + '%';
      QApplication::style ()->drawControl (control_element, &progress_option, painter);
    }
  else
    {
      QStyledItemDelegate::paint (painter, option, index);
    }
}