LeechCraft 0.6.70-17793-g6e56308e78
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
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
13namespace 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 QStyleOptionProgressBar progressBarOption;
24 progressBarOption.state = option.state | QStyle::StateFlag::State_Horizontal;
25 progressBarOption.direction = option.direction;
26 progressBarOption.rect = option.rect;
27 progressBarOption.fontMetrics = option.fontMetrics;
28 progressBarOption.palette = option.palette;
29 progressBarOption.textAlignment = Qt::AlignCenter;
30 progressBarOption.textVisible = true;
31
32 const auto& progress = ProgressGetter_ (index);
33 progressBarOption.minimum = progress.Minimum_;
34 progressBarOption.maximum = progress.Maximum_;
35 progressBarOption.progress = progress.Progress_;
36 progressBarOption.text = ElideProgressBarText (progress.Text_, option);
37
38 QApplication::style ()->drawControl (QStyle::CE_ProgressBar, &progressBarOption, painter);
39 }
40}
std::function< Progress(QModelIndex)> ProgressGetter_t
ProgressDelegate(ProgressGetter_t &&progress, QObject *parent=nullptr)
void paint(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const override
QString ElideProgressBarText(const QString &text, const QStyleOptionViewItem &option)
Definition util.cpp:101