From: vsv Date: Mon, 24 Mar 2014 14:43:12 +0000 (+0400) Subject: Management of sub window in MDI area added X-Git-Tag: V_0.1~50 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fd4ecf538c9c74a08ef5f467ee2436b2272f9fda;p=modules%2Fshaper.git Management of sub window in MDI area added --- 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 000000000..8b0d09242 Binary files /dev/null and b/src/XGUI/pictures/wnd_grip.png differ diff --git a/src/XGUI/pictures/wnd_restore.png b/src/XGUI/pictures/wnd_restore.png new file mode 100644 index 000000000..65a123e03 Binary files /dev/null and b/src/XGUI/pictures/wnd_restore.png differ