From: vsv Date: Tue, 13 May 2014 14:14:25 +0000 (+0400) Subject: Issue #8 : Provide Pop-up menu for windows management X-Git-Tag: V_0.2~72 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b5dc9fda0c8efc45a6807745ef0c21da8dce1aaf;p=modules%2Fshaper.git Issue #8 : Provide Pop-up menu for windows management --- diff --git a/src/XGUI/XGUI_MainWindow.cpp b/src/XGUI/XGUI_MainWindow.cpp index cbc3e67f3..02971608f 100644 --- a/src/XGUI/XGUI_MainWindow.cpp +++ b/src/XGUI/XGUI_MainWindow.cpp @@ -9,22 +9,10 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include +#include +#include XGUI_MainWindow::XGUI_MainWindow(QWidget* parent) : QMainWindow(parent), @@ -34,9 +22,29 @@ XGUI_MainWindow::XGUI_MainWindow(QWidget* parent) myMenuBar = new XGUI_MainMenu(this); QMdiArea* aMdiArea = new QMdiArea(this); + aMdiArea->setContextMenuPolicy(Qt::ActionsContextMenu); setCentralWidget(aMdiArea); + connect(aMdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)), + this, SLOT(onViewActivated(QMdiSubWindow*))); + + // Create actions of MDI area + QAction* aAction = new QAction(QIcon(":pictures/new_view.png"), tr("Create Window"), aMdiArea); + aMdiArea->addAction(aAction); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(createSubWindow())); + + aAction = new QAction(QIcon(":pictures/tile_views.png"), tr("Tile"), aMdiArea); + aMdiArea->addAction(aAction); + connect(aAction, SIGNAL(triggered(bool)), aMdiArea, SLOT(tileSubWindows())); + + aAction = new QAction(QIcon(":pictures/cascade_views.png"), tr("Cascade"), aMdiArea); + aMdiArea->addAction(aAction); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(cascadeWindows())); myViewer = new XGUI_Viewer(this); + connect(myViewer, SIGNAL(viewCreated(XGUI_ViewWindow*)), + this, SLOT(onViewCreated(XGUI_ViewWindow*))); + connect(myViewer, SIGNAL(deleteView(XGUI_ViewWindow*)), + this, SLOT(onViewCreated(XGUI_ViewWindow*))); } XGUI_MainWindow::~XGUI_MainWindow(void) @@ -73,4 +81,117 @@ void XGUI_MainWindow::hidePythonConsole() myPythonConsole->parentWidget()->hide(); } +//****************************************************** +void XGUI_MainWindow::createSubWindow() +{ + viewer()->createView(); +} +//****************************************************** +void XGUI_MainWindow::cascadeWindows() +{ + QMdiArea* aMdiArea = static_cast(centralWidget()); + QList aWindows = aMdiArea->subWindowList(); + + QSize aSize = aMdiArea->size(); + QRect aRect = aMdiArea->geometry(); + const int aOffset = 30; + int i = 0, j = 0; + int x, y; + int w = aSize.width() / 2; + int h = aSize.height() / 2; + QMdiSubWindow* aLastWnd; + foreach(QMdiSubWindow* aWnd, aWindows) { + aWnd->showNormal(); + aWnd->raise(); + x = aOffset * i; + if ((x + w) > aSize.width()) { + x = 0; + i = 0; + } + y = aOffset * j; + if ((y + h) > aSize.height()) { + y = 0; + j = 0; + } + aWnd->setGeometry(QStyle::visualRect(aWnd->layoutDirection(), aRect, + QRect(x, y, w, h))); + i++; + j++; + viewer()->onWindowActivated(aWnd); + aLastWnd = aWnd; + QApplication::processEvents(); + } + aLastWnd->setFocus(); +} + +void XGUI_MainWindow::onViewCreated(XGUI_ViewWindow* theWindow) +{ + QWidget* aSubWindow = theWindow->parentWidget(); + QWidget* aMDIWidget = centralWidget(); + QAction* aAction; + if (aMDIWidget->actions().size() == 3) { + aAction = new QAction(aMDIWidget); + aAction->setSeparator(true); + aMDIWidget->addAction(aAction); + } + aAction = new QAction(aSubWindow->windowTitle(), aMDIWidget); + aAction->setCheckable(true); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(activateView())); + aMDIWidget->addAction(aAction); + + QList aActions = aMDIWidget->actions(); + foreach(QAction* aAct, aActions) { + if (aAct->isCheckable()) + aAct->setChecked(false); + } + aAction->setChecked(true); +} + +void XGUI_MainWindow::onDeleteView(XGUI_ViewWindow* theWindow) +{ + QWidget* aSubWindow = theWindow->parentWidget(); + QString aTitle = aSubWindow->windowTitle(); + QWidget* aMDIWidget = centralWidget(); + QList aActions = aMDIWidget->actions(); + + QAction* aDelAct = 0; + foreach(QAction* aAct, aActions) { + if (aAct->text() == aTitle) { + aDelAct = aAct; + break; + } + } + aMDIWidget->removeAction(aDelAct); +} + +void XGUI_MainWindow::activateView() +{ + QAction* aAction = static_cast(sender()); + QString aWndTitle = aAction->text(); + QMdiArea* aMdiArea = static_cast(centralWidget()); + + QList aWndList = aMdiArea->subWindowList(); + foreach(QMdiSubWindow* aWnd, aWndList) { + if (aWnd->windowTitle() == aWndTitle) { + aWnd->raise(); + aWnd->activateWindow(); + aWnd->setFocus(); + break; + } + } + QApplication::processEvents(); +} + +void XGUI_MainWindow::onViewActivated(QMdiSubWindow* theSubWnd) +{ + if (!theSubWnd) + return; + QMdiArea* aMdiArea = static_cast(centralWidget()); + QString aWndTitle = theSubWnd->windowTitle(); + QList aActionList = aMdiArea->actions(); + foreach(QAction* aAct, aActionList) { + if (aAct->isCheckable()) + aAct->setChecked(aAct->text() == aWndTitle); + } +} \ No newline at end of file diff --git a/src/XGUI/XGUI_MainWindow.h b/src/XGUI/XGUI_MainWindow.h index 17357858d..9b29ec3ea 100644 --- a/src/XGUI/XGUI_MainWindow.h +++ b/src/XGUI/XGUI_MainWindow.h @@ -7,7 +7,9 @@ class XGUI_MainMenu; class XGUI_Viewer; class XGUI_ActionsMgr; +class XGUI_ViewWindow; class QMdiArea; +class QMdiSubWindow; class PyConsole_EnhConsole; /**\class XGUI_MainWindow @@ -42,6 +44,15 @@ public slots: void showPythonConsole(); void hidePythonConsole(); + void createSubWindow(); + +private slots: + void cascadeWindows(); + void onViewCreated(XGUI_ViewWindow* theWindow); + void onDeleteView(XGUI_ViewWindow* theWindow); + void activateView(); + void onViewActivated(QMdiSubWindow* theSubWnd); + private: XGUI_MainMenu* myMenuBar; XGUI_Viewer* myViewer; diff --git a/src/XGUI/XGUI_Viewer.cpp b/src/XGUI/XGUI_Viewer.cpp index 6fae264d2..12eae6e4a 100644 --- a/src/XGUI/XGUI_Viewer.cpp +++ b/src/XGUI/XGUI_Viewer.cpp @@ -89,7 +89,8 @@ XGUI_Viewer::XGUI_Viewer(XGUI_MainWindow* theParent, bool DisplayTrihedron) myIsRelative(true), myInteractionStyle(XGUI::STANDARD), myTrihedronSize(100), - myActiveView(0) + myActiveView(0), + myWndIdCount(0) { if (!isInitialized) { isInitialized = true; @@ -185,9 +186,11 @@ QMdiSubWindow* XGUI_Viewer::createView(V3d_TypeOfView theType) QMdiArea* aMDI = myMainWindow->mdiArea(); QMdiSubWindow* aWnd = aMDI->addSubWindow(view, Qt::FramelessWindowHint); - addView(aWnd); + addView(aWnd); aWnd->setGeometry(0, 0, aMDI->width() / 2, aMDI->height() / 2); aWnd->show(); + aWnd->setWindowTitle(QString("Viewer #%1").arg(++myWndIdCount)); + emit viewCreated(view); return aWnd; } @@ -440,8 +443,11 @@ void XGUI_Viewer::addView(QMdiSubWindow* theView) connect(aWindow, SIGNAL(keyReleased(XGUI_ViewWindow*, QKeyEvent*)), this, SIGNAL(keyRelease(XGUI_ViewWindow*, QKeyEvent*))); -// connect(aWindow, SIGNAL(contextMenuRequested( QContextMenuEvent* )), -// this, SLOT (onContextMenuRequested( QContextMenuEvent* ))); + //connect(aWindow, SIGNAL(contextMenuRequested( QContextMenuEvent* )), + // this, SLOT (onContextMenuRequested( QContextMenuEvent* ))); + //connect(aWindow, SIGNAL( contextMenuRequested(QContextMenuEvent*) ), + // this, SIGNAL( contextMenuRequested(QContextMenuEvent*) ) ); + connect(aWindow, SIGNAL(mouseMoving(XGUI_ViewWindow*, QMouseEvent*)), this, SLOT(onMouseMove(XGUI_ViewWindow*, QMouseEvent*))); @@ -457,6 +463,7 @@ void XGUI_Viewer::addView(QMdiSubWindow* theView) void XGUI_Viewer::onWindowActivated(QMdiSubWindow* view) { if (view && (view != myActiveView) && (!view->isMinimized())) { + qDebug("onWindowActivated"); myActiveView = view; ((XGUI_ViewWindow*)myActiveView->widget())->windowActivated(); QList::iterator aIt; diff --git a/src/XGUI/XGUI_Viewer.h b/src/XGUI/XGUI_Viewer.h index 4031430a3..1eb2bd47e 100644 --- a/src/XGUI/XGUI_Viewer.h +++ b/src/XGUI/XGUI_Viewer.h @@ -191,6 +191,9 @@ private: /// Points used for selection management QPoint myStartPnt, myEndPnt, myCurPnt; + + // A counter of created windows + int myWndIdCount; }; #endif diff --git a/src/XGUI/XGUI_pictures.qrc b/src/XGUI/XGUI_pictures.qrc index 399af8230..1efefb080 100644 --- a/src/XGUI/XGUI_pictures.qrc +++ b/src/XGUI/XGUI_pictures.qrc @@ -48,5 +48,9 @@ pictures/button_cancel.png pictures/button_help.png pictures/button_ok.png + + pictures/cascade_views.png + pictures/tile_views.png + pictures/new_view.png diff --git a/src/XGUI/pictures/cascade_views.png b/src/XGUI/pictures/cascade_views.png new file mode 100644 index 000000000..db4511144 Binary files /dev/null and b/src/XGUI/pictures/cascade_views.png differ diff --git a/src/XGUI/pictures/new_view.png b/src/XGUI/pictures/new_view.png new file mode 100644 index 000000000..352437dc2 Binary files /dev/null and b/src/XGUI/pictures/new_view.png differ diff --git a/src/XGUI/pictures/tile_views.png b/src/XGUI/pictures/tile_views.png new file mode 100644 index 000000000..fd9fece12 Binary files /dev/null and b/src/XGUI/pictures/tile_views.png differ