Skip to content

Commit

Permalink
tickets: afwatch: ticket border colorizes count/usage
Browse files Browse the repository at this point in the history
References #459.
  • Loading branch information
timurhai committed Feb 24, 2020
1 parent 40ad2e1 commit 7de38b7
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 73 deletions.
21 changes: 4 additions & 17 deletions afanasy/src/watch/blockinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,6 @@ void BlockInfo::paint( QPainter * i_painter, const QStyleOptionViewItem &option,
// Setup font size and color:
i_painter->setFont(afqt::QEnvironment::f_info);
QPen pen(Item::clrTextInfo(p_tasksrunning, option.state & QStyle::State_Selected, m_item->isLocked()));
i_painter->setPen(pen);


// Draw tickets:
int tk_w = 0;
Expand All @@ -558,25 +556,14 @@ void BlockInfo::paint( QPainter * i_painter, const QStyleOptionViewItem &option,
{
it.next();

QRect tk_rect;
i_painter->drawText(x+xoffset+5, tk_y, w-10-xoffset-tk_w, 15, Qt::AlignRight | Qt::AlignTop, QString("x%1").arg(it.value()), &tk_rect);
tk_w += tk_rect.width() + 1;

const QPixmap * icon = Watch::getTicketIcon(it.key());
if (icon)
{
i_painter->drawPixmap(x+xoffset+5+w-10-xoffset-tk_w-icon->width(), tk_y-1, *icon);
tk_w += icon->width();
}
else
{
i_painter->drawText(x+xoffset+5, tk_y, w-10-xoffset-tk_w, 15, Qt::AlignRight | Qt::AlignTop, it.key(), &tk_rect);
tk_w += tk_rect.width();
}
tk_w += Item::drawTicket(i_painter, pen, x+5 + xoffset, tk_y, w-10 - xoffset - tk_w,
Item::TKD_LEFT,
it.key(), it.value());

tk_w += 8;
}

i_painter->setPen(pen);

// Paint parameters:
QRect rect_params;
Expand Down
82 changes: 82 additions & 0 deletions afanasy/src/watch/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,85 @@ void Item::drawStar( int size, int posx, int posy, QPainter * painter)
painter->drawPolygon( ms_star_pointsDraw);//, Qt::WindingFill);
}

int Item::drawTicket(QPainter * i_painter, const QPen & i_text_pen,
int i_x, int i_y, int i_w,
int i_opts,
const QString & i_name, int i_count, int i_usage)
{
i_painter->setPen(i_text_pen);

QPen border_pen;
if (i_opts & TKD_BORDER)
{
i_x += 2;
i_y += 2;

if (i_usage >= i_count)
border_pen.setColor(afqt::QEnvironment::clr_error.c);
else if (i_usage > 0)
border_pen.setColor(afqt::QEnvironment::clr_running.c);
else
border_pen.setColor(afqt::QEnvironment::clr_done.c);
}

const QPixmap * icon = Watch::getTicketIcon(i_name);
QString text;
if (i_usage == -1)
text = QString("x%1").arg(i_count);
else
text = QString("x%1 / %2").arg(i_count).arg(i_usage);

QRect tk_rect;
int tk_width = 0;
if (i_opts & TKD_RIGHT)
{
if (icon)
{
i_painter->drawPixmap(i_x + tk_width, i_y-1, *icon);
tk_width += icon->width();
}
else
{
i_painter->drawText(i_x + tk_width, i_y, i_w, 15, Qt::AlignLeft | Qt::AlignTop, i_name, &tk_rect);
tk_width += tk_rect.width();
}

i_painter->drawText(i_x + tk_width, i_y, i_w, 15, Qt::AlignLeft | Qt::AlignTop, text, &tk_rect);
tk_width += tk_rect.width() + 1;

if (i_opts & TKD_BORDER)
{
i_painter->setPen(border_pen);
i_painter->setBrush(Qt::NoBrush);
i_painter->drawRect(i_x - 2, i_y - 2, tk_width + 4, HeightTickets - 5);
tk_width += 4;
}
}
else
{
i_painter->drawText(i_x, i_y, i_w - tk_width, 15, Qt::AlignRight | Qt::AlignTop, text, &tk_rect);
tk_width += tk_rect.width() + 1;

if (icon)
{
i_painter->drawPixmap(i_x + i_w - tk_width - icon->width(), i_y-1, *icon);
tk_width += icon->width();
}
else
{
i_painter->drawText(i_x, i_y, i_w - tk_width, 15, Qt::AlignRight | Qt::AlignTop, i_name, &tk_rect);
tk_width += tk_rect.width();
}

if (i_opts & TKD_BORDER)
{
i_painter->setPen(border_pen);
i_painter->setBrush(Qt::NoBrush);
i_painter->drawRect(i_x + i_w - 2 - tk_width, i_y - 2, tk_width + 4, HeightTickets - 5);
tk_width += 4;
}
}

return tk_width;
}

14 changes: 14 additions & 0 deletions afanasy/src/watch/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class Item
Item(const QString &i_name, int i_id, EType i_type);
virtual ~Item();

static const int HeightTickets = 24;

virtual QSize sizeHint( const QStyleOptionViewItem &option) const;

inline int getHeight() const { return m_height;}
Expand Down Expand Up @@ -95,6 +97,18 @@ class Item
inline bool hasParam(const QString & i_name) const {return m_params.contains(i_name);}
const QVariant & getParamVar(const QString & i_name) const;

enum ETK_DRAW_OPTS {
TKD_LEFT = 0,
TKD_RIGHT = 1,
TKD_BORDER = 1 << 1
};

/// Draw ticket and return its width
static int drawTicket(QPainter * i_painter, const QPen & i_text_pen,
int i_x, int i_y, int i_w,
int i_opts,
const QString & i_name, int i_count, int i_usage = -1);

protected:
void drawBack(QPainter * i_painter, const QRect & i_rect, const QStyleOptionViewItem & i_option, const QColor * i_clrItem = NULL, const QColor * i_clrBorder = NULL) const;

Expand Down
70 changes: 30 additions & 40 deletions afanasy/src/watch/itemfarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,59 +125,49 @@ void ItemFarm::drawTickets(QPainter * i_painter, int i_x, int i_y, int i_w, int
{
i_painter->setFont(afqt::QEnvironment::f_info);
QPen pen(afqt::QEnvironment::qclr_black);
i_painter->setPen(pen);

int tkp_w = 0;
QMapIterator<QString, af::Farm::Tiks> tkp_it(m_tickets_pool);
while (tkp_it.hasNext())
if (getType() == Item::TPool)
{
tkp_it.next();
int tkp_w = 0;
QMapIterator<QString, af::Farm::Tiks> tkp_it(m_tickets_pool);
while (tkp_it.hasNext())
{
tkp_it.next();

QRect tk_rect;
tkp_w += drawTicket(i_painter, pen, i_x + 5 + tkp_w, i_y, i_w - 10,
Item::TKD_RIGHT | Item::TKD_BORDER,
tkp_it.key(), tkp_it.value().count, tkp_it.value().usage);

const QPixmap * icon = Watch::getTicketIcon(tkp_it.key());
if (icon)
{
i_painter->drawPixmap(i_x+5+tkp_w, i_y-1, *icon);
tkp_w += icon->width();
tkp_w += 8;
}
else

int tkh_w = 0;
QMapIterator<QString, af::Farm::Tiks> tkh_it(m_tickets_host);
while (tkh_it.hasNext())
{
i_painter->drawText(i_x+5+tkp_w, i_y, i_w-10, 15, Qt::AlignLeft | Qt::AlignTop, tkp_it.key(), &tk_rect);
tkp_w += tk_rect.width();
}
tkh_it.next();

i_painter->drawText(i_x+5+tkp_w, i_y, i_w-10, 15, Qt::AlignLeft | Qt::AlignTop,
QString("x%1 / %2").arg(tkp_it.value().count).arg(tkp_it.value().usage), &tk_rect);
tkp_w += tk_rect.width() + 1;
tkh_w += drawTicket(i_painter, pen, i_x + 5, i_y + 3, i_w - 10 - tkh_w,
Item::TKD_LEFT,
tkh_it.key(), tkh_it.value().count);

tkp_w += 8;
tkh_w += 8;
}
}

int tkh_w = 0;
QMapIterator<QString, af::Farm::Tiks> tkh_it(m_tickets_host);
while (tkh_it.hasNext())
else
{
tkh_it.next();
int tkh_w = 0;
QMapIterator<QString, af::Farm::Tiks> tkh_it(m_tickets_host);
while (tkh_it.hasNext())
{
tkh_it.next();

QRect tk_rect;
i_painter->drawText(i_x+5, i_y, i_w-10-tkh_w, 15, Qt::AlignRight | Qt::AlignTop,
QString("x%1 / %2").arg(tkh_it.value().count).arg(tkh_it.value().usage), &tk_rect);
tkh_w += tk_rect.width() + 1;
tkh_w += drawTicket(i_painter, pen, i_x + 5, i_y, i_w - 10 - tkh_w,
Item::TKD_LEFT | Item::TKD_BORDER,
tkh_it.key(), tkh_it.value().count, tkh_it.value().usage);

const QPixmap * icon = Watch::getTicketIcon(tkh_it.key());
if (icon)
{
i_painter->drawPixmap(i_x+5+i_w-10-tkh_w-icon->width(), i_y-1, *icon);
tkh_w += icon->width();
tkh_w += 8;
}
else
{
i_painter->drawText(i_x+5, i_y, i_w-10-tkh_w, 15, Qt::AlignRight | Qt::AlignTop, tkh_it.key(), &tk_rect);
tkh_w += tk_rect.width();
}

tkh_w += 8;
}
}

2 changes: 0 additions & 2 deletions afanasy/src/watch/itemfarm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class ItemFarm : public ItemNode

static const int HeightServices = 24;

static const int HeightTickets = 24;

static const int DepthOffset = 32;

QList<QString> m_services;
Expand Down
40 changes: 28 additions & 12 deletions afanasy/src/watch/itemrender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ ItemRender::~ItemRender()
void ItemRender::deleteTasks()
{
for( std::list<af::TaskExec*>::iterator it = m_tasks.begin(); it != m_tasks.end(); it++) delete *it;
m_tasksicons.clear();
}

void ItemRender::deletePlots()
Expand Down Expand Up @@ -263,7 +262,6 @@ void ItemRender::v_updateValues(af::Node * i_afnode, int i_msgType)
m_elder_task_time = time(NULL);
for( std::list<af::TaskExec*>::const_iterator it = m_tasks.begin(); it != m_tasks.end(); it++)
{
m_tasksicons.push_back( Watch::getServiceIconSmall( QString::fromUtf8( (*it)->getServiceType().c_str())));
QString tusr = QString::fromUtf8( (*it)->getUserName().c_str());
int pos = tasks_users.indexOf( tusr);
if( pos != -1) tasks_counts[pos]++;
Expand Down Expand Up @@ -707,9 +705,9 @@ void ItemRender::v_paint(QPainter * i_painter, const QRect & i_rect, const QStyl
}

std::list<af::TaskExec*>::const_iterator it = m_tasks.begin();
std::list<const QPixmap*>::const_iterator icons_it = m_tasksicons.begin();
for (int numtask = 0; it != m_tasks.end(); it++, icons_it++, numtask++)
for (int numtask = 0; it != m_tasks.end(); it++, numtask++)
{
int tw = 0;
// Prepare strings
QString taskstr = QString("%1").arg((*it)->getCapacity());
if ((*it)->getCapCoeff())
Expand Down Expand Up @@ -739,18 +737,36 @@ void ItemRender::v_paint(QPainter * i_painter, const QRect & i_rect, const QStyl
i_painter->setOpacity(1.0);
}

i_painter->setPen(clrTextInfo(i_option));
i_painter->drawText(x, y_cur, w-5, HeightTask,
Qt::AlignVCenter | Qt::AlignRight, user_time, &rect_usertime );
i_painter->drawText(x+18, y_cur, w-30-rect_usertime.width(), HeightTask,
Qt::AlignVCenter | Qt::AlignLeft, taskstr);
// Draw an icon if exists:
const QPixmap * icon = Watch::getServiceIconSmall(afqt::stoq((*it)->getServiceType()));
if (icon)
{
i_painter->drawPixmap(x+5, y_cur, *icon);
tw += icon->width() + 2;
}

// Setup pen color
QPen pen(clrTextInfo(i_option));

// Draw an icon only if pointer is not NULL:
if (*icons_it)
// Draw tickets
for (auto const & tIt : (*it)->m_tickets)
{
i_painter->drawPixmap(x+5, y_cur, *(*icons_it));
tw += Item::drawTicket(i_painter, pen, x+5 + tw, y_cur, w-10 - tw,
Item::TKD_RIGHT,
afqt::stoq(tIt.first), tIt.second);

tw += 8;
}

i_painter->setPen(pen);

// Draw informatin strings
i_painter->drawText(x+5, y_cur, w-5, HeightTask,
Qt::AlignVCenter | Qt::AlignRight, user_time, &rect_usertime );

i_painter->drawText(x+5 + tw, y_cur, w-10 - rect_usertime.width(), HeightTask,
Qt::AlignVCenter | Qt::AlignLeft, taskstr);

y_cur += HeightTask;
}

Expand Down
1 change: 0 additions & 1 deletion afanasy/src/watch/itemrender.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ class ItemRender : public ItemFarm
QString m_state;
std::list<af::TaskExec*> m_tasks;
std::vector<int32_t> m_tasks_percents;
std::list<const QPixmap*> m_tasksicons;
long long m_taskstartfinishtime;
QString m_taskstartfinishtime_str;
QString m_offlineState;
Expand Down
2 changes: 1 addition & 1 deletion afanasy/src/watch/listjobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ ListJobs::ListJobs(QWidget * i_parent):

addButtonsMenu(Item::TJob, "Restart","Restart jobs tasks menu.");

bp = addButtonPanel(Item::TJob, "SELECTED","jobs_restart","Restart all selected jobs tasks.","", true);
bp = addButtonPanel(Item::TJob, "ALL TASKS","jobs_restart","Restart all tasks of all selected jobs.","", true);
connect(bp, SIGNAL(sigClicked()), this, SLOT(actRestart()));

bp = addButtonPanel(Item::TJob, "AND PAUSE","jobs_restart_pause","Restart tasks and pause selected jobs.","", true);
Expand Down

0 comments on commit 7de38b7

Please sign in to comment.