Salome HOME
3fd85eca51973ba86a699c18fac48415def72c54
[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 XGUI_MainWindow::XGUI_MainWindow(QWidget* parent)
28     : QMainWindow(parent), 
29     myObjectBrowser(0), 
30     myPythonConsole(0)
31 {
32   setWindowTitle(tr("WINDOW_TITLE"));
33   myMenuBar = new XGUI_MainMenu(this);
34
35   QDockWidget* aDoc = new QDockWidget(this);
36   aDoc->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
37   aDoc->setWindowTitle(tr("OBJECT_BROWSER_TITLE"));
38
39   myObjectBrowser = new XGUI_ObjectsBrowser(aDoc);
40   //myObjectBrowser->setColumnCount(1);
41   //myObjectBrowser->setHeaderHidden(true);
42   aDoc->setWidget(myObjectBrowser);
43   addDockWidget(Qt::LeftDockWidgetArea, aDoc);
44   //aDoc->hide();
45
46   QMdiArea* aMdiArea = new QMdiArea(this);
47   setCentralWidget(aMdiArea);
48
49   myViewer = new XGUI_Viewer(this);
50
51   //fillObjectBrowser();
52   //addPropertyPanel();
53 }
54
55 XGUI_MainWindow::~XGUI_MainWindow(void)
56 {
57 }
58
59 //******************************************************
60 QMdiArea* XGUI_MainWindow::mdiArea() const
61 {
62   return static_cast<QMdiArea*>(centralWidget());
63 }
64
65 //******************************************************
66 void XGUI_MainWindow::showObjectBrowser()
67 {
68   myObjectBrowser->parentWidget()->show();
69 }
70
71 //******************************************************
72 void XGUI_MainWindow::hideObjectBrowser()
73 {
74   myObjectBrowser->parentWidget()->hide();
75 }
76
77 //******************************************************
78 void XGUI_MainWindow::showPythonConsole()
79 {
80   if (!myPythonConsole) {
81
82     QDockWidget* aDoc = new QDockWidget(this);
83     aDoc->setFeatures(QDockWidget::AllDockWidgetFeatures | QDockWidget::DockWidgetVerticalTitleBar);
84     aDoc->setMinimumHeight(0);
85     aDoc->setWindowTitle("Console");
86     myPythonConsole = new PyConsole_EnhConsole( aDoc, new PyConsole_EnhInterp());
87     //myPythonConsole = new QTextEdit(aDoc);
88     //myPythonConsole->setGeometry(0,0,200, 50);
89     //myPythonConsole->setText(">>>");
90     aDoc->setWidget(myPythonConsole);
91     //myPythonConsole->setMinimumHeight(0);
92     addDockWidget(Qt::TopDockWidgetArea, aDoc);
93     tabifyDockWidget(myMenuBar->getLastDockWindow(), aDoc);
94   }
95   myPythonConsole->parentWidget()->show();
96 }
97
98 //******************************************************
99 void XGUI_MainWindow::hidePythonConsole()
100 {
101   if (myPythonConsole)
102     myPythonConsole->parentWidget()->hide();
103 }
104
105
106
107 //******************************************************
108
109 // TEST FUNCTIONS
110
111 //******************************************************
112 /*void XGUI_MainWindow::fillObjectBrowser()
113 {
114   QStringList aNames;
115   aNames << "Parameters" << "Constructions";
116   aNames << "Part 1" << "Part 2" << "Part 3";
117   aNames << "Properties";
118
119   QStringList aIcons;
120   aIcons << ":pictures/params_folder.png";
121   aIcons << ":pictures/constr_folder.png";
122   aIcons << ":pictures/part_ico.png";
123   aIcons << ":pictures/part_ico.png";
124   aIcons << ":pictures/part_ico.png";
125   aIcons << ":pictures/properties.png";
126
127   QList<QTreeWidgetItem*> aItems;
128   foreach(QString aName, aNames)
129   {
130     QTreeWidgetItem* aItem = new QTreeWidgetItem(myObjectBrowser);
131     aItem->setText(0, aName);
132     aItems.append(aItem);
133   }
134   for(int i = 0; i < aItems.length(); i++) {
135     aItems[i]->setIcon(0, QIcon(aIcons[i]));
136   }
137   myObjectBrowser->addTopLevelItems(aItems);
138
139   for(int i = 2; i < 5; i++) {
140     QTreeWidgetItem* aItem = new QTreeWidgetItem(aItems[i]);
141     aItem->setText(0, "Parameters");
142     aItem->setIcon(0, QIcon(":pictures/params_folder.png"));
143
144     aItem = new QTreeWidgetItem(aItems[i]);
145     aItem->setText(0, "Construction");
146     aItem->setIcon(0, QIcon(":pictures/constr_folder.png"));
147
148     aItem = new QTreeWidgetItem(aItems[i]);
149     aItem->setText(0, "Bodies");
150     aItem->setIcon(0, QIcon(":pictures/part_ico.png"));
151
152     aItem = new QTreeWidgetItem(aItems[i]);
153     aItem->setText(0, "Features");
154     aItem->setIcon(0, QIcon(":pictures/features.png"));
155   }
156 }*/
157
158 void XGUI_MainWindow::addPropertyPanel()
159 {
160   QDockWidget* aPropPanel = new QDockWidget(this);
161   aPropPanel->setWindowTitle("Point");
162
163   QWidget* aContent = new QWidget(aPropPanel);
164   QVBoxLayout* aMainLay = new QVBoxLayout(aContent);
165   aMainLay->setContentsMargins(3, 3, 3, 3);
166   aPropPanel->setWidget(aContent);
167
168   /*QWidget* aNameWgt = new QWidget(aContent);
169    QHBoxLayout* aNameLay = new QHBoxLayout(aNameWgt);
170    aNameLay->setContentsMargins(0,0,0,0);
171    aMainLay->addWidget(aNameWgt);
172
173    aNameLay->addWidget(new QLabel("Name", aNameWgt));
174    aNameLay->addWidget(new QLineEdit(aNameWgt));*/
175
176   QComboBox* aCombo = new QComboBox(aContent);
177   aCombo->addItem("By coordinates");
178   aMainLay->addWidget(aCombo);
179
180   QWidget* aGrpBox1 = new QWidget(aContent);
181   //aGrpBox1->setFlat(true);
182   QFormLayout* aFrmLay = new QFormLayout(aGrpBox1);
183   aFrmLay->setContentsMargins(0, 6, 0, 0);
184   aMainLay->addWidget(aGrpBox1);
185
186   QLabel* aLbl = new QLabel(aGrpBox1);
187   aLbl->setPixmap(QPixmap(":pictures/x_point.png"));
188   aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));
189
190   aLbl = new QLabel(aGrpBox1);
191   aLbl->setPixmap(QPixmap(":pictures/y_point.png"));
192   aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));
193
194   aLbl = new QLabel(aGrpBox1);
195   aLbl->setPixmap(QPixmap(":pictures/z_point.png"));
196   aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));
197
198   /*    aGrpBox1 = new QGroupBox("Normal vector", aContent);
199    aGrpBox1->setFlat(true);
200    aFrmLay = new QFormLayout(aGrpBox1);
201    aFrmLay->setContentsMargins(0, 6, 0, 0);
202    aMainLay->addWidget(aGrpBox1);
203
204    aLbl = new QLabel(aGrpBox1);
205    aLbl->setPixmap(QPixmap(":pictures/x_size.png"));
206    aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));
207
208    aLbl = new QLabel(aGrpBox1);
209    aLbl->setPixmap(QPixmap(":pictures/y_size.png"));
210    aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));
211
212    aLbl = new QLabel(aGrpBox1);
213    aLbl->setPixmap(QPixmap(":pictures/z_size.png"));
214    aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));*/
215
216   aMainLay->addStretch(1);
217
218   QFrame* aFrm = new QFrame(aContent);
219   aFrm->setFrameStyle(QFrame::Sunken);
220   aFrm->setFrameShape(QFrame::Panel);
221   QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm);
222   aBtnLay->setContentsMargins(0, 0, 0, 0);
223   aMainLay->addWidget(aFrm);
224
225   QPushButton* aBtn = new QPushButton(QIcon(":pictures/button_help.png"), "", aFrm);
226   aBtn->setFlat(true);
227   aBtnLay->addWidget(aBtn);
228   aBtnLay->addStretch(1);
229   aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm);
230   aBtn->setFlat(true);
231   aBtnLay->addWidget(aBtn);
232   aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm);
233   aBtn->setFlat(true);
234   aBtnLay->addWidget(aBtn);
235
236   addDockWidget(Qt::RightDockWidgetArea, aPropPanel);
237 }