Mercurial > minori
changeset 171:03b444cbe55f
graph: improve? drawing the text
dark stylesheet: add borders on QMenu, taking inspiration from MPC-HC
media: fix warning about missing enums
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 27 Nov 2023 13:51:27 -0500 |
parents | c8375765f0fc |
children | 45a0967485f1 |
files | include/gui/widgets/graph.h rc/dark.qss src/track/media.cc |
diffstat | 3 files changed, 30 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/include/gui/widgets/graph.h Tue Nov 21 11:04:13 2023 -0500 +++ b/include/gui/widgets/graph.h Mon Nov 27 13:51:27 2023 -0500 @@ -15,7 +15,7 @@ #include <algorithm> #include <unordered_map> -template <typename T> +template<typename T> class Graph final : public QWidget { public: Graph(QWidget* parent = nullptr) : QWidget(parent) {}; @@ -24,38 +24,51 @@ protected: static constexpr int SPACING = 5; + + std::unordered_map<T, unsigned long> map = {}; + + QSize minimumSizeHint() const override { + QFontMetrics metric(font()); + /* wtf?... */ + return QSize(100, metric.height() * map.size() + (2 * (map.size() - 2))); + } + + /* helper functions */ inline unsigned long GetTotal() { unsigned long count = 0; + for (const auto& item : map) count += item.second; + return count; } - QSize minimumSizeHint() const override { - QFontMetrics metric(font()); - return QSize(100, metric.height() * map.size() + 2 * (map.size() - 2)); - }; + inline unsigned long GetTextWidth() { unsigned long ret = 0; QFontMetrics metric(font()); + for (const auto& item : map) { unsigned long width = metric.boundingRect(QString::number(item.first)).width(); if (width > ret) ret = width; } + return ret; } + void paintEvent(QPaintEvent* event) override { const QRect rect = event->rect(); const int height_of_each = QFontMetrics(font()).height(); const int size = GetTotal(); const int text_width = GetTextWidth(); - int current_y = rect.y(); + const int x = rect.x(); + int y = rect.y(); /* now we do the actual painting */ QPainter painter(this); for (const auto& item : map) { - painter.drawText(QRect(rect.x(), current_y, text_width, height_of_each), Qt::AlignRight | Qt::AlignVCenter, QString::number(item.first)); + painter.drawText(QRect(x + 2, y, text_width - 2, height_of_each), Qt::AlignRight | Qt::AlignVCenter, QString::number(item.first)); if (size) { painter.save(); @@ -64,16 +77,16 @@ painter.setPen(pen); QPainterPath path; - path.addRect(rect.x() + text_width + SPACING, current_y, (static_cast<double>(item.second)/size)*(rect.width() - text_width - SPACING), height_of_each); + path.addRect(x + text_width + 2 + SPACING, y, (static_cast<double>(item.second)/size) * (rect.width() - text_width + 2 - SPACING), height_of_each); painter.fillPath(path, Qt::darkBlue); painter.drawPath(path); painter.restore(); } - current_y += height_of_each + 2; + + y += height_of_each + 2; } - }; - std::unordered_map<T, unsigned long> map = {}; + } }; #endif // __gui__widgets__graph_h \ No newline at end of file
--- a/rc/dark.qss Tue Nov 21 11:04:13 2023 -0500 +++ b/rc/dark.qss Mon Nov 27 13:51:27 2023 -0500 @@ -198,7 +198,8 @@ QMenu { color: white; background-color: #353535; - margin: 0.18em; + padding: 0.18em 0.18em; + border: 0.09em solid #A0A0A0; } QMenu::icon { @@ -280,7 +281,7 @@ QHeaderView::section:checked { color: white; - background-color: #2A82DA; + background-color: #808080; } /* Note that this doesn't work for QTreeView unless the header is clickable */ @@ -289,5 +290,5 @@ QHeaderView::section::horizontal::only-one:hover, QHeaderView::section::vertical::first:hover, QHeaderView::section::vertical::only-one:hover { - border: 0.04em solid #2A82DA; + background-color: #353535; }