From 7de38b736fb8a13221e926af7b52488e420b0585 Mon Sep 17 00:00:00 2001 From: timurhai Date: Mon, 24 Feb 2020 20:55:53 +0300 Subject: [PATCH] tickets: afwatch: ticket border colorizes count/usage References #459. --- afanasy/src/watch/blockinfo.cpp | 21 ++------ afanasy/src/watch/item.cpp | 82 ++++++++++++++++++++++++++++++++ afanasy/src/watch/item.h | 14 ++++++ afanasy/src/watch/itemfarm.cpp | 70 ++++++++++++--------------- afanasy/src/watch/itemfarm.h | 2 - afanasy/src/watch/itemrender.cpp | 40 +++++++++++----- afanasy/src/watch/itemrender.h | 1 - afanasy/src/watch/listjobs.cpp | 2 +- 8 files changed, 159 insertions(+), 73 deletions(-) diff --git a/afanasy/src/watch/blockinfo.cpp b/afanasy/src/watch/blockinfo.cpp index b41832232..cb80e2552 100644 --- a/afanasy/src/watch/blockinfo.cpp +++ b/afanasy/src/watch/blockinfo.cpp @@ -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; @@ -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; diff --git a/afanasy/src/watch/item.cpp b/afanasy/src/watch/item.cpp index 8beadd5dd..fb9983da5 100644 --- a/afanasy/src/watch/item.cpp +++ b/afanasy/src/watch/item.cpp @@ -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; +} + diff --git a/afanasy/src/watch/item.h b/afanasy/src/watch/item.h index db91a040e..7f1890d30 100644 --- a/afanasy/src/watch/item.h +++ b/afanasy/src/watch/item.h @@ -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;} @@ -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; diff --git a/afanasy/src/watch/itemfarm.cpp b/afanasy/src/watch/itemfarm.cpp index fc2199c12..d862ee2ea 100644 --- a/afanasy/src/watch/itemfarm.cpp +++ b/afanasy/src/watch/itemfarm.cpp @@ -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 tkp_it(m_tickets_pool); - while (tkp_it.hasNext()) + if (getType() == Item::TPool) { - tkp_it.next(); + int tkp_w = 0; + QMapIterator 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 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 tkh_it(m_tickets_host); - while (tkh_it.hasNext()) + else { - tkh_it.next(); + int tkh_w = 0; + QMapIterator 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; } } diff --git a/afanasy/src/watch/itemfarm.h b/afanasy/src/watch/itemfarm.h index d4913b295..79e118790 100644 --- a/afanasy/src/watch/itemfarm.h +++ b/afanasy/src/watch/itemfarm.h @@ -19,8 +19,6 @@ class ItemFarm : public ItemNode static const int HeightServices = 24; - static const int HeightTickets = 24; - static const int DepthOffset = 32; QList m_services; diff --git a/afanasy/src/watch/itemrender.cpp b/afanasy/src/watch/itemrender.cpp index 9adb7ae06..0593b3cae 100644 --- a/afanasy/src/watch/itemrender.cpp +++ b/afanasy/src/watch/itemrender.cpp @@ -100,7 +100,6 @@ ItemRender::~ItemRender() void ItemRender::deleteTasks() { for( std::list::iterator it = m_tasks.begin(); it != m_tasks.end(); it++) delete *it; - m_tasksicons.clear(); } void ItemRender::deletePlots() @@ -263,7 +262,6 @@ void ItemRender::v_updateValues(af::Node * i_afnode, int i_msgType) m_elder_task_time = time(NULL); for( std::list::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]++; @@ -707,9 +705,9 @@ void ItemRender::v_paint(QPainter * i_painter, const QRect & i_rect, const QStyl } std::list::const_iterator it = m_tasks.begin(); - std::list::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()) @@ -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; } diff --git a/afanasy/src/watch/itemrender.h b/afanasy/src/watch/itemrender.h index 4351491fd..09b218c5a 100644 --- a/afanasy/src/watch/itemrender.h +++ b/afanasy/src/watch/itemrender.h @@ -109,7 +109,6 @@ class ItemRender : public ItemFarm QString m_state; std::list m_tasks; std::vector m_tasks_percents; - std::list m_tasksicons; long long m_taskstartfinishtime; QString m_taskstartfinishtime_str; QString m_offlineState; diff --git a/afanasy/src/watch/listjobs.cpp b/afanasy/src/watch/listjobs.cpp index 36a09ecb4..edbaad5ea 100644 --- a/afanasy/src/watch/listjobs.cpp +++ b/afanasy/src/watch/listjobs.cpp @@ -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);