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_MainMenu.h"
3
4 #include <QMdiArea>
5 #include <QTreeWidget>
6 #include <QDockWidget>
7 #include <QTextEdit>
8 #include <QMdiSubWindow>
9 #include <QLabel>
10 #include <QToolBar>
11 #include <QToolButton>
12 #include <QAction>
13 #include <QTreeWidgetItem>
14 #include <QLayout>
15 #include <QLineEdit>
16 #include <QGroupBox>
17 #include <QFormLayout>
18 #include <QDoubleSpinBox>
19 #include <QPushButton>
20 #include <QScrollArea>
21
22 XGUI_MainWindow::XGUI_MainWindow(QWidget* parent) :
23     QMainWindow(parent), myObjectBrowser(0)
24 {
25     //menuBar();
26     myMenuBar = new XGUI_MainMenu(this);
27
28     QDockWidget* aDoc = new QDockWidget(this);
29     aDoc->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
30     aDoc->setWindowTitle(tr("OBJECT_BROWSER_TITLE"));
31     myObjectBrowser = new QTreeWidget(aDoc);
32     myObjectBrowser->setColumnCount(1);
33     myObjectBrowser->setHeaderHidden(true);
34     aDoc->setWidget(myObjectBrowser);
35     addDockWidget(Qt::LeftDockWidgetArea, aDoc);
36     //aDoc->hide();
37
38     aDoc = new QDockWidget(this);
39     aDoc->setFeatures(QDockWidget::AllDockWidgetFeatures | QDockWidget::DockWidgetVerticalTitleBar);
40     aDoc->setMinimumHeight(0);
41     aDoc->setWindowTitle("Console");
42     QTextEdit* aTextEdt = new QTextEdit(aDoc);
43     aTextEdt->setText(">>>");
44     aDoc->setWidget(aTextEdt);
45     aTextEdt->setMinimumHeight(0);
46     addDockWidget(Qt::BottomDockWidgetArea, aDoc);
47
48     QMdiArea* aMdiArea = new QMdiArea(this);
49     setCentralWidget(aMdiArea);
50
51     aMdiArea->addSubWindow(getSubWindow(), Qt::FramelessWindowHint);
52
53     fillObjectBrowser();
54     addPropertyPanel();
55 }
56
57
58 QWidget* XGUI_MainWindow::getSubWindow()
59 {
60     QMdiSubWindow* aSub = new QMdiSubWindow(this);
61     QLabel* aLbl = new QLabel(aSub);
62     aLbl->setFrameStyle(QFrame::Sunken);
63     aLbl->setFrameShape(QFrame::Panel);
64     aLbl->setPixmap(QPixmap(":pictures/ViewPort.png"));
65     aLbl->setScaledContents(true);
66     aSub->setWidget(aLbl);
67
68     QStringList aPictures;
69     aPictures<<":pictures/occ_view_camera_dump.png"<<":pictures/occ_view_style_switch.png";
70     aPictures<<":pictures/occ_view_triedre.png"<<":pictures/occ_view_fitall.png";
71     aPictures<<":pictures/occ_view_fitarea.png"<<":pictures/occ_view_zoom.png";
72     aPictures<<":pictures/occ_view_pan.png"<<":pictures/occ_view_glpan.png";
73     aPictures<<":pictures/occ_view_rotate.png"<<":pictures/occ_view_front.png";
74     aPictures<<":pictures/occ_view_back.png"<<":pictures/occ_view_left.png";
75     aPictures<<":pictures/occ_view_right.png"<<":pictures/occ_view_top.png";
76     aPictures<<":pictures/occ_view_bottom.png"<<":pictures/occ_view_clone.png";
77
78     QToolBar* aBar = new QToolBar(aSub);
79     aBar->setGeometry(0,0,500,30);
80
81     QAction* aBtn;
82     foreach(QString aName, aPictures) {
83         aBtn = new QAction(aBar);
84         aBtn->setIcon(QIcon(aName));
85         aBar->addAction(aBtn);
86     }
87     
88     aBar = new QToolBar(aSub);
89     aBar->setGeometry(615,0,100,25);
90     QStringList aWndIcons;
91     aWndIcons<<":pictures/wnd_minimize.png"<<":pictures/wnd_maximize.png"<<":pictures/wnd_close.png";
92     foreach(QString aName, aWndIcons) {
93         aBtn = new QAction(aBar);
94         aBtn->setIcon(QIcon(aName));
95         aBar->addAction(aBtn);
96     }
97
98     return aSub;
99 }
100
101
102 XGUI_MainWindow::~XGUI_MainWindow(void)
103 {
104 }
105
106 //******************************************************
107 void XGUI_MainWindow::showObjectBrowser()
108 {
109     myObjectBrowser->parentWidget()->show();
110 }
111
112 //******************************************************
113 void XGUI_MainWindow::hideObjectBrowser()
114 {
115     myObjectBrowser->parentWidget()->hide();
116 }
117
118 //******************************************************
119 void XGUI_MainWindow::fillObjectBrowser()
120 {
121     QStringList aNames;
122     aNames << "Parameters" << "Constructions";
123     aNames << "Part 1" << "Part 2" << "Part 3";
124     aNames << "Properties";
125
126     QStringList aIcons;
127     aIcons << ":pictures/params_folder.png";
128     aIcons << ":pictures/constr_folder.png";
129     aIcons << ":pictures/part_ico.png";
130     aIcons << ":pictures/part_ico.png";
131     aIcons << ":pictures/part_ico.png";
132     aIcons << ":pictures/properties.png";
133
134     QList<QTreeWidgetItem*> aItems;
135     foreach(QString aName, aNames) {
136         QTreeWidgetItem* aItem = new QTreeWidgetItem(myObjectBrowser);
137         aItem->setText(0, aName);
138         aItems.append(aItem);
139     }
140     for(int i = 0; i < aItems.length(); i++) {
141         aItems[i]->setIcon(0, QIcon(aIcons[i]));
142     }
143     myObjectBrowser->addTopLevelItems(aItems);
144
145     for (int i = 2; i < 5; i++) {
146         QTreeWidgetItem* aItem = new QTreeWidgetItem(aItems[i]);
147         aItem->setText(0, "Parameters");
148         aItem->setIcon(0, QIcon(":pictures/params_folder.png"));
149
150         aItem = new QTreeWidgetItem(aItems[i]);
151         aItem->setText(0, "Construction");
152         aItem->setIcon(0, QIcon(":pictures/constr_folder.png"));
153
154         aItem = new QTreeWidgetItem(aItems[i]);
155         aItem->setText(0, "Bodies");
156         aItem->setIcon(0, QIcon(":pictures/part_ico.png"));
157
158         aItem = new QTreeWidgetItem(aItems[i]);
159         aItem->setText(0, "Features");
160         aItem->setIcon(0, QIcon(":pictures/features.png"));
161     }
162 }
163
164
165 void XGUI_MainWindow::addPropertyPanel()
166 {
167     QDockWidget* aPropPanel = new QDockWidget(this);
168     aPropPanel->setWindowTitle("Property panel");
169
170     QWidget* aContent = new QWidget(aPropPanel);
171     QVBoxLayout* aMainLay = new QVBoxLayout(aContent);
172     aMainLay->setContentsMargins(3,3,3,3);
173     aPropPanel->setWidget(aContent);
174
175     QWidget* aNameWgt = new QWidget(aContent);
176     QHBoxLayout* aNameLay = new QHBoxLayout(aNameWgt);
177     aNameLay->setContentsMargins(0,0,0,0);
178     aMainLay->addWidget(aNameWgt);
179
180     aNameLay->addWidget(new QLabel("Name", aNameWgt));
181     aNameLay->addWidget(new QLineEdit(aNameWgt));
182
183     QGroupBox* aGrpBox1 = new QGroupBox("Point", aContent);
184     aGrpBox1->setFlat(true);
185     QFormLayout* aFrmLay = new QFormLayout(aGrpBox1);
186     aFrmLay->setContentsMargins(0, 6, 0, 0);
187     aMainLay->addWidget(aGrpBox1);
188
189     QLabel* aLbl = new QLabel(aGrpBox1);
190     aLbl->setPixmap(QPixmap(":pictures/x_point.png"));
191     aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));
192
193     aLbl = new QLabel(aGrpBox1);
194     aLbl->setPixmap(QPixmap(":pictures/y_point.png"));
195     aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));
196
197     aLbl = new QLabel(aGrpBox1);
198     aLbl->setPixmap(QPixmap(":pictures/z_point.png"));
199     aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));
200     
201
202     aGrpBox1 = new QGroupBox("Normal vector", aContent);
203     aGrpBox1->setFlat(true);
204     aFrmLay = new QFormLayout(aGrpBox1);
205     aFrmLay->setContentsMargins(0, 6, 0, 0);
206     aMainLay->addWidget(aGrpBox1);
207
208     aLbl = new QLabel(aGrpBox1);
209     aLbl->setPixmap(QPixmap(":pictures/x_size.png"));
210     aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));
211
212     aLbl = new QLabel(aGrpBox1);
213     aLbl->setPixmap(QPixmap(":pictures/y_size.png"));
214     aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));
215
216     aLbl = new QLabel(aGrpBox1);
217     aLbl->setPixmap(QPixmap(":pictures/z_size.png"));
218     aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));
219     
220     aMainLay->addStretch(1);
221
222     QFrame* aFrm = new QFrame(aContent);
223     aFrm->setFrameStyle(QFrame::Sunken);
224     aFrm->setFrameShape(QFrame::Panel);
225     QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm);
226     aBtnLay->setContentsMargins(0, 0, 0, 0);
227     aMainLay->addWidget(aFrm);
228
229     QPushButton* aBtn = new QPushButton(QIcon(":pictures/button_help.png"), "", aFrm);
230     aBtn->setFlat(true);
231     aBtnLay->addWidget(aBtn);
232     aBtnLay->addStretch(1);
233     aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm);
234     aBtn->setFlat(true);
235     aBtnLay->addWidget(aBtn);
236     aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm);
237     aBtn->setFlat(true);
238     aBtnLay->addWidget(aBtn);
239
240     addDockWidget(Qt::RightDockWidgetArea, aPropPanel);
241 }