LeechCraft  0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
progressdelegate.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Distributed under the Boost Software License, Version 1.0.
6  * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7  **********************************************************************/
8 
9 #include "progressdelegate.h"
10 #include <QApplication>
11 #include "util.h"
12 
13 namespace LC::Util
14 {
16  : QStyledItemDelegate { parent }
17  , ProgressGetter_ { std::move (progress) }
18  {
19  }
20 
21  void ProgressDelegate::paint (QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
22  {
23  const auto& progress = ProgressGetter_ (index);
24  if (!progress)
25  {
26  QStyledItemDelegate::paint (painter, option, index);
27  return;
28  }
29 
30  const auto style = option.widget ? option.widget->style () : QApplication::style ();
31  style->drawPrimitive (QStyle::PE_PanelItemViewItem, &option, painter, option.widget);
32 
33  QStyleOptionProgressBar progressBarOption;
34  progressBarOption.state = option.state | QStyle::StateFlag::State_Horizontal;
35  progressBarOption.direction = option.direction;
36  progressBarOption.rect = option.rect;
37  progressBarOption.fontMetrics = option.fontMetrics;
38  progressBarOption.palette = option.palette;
39  progressBarOption.textAlignment = Qt::AlignCenter;
40  progressBarOption.textVisible = true;
41 
42  progressBarOption.minimum = progress->Minimum_;
43  progressBarOption.maximum = progress->Maximum_;
44  progressBarOption.progress = progress->Progress_;
45  progressBarOption.text = ElideProgressBarText (progress->Text_, option);
46 
47  style->drawControl (QStyle::CE_ProgressBar, &progressBarOption, painter, option.widget);
48  }
49 }
QString ElideProgressBarText(const QString &text, const QStyleOptionViewItem &option)
Definition: util.cpp:101
void paint(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const override
ProgressDelegate(ProgressGetter_t &&progress, QObject *parent=nullptr)
std::function< std::optional< Progress >(QModelIndex)> ProgressGetter_t