From 9748d7274fee07b6a5f38696e6b86205cfc5aa02 Mon Sep 17 00:00:00 2001 From: Victor Zarubkin Date: Wed, 14 Sep 2016 23:14:24 +0300 Subject: [PATCH] (profiler_gui) Bold and colorized font in EasyTreeWidget header --- profiler_gui/blocks_graphics_view.cpp | 18 ++--- profiler_gui/blocks_tree_widget.cpp | 99 +++++++++++++++++++-------- profiler_gui/common_types.h | 18 +++++ 3 files changed, 92 insertions(+), 43 deletions(-) diff --git a/profiler_gui/blocks_graphics_view.cpp b/profiler_gui/blocks_graphics_view.cpp index acd6f7a..c3420d8 100644 --- a/profiler_gui/blocks_graphics_view.cpp +++ b/profiler_gui/blocks_graphics_view.cpp @@ -102,20 +102,10 @@ const uint64_t IDLE_TIME = 400; const int FLICKER_INTERVAL = 10; // 100Hz const qreal FLICKER_FACTOR = 16.0 / FLICKER_INTERVAL; -QFont EFont(const char* _family, int _size, int _weight = -1) -{ - QFont f; - f.setStyleHint(QFont::Helvetica, QFont::PreferMatch); - f.setFamily(_family); - f.setPointSize(_size); - f.setWeight(_weight); - return f; -} - -const auto BG_FONT = EFont("Helvetica", 10, QFont::Bold); -const auto CHRONOMETER_FONT = EFont("Helvetica", 16, QFont::Bold); -const auto ITEMS_FONT = EFont("Helvetica", 10, QFont::Medium); -const auto SELECTED_ITEM_FONT = EFont("Helvetica", 10, QFont::Bold); +const auto BG_FONT = ::profiler_gui::EFont("Helvetica", 10, QFont::Bold); +const auto CHRONOMETER_FONT = ::profiler_gui::EFont("Helvetica", 16, QFont::Bold); +const auto ITEMS_FONT = ::profiler_gui::EFont("Helvetica", 10, QFont::Medium); +const auto SELECTED_ITEM_FONT = ::profiler_gui::EFont("Helvetica", 10, QFont::Bold); #ifdef _WIN32 const qreal FONT_METRICS_FACTOR = 1.05; diff --git a/profiler_gui/blocks_tree_widget.cpp b/profiler_gui/blocks_tree_widget.cpp index 3418eed..48757ee 100644 --- a/profiler_gui/blocks_tree_widget.cpp +++ b/profiler_gui/blocks_tree_widget.cpp @@ -38,6 +38,7 @@ ************************************************************************/ #include +#include #include #include #include @@ -78,44 +79,73 @@ EasyTreeWidget::EasyTreeWidget(QWidget* _parent) setSortingEnabled(false); setColumnCount(COL_COLUMNS_NUMBER); - auto header = new QTreeWidgetItem(); + auto header_item = new QTreeWidgetItem(); + auto f = header()->font(); + f.setBold(true); + header()->setFont(f);// ::profiler_gui::EFont("Helvetica", 9, QFont::Bold)); - header->setText(COL_NAME, "Name"); + header_item->setText(COL_NAME, "Name"); - header->setText(COL_BEGIN, "Begin, ms"); + header_item->setText(COL_BEGIN, "Begin, ms"); - header->setText(COL_DURATION, "Duration"); - header->setText(COL_SELF_DURATION, "Self Dur."); - //header->setToolTip(COL_SELF_DURATION, ""); - header->setText(COL_DURATION_SUM_PER_PARENT, "Tot. Dur./Parent"); - header->setText(COL_DURATION_SUM_PER_FRAME, "Tot. Dur./Frame"); - header->setText(COL_DURATION_SUM_PER_THREAD, "Tot. Dur./Thread"); + header_item->setText(COL_DURATION, "Duration"); + header_item->setText(COL_SELF_DURATION, "Self Dur."); + //header_item->setToolTip(COL_SELF_DURATION, ""); + header_item->setText(COL_DURATION_SUM_PER_PARENT, "Tot. Dur./Parent"); + header_item->setText(COL_DURATION_SUM_PER_FRAME, "Tot. Dur./Frame"); + header_item->setText(COL_DURATION_SUM_PER_THREAD, "Tot. Dur./Thread"); - header->setText(COL_SELF_DURATION_PERCENT, "Self %"); - header->setText(COL_PERCENT_PER_PARENT, "% / Parent"); - header->setText(COL_PERCENT_PER_FRAME, "% / Frame"); - header->setText(COL_PERCENT_SUM_PER_FRAME, "Tot. % / Frame"); - header->setText(COL_PERCENT_SUM_PER_PARENT, "Tot. % / Parent"); - header->setText(COL_PERCENT_SUM_PER_THREAD, "Tot. % / Thread"); + header_item->setText(COL_SELF_DURATION_PERCENT, "Self %"); + header_item->setText(COL_PERCENT_PER_PARENT, "% / Parent"); + header_item->setText(COL_PERCENT_PER_FRAME, "% / Frame"); + header_item->setText(COL_PERCENT_SUM_PER_FRAME, "Tot. % / Frame"); + header_item->setText(COL_PERCENT_SUM_PER_PARENT, "Tot. % / Parent"); + header_item->setText(COL_PERCENT_SUM_PER_THREAD, "Tot. % / Thread"); - header->setText(COL_END, "End, ms"); + header_item->setText(COL_END, "End, ms"); - header->setText(COL_MIN_PER_FRAME, "Min dur./Frame"); - header->setText(COL_MAX_PER_FRAME, "Max dur./Frame"); - header->setText(COL_AVERAGE_PER_FRAME, "Average dur./Frame"); - header->setText(COL_NCALLS_PER_FRAME, "N Calls/Frame"); + header_item->setText(COL_MIN_PER_FRAME, "Min dur./Frame"); + header_item->setText(COL_MAX_PER_FRAME, "Max dur./Frame"); + header_item->setText(COL_AVERAGE_PER_FRAME, "Average dur./Frame"); + header_item->setText(COL_NCALLS_PER_FRAME, "N Calls/Frame"); - header->setText(COL_MIN_PER_PARENT, "Min dur./Parent"); - header->setText(COL_MAX_PER_PARENT, "Max dur./Parent"); - header->setText(COL_AVERAGE_PER_PARENT, "Average dur./Parent"); - header->setText(COL_NCALLS_PER_PARENT, "N Calls/Parent"); + header_item->setText(COL_MIN_PER_PARENT, "Min dur./Parent"); + header_item->setText(COL_MAX_PER_PARENT, "Max dur./Parent"); + header_item->setText(COL_AVERAGE_PER_PARENT, "Average dur./Parent"); + header_item->setText(COL_NCALLS_PER_PARENT, "N Calls/Parent"); - header->setText(COL_MIN_PER_THREAD, "Min dur./Thread"); - header->setText(COL_MAX_PER_THREAD, "Max dur./Thread"); - header->setText(COL_AVERAGE_PER_THREAD, "Average dur./Thread"); - header->setText(COL_NCALLS_PER_THREAD, "N Calls/Thread"); + header_item->setText(COL_MIN_PER_THREAD, "Min dur./Thread"); + header_item->setText(COL_MAX_PER_THREAD, "Max dur./Thread"); + header_item->setText(COL_AVERAGE_PER_THREAD, "Average dur./Thread"); + header_item->setText(COL_NCALLS_PER_THREAD, "N Calls/Thread"); - setHeaderItem(header); + auto color = QColor::fromRgb(::profiler::colors::DeepOrange900); + header_item->setForeground(COL_MIN_PER_THREAD, color); + header_item->setForeground(COL_MAX_PER_THREAD, color); + header_item->setForeground(COL_AVERAGE_PER_THREAD, color); + header_item->setForeground(COL_NCALLS_PER_THREAD, color); + header_item->setForeground(COL_PERCENT_SUM_PER_THREAD, color); + header_item->setForeground(COL_DURATION_SUM_PER_THREAD, color); + + color = QColor::fromRgb(::profiler::colors::Blue900); + header_item->setForeground(COL_MIN_PER_FRAME, color); + header_item->setForeground(COL_MAX_PER_FRAME, color); + header_item->setForeground(COL_AVERAGE_PER_FRAME, color); + header_item->setForeground(COL_NCALLS_PER_FRAME, color); + header_item->setForeground(COL_PERCENT_SUM_PER_FRAME, color); + header_item->setForeground(COL_DURATION_SUM_PER_FRAME, color); + header_item->setForeground(COL_PERCENT_PER_FRAME, color); + + color = QColor::fromRgb(::profiler::colors::Teal900); + header_item->setForeground(COL_MIN_PER_PARENT, color); + header_item->setForeground(COL_MAX_PER_PARENT, color); + header_item->setForeground(COL_AVERAGE_PER_PARENT, color); + header_item->setForeground(COL_NCALLS_PER_PARENT, color); + header_item->setForeground(COL_PERCENT_SUM_PER_PARENT, color); + header_item->setForeground(COL_DURATION_SUM_PER_PARENT, color); + header_item->setForeground(COL_PERCENT_PER_PARENT, color); + + setHeaderItem(header_item); connect(&EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::selectedThreadChanged, this, &This::onSelectedThreadChange); connect(&EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::selectedBlockChanged, this, &This::onSelectedBlockChange); @@ -329,9 +359,11 @@ void EasyTreeWidget::contextMenuEvent(QContextMenuEvent* _event) { action = menu.addAction("Expand all"); connect(action, &QAction::triggered, this, &This::onExpandAllClicked); + { QIcon icon(":/Expand"); if (!icon.isNull()) action->setIcon(icon); } action = menu.addAction("Collapse all"); connect(action, &QAction::triggered, this, &This::onCollapseAllClicked); + { QIcon icon(":/Collapse"); if (!icon.isNull()) action->setIcon(icon); } if (item != nullptr && col >= 0) { @@ -339,9 +371,11 @@ void EasyTreeWidget::contextMenuEvent(QContextMenuEvent* _event) action = menu.addAction("Expand all children"); connect(action, &QAction::triggered, this, &This::onExpandAllChildrenClicked); + { QIcon icon(":/Expand"); if (!icon.isNull()) action->setIcon(icon); } action = menu.addAction("Collapse all children"); connect(action, &QAction::triggered, this, &This::onCollapseAllChildrenClicked); + { QIcon icon(":/Collapse"); if (!icon.isNull()) action->setIcon(icon); } } menu.addSeparator(); @@ -351,6 +385,13 @@ void EasyTreeWidget::contextMenuEvent(QContextMenuEvent* _event) action->setCheckable(true); action->setChecked(m_bColorRows); connect(action, &QAction::triggered, this, &This::onColorizeRowsTriggered); + if (m_bColorRows) { + auto f = action->font(); + f.setBold(true); + action->setFont(f); + { QIcon icon(":/Color"); if (!icon.isNull()) action->setIcon(icon); } + } + else { QIcon icon(":/NoColor"); if (!icon.isNull()) action->setIcon(icon); } if (item != nullptr && item->parent() != nullptr) { diff --git a/profiler_gui/common_types.h b/profiler_gui/common_types.h index 4c2e3c4..8c9e63e 100644 --- a/profiler_gui/common_types.h +++ b/profiler_gui/common_types.h @@ -37,6 +37,7 @@ #include #include #include +#include #include "profiler/reader.h" ////////////////////////////////////////////////////////////////////////// @@ -281,6 +282,23 @@ inline int percent(::profiler::timestamp_t _partial, ::profiler::timestamp_t _to ////////////////////////////////////////////////////////////////////////// +inline QFont EFont(QFont::StyleHint _hint, const char* _family, int _size, int _weight = -1) +{ + QFont f; + f.setStyleHint(_hint, QFont::PreferMatch); + f.setFamily(_family); + f.setPointSize(_size); + f.setWeight(_weight); + return f; +} + +inline QFont EFont(const char* _family, int _size, int _weight = -1) +{ + return EFont(QFont::Helvetica, _family, _size, _weight); +} + +////////////////////////////////////////////////////////////////////////// + } // END of namespace profiler_gui. //////////////////////////////////////////////////////////////////////////