From 0ecd1bb6dc7714a503d21c80ccb94d34adfacead Mon Sep 17 00:00:00 2001 From: timurhai Date: Tue, 24 Dec 2024 15:13:42 +0300 Subject: [PATCH] afwatch: render item mark task with running time over specified value. References: #615. --- afanasy/src/libafqt/qenvironment.cpp | 2 ++ afanasy/src/libafqt/qenvironment.h | 1 + afanasy/src/watch/ctrljobs.cpp | 2 +- afanasy/src/watch/ctrlrenders.cpp | 34 ++++++++++++++++++- afanasy/src/watch/ctrlrenders.h | 4 +++ afanasy/src/watch/itemrender.cpp | 50 ++++++++++++++++++++++++---- 6 files changed, 84 insertions(+), 9 deletions(-) diff --git a/afanasy/src/libafqt/qenvironment.cpp b/afanasy/src/libafqt/qenvironment.cpp index b6d361052..3e436c99b 100644 --- a/afanasy/src/libafqt/qenvironment.cpp +++ b/afanasy/src/libafqt/qenvironment.cpp @@ -120,6 +120,7 @@ AttrColor QEnvironment::clr_textdone( "clr_textdone", "Done Text" AttrColor QEnvironment::clr_textmuted( "clr_textmuted", "Muted Text", AFGUI::CLR_TEXTMUTED ); AttrColor QEnvironment::clr_textstars( "clr_textstars", "Stars Text", AFGUI::CLR_TEXTSTARS ); +AttrNumber QEnvironment::renders_run_time_max_secs("renders_run_time_max_secs", "Renders Item Run Time Max", 0); AttrNumber QEnvironment::jobs_run_time_max_secs("jobs_run_time_max_secs", "Job Item Run Time Max", 0); AttrNumber QEnvironment::work_run_time_max_secs("work_run_time_max_secs", "Job Item Run Time Max", 0); AttrNumber QEnvironment::thumb_jobs_height("thumb_jobs_height", "Job Item Height", AFGUI::THUMB_JOBS_HEIGHT); @@ -173,6 +174,7 @@ QEnvironment::QEnvironment( const QString & i_name) ms_attrs_prefs.append(&showServerPort ); ms_attrs_prefs.append( &showOfflineNoise ); + ms_attrs_prefs.append(&renders_run_time_max_secs); ms_attrs_prefs.append(&jobs_run_time_max_secs); ms_attrs_prefs.append(&work_run_time_max_secs); ms_attrs_prefs.append(&thumb_jobs_height); diff --git a/afanasy/src/libafqt/qenvironment.h b/afanasy/src/libafqt/qenvironment.h index 8f31cd0fb..efea035fb 100644 --- a/afanasy/src/libafqt/qenvironment.h +++ b/afanasy/src/libafqt/qenvironment.h @@ -148,6 +148,7 @@ class afqt::QEnvironment static QFont f_plotter; static QFont f_min; + static AttrNumber renders_run_time_max_secs; static AttrNumber jobs_run_time_max_secs; static AttrNumber work_run_time_max_secs; static AttrNumber thumb_jobs_height; diff --git a/afanasy/src/watch/ctrljobs.cpp b/afanasy/src/watch/ctrljobs.cpp index 062022bcd..c2356ad23 100644 --- a/afanasy/src/watch/ctrljobs.cpp +++ b/afanasy/src/watch/ctrljobs.cpp @@ -55,7 +55,7 @@ CtrlJobs::CtrlJobs(QWidget * i_parent, ListJobs * i_listjobs, bool i_inworklist) QLabel * lMax = new QLabel("Max(hrs):", this); lMax->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); - lMax->setToolTip("Mark job blocks with tasks maximum running time above this value."); + lMax->setToolTip("Mark job blocks with tasks maximum running time above this value.\nType zero to disable."); layout->addWidget(lMax); m_max_runtime_edit = new QLineEdit(this); diff --git a/afanasy/src/watch/ctrlrenders.cpp b/afanasy/src/watch/ctrlrenders.cpp index 21394c098..94be8ff20 100644 --- a/afanasy/src/watch/ctrlrenders.cpp +++ b/afanasy/src/watch/ctrlrenders.cpp @@ -21,8 +21,11 @@ CtrlRenders::CtrlRenders(QWidget * i_parent, ListRenders * i_listrenders): setFrameShadow(QFrame::Raised); QHBoxLayout * layout = new QHBoxLayout(this); + layout->setSizeConstraint(QLayout::SetMaximumSize); - layout->addWidget(new QLabel("Size:", this)); + QLabel * lSize = new QLabel("Size:", this); + lSize->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); + layout->addWidget(lSize); for (int i = 0; i < ms_sizes_names.size(); i++) { @@ -39,6 +42,22 @@ CtrlRenders::CtrlRenders(QWidget * i_parent, ListRenders * i_listrenders): btn->setToolTip("Variable size."); } + QLabel * lMax = new QLabel("Max(hrs):", this); + lMax->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); + lMax->setToolTip("Mark tasks maximum running time above this value.\nType zero to disable."); + layout->addWidget(lMax); + + m_max_runtime_edit = new QLineEdit(this); + QDoubleValidator * dv = new QDoubleValidator(0, 24*10, 2, m_max_runtime_edit); + dv->setNotation(QDoubleValidator::StandardNotation); + m_max_runtime_edit->setValidator(dv); + m_max_runtime_edit->setFixedWidth(32); + connect(m_max_runtime_edit, SIGNAL(editingFinished()), this, SLOT(slot_MaxEditingFinished())); + layout->addWidget(m_max_runtime_edit); + int seconds = afqt::QEnvironment::renders_run_time_max_secs.n; + if (seconds) + m_max_runtime_edit->setText(QString::number(double(seconds) / 60.0 / 60.0, 'f', 2)); + CtrlRendersViewOptions * viewOpts = new CtrlRendersViewOptions(this, m_listrenders); layout->addWidget(viewOpts); } @@ -66,11 +85,24 @@ void CtrlRenders::slot_ThumsButtonClicked(Button * i_btn) m_listrenders->itemsSizeChanged(); } +void CtrlRenders::slot_MaxEditingFinished() +{ + QString text = m_max_runtime_edit->text(); + double hours = text.toDouble(); + if (hours <= 0) + m_max_runtime_edit->clear(); + int seconds = int(hours * 60 * 60); + if (seconds < 0) + seconds = 0; + afqt::QEnvironment::renders_run_time_max_secs.n = seconds; + m_listrenders->repaintItems(); +} CtrlRendersViewOptions::CtrlRendersViewOptions(QWidget * i_parent, ListRenders * i_listrenders): QLabel("View Options", i_parent), m_listrenders(i_listrenders) { + setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); setFrameShape(QFrame::StyledPanel); setFrameShadow(QFrame::Raised); } diff --git a/afanasy/src/watch/ctrlrenders.h b/afanasy/src/watch/ctrlrenders.h index 357bf70be..8c661189d 100644 --- a/afanasy/src/watch/ctrlrenders.h +++ b/afanasy/src/watch/ctrlrenders.h @@ -4,6 +4,7 @@ #include #include +#include class Button; class ListRenders; @@ -17,12 +18,15 @@ Q_OBJECT private slots: void slot_ThumsButtonClicked(Button*); + void slot_MaxEditingFinished(); private: QList m_thumbs_btns; static const QStringList ms_sizes_names; static const QList ms_sizes_enums; + QLineEdit * m_max_runtime_edit; + ListRenders * m_listrenders; }; diff --git a/afanasy/src/watch/itemrender.cpp b/afanasy/src/watch/itemrender.cpp index 2164ab53c..6711a266f 100644 --- a/afanasy/src/watch/itemrender.cpp +++ b/afanasy/src/watch/itemrender.cpp @@ -991,7 +991,47 @@ void ItemRender::drawTask(QPainter * i_painter, const QStyleOptionViewItem & i_o const af::TaskExec * i_exec, int i_percent, int i_x, int i_y, int i_w, int i_h) const { - int tw = 0; + int runtime = time(NULL) - i_exec->getTimeStart(); + + // Draw task border: + i_painter->setBrush(Qt::NoBrush); + QColor borderColor(afqt::QEnvironment::clr_outline.c); + QPen borderPen(borderColor); + int run_time_max_sec = afqt::QEnvironment::renders_run_time_max_secs.n; + float factor_warning = 0.8; + if (runtime && run_time_max_sec && (runtime >= (factor_warning * run_time_max_sec))) + { + int clr_warn[3] = { 80, 80, 30}; + int clr_badly[3] = {150, 80, 80}; + int clr_worse[3] = {250, 80, 80}; + int alpha = 80; + float factor = float(runtime) / float(run_time_max_sec); + if (factor < 1) + { + factor = 1 - (1 - factor) / (1 - factor_warning); + clr_badly[0] = borderColor.red(); + clr_badly[1] = borderColor.green(); + clr_badly[2] = borderColor.blue(); + clr_worse[0] = clr_warn[0]; + clr_worse[1] = clr_warn[1]; + clr_worse[2] = clr_warn[2]; + alpha *= factor; + } + else + { + factor = factor - 1; + } + if (factor < 0) factor = 0; + if (factor > 1) factor = 1; + int clr[3] = {0,0,0}; + for (int i = 0; i < 3; i++) + clr[i] = int((1.0 - factor) * clr_badly[i] + factor * clr_worse[i]); + borderPen.setColor(QColor(clr[0], clr[1], clr[2])); + i_painter->setBrush(QColor(clr[0], clr[1], clr[2], alpha)); + } + i_painter->setPen(borderPen); + i_painter->drawRoundedRect(i_x, i_y, i_w, i_h, 1.0, 1.0); + // Prepare strings QString taskstr = QString("%1").arg(i_exec->getCapacity()); if (i_exec->getCapCoeff()) @@ -1004,7 +1044,7 @@ void ItemRender::drawTask(QPainter * i_painter, const QStyleOptionViewItem & i_o QString user_time = QString("%1 - %2") .arg(QString::fromUtf8(i_exec->getUserName().c_str())) - .arg( af::time2strHMS( time(NULL) - i_exec->getTimeStart()).c_str()); + .arg(af::time2strHMS(runtime).c_str()); // Show task percent if (i_percent > 0) @@ -1020,6 +1060,7 @@ void ItemRender::drawTask(QPainter * i_painter, const QStyleOptionViewItem & i_o } // Draw an icon if exists: + int tw = 0; const QPixmap * icon = Watch::getServiceIconSmall(afqt::stoq(i_exec->getServiceType())); if (icon) { @@ -1050,11 +1091,6 @@ void ItemRender::drawTask(QPainter * i_painter, const QStyleOptionViewItem & i_o i_painter->drawText(i_x+5 + tw, i_y, i_w-15 - tw - rect_usertime.width(), i_h, Qt::AlignVCenter | Qt::AlignLeft, taskstr); - - // Draw task border: - i_painter->setPen(afqt::QEnvironment::clr_outline.c); - i_painter->setBrush(Qt::NoBrush); - i_painter->drawRoundedRect(i_x, i_y, i_w, i_h, 1.0, 1.0); } void ItemRender::v_setSortType( int i_type1, int i_type2 )