UI: Refactor menu's widget relayout

This commit is contained in:
Nodir Temirkhodjaev 2023-12-22 11:17:45 +03:00
parent af6218419e
commit 6cdfaea1e2
5 changed files with 47 additions and 3 deletions

View File

@ -47,6 +47,7 @@ SOURCES += \
form/controls/labelspincombo.cpp \
form/controls/listview.cpp \
form/controls/mainwindow.cpp \
form/controls/menuwidget.cpp \
form/controls/plaintextedit.cpp \
form/controls/sidebutton.cpp \
form/controls/spinbox.cpp \
@ -242,6 +243,7 @@ HEADERS += \
form/controls/labelspincombo.h \
form/controls/listview.h \
form/controls/mainwindow.h \
form/controls/menuwidget.h \
form/controls/plaintextedit.h \
form/controls/sidebutton.h \
form/controls/spinbox.h \

View File

@ -19,6 +19,7 @@
#include "labeldoublespin.h"
#include "labelspin.h"
#include "labelspincombo.h"
#include "menuwidget.h"
#include "sidebutton.h"
#include "spinbox.h"
@ -176,13 +177,15 @@ QMenu *ControlUtil::createMenuByLayout(QBoxLayout *layout, QWidget *parent)
{
auto menu = createMenu(parent);
auto menuWidget = new QWidget();
auto menuWidget = new MenuWidget();
menuWidget->setLayout(layout);
auto wa = new QWidgetAction(menu);
wa->setDefaultWidget(menuWidget);
menu->addAction(wa);
menu->connect(menuWidget, &MenuWidget::layoutRequested, [=] { relayoutMenu(menu, wa); });
return menu;
}

View 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;
}

View 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

View File

@ -158,8 +158,6 @@ void ZonesSelector::createZonesMenu()
m_menuLayout->addWidget(cb);
}
ControlUtil::relayoutMenu(m_menuZones);
}
void ZonesSelector::updateZonesMenu()