0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-28 01:04:41 +08:00

(profiler_gui) Bold and colorized font in EasyTreeWidget header

This commit is contained in:
Victor Zarubkin 2016-09-14 23:14:24 +03:00
parent 0166038e74
commit 9748d7274f
3 changed files with 92 additions and 43 deletions

View File

@ -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;

View File

@ -38,6 +38,7 @@
************************************************************************/
#include <QMenu>
#include <QHeaderView>
#include <QContextMenuEvent>
#include <QSignalBlocker>
#include <QSettings>
@ -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)
{

View File

@ -37,6 +37,7 @@
#include <unordered_map>
#include <QRgb>
#include <QString>
#include <QFont>
#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.
//////////////////////////////////////////////////////////////////////////