From 196e9b5ccfef56a00ce7764708469685613616c9 Mon Sep 17 00:00:00 2001 From: sbh Date: Fri, 4 Apr 2014 12:21:55 +0400 Subject: [PATCH] Minor GUI tweaks according to MPV's notes + re-factoring: * Posibility to fetch from xml icons, tooltips added to property panel's widgets. * Property panel's margins and spacers corrected * XGUI_MainWindow re-factoring: pices of code for dock widgets creation extracted as functions --- src/Config/Config_WidgetAPI.cpp | 20 +++- src/Config/Config_WidgetAPI.h | 6 ++ src/Config/plugin-PartSet.xml | 9 +- src/PartSet/PartSet_Module.cpp | 4 +- src/XGUI/XGUI_MainWindow.cpp | 166 ++++++++++++-------------------- src/XGUI/XGUI_MainWindow.h | 4 +- src/XGUI/XGUI_WidgetFactory.cpp | 15 ++- src/XGUI/XGUI_Workshop.cpp | 1 + 8 files changed, 110 insertions(+), 115 deletions(-) diff --git a/src/Config/Config_WidgetAPI.cpp b/src/Config/Config_WidgetAPI.cpp index 38b4476ad..14d5fa2aa 100644 --- a/src/Config/Config_WidgetAPI.cpp +++ b/src/Config/Config_WidgetAPI.cpp @@ -29,12 +29,13 @@ void Config_WidgetAPI::reset() if(aRoot) { myCurrentNode = aRoot->children; } - } bool Config_WidgetAPI::nextWidget() { - myCurrentNode = myCurrentNode->next; + if(myCurrentNode) { + myCurrentNode = myCurrentNode->next; + } return myCurrentNode != NULL; } @@ -57,6 +58,21 @@ std::string Config_WidgetAPI::getProperty(const char* thePropName) return result; } +std::string Config_WidgetAPI::widgetTooltip() +{ + return getProperty("tooltip"); +} + +std::string Config_WidgetAPI::widgetIcon() +{ + return getProperty("icon"); +} + +std::string Config_WidgetAPI::widgetLabel() +{ + return getProperty("label"); +} + bool Config_WidgetAPI::isNode(xmlNodePtr theNode, const char* theNodeName, ...) { bool result = false; diff --git a/src/Config/Config_WidgetAPI.h b/src/Config/Config_WidgetAPI.h index 0bcb4a454..59f44f2b8 100644 --- a/src/Config/Config_WidgetAPI.h +++ b/src/Config/Config_WidgetAPI.h @@ -34,7 +34,13 @@ public: void reset(); bool nextWidget(); + std::string widgetType(); + + std::string widgetIcon(); + std::string widgetLabel(); + std::string widgetTooltip(); + std::string getProperty(const char* thePropName); protected: diff --git a/src/Config/plugin-PartSet.xml b/src/Config/plugin-PartSet.xml index 76c67c75c..decbb89ef 100644 --- a/src/Config/plugin-PartSet.xml +++ b/src/Config/plugin-PartSet.xml @@ -9,9 +9,12 @@ - - - + + + diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 7f87997da..f8e60b9e4 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -40,9 +40,7 @@ void PartSet_Module::createFeatures() void PartSet_Module::featureCreated(XGUI_Command* theFeature) { QString aFtId = theFeature->getId(); - if (aFtId == "new_point") { - theFeature->connectTo(this, SLOT(onCommandTriggered())); - } + theFeature->connectTo(this, SLOT(onCommandTriggered())); } void PartSet_Module::onCommandTriggered() diff --git a/src/XGUI/XGUI_MainWindow.cpp b/src/XGUI/XGUI_MainWindow.cpp index 0e6ee35b8..40a0d26cf 100644 --- a/src/XGUI/XGUI_MainWindow.cpp +++ b/src/XGUI/XGUI_MainWindow.cpp @@ -23,6 +23,7 @@ #include #include + XGUI_MainWindow::XGUI_MainWindow(QWidget* parent) : QMainWindow(parent), myObjectBrowser(0), @@ -31,23 +32,12 @@ XGUI_MainWindow::XGUI_MainWindow(QWidget* parent) setWindowTitle(tr("WINDOW_TITLE")); myMenuBar = new XGUI_MainMenu(this); - QDockWidget* aDoc = new QDockWidget(this); - aDoc->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - aDoc->setWindowTitle(tr("OBJECT_BROWSER_TITLE")); - myObjectBrowser = new QTreeWidget(aDoc); - myObjectBrowser->setColumnCount(1); - myObjectBrowser->setHeaderHidden(true); - aDoc->setWidget(myObjectBrowser); - addDockWidget(Qt::LeftDockWidgetArea, aDoc); - //aDoc->hide(); - QMdiArea* aMdiArea = new QMdiArea(this); setCentralWidget(aMdiArea); myViewer = new XGUI_Viewer(this); - //fillObjectBrowser(); - //addPropertyPanel(); + createDockWidgets(); } XGUI_MainWindow::~XGUI_MainWindow(void) @@ -100,7 +90,69 @@ void XGUI_MainWindow::hidePythonConsole() myPythonConsole->parentWidget()->hide(); } +/* + * Creates dock widgets, places them in corresponding area + * and tabifies if necessary. + */ +void XGUI_MainWindow::createDockWidgets() +{ + QDockWidget* aObjDock = createObjectBrowser(); + addDockWidget(Qt::LeftDockWidgetArea, aObjDock); + QDockWidget* aPropPanelDock = createPropertyPanel(); + addDockWidget(Qt::LeftDockWidgetArea, aPropPanelDock); + + tabifyDockWidget(aPropPanelDock, aObjDock); +} + + +QDockWidget* XGUI_MainWindow::createPropertyPanel() +{ + QDockWidget* aPropPanel = new QDockWidget(this); + aPropPanel->setWindowTitle(tr("Property Panel")); + + QWidget* aContent = new QWidget(aPropPanel); + QVBoxLayout* aMainLay = new QVBoxLayout(aContent); + aMainLay->setContentsMargins(3, 3, 3, 3); + aPropPanel->setWidget(aContent); + + QWidget* aCustomWidget = new QWidget(aContent); + aCustomWidget->setObjectName("PropertyPanelWidget"); + aMainLay->addWidget(aCustomWidget); + aMainLay->addStretch(1); + + QFrame* aFrm = new QFrame(aContent); + aFrm->setFrameStyle(QFrame::Sunken); + aFrm->setFrameShape(QFrame::Panel); + QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm); + aBtnLay->setContentsMargins(0, 0, 0, 0); + aMainLay->addWidget(aFrm); + + QPushButton* aBtn = new QPushButton(QIcon(":pictures/button_help.png"), "", aFrm); + aBtn->setFlat(true); + aBtnLay->addWidget(aBtn); + aBtnLay->addStretch(1); + aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm); + aBtn->setFlat(true); + aBtnLay->addWidget(aBtn); + aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm); + aBtn->setFlat(true); + aBtnLay->addWidget(aBtn); + + return aPropPanel; +} +QDockWidget* XGUI_MainWindow::createObjectBrowser() +{ + QDockWidget* aObjDock = new QDockWidget(this); + aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + aObjDock->setWindowTitle(tr("OBJECT_BROWSER_TITLE")); + myObjectBrowser = new QTreeWidget(aObjDock); + myObjectBrowser->setColumnCount(1); + myObjectBrowser->setHeaderHidden(true); + aObjDock->setWidget(myObjectBrowser); +// fillObjectBrowser(); + return aObjDock; +} //****************************************************** @@ -152,93 +204,3 @@ void XGUI_MainWindow::fillObjectBrowser() aItem->setIcon(0, QIcon(":pictures/features.png")); } } - -void XGUI_MainWindow::addPropertyPanel() -{ - QDockWidget* aPropPanel = new QDockWidget(this); - aPropPanel->setWindowTitle("Property Panel"); - - QWidget* aContent = new QWidget(aPropPanel); - QVBoxLayout* aMainLay = new QVBoxLayout(aContent); - aMainLay->setContentsMargins(3, 3, 3, 3); - aPropPanel->setWidget(aContent); - - QWidget* aCustomWidget = new QWidget(aContent); - aCustomWidget->setObjectName("PropertyPanelWidget"); - aMainLay->addWidget(aCustomWidget); - - /* - QWidget* aNameWgt = new QWidget(aContent); - QHBoxLayout* aNameLay = new QHBoxLayout(aNameWgt); - aNameLay->setContentsMargins(0,0,0,0); - aMainLay->addWidget(aNameWgt); - - aNameLay->addWidget(new QLabel("Name", aNameWgt)); - aNameLay->addWidget(new QLineEdit(aNameWgt)); - */ - -/* Moved into PartSetModule by sbh - QComboBox* aCombo = new QComboBox(aContent); - aCombo->addItem("By coordinates"); - aMainLay->addWidget(aCombo); - - QWidget* aGrpBox1 = new QWidget(aContent); - QFormLayout* aFrmLay = new QFormLayout(aGrpBox1); - aFrmLay->setContentsMargins(0, 6, 0, 0); - aMainLay->addWidget(aGrpBox1); - - QLabel* aLbl = new QLabel(aGrpBox1); - aLbl->setPixmap(QPixmap(":pictures/x_point.png")); - aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1)); - - aLbl = new QLabel(aGrpBox1); - aLbl->setPixmap(QPixmap(":pictures/y_point.png")); - aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1)); - - aLbl = new QLabel(aGrpBox1); - aLbl->setPixmap(QPixmap(":pictures/z_point.png")); - aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1)); - */ - - /* - aGrpBox1 = new QGroupBox("Normal vector", aContent); - aGrpBox1->setFlat(true); - aFrmLay = new QFormLayout(aGrpBox1); - aFrmLay->setContentsMargins(0, 6, 0, 0); - aMainLay->addWidget(aGrpBox1); - - aLbl = new QLabel(aGrpBox1); - aLbl->setPixmap(QPixmap(":pictures/x_size.png")); - aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1)); - - aLbl = new QLabel(aGrpBox1); - aLbl->setPixmap(QPixmap(":pictures/y_size.png")); - aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1)); - - aLbl = new QLabel(aGrpBox1); - aLbl->setPixmap(QPixmap(":pictures/z_size.png")); - aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1)); - */ - - aMainLay->addStretch(1); - - QFrame* aFrm = new QFrame(aContent); - aFrm->setFrameStyle(QFrame::Sunken); - aFrm->setFrameShape(QFrame::Panel); - QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm); - aBtnLay->setContentsMargins(0, 0, 0, 0); - aMainLay->addWidget(aFrm); - - QPushButton* aBtn = new QPushButton(QIcon(":pictures/button_help.png"), "", aFrm); - aBtn->setFlat(true); - aBtnLay->addWidget(aBtn); - aBtnLay->addStretch(1); - aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm); - aBtn->setFlat(true); - aBtnLay->addWidget(aBtn); - aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm); - aBtn->setFlat(true); - aBtnLay->addWidget(aBtn); - - addDockWidget(Qt::RightDockWidgetArea, aPropPanel); -} diff --git a/src/XGUI/XGUI_MainWindow.h b/src/XGUI/XGUI_MainWindow.h index ec5da26a6..0806b5863 100644 --- a/src/XGUI/XGUI_MainWindow.h +++ b/src/XGUI/XGUI_MainWindow.h @@ -41,9 +41,11 @@ public: void hidePythonConsole(); private: + void createDockWidgets(); + QDockWidget* createObjectBrowser(); + QDockWidget* createPropertyPanel(); //!! For test purposes only void fillObjectBrowser(); - void addPropertyPanel(); XGUI_MainMenu* myMenuBar; QTreeWidget* myObjectBrowser; diff --git a/src/XGUI/XGUI_WidgetFactory.cpp b/src/XGUI/XGUI_WidgetFactory.cpp index 9cc69af89..b2551c62c 100644 --- a/src/XGUI/XGUI_WidgetFactory.cpp +++ b/src/XGUI/XGUI_WidgetFactory.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #ifdef _DEBUG #include @@ -36,6 +37,7 @@ void XGUI_WidgetFactory::fillWidget(QWidget* theParent) } QVBoxLayout* aWidgetLay = new QVBoxLayout(theParent); + aWidgetLay->setContentsMargins(0, 0, 0, 0); do { std::string aWdgType = myWidgetApi->widgetType(); QWidget* aWidget = NULL; @@ -50,7 +52,6 @@ void XGUI_WidgetFactory::fillWidget(QWidget* theParent) aWidgetLay->addWidget(aWidget); } } while(myWidgetApi->nextWidget()); - aWidgetLay->addStretch(1); theParent->setLayout(aWidgetLay); } @@ -58,8 +59,12 @@ QWidget* XGUI_WidgetFactory::valueWidget() { QWidget* result = new QWidget(); QHBoxLayout* aControlLay = new QHBoxLayout(result); - QString aLabelVal = qs(myWidgetApi->getProperty("label")); - QLabel* aLabel = new QLabel(aLabelVal); + aControlLay->setContentsMargins(0, 0, 0, 0); + QString aLabelText = qs(myWidgetApi->widgetLabel()); + QString aLabelIcon = qs(myWidgetApi->widgetIcon()); + QLabel* aLabel = new QLabel(aLabelText); + aLabel->setPixmap(QPixmap(aLabelIcon)); + aControlLay->addWidget(aLabel); QDoubleSpinBox* aBox = new QDoubleSpinBox(result); bool isOk = false; @@ -79,8 +84,10 @@ QWidget* XGUI_WidgetFactory::valueWidget() if (isOk) { aBox->setValue(aDefVal); } + QString aTTip = qs(myWidgetApi->widgetTooltip()); + aBox->setToolTip(aTTip); aControlLay->addWidget(aBox); - aControlLay->addStretch(); + aControlLay->setStretch(1, 1); result->setLayout(aControlLay); return result; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index b083080f9..55e16fcf8 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -177,6 +177,7 @@ void XGUI_Workshop::fillPropertyPanel(const Config_WidgetMessage* theMessage) #endif return; } + qDeleteAll(aPropWidget->children()); std::string aXml = theMessage->xmlRepresentation(); XGUI_WidgetFactory aFactory = XGUI_WidgetFactory(aXml); aFactory.fillWidget(aPropWidget); -- 2.39.2