mirror of
https://github.com/tnodir/fort
synced 2024-11-15 08:56:22 +00:00
UI: HomeWindow: Add SideButton
This commit is contained in:
parent
4c7960902d
commit
a029a38b17
@ -47,6 +47,7 @@ SOURCES += \
|
||||
form/controls/listview.cpp \
|
||||
form/controls/mainwindow.cpp \
|
||||
form/controls/plaintextedit.cpp \
|
||||
form/controls/sidebutton.cpp \
|
||||
form/controls/spinbox.cpp \
|
||||
form/controls/spincombo.cpp \
|
||||
form/controls/tabbar.cpp \
|
||||
@ -233,6 +234,7 @@ HEADERS += \
|
||||
form/controls/listview.h \
|
||||
form/controls/mainwindow.h \
|
||||
form/controls/plaintextedit.h \
|
||||
form/controls/sidebutton.h \
|
||||
form/controls/spinbox.h \
|
||||
form/controls/spincombo.h \
|
||||
form/controls/tabbar.h \
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "labeldoublespin.h"
|
||||
#include "labelspin.h"
|
||||
#include "labelspincombo.h"
|
||||
#include "sidebutton.h"
|
||||
#include "spinbox.h"
|
||||
|
||||
QCheckBox *ControlUtil::createCheckBox(
|
||||
@ -70,6 +71,25 @@ QPushButton *ControlUtil::createButton(
|
||||
return c;
|
||||
}
|
||||
|
||||
QToolButton *ControlUtil::createSideButton(
|
||||
const QString &iconPath, const std::function<void()> &onClicked)
|
||||
{
|
||||
auto c = new SideButton();
|
||||
c->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
||||
c->setAutoRaise(true);
|
||||
c->setAutoExclusive(true);
|
||||
c->setCheckable(true);
|
||||
|
||||
c->setIcon(IconCache::icon(iconPath));
|
||||
|
||||
c->setIconSize(QSize(24, 24));
|
||||
c->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
|
||||
|
||||
c->connect(c, &QToolButton::clicked, onClicked);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
QToolButton *ControlUtil::createToolButton(
|
||||
const QString &iconPath, const std::function<void()> &onClicked)
|
||||
{
|
||||
|
@ -39,6 +39,8 @@ public:
|
||||
static QPushButton *createButton(
|
||||
const QString &iconPath, const std::function<void()> &onClicked);
|
||||
|
||||
static QToolButton *createSideButton(
|
||||
const QString &iconPath, const std::function<void()> &onClicked);
|
||||
static QToolButton *createToolButton(
|
||||
const QString &iconPath, const std::function<void()> &onClicked);
|
||||
static QToolButton *createFlatToolButton(
|
||||
|
33
src/ui/form/controls/sidebutton.cpp
Normal file
33
src/ui/form/controls/sidebutton.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include "sidebutton.h"
|
||||
|
||||
#include <QStylePainter>
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr int indicatorWidth = 4;
|
||||
|
||||
}
|
||||
|
||||
SideButton::SideButton(QWidget *parent) : QToolButton(parent) { }
|
||||
|
||||
QSize SideButton::sizeHint() const
|
||||
{
|
||||
QSize sh = QToolButton::sizeHint();
|
||||
sh.setWidth(sh.width() + indicatorWidth);
|
||||
return sh;
|
||||
}
|
||||
|
||||
void SideButton::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QToolButton::paintEvent(event);
|
||||
|
||||
if (!isChecked())
|
||||
return;
|
||||
|
||||
QRect r = rect();
|
||||
r.setX(r.width() - indicatorWidth);
|
||||
r.setWidth(indicatorWidth);
|
||||
|
||||
QPainter p(this);
|
||||
p.fillRect(r, QColor(0x3a, 0xd2, 0x4c));
|
||||
}
|
19
src/ui/form/controls/sidebutton.h
Normal file
19
src/ui/form/controls/sidebutton.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef SIDEBUTTON_H
|
||||
#define SIDEBUTTON_H
|
||||
|
||||
#include <QToolButton>
|
||||
|
||||
class SideButton : public QToolButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SideButton(QWidget *parent = nullptr);
|
||||
|
||||
QSize sizeHint() const override;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
};
|
||||
|
||||
#endif // SIDEBUTTON_H
|
@ -15,23 +15,6 @@
|
||||
#include "aboutpage.h"
|
||||
#include "updatespage.h"
|
||||
|
||||
namespace {
|
||||
|
||||
QToolButton *createToolButton(const QString &iconPath, const std::function<void()> &onClicked)
|
||||
{
|
||||
auto c = ControlUtil::createFlatToolButton(iconPath, onClicked);
|
||||
c->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
||||
c->setAutoExclusive(true);
|
||||
c->setCheckable(true);
|
||||
|
||||
c->setIconSize(QSize(24, 24));
|
||||
c->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
HomeMainPage::HomeMainPage(HomeController *ctrl, QWidget *parent) : HomeBasePage(ctrl, parent)
|
||||
{
|
||||
setupUi();
|
||||
@ -47,6 +30,7 @@ void HomeMainPage::setupUi()
|
||||
{
|
||||
auto layout = new QHBoxLayout();
|
||||
layout->setContentsMargins(6, 6, 6, 6);
|
||||
layout->setSpacing(0);
|
||||
|
||||
// Side Bar
|
||||
auto sideBar = setupSideBar();
|
||||
@ -55,7 +39,6 @@ void HomeMainPage::setupUi()
|
||||
setupStackedLayout();
|
||||
|
||||
layout->addLayout(sideBar);
|
||||
layout->addWidget(ControlUtil::createSeparator(Qt::Vertical));
|
||||
layout->addLayout(m_stackedLayout, 1);
|
||||
|
||||
this->setLayout(layout);
|
||||
@ -78,15 +61,12 @@ QLayout *HomeMainPage::setupSideBar()
|
||||
|
||||
void HomeMainPage::setupSideBarButtons()
|
||||
{
|
||||
QPalette palette;
|
||||
palette.setColor(QPalette::Highlight, QColor(0x26, 0x26, 0x26));
|
||||
|
||||
m_btUpdates = createToolButton(":/icons/arrow_refresh_small.png", [&] { setCurrentIndex(0); });
|
||||
m_btUpdates->setPalette(palette);
|
||||
m_btUpdates = ControlUtil::createSideButton(
|
||||
":/icons/arrow_refresh_small.png", [&] { setCurrentIndex(0); });
|
||||
m_btUpdates->setChecked(true);
|
||||
|
||||
m_btAbout = createToolButton(":/icons/information.png", [&] { setCurrentIndex(1); });
|
||||
m_btAbout->setPalette(palette);
|
||||
m_btAbout =
|
||||
ControlUtil::createSideButton(":/icons/information.png", [&] { setCurrentIndex(1); });
|
||||
}
|
||||
|
||||
void HomeMainPage::setupStackedLayout()
|
||||
|
Loading…
Reference in New Issue
Block a user