mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-30 05:51:23 +08:00
refs #335, changed info areas, obtain actions for main menu
This commit is contained in:
committed by
Roland Winklmeier
parent
11521b2f47
commit
48741c218f
@@ -16,6 +16,10 @@
|
|||||||
#include <QSignalMapper>
|
#include <QSignalMapper>
|
||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
#include <QStatusBar>
|
#include <QStatusBar>
|
||||||
|
#include <QAction>
|
||||||
|
#include <QShortcut>
|
||||||
|
#include <QKeySequence>
|
||||||
|
#include <QIcon>
|
||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
|
|
||||||
@@ -82,9 +86,9 @@ namespace BlackGui
|
|||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
QMenu *subMenuToggleFloat = new QMenu("Toggle Float/Dock", menu);
|
QMenu *subMenuToggleFloat = new QMenu("Toggle Float/Dock", menu);
|
||||||
QMenu *subMenuDisplay = new QMenu("Display", menu);
|
QMenu *subMenuDisplay = new QMenu("Display", menu);
|
||||||
|
subMenuDisplay->addActions(this->getInfoAreaSelectActions(subMenuDisplay));
|
||||||
|
|
||||||
QSignalMapper *signalMapperToggleFloating = new QSignalMapper(menu);
|
QSignalMapper *signalMapperToggleFloating = new QSignalMapper(menu);
|
||||||
QSignalMapper *signalMapperDisplay = new QSignalMapper(menu);
|
|
||||||
bool c = false;
|
bool c = false;
|
||||||
|
|
||||||
for (int i = 0; i < this->m_dockWidgetInfoAreas.size(); i++)
|
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()));
|
c = connect(toggleFloatingMenuAction, SIGNAL(toggled(bool)), signalMapperToggleFloating, SLOT(map()));
|
||||||
Q_ASSERT(c);
|
Q_ASSERT(c);
|
||||||
signalMapperToggleFloating->setMapping(toggleFloatingMenuAction, i);
|
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)));
|
c = connect(signalMapperToggleFloating, SIGNAL(mapped(int)), this, SLOT(toggleFloating(int)));
|
||||||
Q_ASSERT(c);
|
Q_ASSERT(c);
|
||||||
|
|
||||||
c = connect(signalMapperDisplay, SIGNAL(mapped(int)), this, SLOT(selectArea(int)));
|
|
||||||
Q_ASSERT(c);
|
|
||||||
|
|
||||||
menu->addMenu(subMenuDisplay);
|
menu->addMenu(subMenuDisplay);
|
||||||
menu->addMenu(subMenuToggleFloat);
|
menu->addMenu(subMenuToggleFloat);
|
||||||
|
|
||||||
@@ -182,12 +171,44 @@ namespace BlackGui
|
|||||||
return constDockWidgets;
|
return constDockWidgets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QAction *> CInfoArea::getInfoAreaSelectActions(QWidget *parent) const
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
QList<QAction *> 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)
|
void CInfoArea::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event);
|
Q_UNUSED(event);
|
||||||
CStyleSheetUtility::useStyleSheetInDerivedWidget(this);
|
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()
|
void CInfoArea::dockAllWidgets()
|
||||||
{
|
{
|
||||||
this->tabifyAllWidgets();
|
this->tabifyAllWidgets();
|
||||||
@@ -251,6 +272,44 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CInfoArea::selectAreaByAction()
|
||||||
|
{
|
||||||
|
const QObject *sender = QObject::sender();
|
||||||
|
Q_ASSERT(sender);
|
||||||
|
const QAction *action = qobject_cast<const QAction *>(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)
|
void CInfoArea::ps_setDockArea(Qt::DockWidgetArea area)
|
||||||
{
|
{
|
||||||
for (CDockWidgetInfoArea *dw : this->m_dockWidgetInfoAreas)
|
for (CDockWidgetInfoArea *dw : this->m_dockWidgetInfoAreas)
|
||||||
|
|||||||
@@ -46,6 +46,11 @@ namespace BlackGui
|
|||||||
//! Own dockable widgets
|
//! Own dockable widgets
|
||||||
QList<const CDockWidgetInfoArea *> getDockWidgetInfoAreas() const;
|
QList<const CDockWidgetInfoArea *> 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<QAction *> getInfoAreaSelectActions(QWidget *parent) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
//! Tab bar changed
|
//! Tab bar changed
|
||||||
void tabBarCurrentChanged(int index);
|
void tabBarCurrentChanged(int index);
|
||||||
@@ -72,6 +77,15 @@ namespace BlackGui
|
|||||||
//! Select area
|
//! Select area
|
||||||
void selectArea(int areaIndex);
|
void selectArea(int areaIndex);
|
||||||
|
|
||||||
|
//! Select area (sender is QAction)
|
||||||
|
void selectAreaByAction();
|
||||||
|
|
||||||
|
//! Select next left tab
|
||||||
|
void selectLeftTab();
|
||||||
|
|
||||||
|
//! Select next right tab
|
||||||
|
void selectRightTab();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
explicit CInfoArea(QWidget *parent = nullptr);
|
explicit CInfoArea(QWidget *parent = nullptr);
|
||||||
@@ -82,6 +96,10 @@ namespace BlackGui
|
|||||||
//! \copydoc QWidget::paintEvent
|
//! \copydoc QWidget::paintEvent
|
||||||
virtual void paintEvent(QPaintEvent *event) override;
|
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)
|
//! Preferred size when floating (size hint)
|
||||||
virtual QSize getPreferredSizeWhenFloating(int areaIndex) const = 0;
|
virtual QSize getPreferredSizeWhenFloating(int areaIndex) const = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user