From ed2b5d27b1d1ad4c6f7b8c652c5e352c5ce28d06 Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Sun, 20 Mar 2022 00:06:12 +0100 Subject: [PATCH] Rudimentary top bar implementation with QToolButton QToolButton seems a better fit because it already provides most of the options we need. Maybe the top bar should become a fully-fledged QToolBar. See #940. --- client/gui-qt/page_game.cpp | 2 ++ client/gui-qt/top_bar.cpp | 20 +++++++++++--------- client/gui-qt/top_bar.h | 3 ++- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/client/gui-qt/page_game.cpp b/client/gui-qt/page_game.cpp index a3b1c1b14e..fdd0421474 100644 --- a/client/gui-qt/page_game.cpp +++ b/client/gui-qt/page_game.cpp @@ -161,7 +161,9 @@ pageGame::pageGame(QWidget *parent) auto page_game_layout = new QVBoxLayout; page_game_layout->addWidget(top_bar_wdg); + page_game_layout->setStretchFactor(top_bar_wdg, 0); page_game_layout->addWidget(game_tab_widget); + page_game_layout->setStretchFactor(game_tab_widget, 1); page_game_layout->setContentsMargins(0, 0, 0, 0); page_game_layout->setSpacing(0); setLayout(page_game_layout); diff --git a/client/gui-qt/top_bar.cpp b/client/gui-qt/top_bar.cpp index 5c48f8cc70..87ff7736a5 100644 --- a/client/gui-qt/top_bar.cpp +++ b/client/gui-qt/top_bar.cpp @@ -60,7 +60,7 @@ void reduce_mod(int &mod, int &val) top_bar_widget::top_bar_widget(QPixmap *pix, const QString &label, const QString &pg, pfcn_bool func, standards type) - : QWidget(), blink(false), keep_blinking(false), disabled(false), + : QToolButton(), blink(false), keep_blinking(false), disabled(false), standard(type), page(pg), hover(false), right_click(nullptr), wheel_down(nullptr), wheel_up(nullptr), left_click(func), def_pixmap(pix), desc(label) @@ -69,16 +69,17 @@ top_bar_widget::top_bar_widget(QPixmap *pix, const QString &label, def_pixmap = new QPixmap(5, 5); } - sfont = fcFont::instance()->getFont(fonts::notify_label); + setText(label); + setToolButtonStyle(Qt::ToolButtonTextBesideIcon); setContextMenuPolicy(Qt::CustomContextMenu); + + if (def_pixmap) { + setIcon(QIcon(*def_pixmap)); + } + timer = new QTimer; timer->setSingleShot(false); timer->setInterval(700); - sfont.setCapitalization(QFont::SmallCaps); - sfont.setItalic(true); - info_font = QFont(sfont); - info_font.setBold(true); - info_font.setItalic(false); connect(timer, &QTimer::timeout, this, &top_bar_widget::sblink); } @@ -104,7 +105,7 @@ void top_bar_widget::setPixmap(QPixmap *pm) /** Sets custom text visible on top of sidewidget */ -void top_bar_widget::setCustomLabels(const QString &l) { custom_label = l; } +void top_bar_widget::setCustomLabels(const QString &l) { setText(l); } /** Sets tooltip for sidewidget @@ -249,6 +250,8 @@ void top_bar_widget::paintEvent(QPaintEvent *event) } p.end(); + + QToolButton::paintEvent(event); } /** @@ -405,7 +408,6 @@ top_bar::top_bar() layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); setLayout(layout); - setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored); setProperty("top_bar", true); } diff --git a/client/gui-qt/top_bar.h b/client/gui-qt/top_bar.h index b6768de087..e5d91274aa 100644 --- a/client/gui-qt/top_bar.h +++ b/client/gui-qt/top_bar.h @@ -10,6 +10,7 @@ #pragma once // Qt +#include #include class QHBoxLayout; @@ -32,7 +33,7 @@ void top_bar_show_map(bool nothing); /*************************************************************************** Class representing single widget(icon) on top_bar ***************************************************************************/ -class top_bar_widget : public QWidget { +class top_bar_widget : public QToolButton { Q_OBJECT public: