Salome HOME
99d2422e9c32dced0a0ce88ac985f384998ed7f5
[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(NULL),
32     myPythonConsole(NULL),
33     myPropertyPanelDock(NULL)
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     //myPythonConsole = new QTextEdit(aDoc);
79     //myPythonConsole->setGeometry(0,0,200, 50);
80     //myPythonConsole->setText(">>>");
81     aDoc->setWidget(myPythonConsole);
82     //myPythonConsole->setMinimumHeight(0);
83     addDockWidget(Qt::TopDockWidgetArea, aDoc);
84     tabifyDockWidget(myMenuBar->getLastDockWindow(), aDoc);
85   }
86   myPythonConsole->parentWidget()->show();
87 }
88
89 //******************************************************
90 void XGUI_MainWindow::hidePythonConsole()
91 {
92   if (myPythonConsole)
93     myPythonConsole->parentWidget()->hide();
94 }
95
96 void XGUI_MainWindow::showPropertyPanel()
97 {
98   QAction* aViewAct = myPropertyPanelDock->toggleViewAction();
99   //<! Restore ability to close panel from the window's menu
100   aViewAct->setEnabled(true);
101   myPropertyPanelDock->show();
102   myPropertyPanelDock->raise();
103 }
104
105 void XGUI_MainWindow::hidePropertyPanel()
106 {
107   QAction* aViewAct = myPropertyPanelDock->toggleViewAction();
108   //<! Do not allow to show empty property panel
109   aViewAct->setEnabled(false);
110   myPropertyPanelDock->hide();
111 }
112
113 /*
114  * Creates dock widgets, places them in corresponding area
115  * and tabifies if necessary.
116  */
117 void XGUI_MainWindow::createDockWidgets()
118 {
119   QDockWidget* aObjDock = createObjectBrowser();
120   addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
121   myPropertyPanelDock = createPropertyPanel();
122   addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanelDock);
123   hidePropertyPanel(); //<! Invisible by default
124
125   tabifyDockWidget(aObjDock, myPropertyPanelDock);
126 }
127
128
129 QDockWidget* XGUI_MainWindow::createPropertyPanel()
130 {
131   QDockWidget* aPropPanel = new QDockWidget(this);
132   aPropPanel->setWindowTitle(tr("Property Panel"));
133   aPropPanel->setObjectName(XGUI::PROP_PANEL);
134
135   QWidget* aContent = new QWidget(aPropPanel);
136   QVBoxLayout* aMainLay = new QVBoxLayout(aContent);
137   aMainLay->setContentsMargins(3, 3, 3, 3);
138   aPropPanel->setWidget(aContent);
139
140   QWidget* aCustomWidget = new QWidget(aContent);
141   aCustomWidget->setObjectName(XGUI::PROP_PANEL_WDG);
142   aMainLay->addWidget(aCustomWidget);
143   aMainLay->addStretch(1);
144
145   QFrame* aFrm = new QFrame(aContent);
146   aFrm->setFrameStyle(QFrame::Sunken);
147   aFrm->setFrameShape(QFrame::Panel);
148   QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm);
149   aBtnLay->setContentsMargins(0, 0, 0, 0);
150   aMainLay->addWidget(aFrm);
151
152   QPushButton* aBtn = new QPushButton(QIcon(":pictures/button_help.png"), "", aFrm);
153   aBtn->setFlat(true);
154   aBtnLay->addWidget(aBtn);
155   aBtnLay->addStretch(1);
156   aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm);
157   aBtn->setObjectName(XGUI::PROP_PANEL_OK);
158   aBtn->setFlat(true);
159   aBtnLay->addWidget(aBtn);
160   aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm);
161   aBtn->setObjectName(XGUI::PROP_PANEL_CANCEL);
162   aBtn->setFlat(true);
163   aBtnLay->addWidget(aBtn);
164
165   return aPropPanel;
166 }
167
168 QDockWidget* XGUI_MainWindow::createObjectBrowser()
169 {
170   QDockWidget* aObjDock = new QDockWidget(this);
171   aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
172   aObjDock->setWindowTitle(tr("Object browser"));
173   myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
174   //myObjectBrowser->setColumnCount(1);
175   //myObjectBrowser->setHeaderHidden(true);
176   aObjDock->setWidget(myObjectBrowser);
177 //  fillObjectBrowser();
178   return aObjDock;
179 }