From 8209f551a69fcb2382e5f897f9064d7b632e4f8f Mon Sep 17 00:00:00 2001 From: Viktor UZLOV Date: Wed, 18 Nov 2020 11:02:22 +0300 Subject: [PATCH] InfoPanel introduction v1. Add Helper to GEOM and SMESH. --- src/LightApp/LightApp_Application.cxx | 15 +++ src/LightApp/LightApp_Application.h | 3 + src/Qtx/CMakeLists.txt | 4 +- src/Qtx/QtxInfoPanel.cxx | 157 ++++++++++++++++++++++++++ src/Qtx/QtxInfoPanel.h | 70 ++++++++++++ 5 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 src/Qtx/QtxInfoPanel.cxx create mode 100644 src/Qtx/QtxInfoPanel.h diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 983648dcf..6a62b70e4 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -88,6 +88,7 @@ #include #include #include +#include #include #include #include @@ -1441,6 +1442,11 @@ SUIT_DataBrowser* LightApp_Application::objectBrowser() return qobject_cast( dockWindow( WT_ObjectBrowser ) ); } +QtxInfoPanel* LightApp_Application::infoPanel() +{ + return qobject_cast( dockWindow( WT_InfoPanel )); +} + /*! \return Log Window */ @@ -1793,6 +1799,7 @@ void LightApp_Application::onStudyCreated( SUIT_Study* theStudy ) } getWindow( WT_ObjectBrowser ); + getWindow( WT_InfoPanel ); loadDockWindowsState(); @@ -1824,6 +1831,7 @@ void LightApp_Application::onStudyOpened( SUIT_Study* theStudy ) } getWindow( WT_ObjectBrowser ); + getWindow( WT_InfoPanel ); loadDockWindowsState(); @@ -2129,6 +2137,13 @@ QWidget* LightApp_Application::createWindow( const int flag ) wid = ob; ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) ); } + else if ( flag == WT_InfoPanel) + { + QtxInfoPanel* ipanel = new QtxInfoPanel( desktop() ); + ipanel->setObjectName( "infoPanel" ); + ipanel->setWindowTitle( tr( "INFO_PANEL" ) ); + wid = ipanel; + } #ifndef DISABLE_PYCONSOLE else if ( flag == WT_PyConsole ) { diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index 448294867..b2df3e1d5 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -40,6 +40,7 @@ #include class LogWindow; +class QtxInfoPanel; #ifndef DISABLE_PYCONSOLE class PyConsole_Console; class PyConsole_Interp; @@ -75,6 +76,7 @@ class LIGHTAPP_EXPORT LightApp_Application : public CAM_Application, public SUIT public: typedef enum { WT_ObjectBrowser, + WT_InfoPanel, #ifndef DISABLE_PYCONSOLE WT_PyConsole, #endif @@ -110,6 +112,7 @@ public: LogWindow* logWindow(); SUIT_DataBrowser* objectBrowser(); + QtxInfoPanel* infoPanel(); #ifndef DISABLE_PYCONSOLE PyConsole_Console* pythonConsole(const bool force = false); #endif diff --git a/src/Qtx/CMakeLists.txt b/src/Qtx/CMakeLists.txt index 74f9edfd1..09835fef8 100644 --- a/src/Qtx/CMakeLists.txt +++ b/src/Qtx/CMakeLists.txt @@ -33,7 +33,7 @@ SET(_link_LIBRARIES ${QT_LIBRARIES} ${OPENGL_LIBRARIES}) # --- headers --- # header files / to be processed by moc -SET(_moc_HEADERS +SET(_moc_HEADERS QtxAction.h QtxActionGroup.h QtxActionMenuMgr.h @@ -53,6 +53,7 @@ SET(_moc_HEADERS QtxFontEdit.h QtxGridBox.h QtxGroupBox.h + QtxInfoPanel.h QtxIntSpinBox.h QtxIntSpinSlider.h QtxListAction.h @@ -146,6 +147,7 @@ SET(_other_SOURCES QtxFontEdit.cxx QtxGridBox.cxx QtxGroupBox.cxx + QtxInfoPanel.cxx QtxIntSpinBox.cxx QtxIntSpinSlider.cxx QtxListAction.cxx diff --git a/src/Qtx/QtxInfoPanel.cxx b/src/Qtx/QtxInfoPanel.cxx new file mode 100644 index 000000000..8f4ef80d0 --- /dev/null +++ b/src/Qtx/QtxInfoPanel.cxx @@ -0,0 +1,157 @@ +// Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : InfoPanel.cxx +// Author : Viktor UZLOV, Open CASCADE S.A.S. (viktor.uzlov@opencascade.com) +// + +#include "QtxInfoPanel.h" + +#include +#include +#include + +QtxInfoPanel::QtxInfoPanel( QWidget* parent ) + : QWidget( parent ) +{ + tbar = new QToolBar(); + tbar->setOrientation(Qt::Vertical); + tbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + QVBoxLayout* layout = new QVBoxLayout(this); + layout->setMargin( 0 ); + layout->addWidget(tbar); +} + +QtxInfoPanel::~QtxInfoPanel() +{ +} + +int QtxInfoPanel::addLabel( const QString& text, Qt::Alignment alignment, const int groupId ) +{ + QLabel *label = new QLabel(text); + label->setAlignment(alignment); + label->setWordWrap(true); + + int id_new = generateId(); + QToolBar* tb = getToolBar(groupId); + QAction* q = tb->addWidget(label); + q->setProperty("id", id_new); + alignLeft(tb->layout()); + + return id_new; +} + +int QtxInfoPanel::addAction( QAction* action, const int groupId ) +{ + int id_new = generateId(); + action->setProperty("id", id_new); + QToolBar* tb = getToolBar(groupId); + tb->addAction(action); + alignLeft(tb->layout()); + + return id_new; +} + +int QtxInfoPanel::addGroup( const QString& text, const int groupId ) +{ + QGroupBox* box = new QGroupBox(text); + QVBoxLayout *vbox = new QVBoxLayout; + box->setLayout(vbox); + QToolBar* toolbar = new QToolBar(); + toolbar->setOrientation(Qt::Vertical); + toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + vbox->addWidget(toolbar); + + int id_new = generateId(); + QToolBar* tb = getToolBar(groupId); + QAction* q = tb->addWidget(box); + box->setProperty("id", id_new); + alignLeft(tb->layout()); + + return id_new; +} + +void QtxInfoPanel::remove(const int actionId, const int groupId) +{ + // TODO: Method don't delete QAction + QToolBar* tb = getToolBar(groupId); + tb->removeAction(getAction(actionId, groupId)); +} + +void QtxInfoPanel::clear(const int groupId) +{ + QToolBar* tb = getToolBar(groupId); + tb->clear(); +} + +void QtxInfoPanel::alignLeft( QLayout* lay ) +{ + for(int i = 0; i < lay->count(); ++i) + lay->itemAt(i)->setAlignment(Qt::AlignLeft); +} + +QToolBar* QtxInfoPanel::getToolBar( const int id ) +{ + if (id == -1) + return this->tbar; + for(QAction* a : this->tbar->actions()) + { + QWidget* w= this->tbar->widgetForAction(a); + if(w != NULL) + { + if (w->property("id").value() == id) + { + QGroupBox *qgb = dynamic_cast(w); + if (qgb) + return dynamic_cast(qgb->layout()->itemAt(0)->widget()); + } + } + } + return nullptr; +} + +QAction* QtxInfoPanel::getAction( const int actionId, const int groupId ) +{ + QToolBar* tb = getToolBar(groupId); + for(QAction* a : tb->actions()) + { + if(a->property("id").value() == actionId) + return a; + } + return nullptr; +} + +void QtxInfoPanel::setVisible( const int actionId, bool state, const int groupId ) +{ + getAction(actionId, groupId)->setVisible(state); +} + +void QtxInfoPanel::setEnabled( const int actionId, bool state, const int groupId ) +{ + getAction(actionId, groupId)->setEnabled(state); +} + +int QtxInfoPanel::generateId() const +{ + static int id = -100; + return --id; +} diff --git a/src/Qtx/QtxInfoPanel.h b/src/Qtx/QtxInfoPanel.h new file mode 100644 index 000000000..3e72473c1 --- /dev/null +++ b/src/Qtx/QtxInfoPanel.h @@ -0,0 +1,70 @@ +// Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : InfoPanel.h +// Author : Viktor UZLOV, Open CASCADE S.A.S. (viktor.uzlov@opencascade.com) +// +#ifndef QTXINFOPANEL_H +#define QTXINFOPANEL_H + +#include "Qtx.h" + +#include +#include +#include +#include + +#ifdef WIN32 +#pragma warning( disable:4251 ) +#endif + +class QAction; + +class QTX_EXPORT QtxInfoPanel : public QWidget +{ + Q_OBJECT + +public: + QtxInfoPanel( QWidget* = 0 ); + ~QtxInfoPanel(); + int addLabel( const QString&, Qt::Alignment = Qt::AlignLeft, const int = -1 ); + int addAction( QAction* action, const int = -1 ); + int addGroup( const QString&, const int = -1 ); + void setVisible( const int , bool, const int = -1 ); + void setEnabled( const int , bool, const int = -1 ); + void remove( const int, const int = -1); + void clear(const int = -1); + +private: + void alignLeft( QLayout* lay ); + QAction* getAction( const int, const int = -1 ); + QToolBar* getToolBar( const int ); + int generateId() const; + + QToolBar* tbar; +}; + +#ifdef WIN32 +#pragma warning( default:4251 ) +#endif + +#endif // QTXINFOPANEL_H -- 2.39.2