Salome HOME
updated copyright message
[modules/gui.git] / src / TreeData / DockWidgets.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // Author: Guillaume Boulant (EDF/R&D)
21
22 #include "DockWidgets.hxx"
23
24 // Qt includes
25 #include <QMainWindow>
26
27 // SALOME includes
28 #include <SUIT_Desktop.h>
29 #include <SUIT_DataBrowser.h>
30 #include <QtxTreeView.h>
31
32 namespace
33 {
34   QString toObjectName( const QString& s )
35   {
36     QStringList words = s.split( QRegExp("\\s+") );
37     QStringList result;
38     if ( words.count() > 0 )
39       result.append( words[0].left(1).toLower() + words[0].mid(1) );
40     for ( int i = 1; i < words.count(); i++ )
41       result.append( words[i].left(1).toUpper() + words[i].mid(1) );
42     return result.join( "" );
43   }
44 }
45
46 /*!
47  * This create a gui container to hold widgets dedicated to the XCAD
48  * data model. By default, the dock widgets are not visible. Use the
49  * show() method to control the visibility (usefull when activating
50  * and desactivating the module to show/hide the dock widgets).
51  *
52  * This class does not make any hypothesis on what will be embedded in
53  * the dock widgets (only that it is QTreeView). The QTreeView is
54  * defined elsewhere and is generaly rendering a tree model containing
55  * tree items.
56  */
57 DockWidgets::DockWidgets(SalomeApp_Application* salomeApp,
58                          bool tabify,
59                          const char * title) {
60   _salomeApp = salomeApp;
61
62   QMainWindow *parent = _salomeApp->desktop();
63   _dwDataPanel = new QDockWidget(parent);
64   _dwDataPanel->setVisible(false);
65   _dwDataPanel->setWindowTitle(title);
66   _dwDataPanel->setObjectName(toObjectName(title)+"Dock");
67   parent->addDockWidget(Qt::LeftDockWidgetArea, _dwDataPanel);
68   //
69   // At this step, the _dwDataPanel is located side by side with the object
70   // browser (or one over the other).
71   //
72   // It is possible to tabify the different dock widgets in one single
73   // tabbed widget. See the above example:
74   this->tabify(tabify);
75 }
76
77 void DockWidgets::tabify(bool tabify) {
78   if ( tabify ) {    
79     // We first get the object browser tree view, and then the
80     // associated DockWidget. Note that the tree view is a SALOME
81     // specific extention of the originate QTreeView and called
82     // QtxTreeView.
83     SUIT_DataBrowser* objectBrowser = _salomeApp->objectBrowser();
84     QtxTreeView* treeView = objectBrowser->treeView();
85     QWidget* pw = treeView->parentWidget();
86     QDockWidget* dwObjectBrowser = 0;
87     while ( pw && !dwObjectBrowser ) {
88       dwObjectBrowser = ::qobject_cast<QDockWidget*>( pw );
89       pw = pw->parentWidget();
90     };
91     QMainWindow *parent = _salomeApp->desktop();
92     parent->tabifyDockWidget(_dwDataPanel, dwObjectBrowser);
93     parent->setTabOrder(_dwDataPanel, dwObjectBrowser);
94     parent->setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North);
95   }
96   else {
97     // TO BE IMPLEMENTED
98   }
99 }
100
101 /*!
102  * This function controls the visibility of the dock widgets.
103  */
104 void DockWidgets::show(bool isVisible) {
105   _dwDataPanel->setVisible(isVisible);
106 }
107
108 /*!
109  * This function initializes the central part of the dock widget with
110  * a tree view that can hold a hierarchical data model.
111  */
112 void DockWidgets::setDataView(QTreeView * dataView) {
113   _tvDataView = dataView;
114   _tvDataView->setParent(_dwDataPanel);
115   _tvDataView->setMinimumHeight(200);
116   _dwDataPanel->setWidget(_tvDataView);
117 }
118
119 void DockWidgets::setPropertiesView(QTreeView * /*propertiesView*/) {
120   // Not implemented yet
121 }
122
123 /*!
124  * This function returns dock widget
125  */
126 QDockWidget * DockWidgets::getDockWidget() {
127   return _dwDataPanel;
128 }