From fd4ecf538c9c74a08ef5f467ee2436b2272f9fda Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 24 Mar 2014 18:43:12 +0400 Subject: [PATCH] Management of sub window in MDI area added --- src/XGUI/XGUI_MainWindow.cpp | 1 + src/XGUI/XGUI_ViewWindow.cpp | 176 +++++++++++++++++++++++------- src/XGUI/XGUI_ViewWindow.h | 20 +++- src/XGUI/XGUI_pictures.qrc | 2 + src/XGUI/pictures/wnd_grip.png | Bin 0 -> 230 bytes src/XGUI/pictures/wnd_restore.png | Bin 0 -> 481 bytes 6 files changed, 156 insertions(+), 43 deletions(-) create mode 100644 src/XGUI/pictures/wnd_grip.png create mode 100644 src/XGUI/pictures/wnd_restore.png diff --git a/src/XGUI/XGUI_MainWindow.cpp b/src/XGUI/XGUI_MainWindow.cpp index 2a88182d2..1a995322f 100644 --- a/src/XGUI/XGUI_MainWindow.cpp +++ b/src/XGUI/XGUI_MainWindow.cpp @@ -47,6 +47,7 @@ XGUI_MainWindow::XGUI_MainWindow(QWidget* parent) : QMdiArea* aMdiArea = new QMdiArea(this); setCentralWidget(aMdiArea); + aMdiArea->addSubWindow(new XGUI_ViewWindow(), Qt::FramelessWindowHint); aMdiArea->addSubWindow(new XGUI_ViewWindow(), Qt::FramelessWindowHint); fillObjectBrowser(); diff --git a/src/XGUI/XGUI_ViewWindow.cpp b/src/XGUI/XGUI_ViewWindow.cpp index 2ca380116..c453028af 100644 --- a/src/XGUI/XGUI_ViewWindow.cpp +++ b/src/XGUI/XGUI_ViewWindow.cpp @@ -7,11 +7,21 @@ #include #include #include +#include +#include #define BORDER_SIZE 2 -XGUI_ViewWindow::XGUI_ViewWindow() +XGUI_ViewWindow::XGUI_ViewWindow(): +QWidget(), + myMoving(false), + ViewPortPxm(":pictures/ViewPort.png"), + MinimizeIco(":pictures/wnd_minimize.png"), + MaximizeIco(":pictures/wnd_maximize.png"), + CloseIco(":pictures/wnd_close.png"), + RestoreIco(":pictures/wnd_restore.png") { + setMouseTracking(true); QVBoxLayout* aLay = new QVBoxLayout(this); aLay->setContentsMargins(BORDER_SIZE,BORDER_SIZE,BORDER_SIZE,BORDER_SIZE); @@ -20,11 +30,13 @@ XGUI_ViewWindow::XGUI_ViewWindow() myViewPort->setFrameStyle(QFrame::Raised); myViewPort->setCursor(Qt::ArrowCursor); myViewPort->setFrameShape(QFrame::Panel); - myViewPort->setPixmap(QPixmap(":pictures/ViewPort.png")); + myViewPort->setPixmap(ViewPortPxm); myViewPort->setScaledContents(true); myPicture = new QLabel(this); aLay->addWidget(myPicture); + myPicture->setMouseTracking(true); + myPicture->installEventFilter(this); myPicture->hide(); QStringList aPictures; @@ -42,64 +54,68 @@ XGUI_ViewWindow::XGUI_ViewWindow() aTitles << "Fit area" << "Zoom" << "Panning" << "Global panning" << "Rotate"; aTitles << "Front" << "Back" << "Left" << "Right" << "Top" << "Bottom" << "Clone view"; - aViewBar = new QToolBar(this); - //aViewBar->move(BORDER_SIZE, BORDER_SIZE); + myGripWgt = new QLabel(this); + myGripWgt->setPixmap(QPixmap(":pictures/wnd_grip.png")); + myGripWgt->setGeometry(BORDER_SIZE + 2, BORDER_SIZE + 4, 25, 25); + myGripWgt->setMouseTracking(true); + myGripWgt->installEventFilter(this); + myViewBar = new QToolBar(this); QAction* aBtn; for (int i = 0; i < aTitles.length(); i++) { - aBtn = new QAction(QIcon(aPictures.at(i)), aTitles.at(i), aViewBar); - aViewBar->addAction(aBtn); + aBtn = new QAction(QIcon(aPictures.at(i)), aTitles.at(i), myViewBar); + myViewBar->addAction(aBtn); } - aWindowBar = new QToolBar(this); - //aWindowBar->move(615,0); - - aBtn = new QAction(aWindowBar); - aBtn->setIcon(QIcon(":pictures/wnd_minimize.png")); - aWindowBar->addAction(aBtn); - connect(aBtn, SIGNAL(triggered()), SLOT(onMinimize())); - connect(aBtn, SIGNAL(triggered()), SLOT(showMinimized())); - - aBtn = new QAction(aWindowBar); - aBtn->setIcon(QIcon(":pictures/wnd_maximize.png")); - aWindowBar->addAction(aBtn); - connect(aBtn, SIGNAL(triggered()), SLOT(showMaximized())); - - aBtn = new QAction(aWindowBar); - aBtn->setIcon(QIcon(":pictures/wnd_close.png")); - aWindowBar->addAction(aBtn); + myWindowBar = new QToolBar(this); + + myMinimizeBtn = new QAction(myWindowBar); + myMinimizeBtn->setIcon(MinimizeIco); + myWindowBar->addAction(myMinimizeBtn); + connect(myMinimizeBtn, SIGNAL(triggered()), SLOT(onMinimize())); + + myMaximizeBtn = new QAction(myWindowBar); + myMaximizeBtn->setIcon(MaximizeIco); + myWindowBar->addAction(myMaximizeBtn); + connect(myMaximizeBtn, SIGNAL(triggered()), SLOT(onMaximize())); + + aBtn = new QAction(myWindowBar); + aBtn->setIcon(CloseIco); + myWindowBar->addAction(aBtn); connect(aBtn, SIGNAL(triggered()), SLOT(onClose())); - aViewBar->hide(); - aWindowBar->hide(); + myViewBar->hide(); + myWindowBar->hide(); + myGripWgt->hide(); } - +//**************************************************************** XGUI_ViewWindow::~XGUI_ViewWindow() { } - +//**************************************************************** void XGUI_ViewWindow::resizeEvent(QResizeEvent* theEvent) { QSize aSize = theEvent->size(); - QSize aWndBarSize = aWindowBar->sizeHint(); - QSize aViewBarSize = aViewBar->sizeHint(); + QSize aWndBarSize = myWindowBar->sizeHint(); + QSize myViewBarSize = myViewBar->sizeHint(); - aWindowBar->move(aSize.width() - aWndBarSize.width() - BORDER_SIZE, BORDER_SIZE); - aViewBar->setGeometry(BORDER_SIZE, BORDER_SIZE, aSize.width() - aWndBarSize.width(), aViewBarSize.height()); + myWindowBar->move(aSize.width() - aWndBarSize.width() - BORDER_SIZE, BORDER_SIZE); + myViewBar->setGeometry(BORDER_SIZE + 16, BORDER_SIZE, aSize.width() - aWndBarSize.width(), myViewBarSize.height()); } - +//**************************************************************** void XGUI_ViewWindow::changeEvent(QEvent* theEvent) { if (theEvent->type() == QEvent::WindowStateChange) { if (isMinimized()) { - parentWidget()->setGeometry(0, 0, 110, 80); + parentWidget()->setGeometry(parentWidget()->x(), parentWidget()->y(), 110, 80); myViewPort->hide(); - aViewBar->hide(); - aWindowBar->hide(); + myViewBar->hide(); + myGripWgt->hide(); + myWindowBar->hide(); myPicture->show(); } else { myViewPort->show(); @@ -109,6 +125,7 @@ void XGUI_ViewWindow::changeEvent(QEvent* theEvent) QWidget::changeEvent(theEvent); } +//**************************************************************** void XGUI_ViewWindow::onClose() { if (parentWidget()) @@ -116,22 +133,99 @@ void XGUI_ViewWindow::onClose() } +//**************************************************************** void XGUI_ViewWindow::enterEvent(QEvent* theEvent) { - if (!isMinimized()) - aViewBar->show(); - aWindowBar->show(); + if (!isMinimized()) { + myViewBar->show(); + if (!isMaximized()) + myGripWgt->show(); + } + myWindowBar->show(); } +//**************************************************************** void XGUI_ViewWindow::leaveEvent(QEvent* theEvent) { - aViewBar->hide(); - aWindowBar->hide(); + myViewBar->hide(); + myGripWgt->hide(); + myWindowBar->hide(); } - +//**************************************************************** void XGUI_ViewWindow::onMinimize() { QPixmap aPMap = grab(); myPicture->setPixmap(aPMap.scaled(110, 80)); + + if (isMinimized()) { + myMinimizeBtn->setIcon(MinimizeIco); + showNormal(); + } else { + myMinimizeBtn->setIcon(RestoreIco); + showMinimized(); + } + myMaximizeBtn->setIcon(MaximizeIco); +} + +//**************************************************************** +void XGUI_ViewWindow::onMaximize() +{ + if (isMaximized()) { + myMaximizeBtn->setIcon(MaximizeIco); + myGripWgt->show(); + showNormal(); + } else { + myMaximizeBtn->setIcon(RestoreIco); + myGripWgt->hide(); + showMaximized(); + } + myMinimizeBtn->setIcon(MinimizeIco); +} + +//**************************************************************** +bool XGUI_ViewWindow::eventFilter(QObject *theObj, QEvent *theEvent) +{ + if ((theObj == myGripWgt) || (theObj == myPicture)) { + switch (theEvent->type()) { + case QEvent::MouseButtonPress: + { + QMouseEvent* aEvent = static_cast(theEvent); + if ((aEvent->button() == Qt::LeftButton) && (!myMoving)){ + myMoving = true; + myMousePnt = aEvent->globalPos(); + return true; + } + } + break; + case QEvent::MouseButtonRelease: + { + QMouseEvent* aEvent = static_cast(theEvent); + if ((aEvent->button() == Qt::LeftButton) && myMoving) { + myMoving = false; + return true; + } + } + break; + case QEvent::MouseMove: + { + QMouseEvent* aEvent = static_cast(theEvent); + if (myMoving) { + QMdiSubWindow* aParent = static_cast(parentWidget()); + QMdiArea* aMDIArea = aParent->mdiArea(); + + QPoint aPnt = aEvent->globalPos(); + QPoint aMDIPnt = aMDIArea->mapFromGlobal(aPnt); + if (aMDIArea->rect().contains(aMDIPnt)) { + int aX = aParent->x() + (aPnt.x() - myMousePnt.x()); + int aY = aParent->y() + (aPnt.y() - myMousePnt.y()); + aParent->move(aX, aY); + myMousePnt = aPnt; + } + return true; + } + } + } + } + return QWidget::eventFilter(theObj, theEvent); } \ No newline at end of file diff --git a/src/XGUI/XGUI_ViewWindow.h b/src/XGUI/XGUI_ViewWindow.h index e4daab713..aefbd3dc7 100644 --- a/src/XGUI/XGUI_ViewWindow.h +++ b/src/XGUI/XGUI_ViewWindow.h @@ -2,6 +2,7 @@ #define XGUI_ViewWindow_H #include +#include class QLabel; class QToolBar; @@ -21,16 +22,31 @@ protected: virtual void enterEvent(QEvent* theEvent); virtual void leaveEvent(QEvent* theEvent); + virtual bool eventFilter(QObject *theObj, QEvent *theEvent); + private slots: void onClose(); void onMinimize(); + void onMaximize(); private: QLabel* myPicture; QLabel* myViewPort; - QToolBar* aViewBar; - QToolBar* aWindowBar; + QLabel* myGripWgt; + QToolBar* myViewBar; + QToolBar* myWindowBar; + QAction* myMinimizeBtn; + QAction* myMaximizeBtn; + + QPixmap ViewPortPxm; + QIcon MinimizeIco; + QIcon MaximizeIco; + QIcon CloseIco; + QIcon RestoreIco; + + bool myMoving; + QPoint myMousePnt; }; #endif \ No newline at end of file diff --git a/src/XGUI/XGUI_pictures.qrc b/src/XGUI/XGUI_pictures.qrc index ddcb76b47..0645767cc 100644 --- a/src/XGUI/XGUI_pictures.qrc +++ b/src/XGUI/XGUI_pictures.qrc @@ -48,6 +48,8 @@ pictures/wnd_close.png pictures/wnd_minimize.png pictures/wnd_maximize.png + pictures/wnd_restore.png + pictures/wnd_grip.png pictures/params_folder.png pictures/constr_folder.png diff --git a/src/XGUI/pictures/wnd_grip.png b/src/XGUI/pictures/wnd_grip.png new file mode 100644 index 0000000000000000000000000000000000000000..8b0d09242b1885ee566b7d950de097fd15639c59 GIT binary patch literal 230 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6;>1s;*b z3=DjSK$uZf!>a)(C{^MbQ4*Y=R#Ki=l*$m0n3-3i=jR%tP-d)Ws%L2E{@KYKs4B_R z#WBRfe{KIk&I1NK%wJd7zcasgd~r$Jxr=k}KDhAhaepAMx)3MJq2g6sn+-RL3r5~t zCo!|OBWI?f(t~$}bFSC8{r>OI=$u*Ru~7X2E6>uKimme;#0{pTwTo0Sg&vSCU{;%% V!o9I@RtV5G22WQ%mvv4FO#nx^ORxX{ literal 0 HcmV?d00001 diff --git a/src/XGUI/pictures/wnd_restore.png b/src/XGUI/pictures/wnd_restore.png new file mode 100644 index 0000000000000000000000000000000000000000..65a123e03570d9a714aff7414d30d9dbc1c46112 GIT binary patch literal 481 zcmV<70UrK|P)N2bPDNB8 zb~7$DE-^7j^FlWO00CV|L_t(IPorW>DtIy0qZ3Ke3!$;nK6&wM>MQ-o!jCi3|lS3Z)i>p?GLA}4z*>H41R z!T0@`L=_6hxPQ1qvsFi}Ug4^u-l(EwUAny{A>i`rLXH~;cuY1sy=Sza9xMmft%MD0$S|` zL|kt?lxuK^kF*5XwgmE@?;sg4o_cUc12UUWpvKM|X3*p5_()nddjw6>k^w>v-!s30Xo0CAYw*0(42N^I3D{p*0gDpsjf3hDhc48vGT2O&iE#H_3LTxlcf{j-1{ Xgk9r4yy^2<00000NkvXXu0mjf&?Cv| literal 0 HcmV?d00001 -- 2.39.2