Salome HOME
Re-factoring: interfaces removed from "XGUI", "GeomModule" renamed to "PartSet"
[modules/shaper.git] / src / XGUI / XGUI_ViewWindow.cpp
1 #include "XGUI_ViewWindow.h"
2
3
4 #include <QLayout>
5 #include <QLabel>
6 #include <QToolBar>
7 #include <QAction>
8 #include <QResizeEvent>
9 #include <QApplication>
10
11 #define BORDER_SIZE 2
12
13 XGUI_ViewWindow::XGUI_ViewWindow()
14 {
15     setMouseTracking(true);
16     QVBoxLayout* aLay = new QVBoxLayout(this);
17     aLay->setContentsMargins(BORDER_SIZE,BORDER_SIZE,BORDER_SIZE,BORDER_SIZE);
18     myViewPort = new QLabel(this);
19     aLay->addWidget(myViewPort);
20     myViewPort->setFrameStyle(QFrame::Raised);
21     myViewPort->setCursor(Qt::ArrowCursor);
22     myViewPort->setFrameShape(QFrame::Panel);
23     myViewPort->setPixmap(QPixmap(":pictures/ViewPort.png"));
24     myViewPort->setScaledContents(true);
25
26     myPicture = new QLabel(this);
27     aLay->addWidget(myPicture);
28     myPicture->hide();
29
30     QStringList aPictures;
31     aPictures<<":pictures/occ_view_camera_dump.png"<<":pictures/occ_view_style_switch.png";
32     aPictures<<":pictures/occ_view_triedre.png"<<":pictures/occ_view_fitall.png";
33     aPictures<<":pictures/occ_view_fitarea.png"<<":pictures/occ_view_zoom.png";
34     aPictures<<":pictures/occ_view_pan.png"<<":pictures/occ_view_glpan.png";
35     aPictures<<":pictures/occ_view_rotate.png"<<":pictures/occ_view_front.png";
36     aPictures<<":pictures/occ_view_back.png"<<":pictures/occ_view_left.png";
37     aPictures<<":pictures/occ_view_right.png"<<":pictures/occ_view_top.png";
38     aPictures<<":pictures/occ_view_bottom.png"<<":pictures/occ_view_clone.png";
39
40     QStringList aTitles;
41     aTitles << "Dump view" << "Mouse style switch" << "Show trihedron" << "Fit all";
42     aTitles << "Fit area" << "Zoom" << "Panning" << "Global panning" << "Rotate";
43     aTitles << "Front" << "Back" << "Left" << "Right" << "Top" << "Bottom" << "Clone view";
44
45     aViewBar = new QToolBar(this);
46     //aViewBar->move(BORDER_SIZE, BORDER_SIZE);
47
48     QAction* aBtn;
49     for (int i = 0; i < aTitles.length(); i++) {
50         aBtn = new QAction(QIcon(aPictures.at(i)), aTitles.at(i), aViewBar);
51         aViewBar->addAction(aBtn);
52     }
53     
54     aWindowBar = new QToolBar(this);
55     //aWindowBar->move(615,0);
56
57     aBtn = new QAction(aWindowBar);
58     aBtn->setIcon(QIcon(":pictures/wnd_minimize.png"));
59     aWindowBar->addAction(aBtn);
60     connect(aBtn, SIGNAL(triggered()), SLOT(onMinimize()));
61     connect(aBtn, SIGNAL(triggered()), SLOT(showMinimized()));
62
63     aBtn = new QAction(aWindowBar);
64     aBtn->setIcon(QIcon(":pictures/wnd_maximize.png"));
65     aWindowBar->addAction(aBtn);
66     connect(aBtn, SIGNAL(triggered()), SLOT(showMaximized()));
67
68     aBtn = new QAction(aWindowBar);
69     aBtn->setIcon(QIcon(":pictures/wnd_close.png"));
70     aWindowBar->addAction(aBtn);
71     connect(aBtn, SIGNAL(triggered()), SLOT(onClose()));
72
73     aViewBar->hide();
74     aWindowBar->hide();
75 }
76
77
78 XGUI_ViewWindow::~XGUI_ViewWindow()
79 {
80 }
81
82
83 void XGUI_ViewWindow::resizeEvent(QResizeEvent* theEvent)
84 {
85     QSize aSize = theEvent->size();
86     QSize aWndBarSize = aWindowBar->sizeHint();
87     QSize aViewBarSize = aViewBar->sizeHint();
88
89     aWindowBar->move(aSize.width() - aWndBarSize.width() - BORDER_SIZE, BORDER_SIZE);
90     aViewBar->setGeometry(BORDER_SIZE, BORDER_SIZE, aSize.width() - aWndBarSize.width(), aViewBarSize.height());
91 }
92
93
94 void XGUI_ViewWindow::changeEvent(QEvent* theEvent)
95 {
96
97     if (theEvent->type() == QEvent::WindowStateChange) {
98         if (isMinimized()) {
99             parentWidget()->setGeometry(0, 0, 110, 80);
100             myViewPort->hide();
101             aViewBar->hide();
102             aWindowBar->hide();
103             myPicture->show();
104         } else {
105             myViewPort->show();
106             myPicture->hide();
107         }
108     } else
109         QWidget::changeEvent(theEvent);
110 }
111
112 void XGUI_ViewWindow::onClose()
113 {
114     if (parentWidget())
115         parentWidget()->close();
116
117 }
118
119 void XGUI_ViewWindow::enterEvent(QEvent* theEvent)
120 {
121     if (!isMinimized())
122         aViewBar->show();
123     aWindowBar->show();
124 }
125
126 void XGUI_ViewWindow::leaveEvent(QEvent* theEvent)
127 {
128     aViewBar->hide();
129     aWindowBar->hide();
130 }
131
132
133 void XGUI_ViewWindow::onMinimize()
134 {
135     QPixmap aPMap = grab();
136     myPicture->setPixmap(aPMap.scaled(110, 80));
137 }