Skip to content

Commit

Permalink
Rudimentary top bar implementation with QToolButton
Browse files Browse the repository at this point in the history
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 longturn#940.
  • Loading branch information
lmoureaux committed Mar 25, 2022
1 parent 3e578d7 commit ed2b5d2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 2 additions & 0 deletions client/gui-qt/page_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 11 additions & 9 deletions client/gui-qt/top_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}

Expand All @@ -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
Expand Down Expand Up @@ -249,6 +250,8 @@ void top_bar_widget::paintEvent(QPaintEvent *event)
}

p.end();

QToolButton::paintEvent(event);
}

/**
Expand Down Expand Up @@ -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);
}

Expand Down
3 changes: 2 additions & 1 deletion client/gui-qt/top_bar.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#pragma once

// Qt
#include <QToolButton>
#include <QWidget>

class QHBoxLayout;
Expand All @@ -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:
Expand Down

0 comments on commit ed2b5d2

Please sign in to comment.