mirror of
https://github.com/tnodir/fort
synced 2024-11-15 10:55:10 +00:00
UI: Refactor menu's widget relayout
This commit is contained in:
parent
af6218419e
commit
6cdfaea1e2
@ -47,6 +47,7 @@ SOURCES += \
|
|||||||
form/controls/labelspincombo.cpp \
|
form/controls/labelspincombo.cpp \
|
||||||
form/controls/listview.cpp \
|
form/controls/listview.cpp \
|
||||||
form/controls/mainwindow.cpp \
|
form/controls/mainwindow.cpp \
|
||||||
|
form/controls/menuwidget.cpp \
|
||||||
form/controls/plaintextedit.cpp \
|
form/controls/plaintextedit.cpp \
|
||||||
form/controls/sidebutton.cpp \
|
form/controls/sidebutton.cpp \
|
||||||
form/controls/spinbox.cpp \
|
form/controls/spinbox.cpp \
|
||||||
@ -242,6 +243,7 @@ HEADERS += \
|
|||||||
form/controls/labelspincombo.h \
|
form/controls/labelspincombo.h \
|
||||||
form/controls/listview.h \
|
form/controls/listview.h \
|
||||||
form/controls/mainwindow.h \
|
form/controls/mainwindow.h \
|
||||||
|
form/controls/menuwidget.h \
|
||||||
form/controls/plaintextedit.h \
|
form/controls/plaintextedit.h \
|
||||||
form/controls/sidebutton.h \
|
form/controls/sidebutton.h \
|
||||||
form/controls/spinbox.h \
|
form/controls/spinbox.h \
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "labeldoublespin.h"
|
#include "labeldoublespin.h"
|
||||||
#include "labelspin.h"
|
#include "labelspin.h"
|
||||||
#include "labelspincombo.h"
|
#include "labelspincombo.h"
|
||||||
|
#include "menuwidget.h"
|
||||||
#include "sidebutton.h"
|
#include "sidebutton.h"
|
||||||
#include "spinbox.h"
|
#include "spinbox.h"
|
||||||
|
|
||||||
@ -176,13 +177,15 @@ QMenu *ControlUtil::createMenuByLayout(QBoxLayout *layout, QWidget *parent)
|
|||||||
{
|
{
|
||||||
auto menu = createMenu(parent);
|
auto menu = createMenu(parent);
|
||||||
|
|
||||||
auto menuWidget = new QWidget();
|
auto menuWidget = new MenuWidget();
|
||||||
menuWidget->setLayout(layout);
|
menuWidget->setLayout(layout);
|
||||||
|
|
||||||
auto wa = new QWidgetAction(menu);
|
auto wa = new QWidgetAction(menu);
|
||||||
wa->setDefaultWidget(menuWidget);
|
wa->setDefaultWidget(menuWidget);
|
||||||
menu->addAction(wa);
|
menu->addAction(wa);
|
||||||
|
|
||||||
|
menu->connect(menuWidget, &MenuWidget::layoutRequested, [=] { relayoutMenu(menu, wa); });
|
||||||
|
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
21
src/ui/form/controls/menuwidget.cpp
Normal file
21
src/ui/form/controls/menuwidget.cpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include "menuwidget.h"
|
||||||
|
|
||||||
|
#include <QEvent>
|
||||||
|
|
||||||
|
MenuWidget::MenuWidget(QWidget *parent) : QWidget(parent) { }
|
||||||
|
|
||||||
|
bool MenuWidget::event(QEvent *event)
|
||||||
|
{
|
||||||
|
const QEvent::Type type = event->type();
|
||||||
|
const bool res = QWidget::event(event);
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case QEvent::LayoutRequest: {
|
||||||
|
emit layoutRequested();
|
||||||
|
} break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
20
src/ui/form/controls/menuwidget.h
Normal file
20
src/ui/form/controls/menuwidget.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#ifndef MENUWIDGET_H
|
||||||
|
#define MENUWIDGET_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
class MenuWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit MenuWidget(QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void layoutRequested();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool event(QEvent *event) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MENUWIDGET_H
|
@ -158,8 +158,6 @@ void ZonesSelector::createZonesMenu()
|
|||||||
|
|
||||||
m_menuLayout->addWidget(cb);
|
m_menuLayout->addWidget(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
ControlUtil::relayoutMenu(m_menuZones);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZonesSelector::updateZonesMenu()
|
void ZonesSelector::updateZonesMenu()
|
||||||
|
Loading…
Reference in New Issue
Block a user