18 #include <QApplication>
19 #include <QMouseEvent>
20 #include <QPaintDevice>
22 #include <QStyleOptionProgressBarV2>
26 : QItemDelegate(parent)
37 const QModelIndex& index)
const
39 if (option.state & QStyle::State_Selected)
40 painter->fillRect(option.rect, option.palette.highlight());
42 const auto* model =
dynamic_cast<const JobListModel*
>(index.model());
45 const JobItem* item = model->jobForIndex(index);
50 painter->setRenderHint(QPainter::Antialiasing,
true);
53 painter->drawText(textRect, item->
jobName());
58 QStyleOptionButton button;
61 button.icon = QIcon(
":/images/dark-close.svg");
62 button.iconSize = QSize(12, 12);
64 QApplication::style()->drawControl(QStyle::CE_PushButton, &button, painter);
71 const QStyleOptionViewItem& option,
const QModelIndex& index)
73 if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonRelease) {
76 return QItemDelegate::editorEvent(event, model, option, index);
79 const auto* jqmodel =
dynamic_cast<const JobListModel*
>(index.model());
82 const JobItem* item = jqmodel->jobForIndex(index);
90 auto* mouseEvent =
dynamic_cast<QMouseEvent*
>(event);
91 if (!buttonRect.contains(mouseEvent->pos())) {
96 if (event->type() == QEvent::MouseButtonPress)
98 else if (event->type() == QEvent::MouseButtonRelease) {
106 const QStyleOptionViewItem& option)
const
112 painter->setRenderHint(QPainter::Antialiasing);
113 painter->setBrush(QColor(204, 223, 230));
114 painter->setPen(QColor(
"transparent"));
115 QRect rect2(rect.x(), rect.y(), rect.width(), rect.height());
116 painter->drawRoundedRect(rect2, 2, 2);
119 int progBarWidth = (rect.width() * progress) / 100;
121 painter->setRenderHint(QPainter::Antialiasing);
122 painter->setPen(QColor(
"transparent"));
124 QRect rect5(rect.x(), rect.y(), progBarWidth, rect.height());
125 painter->drawRoundedRect(rect5, 2, 2);
132 int width = optionRect.width() * 0.4;
133 int height = optionRect.height();
134 int x = optionRect.x() + 3;
135 int y = optionRect.y();
136 QRect result(x, y, width, height);
143 int width = optionRect.width() * 0.4;
144 int height = optionRect.height() * 0.6;
145 int x = optionRect.x() + optionRect.width() * 0.5;
146 int y = optionRect.y() + (optionRect.height() - height) / 2.;
147 QRect result(x, y, width, height);
156 int x = optionRect.x() + optionRect.width() * 0.92;
157 int y = optionRect.y() + (optionRect.height() - height) / 2.;
158 QRect result(x, y, width, height);
Defines class JobListModel.
Defines class JobListViewDelegate.
@ Completed
the job was successfully completed
@ Canceled
the job was stopped by the user
@ Running
the job is busy calculating
@ Failed
the job aborted because it hit an error
@ Idle
the job has not been started yet
JobStatus getStatus() const
JobListViewDelegate(QWidget *parent)
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override
void cancelButtonClicked(const QModelIndex &index)
QRect getProgressBarRect(QRect optionRect) const
Returns rectangle for progress bar.
QStyle::State m_buttonState
QRect getTextRect(QRect optionRect) const
Returns rectangle for text.
QRect getButtonRect(QRect optionRect) const
Returns rectangle for button.
QMap< JobStatus, QColor > m_status_to_color
void drawCustomProjectBar(const JobItem *item, QPainter *painter, const QStyleOptionViewItem &option) const