From 1fc01ac1c722d79e1c86e7acd0862532fdacf63e Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Wed, 5 Oct 2016 13:55:34 +0200 Subject: [PATCH] ScxmlEditor: Inline the ShapeGroupWidget ui creation Change-Id: I519716e73a5d2c0c50642d65f8312e671a0e1595 Reviewed-by: Alessandro Portale --- src/plugins/scxmleditor/common/common.pri | 1 - .../scxmleditor/common/shapegroupwidget.cpp | 46 +++-- .../scxmleditor/common/shapegroupwidget.h | 11 +- .../scxmleditor/common/shapegroupwidget.ui | 157 ------------------ src/plugins/scxmleditor/scxmleditor.qbs | 1 - 5 files changed, 41 insertions(+), 175 deletions(-) delete mode 100644 src/plugins/scxmleditor/common/shapegroupwidget.ui diff --git a/src/plugins/scxmleditor/common/common.pri b/src/plugins/scxmleditor/common/common.pri index c7febda9939..f68a64ce37b 100644 --- a/src/plugins/scxmleditor/common/common.pri +++ b/src/plugins/scxmleditor/common/common.pri @@ -63,7 +63,6 @@ FORMS += \ $$PWD/magnifier.ui \ $$PWD/navigatorslider.ui \ $$PWD/search.ui \ - $$PWD/shapegroupwidget.ui \ $$PWD/shapestoolbox.ui \ $$PWD/stateview.ui \ $$PWD/statistics.ui \ diff --git a/src/plugins/scxmleditor/common/shapegroupwidget.cpp b/src/plugins/scxmleditor/common/shapegroupwidget.cpp index b6ebaf00249..17edf2fb873 100644 --- a/src/plugins/scxmleditor/common/shapegroupwidget.cpp +++ b/src/plugins/scxmleditor/common/shapegroupwidget.cpp @@ -30,18 +30,18 @@ #include #include +#include +#include + using namespace ScxmlEditor::PluginInterface; using namespace ScxmlEditor::Common; ShapeGroupWidget::ShapeGroupWidget(ShapeProvider *shapeProvider, int groupIndex, QWidget *parent) : QWidget(parent) { - m_ui.setupUi(this); - m_ui.m_closeButton->setIcon(Utils::Icons::COLLAPSE_TOOLBAR.icon()); - auto layout = new Utils::FlowLayout; - layout->setContentsMargins(0, 0, 0, 0); + createUi(); - m_ui.m_title->setText(shapeProvider->groupTitle(groupIndex)); + m_title->setText(shapeProvider->groupTitle(groupIndex)); for (int i = 0; i < shapeProvider->shapeCount(groupIndex); ++i) { auto button = new DragShapeButton(this); @@ -49,15 +49,35 @@ ShapeGroupWidget::ShapeGroupWidget(ShapeProvider *shapeProvider, int groupIndex, button->setIcon(shapeProvider->shapeIcon(groupIndex, i)); button->setShapeInfo(groupIndex, i); - layout->addWidget(button); + m_content->layout()->addWidget(button); } - connect(m_ui.m_closeButton, &QToolButton::clicked, this, [this]() { - m_ui.m_content->setVisible(!m_ui.m_content->isVisible()); - m_ui.m_closeButton->setIcon(m_ui.m_content->isVisible() - ? Utils::Icons::COLLAPSE_TOOLBAR.icon() - : Utils::Icons::EXPAND_TOOLBAR.icon()); + connect(m_closeButton, &QToolButton::clicked, this, [this]() { + m_content->setVisible(!m_content->isVisible()); + m_closeButton->setIcon(m_content->isVisible() + ? Utils::Icons::COLLAPSE_TOOLBAR.icon() + : Utils::Icons::EXPAND_TOOLBAR.icon()); }); - - m_ui.m_content->setLayout(layout); +} + +void ShapeGroupWidget::createUi() +{ + m_title = new QLabel; + m_title->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); + + m_closeButton = new QToolButton; + m_closeButton->setIcon(Utils::Icons::COLLAPSE_TOOLBAR.icon()); + + auto toolBar = new QToolBar; + toolBar->addWidget(m_title); + toolBar->addWidget(m_closeButton); + + m_content = new QWidget; + m_content->setLayout(new Utils::FlowLayout); + + setLayout(new QVBoxLayout); + layout()->setMargin(0); + layout()->setSpacing(0); + layout()->addWidget(toolBar); + layout()->addWidget(m_content); } diff --git a/src/plugins/scxmleditor/common/shapegroupwidget.h b/src/plugins/scxmleditor/common/shapegroupwidget.h index e8a82149c1f..c6f1fda8b0c 100644 --- a/src/plugins/scxmleditor/common/shapegroupwidget.h +++ b/src/plugins/scxmleditor/common/shapegroupwidget.h @@ -25,10 +25,11 @@ #pragma once -#include "ui_shapegroupwidget.h" - #include +QT_FORWARD_DECLARE_CLASS(QLabel) +QT_FORWARD_DECLARE_CLASS(QToolButton) + namespace ScxmlEditor { namespace PluginInterface { class ShapeProvider; } @@ -43,7 +44,11 @@ public: explicit ShapeGroupWidget(PluginInterface::ShapeProvider *shapeProvider, int groupIndex, QWidget *parent = nullptr); private: - Ui::ShapeGroupWidget m_ui; + void createUi(); + + QLabel *m_title = nullptr; + QToolButton *m_closeButton = nullptr; + QWidget *m_content = nullptr; }; } // namespace Common diff --git a/src/plugins/scxmleditor/common/shapegroupwidget.ui b/src/plugins/scxmleditor/common/shapegroupwidget.ui deleted file mode 100644 index 41a20880ab0..00000000000 --- a/src/plugins/scxmleditor/common/shapegroupwidget.ui +++ /dev/null @@ -1,157 +0,0 @@ - - - ScxmlEditor::Common::ShapeGroupWidget - - - - 0 - 0 - 113 - 184 - - - - Form - - - - 2 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - - 0 - 30 - - - - - 16777215 - 16777215 - - - - - 0 - 0 - - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Plain - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - - 0 - 0 - - - - Shape title - - - 5 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - false - - - true - - - Qt::NoArrow - - - - - - - - - - Qt::Vertical - - - - 20 - 0 - - - - - - - - - - - - diff --git a/src/plugins/scxmleditor/scxmleditor.qbs b/src/plugins/scxmleditor/scxmleditor.qbs index 58d4db5afe9..8b98b35556b 100644 --- a/src/plugins/scxmleditor/scxmleditor.qbs +++ b/src/plugins/scxmleditor/scxmleditor.qbs @@ -74,7 +74,6 @@ QtcPlugin { "colorthemedialog.ui", "navigatorslider.ui", "search.ui", - "shapegroupwidget.ui", "shapestoolbox.ui", "stateview.ui", "statistics.ui",