Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[modules/shaper.git] / src / XGUI / XGUI_MainWindow.cpp
1 #include "XGUI_MainWindow.h"
2 #include "XGUI_Constants.h"
3 #include "XGUI_MainMenu.h"
4 #include "XGUI_ViewWindow.h"
5 #include "XGUI_Viewer.h"
6 #include "XGUI_ObjectsBrowser.h"
7
8 #include <PyConsole_Console.h>
9 #include <PyConsole_EnhInterp.h>
10
11 #include <QMdiArea>
12 #include <QTreeWidget>
13 #include <QDockWidget>
14 #include <QTextEdit>
15 #include <QLabel>
16 #include <QToolBar>
17 #include <QToolButton>
18 #include <QTreeWidgetItem>
19 #include <QLayout>
20 #include <QLineEdit>
21 #include <QGroupBox>
22 #include <QFormLayout>
23 #include <QDoubleSpinBox>
24 #include <QPushButton>
25 #include <QScrollArea>
26 #include <QComboBox>
27 #include <QAction>
28
29 XGUI_MainWindow::XGUI_MainWindow(QWidget* parent)
30     : QMainWindow(parent), 
31     myObjectBrowser(0),
32     myPythonConsole(0),
33     myPropertyPanelDock(0)
34 {
35   setWindowTitle(tr("New Geom"));
36   myMenuBar = new XGUI_MainMenu(this);
37
38   QMdiArea* aMdiArea = new QMdiArea(this);
39   setCentralWidget(aMdiArea);
40
41   myViewer = new XGUI_Viewer(this);
42
43   //createDockWidgets();
44 }
45
46 XGUI_MainWindow::~XGUI_MainWindow(void)
47 {
48 }
49
50 //******************************************************
51 QMdiArea* XGUI_MainWindow::mdiArea() const
52 {
53   return static_cast<QMdiArea*>(centralWidget());
54 }
55
56 //******************************************************
57 void XGUI_MainWindow::showObjectBrowser()
58 {
59   myObjectBrowser->parentWidget()->show();
60 }
61
62 //******************************************************
63 void XGUI_MainWindow::hideObjectBrowser()
64 {
65   myObjectBrowser->parentWidget()->hide();
66 }
67
68 //******************************************************
69 void XGUI_MainWindow::showPythonConsole()
70 {
71   if (!myPythonConsole) {
72
73     QDockWidget* aDoc = new QDockWidget(this);
74     aDoc->setFeatures(QDockWidget::AllDockWidgetFeatures | QDockWidget::DockWidgetVerticalTitleBar);
75     aDoc->setMinimumHeight(0);
76     aDoc->setWindowTitle("Console");
77     myPythonConsole = new PyConsole_EnhConsole( aDoc, new PyConsole_EnhInterp());
78     aDoc->setWidget(myPythonConsole);
79     addDockWidget(Qt::TopDockWidgetArea, aDoc);
80     tabifyDockWidget(myMenuBar->getLastDockWindow(), aDoc);
81   }
82   myPythonConsole->parentWidget()->show();
83 }
84
85 //******************************************************
86 void XGUI_MainWindow::hidePythonConsole()
87 {
88   if (myPythonConsole)
89     myPythonConsole->parentWidget()->hide();
90 }
91
92 void XGUI_MainWindow::showPropertyPanel()
93 {
94   QAction* aViewAct = myPropertyPanelDock->toggleViewAction();
95   //<! Restore ability to close panel from the window's menu
96   aViewAct->setEnabled(true);
97   myPropertyPanelDock->show();
98   myPropertyPanelDock->raise();
99 }
100
101 void XGUI_MainWindow::hidePropertyPanel()
102 {
103   QAction* aViewAct = myPropertyPanelDock->toggleViewAction();
104   //<! Do not allow to show empty property panel
105   aViewAct->setEnabled(false);
106   myPropertyPanelDock->hide();
107 }
108
109 /*
110  * Creates dock widgets, places them in corresponding area
111  * and tabifies if necessary.
112  */
113 void XGUI_MainWindow::createDockWidgets()
114 {
115   QDockWidget* aObjDock = createObjectBrowser();
116   addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
117   myPropertyPanelDock = createPropertyPanel();
118   addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanelDock);
119   hidePropertyPanel(); //<! Invisible by default
120   hideObjectBrowser();
121   tabifyDockWidget(aObjDock, myPropertyPanelDock);
122 }
123
124 void XGUI_MainWindow::setPropertyPannelTitle(const QString& theTitle)
125 {
126   myPropertyPanelDock->setWindowTitle(theTitle);
127 }
128
129
130 QDockWidget* XGUI_MainWindow::createPropertyPanel()
131 {
132   QDockWidget* aPropPanel = new QDockWidget(this);
133   aPropPanel->setWindowTitle(tr("Property Panel"));
134   QAction* aViewAct = aPropPanel->toggleViewAction();
135   aPropPanel->setObjectName(XGUI::PROP_PANEL);
136
137   QWidget* aContent = new QWidget(aPropPanel);
138   QVBoxLayout* aMainLay = new QVBoxLayout(aContent);
139   aMainLay->setContentsMargins(3, 3, 3, 3);
140   aPropPanel->setWidget(aContent);
141
142   QWidget* aCustomWidget = new QWidget(aContent);
143   aCustomWidget->setObjectName(XGUI::PROP_PANEL_WDG);
144   aMainLay->addWidget(aCustomWidget);
145   aMainLay->addStretch(1);
146
147   QFrame* aFrm = new QFrame(aContent);
148   aFrm->setFrameStyle(QFrame::Sunken);
149   aFrm->setFrameShape(QFrame::Panel);
150   QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm);
151   aBtnLay->setContentsMargins(0, 0, 0, 0);
152   aMainLay->addWidget(aFrm);
153
154   QPushButton* aBtn = new QPushButton(QIcon(":pictures/button_help.png"), "", aFrm);
155   aBtn->setFlat(true);
156   //connect(aBtn, SIGNAL(clicked()), this, SIGNAL(propertyHelpPressed()));
157   aBtnLay->addWidget(aBtn);
158   aBtnLay->addStretch(1);
159   aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm);
160   aBtn->setObjectName(XGUI::PROP_PANEL_OK);
161   aBtn->setFlat(true);
162   //connect(aBtn, SIGNAL(clicked()), this, SIGNAL(propertyOkPressed()));
163   aBtnLay->addWidget(aBtn);
164   aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm);
165   aBtn->setObjectName(XGUI::PROP_PANEL_CANCEL);
166   aBtn->setFlat(true);
167   //connect(aBtn, SIGNAL(clicked()), this, SIGNAL(propertyClosePressed()));
168   aBtnLay->addWidget(aBtn);
169
170   return aPropPanel;
171 }
172
173 QDockWidget* XGUI_MainWindow::createObjectBrowser()
174 {
175   QDockWidget* aObjDock = new QDockWidget(this);
176   aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
177   aObjDock->setWindowTitle(tr("Object browser"));
178   myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
179   aObjDock->setWidget(myObjectBrowser);
180   return aObjDock;
181 }