From 48741c218fa156ef9970672e78b681a4f6ec6b8c Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 22 Oct 2014 14:47:29 +0200 Subject: [PATCH] refs #335, changed info areas, obtain actions for main menu --- src/blackgui/infoarea.cpp | 91 ++++++++++++++++++++++++++++++++------- src/blackgui/infoarea.h | 18 ++++++++ 2 files changed, 93 insertions(+), 16 deletions(-) diff --git a/src/blackgui/infoarea.cpp b/src/blackgui/infoarea.cpp index ff77d96b1..c6680aace 100644 --- a/src/blackgui/infoarea.cpp +++ b/src/blackgui/infoarea.cpp @@ -16,6 +16,10 @@ #include #include #include +#include +#include +#include +#include using namespace BlackMisc; @@ -82,9 +86,9 @@ namespace BlackGui menu->addSeparator(); QMenu *subMenuToggleFloat = new QMenu("Toggle Float/Dock", menu); QMenu *subMenuDisplay = new QMenu("Display", menu); + subMenuDisplay->addActions(this->getInfoAreaSelectActions(subMenuDisplay)); QSignalMapper *signalMapperToggleFloating = new QSignalMapper(menu); - QSignalMapper *signalMapperDisplay = new QSignalMapper(menu); bool c = false; for (int i = 0; i < this->m_dockWidgetInfoAreas.size(); i++) @@ -103,25 +107,10 @@ namespace BlackGui c = connect(toggleFloatingMenuAction, SIGNAL(toggled(bool)), signalMapperToggleFloating, SLOT(map())); Q_ASSERT(c); signalMapperToggleFloating->setMapping(toggleFloatingMenuAction, i); - - QAction *displayMenuAction = new QAction(menu); - displayMenuAction->setObjectName(QString(t).append("DisplayAction")); - displayMenuAction->setIconText(t); - displayMenuAction->setIcon(pm); - displayMenuAction->setData(QVariant(i)); - displayMenuAction->setCheckable(false); - - subMenuDisplay->addAction(displayMenuAction); - c = connect(displayMenuAction, SIGNAL(triggered(bool)), signalMapperDisplay, SLOT(map())); - Q_ASSERT(c); - signalMapperDisplay->setMapping(displayMenuAction, i); // action to index } c = connect(signalMapperToggleFloating, SIGNAL(mapped(int)), this, SLOT(toggleFloating(int))); Q_ASSERT(c); - c = connect(signalMapperDisplay, SIGNAL(mapped(int)), this, SLOT(selectArea(int))); - Q_ASSERT(c); - menu->addMenu(subMenuDisplay); menu->addMenu(subMenuToggleFloat); @@ -182,12 +171,44 @@ namespace BlackGui return constDockWidgets; } + QList CInfoArea::getInfoAreaSelectActions(QWidget *parent) const + { + int i = 0; + QList actions; + foreach(const CDockWidgetInfoArea * dockWidgetInfoArea, m_dockWidgetInfoAreas) + { + const QPixmap pm = this->indexToPixmap(i); + QAction *action = new QAction(QIcon(pm), dockWidgetInfoArea->windowTitleBackup(), parent); + action->setData(i); + connect(action, &QAction::triggered, this, &CInfoArea::selectAreaByAction); + actions.append(action); + i++; + } + return actions; + } + void CInfoArea::paintEvent(QPaintEvent *event) { Q_UNUSED(event); CStyleSheetUtility::useStyleSheetInDerivedWidget(this); } + void CInfoArea::keyPressEvent(QKeyEvent *event) + { + if (event->key() == Qt::Key_Right) + { + this->selectRightTab(); + } + else if (event->key() == Qt::Key_Left) + { + this->selectLeftTab(); + } + else + { + QWidget::keyPressEvent(event); + } + } + void CInfoArea::dockAllWidgets() { this->tabifyAllWidgets(); @@ -251,6 +272,44 @@ namespace BlackGui } } + void CInfoArea::selectAreaByAction() + { + const QObject *sender = QObject::sender(); + Q_ASSERT(sender); + const QAction *action = qobject_cast(sender); + Q_ASSERT(action); + this->selectArea(action->data().toInt()); + } + + void CInfoArea::selectLeftTab() + { + if (!this->m_tabBar) return; + if (this->m_tabBar->count() < 2) return; + if (this->m_tabBar->currentIndex() > 0) + { + this->m_tabBar->setCurrentIndex(this->m_tabBar->currentIndex() - 1); + } + else + { + this->m_tabBar->setCurrentIndex(this->m_tabBar->count() - 1); + } + } + + void CInfoArea::selectRightTab() + { + if (!this->m_tabBar) return; + if (this->m_tabBar->count() < 2) return; + if (this->m_tabBar->currentIndex() < this->m_tabBar->count() - 2) + { + this->m_tabBar->setCurrentIndex(this->m_tabBar->currentIndex() + 1); + } + else + { + this->m_tabBar->setCurrentIndex(0); + } + } + + void CInfoArea::ps_setDockArea(Qt::DockWidgetArea area) { for (CDockWidgetInfoArea *dw : this->m_dockWidgetInfoAreas) diff --git a/src/blackgui/infoarea.h b/src/blackgui/infoarea.h index 71d71b648..532339ac6 100644 --- a/src/blackgui/infoarea.h +++ b/src/blackgui/infoarea.h @@ -46,6 +46,11 @@ namespace BlackGui //! Own dockable widgets QList getDockWidgetInfoAreas() const; + //! Create a list of actions to select the info areas. This could be used in a menu + //! or somewhere else. + //! \param parent which will own the action (deletion) + QList getInfoAreaSelectActions(QWidget *parent) const; + signals: //! Tab bar changed void tabBarCurrentChanged(int index); @@ -72,6 +77,15 @@ namespace BlackGui //! Select area void selectArea(int areaIndex); + //! Select area (sender is QAction) + void selectAreaByAction(); + + //! Select next left tab + void selectLeftTab(); + + //! Select next right tab + void selectRightTab(); + protected: //! Constructor explicit CInfoArea(QWidget *parent = nullptr); @@ -82,6 +96,10 @@ namespace BlackGui //! \copydoc QWidget::paintEvent virtual void paintEvent(QPaintEvent *event) override; + //! \copydoc QWidget::keyPressEvent + //! \remarks nor fully sufficient, as the info area is hardly having focus + virtual void keyPressEvent(QKeyEvent * event) override; + //! Preferred size when floating (size hint) virtual QSize getPreferredSizeWhenFloating(int areaIndex) const = 0;