15#include <QScopedPointer>
16#include <QSignalMapper>
42 this->setWholeInfoAreaFloating(m_infoAreaFloating);
52 m_childInfoAreas = this->findOwnChildInfoAreas();
53 m_dockWidgetInfoAreas = this->findOwnDockWidgetInfoAreas();
56 this->connectTopLevelChanged();
59 this->tabifyAllWidgets();
68 this->onStyleSheetChanged();
82 myself->emitInfoAreaStatus();
93 bool hasDockedWidgets = this->countDockedWidgetInfoAreas() > 0;
104 auto *lockTabBarMenuAction =
new QAction(menu);
105 lockTabBarMenuAction->setObjectName(this->
objectName().append(
"LockTabBar"));
106 lockTabBarMenuAction->setIconText(
"Lock tab bar");
108 lockTabBarMenuAction->setCheckable(
true);
109 lockTabBarMenuAction->setChecked(m_lockTabBar);
114 auto *subMenuToggleFloat =
new QMenu(
"Toggle Float/Dock", menu);
115 auto *subMenuDisplay =
new QMenu(
"Display", menu);
116 auto *subMenuRestore =
new QMenu(
"Restore from settings", menu);
117 auto *subMenuResetPositions =
new QMenu(
"Reset position", menu);
127 for (
int i = 0; i < m_dockWidgetInfoAreas.size(); i++)
132 auto *toggleFloatingMenuAction =
new QAction(menu);
133 toggleFloatingMenuAction->setObjectName(
QString(t).append(
"ToggleFloatingAction"));
134 toggleFloatingMenuAction->setIconText(t);
135 toggleFloatingMenuAction->setIcon(pm);
136 toggleFloatingMenuAction->setData(
QVariant(i));
137 toggleFloatingMenuAction->setCheckable(
true);
138 toggleFloatingMenuAction->setChecked(!dw->
isFloating());
139 subMenuToggleFloat->addAction(toggleFloatingMenuAction);
143 "Cannot map floating action");
144 signalMapperToggleFloating->setMapping(toggleFloatingMenuAction, i);
149 "Cannot connect mapper");
154 menu->
addMenu(subMenuToggleFloat);
156 menu->
addMenu(subMenuResetPositions);
161 auto *showMenuText =
new QAction(menu);
162 showMenuText->setObjectName(
"ShowDockedWidgetTextAction");
163 showMenuText->setIconText(
"Show tab text");
165 showMenuText->setCheckable(
true);
166 showMenuText->setChecked(m_showTabTexts);
171 auto *showTabbar =
new QAction(menu);
172 showTabbar->setObjectName(
"ShowTabBar");
173 showTabbar->setIconText(
"Show tab bar");
175 showTabbar->setCheckable(
true);
176 showTabbar->setChecked(m_showTabBar);
200 if (!m_tabBar || m_tabBar->count() < 1)
212 if (!m_tabBar || m_tabBar->count() < 1)
218 if (ia->isFloating())
222 if (ia->isWidgetVisible())
238 int ia = getAreaIndexByWindowTitle(t);
255 const QString wt(dockWidgetInfoArea->windowTitleBackup());
256 static const QString keys(
"123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
259 action->setObjectName(this->
objectName().append(
":getInfoAreaSelectActions:").append(wt));
260 if (withShortcut && i < keys.
length())
265 action->setShortcut(
QKeySequence(QStringLiteral(
"Ctrl+Shift+%1").arg(keys.
at(i))));
283 const QString wt(dockWidgetInfoArea->windowTitleBackup());
286 action->setObjectName(this->
objectName().append(
":getInfoAreaResetPositionActions:").append(wt));
302 const QString wt(dockWidgetInfoArea->windowTitleBackup());
305 action->setObjectName(this->
objectName().append(
":getInfoAreaToggleFloatingActions:").append(wt));
321 const QString wt(dockWidgetInfoArea->windowTitleBackup());
324 action->setObjectName(this->
objectName().append(
":getInfoAreaRestoreActions:").append(wt));
335 for (
int i = 0; i < m_dockWidgetInfoAreas.size(); i++)
337 if (m_dockWidgetInfoAreas.at(i)->isFloating() == floating)
383 if (dw->isFloating())
387 dw->toggleFloating();
395 if (!dw || !dw->isFloating())
407 if (!dw || !dw->isFloating())
419 const bool f = dw->isFloating();
432 if (!this->isValidAreaIndex(areaIndex))
447 if (!this->isValidAreaIndex(areaIndex))
469 if (m_tabBar->count() < 1)
504 const int index = action->data().toInt();
517 const int index = action->data().toInt();
530 const int index = action->data().toInt();
543 const int index = action->data().toInt();
549 if (!this->isValidAreaIndex(areaIndex))
564 if (!m_tabBar)
return;
565 if (m_tabBar->count() < 2)
return;
566 if (m_tabBar->currentIndex() > 0)
568 m_tabBar->setCurrentIndex(m_tabBar->currentIndex() - 1);
572 m_tabBar->setCurrentIndex(m_tabBar->count() - 1);
578 if (!m_tabBar)
return;
579 if (m_tabBar->count() < 2)
return;
580 if (m_tabBar->currentIndex() < m_tabBar->count() - 2)
582 m_tabBar->setCurrentIndex(m_tabBar->currentIndex() + 1);
586 m_tabBar->setCurrentIndex(0);
594 dw->displayStatusMessage(statusMessage);
596 for (
CInfoArea *ia : std::as_const(m_childInfoAreas))
598 ia->displayStatusMessage(statusMessage);
606 dw->displayStatusMessages(statusMessages);
608 for (
CInfoArea *ia : std::as_const(m_childInfoAreas))
610 ia->displayStatusMessages(statusMessages);
620 if (oldAreas == newAreas)
624 dw->setAllowedAreas(newAreas);
629 void CInfoArea::setWholeInfoAreaFloating(
bool floating)
632 m_infoAreaFloating = floating;
633 if (m_infoAreaFloating)
638 this->
move(p.
rx() + 20, p.
ry() + 20);
659 void CInfoArea::tabifyAllWidgets()
666 const bool init = m_tabBar ==
nullptr;
668 for (
int i = 0; i < m_dockWidgetInfoAreas.size(); i++)
670 CDockWidgetInfoArea *first = i > 0 ? m_dockWidgetInfoAreas.at(i - 1) :
nullptr;
671 CDockWidgetInfoArea *after = m_dockWidgetInfoAreas.at(i);
679 const QPoint offset(i * 10, i * 10);
682 after->setOffsetWhenFloating(offset, after->isFrameless());
684 after->setPreferredSizeWhenFloating(floatingSize);
685 after->initialFloating();
692 after->resetWasAlreadyFloating();
696 after->setFloating(
false);
714 if (m_tabBar &&
sGui)
717 m_tabBar->setStyleSheet(qss);
718 m_tabBar->setObjectName(
"comp_MainInfoAreaDockWidgetTab");
719 m_tabBar->setMovable(
false);
721 m_tabBar->setUsesScrollButtons(
true);
736 m_tabBar =
new QTabBar(
this);
742 if (this->countDockedWidgetInfoAreas() > 0)
744 m_tabBar->setCurrentIndex(0);
746 if (m_tabBar->count() > 0)
748 this->setTabPixmaps();
752 void CInfoArea::unTabifyAllWidgets()
754 if (m_dockWidgetInfoAreas.size() < 2)
return;
755 CDockWidgetInfoArea *first = m_dockWidgetInfoAreas.constFirst();
756 for (
int i = 1; i < m_dockWidgetInfoAreas.size(); i++)
758 CDockWidgetInfoArea *after = m_dockWidgetInfoAreas.at(i);
764 bool CInfoArea::isValidAreaIndex(
int areaIndex)
const
770 return areaIndex >= 0 && areaIndex < m_dockWidgetInfoAreas.size();
773 void CInfoArea::connectTopLevelChanged()
775 for (CDockWidgetInfoArea *dw : std::as_const(m_dockWidgetInfoAreas))
782 QList<CDockWidgetInfoArea *> CInfoArea::findOwnDockWidgetInfoAreas()
const
788 QList<CInfoArea *> CInfoArea::findOwnChildInfoAreas()
const
793 void CInfoArea::emitInfoAreaStatus()
805 void CInfoArea::onTabBarIndexChanged(
int tabBarIndex)
808 this->emitInfoAreaStatus();
811 int CInfoArea::countDockedWidgetInfoAreas()
const
817 return m_tabBar->count();
822 if (tabBarIndex >= m_dockWidgetInfoAreas.count() || tabBarIndex < 0)
830 const QString t(m_tabBar->tabText(tabBarIndex));
835 return this->getDockWidgetInfoAreaByWindowTitle(t);
841 for (CDockWidgetInfoArea *dw : m_dockWidgetInfoAreas)
843 if (dw->isFloating())
847 if (c == tabBarIndex)
853 Q_ASSERT_X(
false, Q_FUNC_INFO,
"no dock widgte found");
857 CDockWidgetInfoArea *CInfoArea::getDockWidgetInfoAreaByWindowTitle(
const QString &title)
const
859 Q_ASSERT_X(!title.
isEmpty(), Q_FUNC_INFO,
"No title");
860 for (CDockWidgetInfoArea *dw : m_dockWidgetInfoAreas)
870 int CInfoArea::getAreaIndexByWindowTitle(
const QString &title)
const
872 Q_ASSERT_X(!title.
isEmpty(), Q_FUNC_INFO,
"No title");
874 for (
int i = 0; i < m_dockWidgetInfoAreas.size(); i++)
881 Q_ASSERT_X(
false, Q_FUNC_INFO,
"No area for title");
885 int CInfoArea::getTabBarIndexByTitle(
const QString &title)
const
893 if (m_tabBar->count() < 1)
897 for (
int i = 0; i < m_tabBar->count(); i++)
899 QString tt = m_tabBar->tabText(i);
902 tt = m_tabBar->tabToolTip(i);
916 int CInfoArea::dockWidgetInfoAreaToTabBarIndex(
const CDockWidgetInfoArea *dockWidgetInfoArea)
const
918 if (!dockWidgetInfoArea)
922 if (dockWidgetInfoArea->isFloating())
926 int index = this->getTabBarIndexByTitle(dockWidgetInfoArea->windowTitleOrBackup());
931 for (
const CDockWidgetInfoArea *a : m_dockWidgetInfoAreas)
933 if (a == dockWidgetInfoArea)
943 if (index >= m_tabBar->count())
958 int tabIndex = this->dockWidgetInfoAreaToTabBarIndex(dockWidgetInfoArea);
959 if (tabIndex >= 0 && tabIndex < m_tabBar->count())
961 m_tabBar->setCurrentIndex(tabIndex);
969 dw->setFeatures(features);
973 void CInfoArea::setTabPixmaps()
979 for (
int i = 0; i < m_tabBar->count(); i++)
981 const QString t(m_tabBar->tabText(i));
982 const int areaIndex = t.isEmpty() ? i : this->getAreaIndexByWindowTitle(t);
984 m_tabBar->setTabToolTip(i, t);
988 void CInfoArea::onTabBarDoubleClicked(
int tabBarIndex)
992 CLogMessage(
this).info(u
"Locked, double click will not cause floating");
995 CDockWidgetInfoArea *dw = this->getDockWidgetInfoAreaByTabBarIndex(tabBarIndex);
1000 dw->toggleFloating();
1002 QPointer<CInfoArea> myself(
this);
1008 myself->emitInfoAreaStatus();
1012 void CInfoArea::onWidgetTopLevelChanged(
CDockWidget *dockWidget,
bool topLevel)
1014 Q_ASSERT(dockWidget);
1022 this->setTabPixmaps();
1027 const CDockWidgetInfoArea *dwia =
dynamic_cast<CDockWidgetInfoArea *
>(dockWidget);
1037 void CInfoArea::onStyleSheetChanged()
1046 m_tabBar->setStyleSheet(qss);
1050 void CInfoArea::showContextMenu(
const QPoint &pos)
1053 QScopedPointer<QMenu> contextMenu(
new QMenu(
this));
1056 QAction *selectedItem = contextMenu.data()->exec(globalPos);
1057 Q_UNUSED(selectedItem)
1060 void CInfoArea::showTabTexts(
bool show)
1062 if (
show == m_showTabTexts)
1066 m_showTabTexts =
show;
1067 for (CDockWidgetInfoArea *dw : std::as_const(m_dockWidgetInfoAreas))
1069 dw->showTitleWhenDocked(
show);
1073 void CInfoArea::showTabBar(
bool show)
1075 if (
show == m_showTabBar)
return;
1076 m_showTabBar =
show;
1077 if (!m_tabBar)
return;
1078 m_tabBar->setVisible(
show);
1079 m_tabBar->setMaximumHeight(
show ? 10000 : 0);
1088 "Wrong tabbar position");
1092 void CInfoArea::toggleTabBarPosition()
1104 event->setAccepted(
false);
bool isShuttingDown() const
Is application shutting down?
CEnableForFramelessWindow(WindowMode mode, bool isMainApplicationWindow, const char *framelessPropertyname, QWidget *correspondingWidget)
Constructor.
const CStyleSheetUtility & getStyleSheetUtility() const
Style sheet handling.
void styleSheetsChanged()
Style sheet changed.
static bool stayOnTop(bool onTop, QWidget *widget)
Window flags / stay on top.
static QPoint mainWidgetGlobalPosition()
Position of main widget.
static bool lenientTitleComparison(const QString &title, const QString &comparison)
Lenient / relaxed.
virtual void toggleFloatingWholeInfoArea()
Toggle dock / floating of the whole info area.
CInfoArea(QWidget *parent=nullptr)
Constructor.
void selectLeftTab()
Select next left tab.
void changedInfoAreaStatus(int currentTabIndex, QList< int > dockedAreas, QList< int > floatingAreas)
Status of info area changed.
void addToContextMenu(QMenu *menu) const
Add items to context menu.
void toggleFloatingByIndex(int areaIndex)
Toggle floating of index.
void closeEvent(QCloseEvent *event)
void toggleVisibility(int areaIndex)
Toggle visibilty.
void selectArea(int areaIndex)
Select area.
void toggleAreaFloatingByAction()
Toggle area floating (sender is QAction).
QList< QAction * > getInfoAreaRestoreActions(QWidget *parent) const
Create a list of actions to restore the info areas. This could be used in a menu or somewhere else.
void floatAllWidgets()
All widgets floating.
QList< QAction * > getInfoAreaToggleFloatingActions(QWidget *parent) const
Create a list of actions to select the info areas and toogle its floating state. This could be used i...
void adjustSizeForAllDockWidgets()
Adjust size for all dock widgets.
void setTabBarPosition(QTabWidget::TabPosition position)
Tab position for docked widgets tab.
void restoreDockWidgetInfoArea()
Restore dock widget`s state (from settings).
void paintEvent(QPaintEvent *event)
void selectRightTab()
Select next right tab.
void selectAreaByAction()
Select area (sender is QAction).
void resetAllWidgetSettings()
Reset all widget settings.
void initInfoArea()
Init area after(!) GUI is initialized.
void toggleTabBarLocked(bool locked)
Toogle lock tabbar.
void changedInfoAreaTabBarIndex(int index)
Tab bar changed.
QList< const CDockWidgetInfoArea * > getDockWidgetInfoAreas() const
Own dockable widgets.
virtual QSize getPreferredSizeWhenFloating(int areaIndex) const =0
Preferred size when floating (size hint).
void changedWholeInfoAreaFloating(bool floating)
Whole info area floating.
void dockAllWidgets()
Dock all widgets.
QList< int > getAreaIndexesDockedOrFloating(bool floating) const
Docked area indexes.
void restoreDockWidgetInfoAreaByIndex(int areaIndex)
Restore dock widget`s state (from settings).
QList< QAction * > getInfoAreaResetPositionActions(QWidget *parent) const
Create a list of actions to reset the position the info areas. This could be used in a menu or somewh...
void displayStatusMessages(const swift::misc::CStatusMessageList &statusMessages)
Display status messages in all info areas (according their state).
bool isFloating() const
Is the area floating?
bool isSelectedDockWidgetInfoArea(const CDockWidgetInfoArea *infoArea) const
Is given widget selected. Means it is not floating, and the one selected.
void resetAllFloatingWidgetSettings()
Reset all floating widget settings.
virtual const QPixmap & indexToPixmap(int areaIndex) const =0
Info area (index) to icon.
QList< QAction * > getInfoAreaSelectActions(bool withShortcut, QWidget *parent) const
Create a list of actions to select the info areas. This could be used in a menu or somewhere else.
void displayStatusMessage(const swift::misc::CStatusMessage &statusMessage)
Display status message in all info areas (according their state).
const CDockWidgetInfoArea * getSelectedDockInfoArea() const
Get the selected info area (non floating, selected in tabbar).
void resetPosition(int areaIndex)
Reset position.
int getSelectedDockInfoAreaIndex() const
Get the selected info area (non floating, selected in tabbar).
void keyPressEvent(QKeyEvent *event)
void resetPositionByAction()
Reset window position of area (sender is QAction).
void allFloatingOnTop()
All floating info areas on top.
static const QString & fileNameDockWidgetTab()
File name dockwidgettab.qss.
static bool useStyleSheetInDerivedWidget(QWidget *derivedWidget, QStyle::PrimitiveElement element=QStyle::PE_Widget)
Use style sheets in derived widgets.
QString style(const QString &fileName) const
Style for given file name.
static const QPixmap & refresh16()
Refresh.
static const QPixmap & floatAll16()
Float all.
static const QPixmap & headingOne16()
Heading 1.
static const QPixmap & dockBottom16()
Docking.
static const QPixmap & floatOne16()
Float all.
static const QPixmap & dockTop16()
Docking.
static const QPixmap & load16()
Load.
static const QPixmap & lockClosed16()
Lock.
Streamable status message, e.g.
Status messages, e.g. from Core -> GUI.
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
Free functions in swift::misc.
auto makeRange(I begin, I2 end) -> CRange< I >
Returns a CRange constructed from begin and end iterators of deduced types.
void toggled(bool checked)
void triggered(bool checked)
void append(QList< T > &&value)
QMainWindow(QWidget *parent, Qt::WindowFlags flags)
void addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget)
virtual bool event(QEvent *event) override
void setTabPosition(Qt::DockWidgetAreas areas, QTabWidget::TabPosition tabPosition)
void splitDockWidget(QDockWidget *first, QDockWidget *second, Qt::Orientation orientation)
QStatusBar * statusBar() const const
QTabWidget::TabPosition tabPosition(Qt::DockWidgetArea area) const const
void tabifyDockWidget(QDockWidget *first, QDockWidget *second)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T findChild(QAnyStringView name, Qt::FindChildOptions options) const const
QList< T > findChildren(QAnyStringView name, Qt::FindChildOptions options) const const
QObject * parent() const const
T qobject_cast(QObject *object)
QObject * sender() const const
const QChar at(qsizetype position) const const
bool isEmpty() const const
qsizetype length() const const
void currentChanged(int index)
void tabBarDoubleClicked(int index)
#define SWIFT_VERIFY_X(COND, WHERE, WHAT)
A weaker kind of assert.
#define SWIFT_VERIFY(COND)
A weaker kind of assert.