Salome HOME
Property pannel connected with the model through the ModuelBase dll.
[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 #include <QAction>
27
28 XGUI_MainWindow::XGUI_MainWindow(QWidget* parent)
29     : QMainWindow(parent), 
30     myObjectBrowser(NULL),
31     myPythonConsole(NULL),
32     myPropertyPanelDock(NULL)
33 {
34   setWindowTitle(tr("New Geom"));
35   myMenuBar = new XGUI_MainMenu(this);
36
37   QMdiArea* aMdiArea = new QMdiArea(this);
38   setCentralWidget(aMdiArea);
39
40   myViewer = new XGUI_Viewer(this);
41
42   createDockWidgets();
43 }
44
45 XGUI_MainWindow::~XGUI_MainWindow(void)
46 {
47 }
48
49 //******************************************************
50 QMdiArea* XGUI_MainWindow::mdiArea() const
51 {
52   return static_cast<QMdiArea*>(centralWidget());
53 }
54
55 //******************************************************
56 void XGUI_MainWindow::showObjectBrowser()
57 {
58   myObjectBrowser->parentWidget()->show();
59 }
60
61 //******************************************************
62 void XGUI_MainWindow::hideObjectBrowser()
63 {
64   myObjectBrowser->parentWidget()->hide();
65 }
66
67 //******************************************************
68 void XGUI_MainWindow::showPythonConsole()
69 {
70   if (!myPythonConsole) {
71
72     QDockWidget* aDoc = new QDockWidget(this);
73     aDoc->setFeatures(QDockWidget::AllDockWidgetFeatures | QDockWidget::DockWidgetVerticalTitleBar);
74     aDoc->setMinimumHeight(0);
75     aDoc->setWindowTitle("Console");
76     myPythonConsole = new PyConsole_EnhConsole( aDoc, new PyConsole_EnhInterp());
77     //myPythonConsole = new QTextEdit(aDoc);
78     //myPythonConsole->setGeometry(0,0,200, 50);
79     //myPythonConsole->setText(">>>");
80     aDoc->setWidget(myPythonConsole);
81     //myPythonConsole->setMinimumHeight(0);
82     addDockWidget(Qt::TopDockWidgetArea, aDoc);
83     tabifyDockWidget(myMenuBar->getLastDockWindow(), aDoc);
84   }
85   myPythonConsole->parentWidget()->show();
86 }
87
88 //******************************************************
89 void XGUI_MainWindow::hidePythonConsole()
90 {
91   if (myPythonConsole)
92     myPythonConsole->parentWidget()->hide();
93 }
94
95 void XGUI_MainWindow::showPropertyPanel()
96 {
97   QAction* aViewAct = myPropertyPanelDock->toggleViewAction();
98   aViewAct->setEnabled(true);
99   myPropertyPanelDock->show();
100   myPropertyPanelDock->raise();
101 }
102
103 void XGUI_MainWindow::hidePropertyPanel()
104 {
105   QAction* aViewAct = myPropertyPanelDock->toggleViewAction();
106   aViewAct->setEnabled(false);
107   myPropertyPanelDock->hide();
108 }
109
110 /*
111  * Creates dock widgets, places them in corresponding area
112  * and tabifies if necessary.
113  */
114 void XGUI_MainWindow::createDockWidgets()
115 {
116   QDockWidget* aObjDock = createObjectBrowser();
117   addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
118   myPropertyPanelDock = createPropertyPanel();
119   addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanelDock);
120   hidePropertyPanel(); //<! Invisible by default
121
122   tabifyDockWidget(aObjDock, myPropertyPanelDock);
123 }
124
125
126 QDockWidget* XGUI_MainWindow::createPropertyPanel()
127 {
128   QDockWidget* aPropPanel = new QDockWidget(this);
129   aPropPanel->setWindowTitle(tr("Property Panel"));
130
131   QWidget* aContent = new QWidget(aPropPanel);
132   QVBoxLayout* aMainLay = new QVBoxLayout(aContent);
133   aMainLay->setContentsMargins(3, 3, 3, 3);
134   aPropPanel->setWidget(aContent);
135
136   QWidget* aCustomWidget = new QWidget(aContent);
137   aCustomWidget->setObjectName("property_panel_widget");
138   aMainLay->addWidget(aCustomWidget);
139   aMainLay->addStretch(1);
140
141   QFrame* aFrm = new QFrame(aContent);
142   aFrm->setFrameStyle(QFrame::Sunken);
143   aFrm->setFrameShape(QFrame::Panel);
144   QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm);
145   aBtnLay->setContentsMargins(0, 0, 0, 0);
146   aMainLay->addWidget(aFrm);
147
148   QPushButton* aBtn = new QPushButton(QIcon(":pictures/button_help.png"), "", aFrm);
149   aBtn->setFlat(true);
150   aBtnLay->addWidget(aBtn);
151   aBtnLay->addStretch(1);
152   aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm);
153   aBtn->setObjectName("property_panel_ok");
154   aBtn->setFlat(true);
155   aBtnLay->addWidget(aBtn);
156   aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm);
157   aBtn->setObjectName("property_panel_cancel");
158   aBtn->setFlat(true);
159   aBtnLay->addWidget(aBtn);
160
161   return aPropPanel;
162 }
163
164 QDockWidget* XGUI_MainWindow::createObjectBrowser()
165 {
166   QDockWidget* aObjDock = new QDockWidget(this);
167   aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
168   aObjDock->setWindowTitle(tr("Object browser"));
169   myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
170   //myObjectBrowser->setColumnCount(1);
171   //myObjectBrowser->setHeaderHidden(true);
172   aObjDock->setWidget(myObjectBrowser);
173 //  fillObjectBrowser();
174   return aObjDock;
175 }