diff --git a/src/ui/FortFirewallUI.pro b/src/ui/FortFirewallUI.pro index 7ba189d3..4fbfc2a5 100644 --- a/src/ui/FortFirewallUI.pro +++ b/src/ui/FortFirewallUI.pro @@ -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 \ diff --git a/src/ui/form/controls/controlutil.cpp b/src/ui/form/controls/controlutil.cpp index bca664d8..41375249 100644 --- a/src/ui/form/controls/controlutil.cpp +++ b/src/ui/form/controls/controlutil.cpp @@ -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 &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 &onClicked) { diff --git a/src/ui/form/controls/controlutil.h b/src/ui/form/controls/controlutil.h index 4ea7d958..fca2b803 100644 --- a/src/ui/form/controls/controlutil.h +++ b/src/ui/form/controls/controlutil.h @@ -39,6 +39,8 @@ public: static QPushButton *createButton( const QString &iconPath, const std::function &onClicked); + static QToolButton *createSideButton( + const QString &iconPath, const std::function &onClicked); static QToolButton *createToolButton( const QString &iconPath, const std::function &onClicked); static QToolButton *createFlatToolButton( diff --git a/src/ui/form/controls/sidebutton.cpp b/src/ui/form/controls/sidebutton.cpp new file mode 100644 index 00000000..31145f76 --- /dev/null +++ b/src/ui/form/controls/sidebutton.cpp @@ -0,0 +1,33 @@ +#include "sidebutton.h" + +#include + +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)); +} diff --git a/src/ui/form/controls/sidebutton.h b/src/ui/form/controls/sidebutton.h new file mode 100644 index 00000000..74c38270 --- /dev/null +++ b/src/ui/form/controls/sidebutton.h @@ -0,0 +1,19 @@ +#ifndef SIDEBUTTON_H +#define SIDEBUTTON_H + +#include + +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 diff --git a/src/ui/form/home/pages/homemainpage.cpp b/src/ui/form/home/pages/homemainpage.cpp index cdf6d6ee..a3cedefc 100644 --- a/src/ui/form/home/pages/homemainpage.cpp +++ b/src/ui/form/home/pages/homemainpage.cpp @@ -15,23 +15,6 @@ #include "aboutpage.h" #include "updatespage.h" -namespace { - -QToolButton *createToolButton(const QString &iconPath, const std::function &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()