1 #include "XGUI_ViewWindow.h"
8 #include <QResizeEvent>
9 #include <QApplication>
11 #include <QMdiSubWindow>
15 XGUI_ViewWindow::XGUI_ViewWindow():
18 ViewPortPxm(":pictures/ViewPort.png"),
19 MinimizeIco(":pictures/wnd_minimize.png"),
20 MaximizeIco(":pictures/wnd_maximize.png"),
21 CloseIco(":pictures/wnd_close.png"),
22 RestoreIco(":pictures/wnd_restore.png")
25 setMouseTracking(true);
26 QVBoxLayout* aLay = new QVBoxLayout(this);
27 aLay->setContentsMargins(BORDER_SIZE,BORDER_SIZE,BORDER_SIZE,BORDER_SIZE);
28 myViewPort = new QLabel(this);
29 aLay->addWidget(myViewPort);
30 myViewPort->setFrameStyle(QFrame::Raised);
31 myViewPort->setCursor(Qt::ArrowCursor);
32 myViewPort->setFrameShape(QFrame::Panel);
33 myViewPort->setPixmap(ViewPortPxm);
34 myViewPort->setScaledContents(true);
36 myPicture = new QLabel(this);
37 aLay->addWidget(myPicture);
38 myPicture->setMouseTracking(true);
39 myPicture->installEventFilter(this);
42 QStringList aPictures;
43 aPictures<<":pictures/occ_view_camera_dump.png"<<":pictures/occ_view_style_switch.png";
44 aPictures<<":pictures/occ_view_triedre.png"<<":pictures/occ_view_fitall.png";
45 aPictures<<":pictures/occ_view_fitarea.png"<<":pictures/occ_view_zoom.png";
46 aPictures<<":pictures/occ_view_pan.png"<<":pictures/occ_view_glpan.png";
47 aPictures<<":pictures/occ_view_rotate.png"<<":pictures/occ_view_front.png";
48 aPictures<<":pictures/occ_view_back.png"<<":pictures/occ_view_left.png";
49 aPictures<<":pictures/occ_view_right.png"<<":pictures/occ_view_top.png";
50 aPictures<<":pictures/occ_view_bottom.png"<<":pictures/occ_view_clone.png";
53 aTitles << "Dump view" << "Mouse style switch" << "Show trihedron" << "Fit all";
54 aTitles << "Fit area" << "Zoom" << "Panning" << "Global panning" << "Rotate";
55 aTitles << "Front" << "Back" << "Left" << "Right" << "Top" << "Bottom" << "Clone view";
57 myGripWgt = new QLabel(this);
58 myGripWgt->setPixmap(QPixmap(":pictures/wnd_grip.png"));
59 myGripWgt->setGeometry(BORDER_SIZE + 2, BORDER_SIZE + 4, 25, 25);
60 myGripWgt->setMouseTracking(true);
61 myGripWgt->installEventFilter(this);
63 myViewBar = new QToolBar(this);
65 for (int i = 0; i < aTitles.length(); i++) {
66 aBtn = new QAction(QIcon(aPictures.at(i)), aTitles.at(i), myViewBar);
67 myViewBar->addAction(aBtn);
70 myWindowBar = new QToolBar(this);
72 myMinimizeBtn = new QAction(myWindowBar);
73 myMinimizeBtn->setIcon(MinimizeIco);
74 myWindowBar->addAction(myMinimizeBtn);
75 connect(myMinimizeBtn, SIGNAL(triggered()), SLOT(onMinimize()));
77 myMaximizeBtn = new QAction(myWindowBar);
78 myMaximizeBtn->setIcon(MaximizeIco);
79 myWindowBar->addAction(myMaximizeBtn);
80 connect(myMaximizeBtn, SIGNAL(triggered()), SLOT(onMaximize()));
82 aBtn = new QAction(myWindowBar);
83 aBtn->setIcon(CloseIco);
84 myWindowBar->addAction(aBtn);
85 connect(aBtn, SIGNAL(triggered()), SLOT(onClose()));
92 //****************************************************************
93 XGUI_ViewWindow::~XGUI_ViewWindow()
97 //****************************************************************
98 void XGUI_ViewWindow::resizeEvent(QResizeEvent* theEvent)
100 QSize aSize = theEvent->size();
101 QSize aWndBarSize = myWindowBar->sizeHint();
102 QSize myViewBarSize = myViewBar->sizeHint();
104 myWindowBar->move(aSize.width() - aWndBarSize.width() - BORDER_SIZE, BORDER_SIZE);
105 myViewBar->setGeometry(BORDER_SIZE + 16, BORDER_SIZE, aSize.width() - aWndBarSize.width(), myViewBarSize.height());
108 //****************************************************************
109 void XGUI_ViewWindow::changeEvent(QEvent* theEvent)
112 if (theEvent->type() == QEvent::WindowStateChange) {
114 parentWidget()->setGeometry(parentWidget()->x(), parentWidget()->y(), 110, 80);
125 QWidget::changeEvent(theEvent);
128 //****************************************************************
129 void XGUI_ViewWindow::onClose()
132 parentWidget()->close();
136 //****************************************************************
137 void XGUI_ViewWindow::enterEvent(QEvent* theEvent)
139 if (!isMinimized()) {
147 //****************************************************************
148 void XGUI_ViewWindow::leaveEvent(QEvent* theEvent)
155 //****************************************************************
156 void XGUI_ViewWindow::onMinimize()
158 QPixmap aPMap = grab();
159 myPicture->setPixmap(aPMap.scaled(110, 80));
162 myMinimizeBtn->setIcon(MinimizeIco);
165 myMinimizeBtn->setIcon(RestoreIco);
168 myMaximizeBtn->setIcon(MaximizeIco);
171 //****************************************************************
172 void XGUI_ViewWindow::onMaximize()
175 myMaximizeBtn->setIcon(MaximizeIco);
179 myMaximizeBtn->setIcon(RestoreIco);
183 myMinimizeBtn->setIcon(MinimizeIco);
186 //****************************************************************
187 bool XGUI_ViewWindow::eventFilter(QObject *theObj, QEvent *theEvent)
189 if ((theObj == myGripWgt) || (theObj == myPicture)) {
190 switch (theEvent->type()) {
191 case QEvent::MouseButtonPress:
193 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
194 if ((aEvent->button() == Qt::LeftButton) && (!myMoving)){
196 myMousePnt = aEvent->globalPos();
201 case QEvent::MouseButtonRelease:
203 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
204 if ((aEvent->button() == Qt::LeftButton) && myMoving) {
210 case QEvent::MouseMove:
212 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
214 QMdiSubWindow* aParent = static_cast<QMdiSubWindow*>(parentWidget());
215 QMdiArea* aMDIArea = aParent->mdiArea();
217 QPoint aPnt = aEvent->globalPos();
218 QPoint aMDIPnt = aMDIArea->mapFromGlobal(aPnt);
219 if (aMDIArea->rect().contains(aMDIPnt)) {
220 int aX = aParent->x() + (aPnt.x() - myMousePnt.x());
221 int aY = aParent->y() + (aPnt.y() - myMousePnt.y());
222 aParent->move(aX, aY);
230 return QWidget::eventFilter(theObj, theEvent);