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();
80 if (myself) { myself->emitInfoAreaStatus(); }
86 if (!menu) {
return; }
87 bool hasDockedWidgets = this->countDockedWidgetInfoAreas() > 0;
92 menu->
addAction(CIcons::refresh16(),
"Reset all floating to defaults",
this,
96 menu->
addAction(CIcons::floatOne16(), QStringLiteral(
"Dock / float '%1'").arg(this->
windowTitle()),
this,
98 auto *lockTabBarMenuAction =
new QAction(menu);
99 lockTabBarMenuAction->setObjectName(this->
objectName().append(
"LockTabBar"));
100 lockTabBarMenuAction->setIconText(
"Lock tab bar");
101 lockTabBarMenuAction->setIcon(CIcons::lockClosed16());
102 lockTabBarMenuAction->setCheckable(
true);
103 lockTabBarMenuAction->setChecked(m_lockTabBar);
108 auto *subMenuToggleFloat =
new QMenu(
"Toggle Float/Dock", menu);
109 auto *subMenuDisplay =
new QMenu(
"Display", menu);
110 auto *subMenuRestore =
new QMenu(
"Restore from settings", menu);
111 auto *subMenuResetPositions =
new QMenu(
"Reset position", menu);
112 subMenuRestore->setIcon(CIcons::load16());
113 subMenuResetPositions->setIcon(CIcons::refresh16());
121 for (
int i = 0; i < m_dockWidgetInfoAreas.size(); i++)
126 auto *toggleFloatingMenuAction =
new QAction(menu);
127 toggleFloatingMenuAction->setObjectName(
QString(t).append(
"ToggleFloatingAction"));
128 toggleFloatingMenuAction->setIconText(t);
129 toggleFloatingMenuAction->setIcon(pm);
130 toggleFloatingMenuAction->setData(
QVariant(i));
131 toggleFloatingMenuAction->setCheckable(
true);
132 toggleFloatingMenuAction->setChecked(!dw->
isFloating());
133 subMenuToggleFloat->addAction(toggleFloatingMenuAction);
137 "Cannot map floating action");
138 signalMapperToggleFloating->setMapping(toggleFloatingMenuAction, i);
143 "Cannot connect mapper");
146 if (c) { menu->
addMenu(subMenuToggleFloat); }
147 menu->
addMenu(subMenuResetPositions);
152 auto *showMenuText =
new QAction(menu);
153 showMenuText->setObjectName(
"ShowDockedWidgetTextAction");
154 showMenuText->setIconText(
"Show tab text");
155 showMenuText->setIcon(CIcons::headingOne16());
156 showMenuText->setCheckable(
true);
157 showMenuText->setChecked(m_showTabTexts);
162 auto *showTabbar =
new QAction(menu);
163 showTabbar->setObjectName(
"ShowTabBar");
164 showTabbar->setIconText(
"Show tab bar");
165 showTabbar->setIcon(CIcons::dockBottom16());
166 showTabbar->setCheckable(
true);
167 showTabbar->setChecked(m_showTabBar);
172 menu->
addAction(CIcons::dockBottom16(),
"Toggle tabbar position",
this, &CInfoArea::toggleTabBarPosition);
179 if (!infoArea) {
return false; }
182 if (!m_tabBar || m_tabBar->
count() < 1) {
return false; }
191 if (!m_tabBar || m_tabBar->
count() < 1) {
return nullptr; }
194 if (ia->isFloating()) {
continue; }
195 if (ia->isWidgetVisible()) {
return ia; }
203 if (!sel) {
return -1; }
205 int ia = getAreaIndexByWindowTitle(t);
222 const QString wt(dockWidgetInfoArea->windowTitleBackup());
223 static const QString keys(
"123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
226 action->setObjectName(this->
objectName().append(
":getInfoAreaSelectActions:").append(wt));
227 if (withShortcut && i < keys.
length())
232 action->setShortcut(
QKeySequence(QStringLiteral(
"Ctrl+Shift+%1").arg(keys.
at(i))));
250 const QString wt(dockWidgetInfoArea->windowTitleBackup());
253 action->setObjectName(this->
objectName().append(
":getInfoAreaResetPositionActions:").append(wt));
269 const QString wt(dockWidgetInfoArea->windowTitleBackup());
272 action->setObjectName(this->
objectName().append(
":getInfoAreaToggleFloatingActions:").append(wt));
288 const QString wt(dockWidgetInfoArea->windowTitleBackup());
291 action->setObjectName(this->
objectName().append(
":getInfoAreaRestoreActions:").append(wt));
302 for (
int i = 0; i < m_dockWidgetInfoAreas.size(); i++)
304 if (m_dockWidgetInfoAreas.at(i)->isFloating() == floating) { indexes.
append(i); }
341 if (dw->isFloating()) {
continue; }
342 dw->toggleFloating();
350 if (!dw || !dw->isFloating()) {
continue; }
359 if (!dw || !dw->isFloating()) {
continue; }
368 const bool f = dw->isFloating();
370 if (f) { dw->show(); }
378 if (!this->isValidAreaIndex(areaIndex)) {
return; }
387 if (!this->isValidAreaIndex(areaIndex)) {
return; }
400 if (m_tabBar->
count() < 1) {
return; }
417 const auto *action = qobject_cast<const QAction *>(
sender);
419 if (!action) {
return; }
420 const int index = action->data().toInt();
427 const auto *action = qobject_cast<const QAction *>(
sender);
429 if (!action) {
return; }
430 const int index = action->data().toInt();
437 const auto *action = qobject_cast<const QAction *>(
sender);
439 if (!action) {
return; }
440 const int index = action->data().toInt();
447 const auto *action = qobject_cast<const QAction *>(
sender);
449 if (!action) {
return; }
450 const int index = action->data().toInt();
456 if (!this->isValidAreaIndex(areaIndex)) {
return; }
465 if (!m_tabBar)
return;
466 if (m_tabBar->
count() < 2)
return;
473 if (!m_tabBar)
return;
474 if (m_tabBar->
count() < 2)
return;
486 dw->displayStatusMessage(statusMessage);
488 for (
CInfoArea *ia : std::as_const(m_childInfoAreas)) { ia->displayStatusMessage(statusMessage); }
495 dw->displayStatusMessages(statusMessages);
497 for (
CInfoArea *ia : std::as_const(m_childInfoAreas)) { ia->displayStatusMessages(statusMessages); }
506 if (oldAreas == newAreas) {
continue; }
507 dw->setAllowedAreas(newAreas);
512 void CInfoArea::setWholeInfoAreaFloating(
bool floating)
515 m_infoAreaFloating = floating;
516 if (m_infoAreaFloating)
521 this->
move(p.
rx() + 20, p.
ry() + 20);
542 void CInfoArea::tabifyAllWidgets()
546 const bool init = m_tabBar ==
nullptr;
548 for (
int i = 0; i < m_dockWidgetInfoAreas.size(); i++)
550 CDockWidgetInfoArea *first = i > 0 ? m_dockWidgetInfoAreas.at(i - 1) :
nullptr;
551 CDockWidgetInfoArea *after = m_dockWidgetInfoAreas.at(i);
559 const QPoint offset(i * 10, i * 10);
562 after->setOffsetWhenFloating(offset, after->isFrameless());
564 after->setPreferredSizeWhenFloating(floatingSize);
565 after->initialFloating();
572 after->resetWasAlreadyFloating();
574 else { after->setFloating(
false); }
577 if (!first) {
continue; }
585 m_tabBar = this->findChild<QTabBar *>();
588 if (m_tabBar &&
sGui)
616 if (this->countDockedWidgetInfoAreas() > 0) { m_tabBar->
setCurrentIndex(0); }
617 if (m_tabBar->
count() > 0) { this->setTabPixmaps(); }
620 void CInfoArea::unTabifyAllWidgets()
622 if (m_dockWidgetInfoAreas.size() < 2)
return;
623 CDockWidgetInfoArea *first = m_dockWidgetInfoAreas.constFirst();
624 for (
int i = 1; i < m_dockWidgetInfoAreas.size(); i++)
626 CDockWidgetInfoArea *after = m_dockWidgetInfoAreas.at(i);
632 bool CInfoArea::isValidAreaIndex(
int areaIndex)
const
634 if (!m_tabBar) {
return false; }
635 return areaIndex >= 0 && areaIndex < m_dockWidgetInfoAreas.size();
638 void CInfoArea::connectTopLevelChanged()
640 for (CDockWidgetInfoArea *dw : std::as_const(m_dockWidgetInfoAreas))
658 void CInfoArea::emitInfoAreaStatus()
667 void CInfoArea::onTabBarIndexChanged(
int tabBarIndex)
670 this->emitInfoAreaStatus();
673 int CInfoArea::countDockedWidgetInfoAreas()
const
675 if (!m_tabBar) {
return 0; }
676 return m_tabBar->
count();
679 CDockWidgetInfoArea *CInfoArea::getDockWidgetInfoAreaByTabBarIndex(
int tabBarIndex)
const
681 if (tabBarIndex >= m_dockWidgetInfoAreas.count() || tabBarIndex < 0) {
return nullptr; }
682 if (!m_tabBar) {
return nullptr; }
686 if (!t.isEmpty()) {
return this->getDockWidgetInfoAreaByWindowTitle(t); }
691 for (CDockWidgetInfoArea *dw : m_dockWidgetInfoAreas)
693 if (dw->isFloating()) {
continue; }
694 if (c == tabBarIndex) {
return dw; }
697 Q_ASSERT_X(
false, Q_FUNC_INFO,
"no dock widgte found");
701 CDockWidgetInfoArea *CInfoArea::getDockWidgetInfoAreaByWindowTitle(
const QString &title)
const
703 Q_ASSERT_X(!title.
isEmpty(), Q_FUNC_INFO,
"No title");
704 for (CDockWidgetInfoArea *dw : m_dockWidgetInfoAreas)
711 int CInfoArea::getAreaIndexByWindowTitle(
const QString &title)
const
713 Q_ASSERT_X(!title.
isEmpty(), Q_FUNC_INFO,
"No title");
715 for (
int i = 0; i < m_dockWidgetInfoAreas.size(); i++)
722 Q_ASSERT_X(
false, Q_FUNC_INFO,
"No area for title");
726 int CInfoArea::getTabBarIndexByTitle(
const QString &title)
const
729 if (title.
isEmpty()) {
return -1; }
731 if (m_tabBar->
count() < 1) {
return -1; }
732 for (
int i = 0; i < m_tabBar->
count(); i++)
736 if (tt.
isEmpty()) {
continue; }
742 int CInfoArea::dockWidgetInfoAreaToTabBarIndex(
const CDockWidgetInfoArea *dockWidgetInfoArea)
const
744 if (!dockWidgetInfoArea) {
return -1; }
745 if (dockWidgetInfoArea->isFloating()) {
return -1; }
746 int index = this->getTabBarIndexByTitle(dockWidgetInfoArea->windowTitleOrBackup());
751 for (
const CDockWidgetInfoArea *a : m_dockWidgetInfoAreas)
753 if (a == dockWidgetInfoArea)
763 if (index >= m_tabBar->
count()) { index = -1; }
771 if (!m_tabBar) {
return; }
772 int tabIndex = this->dockWidgetInfoAreaToTabBarIndex(dockWidgetInfoArea);
773 if (tabIndex >= 0 && tabIndex < m_tabBar->count()) { m_tabBar->
setCurrentIndex(tabIndex); }
778 for (
CDockWidgetInfoArea *dw : std::as_const(m_dockWidgetInfoAreas)) { dw->setFeatures(features); }
781 void CInfoArea::setTabPixmaps()
783 if (!m_tabBar) {
return; }
784 for (
int i = 0; i < m_tabBar->
count(); i++)
787 const int areaIndex = t.isEmpty() ? i : this->getAreaIndexByWindowTitle(t);
793 void CInfoArea::onTabBarDoubleClicked(
int tabBarIndex)
797 CLogMessage(
this).
info(u
"Locked, double click will not cause floating");
800 CDockWidgetInfoArea *dw = this->getDockWidgetInfoAreaByTabBarIndex(tabBarIndex);
802 dw->toggleFloating();
806 if (!myself) {
return; }
807 myself->emitInfoAreaStatus();
811 void CInfoArea::onWidgetTopLevelChanged(CDockWidget *dockWidget,
bool topLevel)
813 Q_ASSERT(dockWidget);
815 if (!dockWidget) {
return; }
818 this->setTabPixmaps();
823 const CDockWidgetInfoArea *dwia =
dynamic_cast<CDockWidgetInfoArea *
>(dockWidget);
833 void CInfoArea::onStyleSheetChanged()
843 void CInfoArea::showContextMenu(
const QPoint &pos)
849 QAction *selectedItem = contextMenu.
data()->exec(globalPos);
850 Q_UNUSED(selectedItem)
853 void CInfoArea::showTabTexts(
bool show)
855 if (
show == m_showTabTexts) {
return; }
856 m_showTabTexts =
show;
857 for (CDockWidgetInfoArea *dw : std::as_const(m_dockWidgetInfoAreas)) { dw->showTitleWhenDocked(
show); }
860 void CInfoArea::showTabBar(
bool show)
862 if (
show == m_showTabBar)
return;
864 if (!m_tabBar)
return;
875 "Wrong tabbar position");
879 void CInfoArea::toggleTabBarPosition()
891 event->setAccepted(
false);
bool isShuttingDown() const
Is application shutting down?
Main window which can be frameless.
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.
Info area, hosting dockable widgets.
virtual void toggleFloatingWholeInfoArea()
Toggle dock / floating of the whole info area.
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.
Class for emitting a log message.
Derived & info(const char16_t(&format)[N])
Set the severity to info, providing a format string.
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.
QVariant data() const const
void toggled(bool checked)
void triggered(bool checked)
void append(QList< T > &&value)
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)
QObject * parent() const const
QObject * sender() const const
void setObjectName(QAnyStringView name)
const QChar at(qsizetype position) const const
bool isEmpty() const const
qsizetype length() const const
void currentChanged(int index)
void setElideMode(Qt::TextElideMode mode)
void setMovable(bool movable)
void setTabIcon(int index, const QIcon &icon)
void setShape(QTabBar::Shape shape)
void tabBarDoubleClicked(int index)
QString tabText(int index) const const
#define SWIFT_VERIFY_X(COND, WHERE, WHAT)
A weaker kind of assert.
#define SWIFT_VERIFY(COND)
A weaker kind of assert.