]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Management of sub window in MDI area added
authorvsv <vitaly.smetannikov@opencascade.com>
Mon, 24 Mar 2014 14:43:12 +0000 (18:43 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Mon, 24 Mar 2014 14:43:12 +0000 (18:43 +0400)
src/XGUI/XGUI_MainWindow.cpp
src/XGUI/XGUI_ViewWindow.cpp
src/XGUI/XGUI_ViewWindow.h
src/XGUI/XGUI_pictures.qrc
src/XGUI/pictures/wnd_grip.png [new file with mode: 0644]
src/XGUI/pictures/wnd_restore.png [new file with mode: 0644]

index 2a88182d297b691cdbf4d21b0c754fdd53be60a2..1a995322faa1798b7f6f9c581848c8f713db1aad 100644 (file)
@@ -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();
index 2ca380116ead4431370528f15a57adc0bd7175ad..c453028af38b03712267a6ca38c00427ea96e2a2 100644 (file)
@@ -7,11 +7,21 @@
 #include <QAction>
 #include <QResizeEvent>
 #include <QApplication>
+#include <QMdiArea>
+#include <QMdiSubWindow>
 
 #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<QMouseEvent*>(theEvent);
+                if ((aEvent->button() == Qt::LeftButton) && (!myMoving)){
+                    myMoving = true;
+                    myMousePnt = aEvent->globalPos();
+                    return true;
+                }
+            }
+            break;
+        case QEvent::MouseButtonRelease: 
+            {
+                QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
+                if ((aEvent->button() == Qt::LeftButton) && myMoving) {
+                    myMoving = false;
+                    return true;
+                }
+            }
+            break;
+        case QEvent::MouseMove: 
+            {
+                QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
+                if (myMoving) {
+                    QMdiSubWindow* aParent = static_cast<QMdiSubWindow*>(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
index e4daab713a708b540e683a6332ebbf94fd6e4642..aefbd3dc723c35b0be145a9c741531878c4a64dd 100644 (file)
@@ -2,6 +2,7 @@
 #define XGUI_ViewWindow_H
 
 #include <QWidget>
+#include <QIcon>
 
 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
index ddcb76b47ffc911e55a85e7d0b99775afb908073..0645767cc9a21f1e126b0a14d771e28fd52658bb 100644 (file)
@@ -48,6 +48,8 @@
      <file>pictures/wnd_close.png</file>
      <file>pictures/wnd_minimize.png</file>
      <file>pictures/wnd_maximize.png</file>
+     <file>pictures/wnd_restore.png</file>
+     <file>pictures/wnd_grip.png</file>
      
      <file>pictures/params_folder.png</file>
      <file>pictures/constr_folder.png</file>
diff --git a/src/XGUI/pictures/wnd_grip.png b/src/XGUI/pictures/wnd_grip.png
new file mode 100644 (file)
index 0000000..8b0d092
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 (file)
index 0000000..65a123e
Binary files /dev/null and b/src/XGUI/pictures/wnd_restore.png differ