Skip to content

Commit

Permalink
afwatch: render item mark task with running time over specified value.
Browse files Browse the repository at this point in the history
References: #615.
  • Loading branch information
timurhai committed Dec 24, 2024
1 parent be7097f commit 0ecd1bb
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 9 deletions.
2 changes: 2 additions & 0 deletions afanasy/src/libafqt/qenvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions afanasy/src/libafqt/qenvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion afanasy/src/watch/ctrljobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
34 changes: 33 additions & 1 deletion afanasy/src/watch/ctrlrenders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions afanasy/src/watch/ctrlrenders.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <QFrame>
#include <QLabel>
#include <QLineEdit>

class Button;
class ListRenders;
Expand All @@ -17,12 +18,15 @@ Q_OBJECT

private slots:
void slot_ThumsButtonClicked(Button*);
void slot_MaxEditingFinished();

private:
QList<Button*> m_thumbs_btns;
static const QStringList ms_sizes_names;
static const QList<int> ms_sizes_enums;

QLineEdit * m_max_runtime_edit;

ListRenders * m_listrenders;
};

Expand Down
50 changes: 43 additions & 7 deletions afanasy/src/watch/itemrender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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)
Expand All @@ -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)
{
Expand Down Expand Up @@ -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 )
Expand Down

0 comments on commit 0ecd1bb

Please sign in to comment.