15 #include <QScopedPointer>
16 #include <QSignalMapper>
42 this->setWholeInfoAreaFloating(m_infoAreaFloating);
54 m_childInfoAreas = this->findOwnChildInfoAreas();
55 m_dockWidgetInfoAreas = this->findOwnDockWidgetInfoAreas();
58 this->connectTopLevelChanged();
61 this->tabifyAllWidgets();
70 this->onStyleSheetChanged();
82 if (myself) { myself->emitInfoAreaStatus(); }
88 if (!menu) {
return; }
89 bool hasDockedWidgets = this->countDockedWidgetInfoAreas() > 0;
94 menu->
addAction(CIcons::refresh16(),
"Reset all floating to defaults",
this,
98 menu->
addAction(CIcons::floatOne16(), QStringLiteral(
"Dock / float '%1'").arg(this->
windowTitle()),
this,
103 lockTabBarMenuAction->
setIcon(CIcons::lockClosed16());
105 lockTabBarMenuAction->
setChecked(m_lockTabBar);
110 QMenu *subMenuToggleFloat =
new QMenu(
"Toggle Float/Dock", menu);
111 QMenu *subMenuDisplay =
new QMenu(
"Display", menu);
112 QMenu *subMenuRestore =
new QMenu(
"Restore from settings", menu);
113 QMenu *subMenuResetPositions =
new QMenu(
"Reset position", menu);
114 subMenuRestore->
setIcon(CIcons::load16());
115 subMenuResetPositions->
setIcon(CIcons::refresh16());
123 for (
int i = 0; i < m_dockWidgetInfoAreas.size(); i++)
131 toggleFloatingMenuAction->
setIcon(pm);
135 subMenuToggleFloat->
addAction(toggleFloatingMenuAction);
139 "Cannot map floating action");
140 signalMapperToggleFloating->
setMapping(toggleFloatingMenuAction, i);
145 "Cannot connect mapper");
148 if (c) { menu->
addMenu(subMenuToggleFloat); }
149 menu->
addMenu(subMenuResetPositions);
157 showMenuText->
setIcon(CIcons::headingOne16());
167 showTabbar->
setIcon(CIcons::dockBottom16());
174 menu->
addAction(CIcons::dockBottom16(),
"Toggle tabbar position",
this, &CInfoArea::toggleTabBarPosition);
181 if (!infoArea) {
return false; }
184 if (!m_tabBar || m_tabBar->
count() < 1) {
return false; }
193 if (!m_tabBar || m_tabBar->
count() < 1) {
return nullptr; }
196 if (ia->isFloating()) {
continue; }
197 if (ia->isWidgetVisible()) {
return ia; }
205 if (!sel) {
return -1; }
207 int ia = getAreaIndexByWindowTitle(t);
224 const QString wt(dockWidgetInfoArea->windowTitleBackup());
225 static const QString keys(
"123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
229 if (withShortcut && i < keys.
length())
252 const QString wt(dockWidgetInfoArea->windowTitleBackup());
271 const QString wt(dockWidgetInfoArea->windowTitleBackup());
290 const QString wt(dockWidgetInfoArea->windowTitleBackup());
304 for (
int i = 0; i < m_dockWidgetInfoAreas.size(); i++)
306 if (m_dockWidgetInfoAreas.at(i)->isFloating() == floating) { indexes.
append(i); }
343 if (dw->isFloating()) {
continue; }
344 dw->toggleFloating();
352 if (!dw || !dw->isFloating()) {
continue; }
361 if (!dw || !dw->isFloating()) {
continue; }
370 const bool f = dw->isFloating();
372 if (f) { dw->show(); }
380 if (!this->isValidAreaIndex(areaIndex)) {
return; }
389 if (!this->isValidAreaIndex(areaIndex)) {
return; }
402 if (m_tabBar->
count() < 1) {
return; }
419 const QAction *action = qobject_cast<const QAction *>(
sender);
421 if (!action) {
return; }
422 const int index = action->
data().
toInt();
429 const QAction *action = qobject_cast<const QAction *>(
sender);
431 if (!action) {
return; }
432 const int index = action->
data().
toInt();
439 const QAction *action = qobject_cast<const QAction *>(
sender);
441 if (!action) {
return; }
442 const int index = action->
data().
toInt();
449 const QAction *action = qobject_cast<const QAction *>(
sender);
451 if (!action) {
return; }
452 const int index = action->
data().
toInt();
458 if (!this->isValidAreaIndex(areaIndex)) {
return; }
467 if (!m_tabBar)
return;
468 if (m_tabBar->
count() < 2)
return;
475 if (!m_tabBar)
return;
476 if (m_tabBar->
count() < 2)
return;
488 dw->displayStatusMessage(statusMessage);
490 for (
CInfoArea *ia : std::as_const(m_childInfoAreas)) { ia->displayStatusMessage(statusMessage); }
497 dw->displayStatusMessages(statusMessages);
499 for (
CInfoArea *ia : std::as_const(m_childInfoAreas)) { ia->displayStatusMessages(statusMessages); }
508 if (oldAreas == newAreas) {
continue; }
509 dw->setAllowedAreas(newAreas);
514 void CInfoArea::setWholeInfoAreaFloating(
bool floating)
517 m_infoAreaFloating = floating;
518 if (m_infoAreaFloating)
523 this->
move(p.
rx() + 20, p.
ry() + 20);
544 void CInfoArea::tabifyAllWidgets()
548 const bool init = m_tabBar ? false :
true;
550 for (
int i = 0; i < m_dockWidgetInfoAreas.size(); i++)
552 CDockWidgetInfoArea *first = i > 0 ? m_dockWidgetInfoAreas.at(i - 1) :
nullptr;
553 CDockWidgetInfoArea *after = m_dockWidgetInfoAreas.at(i);
561 const QPoint offset(i * 10, i * 10);
564 after->setOffsetWhenFloating(offset, after->isFrameless());
566 after->setPreferredSizeWhenFloating(floatingSize);
567 after->initialFloating();
574 after->resetWasAlreadyFloating();
576 else { after->setFloating(
false); }
579 if (!first) {
continue; }
587 m_tabBar = this->findChild<QTabBar *>();
590 if (m_tabBar &&
sGui)
618 if (this->countDockedWidgetInfoAreas() > 0) { m_tabBar->
setCurrentIndex(0); }
619 if (m_tabBar->
count() > 0) { this->setTabPixmaps(); }
622 void CInfoArea::unTabifyAllWidgets()
624 if (m_dockWidgetInfoAreas.size() < 2)
return;
625 CDockWidgetInfoArea *first = m_dockWidgetInfoAreas.constFirst();
626 for (
int i = 1; i < m_dockWidgetInfoAreas.size(); i++)
628 CDockWidgetInfoArea *after = m_dockWidgetInfoAreas.at(i);
634 bool CInfoArea::isValidAreaIndex(
int areaIndex)
const
636 if (!m_tabBar) {
return false; }
637 return areaIndex >= 0 && areaIndex < m_dockWidgetInfoAreas.size();
640 void CInfoArea::connectTopLevelChanged()
642 for (CDockWidgetInfoArea *dw : std::as_const(m_dockWidgetInfoAreas))
660 void CInfoArea::emitInfoAreaStatus()
669 void CInfoArea::onTabBarIndexChanged(
int tabBarIndex)
672 this->emitInfoAreaStatus();
675 int CInfoArea::countDockedWidgetInfoAreas()
const
677 if (!m_tabBar) {
return 0; }
678 return m_tabBar->
count();
681 CDockWidgetInfoArea *CInfoArea::getDockWidgetInfoAreaByTabBarIndex(
int tabBarIndex)
const
683 if (tabBarIndex >= m_dockWidgetInfoAreas.count() || tabBarIndex < 0) {
return nullptr; }
684 if (!m_tabBar) {
return nullptr; }
688 if (!t.isEmpty()) {
return this->getDockWidgetInfoAreaByWindowTitle(t); }
693 for (CDockWidgetInfoArea *dw : m_dockWidgetInfoAreas)
695 if (dw->isFloating()) {
continue; }
696 if (c == tabBarIndex) {
return dw; }
699 Q_ASSERT_X(
false, Q_FUNC_INFO,
"no dock widgte found");
703 CDockWidgetInfoArea *CInfoArea::getDockWidgetInfoAreaByWindowTitle(
const QString &title)
const
705 Q_ASSERT_X(!title.
isEmpty(), Q_FUNC_INFO,
"No title");
706 for (CDockWidgetInfoArea *dw : m_dockWidgetInfoAreas)
713 int CInfoArea::getAreaIndexByWindowTitle(
const QString &title)
const
715 Q_ASSERT_X(!title.
isEmpty(), Q_FUNC_INFO,
"No title");
717 for (
int i = 0; i < m_dockWidgetInfoAreas.size(); i++)
724 Q_ASSERT_X(
false, Q_FUNC_INFO,
"No area for title");
728 int CInfoArea::getTabBarIndexByTitle(
const QString &title)
const
731 if (title.
isEmpty()) {
return -1; }
733 if (m_tabBar->
count() < 1) {
return -1; }
734 for (
int i = 0; i < m_tabBar->
count(); i++)
738 if (tt.
isEmpty()) {
continue; }
744 int CInfoArea::dockWidgetInfoAreaToTabBarIndex(
const CDockWidgetInfoArea *dockWidgetInfoArea)
const
746 if (!dockWidgetInfoArea) {
return -1; }
747 if (dockWidgetInfoArea->isFloating()) {
return -1; }
748 int index = this->getTabBarIndexByTitle(dockWidgetInfoArea->windowTitleOrBackup());
753 for (
const CDockWidgetInfoArea *a : m_dockWidgetInfoAreas)
755 if (a == dockWidgetInfoArea)
765 if (index >= m_tabBar->
count()) { index = -1; }
773 if (!m_tabBar) {
return; }
774 int tabIndex = this->dockWidgetInfoAreaToTabBarIndex(dockWidgetInfoArea);
775 if (tabIndex >= 0 && tabIndex < m_tabBar->count()) { m_tabBar->
setCurrentIndex(tabIndex); }
780 for (
CDockWidgetInfoArea *dw : std::as_const(m_dockWidgetInfoAreas)) { dw->setFeatures(features); }
783 void CInfoArea::setTabPixmaps()
785 if (!m_tabBar) {
return; }
786 for (
int i = 0; i < m_tabBar->
count(); i++)
789 const int areaIndex = t.isEmpty() ? i : this->getAreaIndexByWindowTitle(t);
795 void CInfoArea::onTabBarDoubleClicked(
int tabBarIndex)
799 CLogMessage(
this).
info(u
"Locked, double click will not cause floating");
802 CDockWidgetInfoArea *dw = this->getDockWidgetInfoAreaByTabBarIndex(tabBarIndex);
804 dw->toggleFloating();
808 if (!myself) {
return; }
809 myself->emitInfoAreaStatus();
813 void CInfoArea::onWidgetTopLevelChanged(CDockWidget *dockWidget,
bool topLevel)
815 Q_ASSERT(dockWidget);
817 if (!dockWidget) {
return; }
820 this->setTabPixmaps();
825 const CDockWidgetInfoArea *dwia =
dynamic_cast<CDockWidgetInfoArea *
>(dockWidget);
835 void CInfoArea::onStyleSheetChanged()
845 void CInfoArea::showContextMenu(
const QPoint &pos)
851 QAction *selectedItem = contextMenu.
data()->exec(globalPos);
852 Q_UNUSED(selectedItem)
855 void CInfoArea::showTabTexts(
bool show)
857 if (
show == m_showTabTexts) {
return; }
858 m_showTabTexts =
show;
859 for (CDockWidgetInfoArea *dw : std::as_const(m_dockWidgetInfoAreas)) { dw->showTitleWhenDocked(
show); }
862 void CInfoArea::showTabBar(
bool show)
864 if (
show == m_showTabBar)
return;
866 if (!m_tabBar)
return;
877 "Wrong tabbar position");
881 void CInfoArea::toggleTabBarPosition()
893 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.
virtual 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)
virtual 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.
virtual ~CInfoArea()
Destructor.
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)
virtual 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 setIcon(const QIcon &icon)
void setIconText(const QString &text)
void setData(const QVariant &data)
void setShortcut(const QKeySequence &shortcut)
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)
void setMapping(QObject *sender, QObject *object)
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
int toInt(bool *ok) const const
#define SWIFT_VERIFY_X(COND, WHERE, WHAT)
A weaker kind of assert.
#define SWIFT_VERIFY(COND)
A weaker kind of assert.