ViewDelegate to show progress bar JobQueuListView.
Definition at line 26 of file JobListViewDelegate.h.
|
| JobListViewDelegate (QWidget *parent) |
|
bool | editorEvent (QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override |
|
void | paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override |
|
◆ JobListViewDelegate()
JobListViewDelegate::JobListViewDelegate |
( |
QWidget * |
parent | ) |
|
Definition at line 25 of file JobListViewDelegate.cpp.
26 : QItemDelegate(parent)
@ 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
QStyle::State m_buttonState
QMap< JobStatus, QColor > m_status_to_color
References Canceled, Completed, Failed, Idle, m_buttonState, m_status_to_color, and Running.
◆ cancelButtonClicked
void JobListViewDelegate::cancelButtonClicked |
( |
const QModelIndex & |
index | ) |
|
|
signal |
◆ drawCustomProjectBar()
void JobListViewDelegate::drawCustomProjectBar |
( |
const JobItem * |
item, |
|
|
QPainter * |
painter, |
|
|
const QStyleOptionViewItem & |
option |
|
) |
| const |
|
private |
Definition at line 105 of file JobListViewDelegate.cpp.
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);
JobStatus getStatus() const
QRect getProgressBarRect(QRect optionRect) const
Returns rectangle for progress bar.
References JobItem::getProgress(), getProgressBarRect(), JobItem::getStatus(), and m_status_to_color.
Referenced by paint().
◆ editorEvent()
bool JobListViewDelegate::editorEvent |
( |
QEvent * |
event, |
|
|
QAbstractItemModel * |
model, |
|
|
const QStyleOptionViewItem & |
option, |
|
|
const QModelIndex & |
index |
|
) |
| |
|
override |
Definition at line 70 of file JobListViewDelegate.cpp.
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) {
void cancelButtonClicked(const QModelIndex &index)
QRect getButtonRect(QRect optionRect) const
Returns rectangle for button.
References cancelButtonClicked(), getButtonRect(), JobItem::isRunning(), and m_buttonState.
◆ getButtonRect()
QRect JobListViewDelegate::getButtonRect |
( |
QRect |
optionRect | ) |
const |
|
private |
Returns rectangle for button.
Definition at line 152 of file JobListViewDelegate.cpp.
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);
Referenced by editorEvent(), and paint().
◆ getProgressBarRect()
QRect JobListViewDelegate::getProgressBarRect |
( |
QRect |
optionRect | ) |
const |
|
private |
Returns rectangle for progress bar.
Definition at line 141 of file JobListViewDelegate.cpp.
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);
Referenced by drawCustomProjectBar().
◆ getTextRect()
QRect JobListViewDelegate::getTextRect |
( |
QRect |
optionRect | ) |
const |
|
private |
Returns rectangle for text.
Definition at line 130 of file JobListViewDelegate.cpp.
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);
Referenced by paint().
◆ paint()
void JobListViewDelegate::paint |
( |
QPainter * |
painter, |
|
|
const QStyleOptionViewItem & |
option, |
|
|
const QModelIndex & |
index |
|
) |
| const |
|
override |
Definition at line 36 of file JobListViewDelegate.cpp.
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);
QRect getTextRect(QRect optionRect) const
Returns rectangle for text.
void drawCustomProjectBar(const JobItem *item, QPainter *painter, const QStyleOptionViewItem &option) const
References drawCustomProjectBar(), getButtonRect(), getTextRect(), JobItem::isRunning(), JobItem::jobName(), and m_buttonState.
◆ m_buttonState
QStyle::State JobListViewDelegate::m_buttonState |
|
private |
◆ m_status_to_color
QMap<JobStatus, QColor> JobListViewDelegate::m_status_to_color |
|
private |
The documentation for this class was generated from the following files: