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