37 #include <QMainWindow> 44 #include <QXmlStreamWriter> 47 #include <QApplication> 142 for (
auto FloatingWidget : FloatingWidgets)
144 FloatingWidget->hide();
186 QString FileName =
":ads/stylesheets/";
188 ?
"focus_highlighting" :
"default";
190 FileName +=
"_linux";
193 QFile StyleSheetFile(FileName);
194 StyleSheetFile.open(QIODevice::ReadOnly);
195 QTextStream StyleSheetStream(&StyleSheetFile);
196 Result = StyleSheetStream.readAll();
197 StyleSheetFile.close();
218 ADS_PRINT(
"d->Containers[i]->restoreState ");
220 if (Container->isFloating())
222 Result = Container->floatingWidget()->restoreState(stream, Testing);
226 Result = Container->restoreState(stream, Testing);
252 s.readNextStartElement();
253 if (s.name() !=
"QtAdvancedDockingSystem")
257 ADS_PRINT(s.attributes().value(
"Version"));
259 int v = s.attributes().value(
"Version").toInt(&ok);
266 ADS_PRINT(s.attributes().value(
"UserVersion"));
269 if (!s.attributes().value(
"UserVersion").isEmpty())
271 v = s.attributes().value(
"UserVersion").toInt(&ok);
272 if (!ok || v != version)
279 #ifdef ADS_DEBUG_PRINT 280 int DockContainers = s.attributes().value(
"Containers").toInt();
286 const auto CentralWidgetAttribute = s.attributes().value(
"CentralWidget");
289 if (CentralWidgetAttribute.isEmpty())
291 qWarning() <<
"Dock manager has central widget but saved state does not have central widget.";
297 if (
CentralWidget->objectName() != CentralWidgetAttribute.toString())
299 qWarning() <<
"Object name of central widget does not match name of central widget in saved state.";
304 int DockContainerCount = 0;
305 while (s.readNextStartElement())
307 if (s.name() ==
"Container")
314 DockContainerCount++;
321 int FloatingWidgetIndex = DockContainerCount - 1;
326 floatingWidget->deleteLater();
366 for (
int i = 0; i < DockContainer->dockAreaCount(); ++i)
369 QString DockWidgetName = DockArea->property(
"currentDockWidget").toString();
371 if (!DockWidgetName.isEmpty())
376 if (!DockWidget || DockWidget->
isClosed())
400 CDockWidget* TopLevelDockWidget = DockContainer->topLevelDockWidget();
401 if (TopLevelDockWidget)
407 for (
int i = 0; i < DockContainer->dockAreaCount(); ++i)
409 auto DockArea = DockContainer->dockArea(i);
410 for (
auto DockWidget : DockArea->dockWidgets())
423 QByteArray
state = State.startsWith(
"<?xml") ? State : qUncompress(State);
426 ADS_PRINT(
"checkFormat: Error checking format!!!!!!!");
436 ADS_PRINT(
"restoreState: Error restoring state!!!!!!!");
454 auto Actions = Menu->actions();
455 auto it = std::find_if(Actions.begin(), Actions.end(),
456 [&Action](
const QAction* a)
458 return a->text().compare(Action->text(), Qt::CaseInsensitive) > 0;
461 if (it == Actions.end())
463 Menu->addAction(Action);
467 Menu->insertAction(*it, Action);
472 Menu->addAction(Action);
483 QMainWindow*
MainWindow = qobject_cast<QMainWindow*>(parent);
486 MainWindow->setCentralWidget(
this);
489 d->
ViewMenu =
new QMenu(tr(
"Show View"),
this);
490 d->
DockAreaOverlay =
new CDockOverlay(
this, CDockOverlay::ModeDockAreaOverlay);
491 d->
ContainerOverlay =
new CDockOverlay(
this, CDockOverlay::ModeContainerOverlay);
501 window()->installEventFilter(
this);
509 for (
auto FloatingWidget : FloatingWidgets)
511 delete FloatingWidget;
518 bool CDockManager::eventFilter(QObject *obj, QEvent *e)
524 if (e->type() == QEvent::WindowActivate)
528 if (!_window->isVisible() || window()->isMinimized())
535 internal::xcb_update_prop(
true, _window->window()->winId(),
536 "_NET_WM_STATE",
"_NET_WM_STATE_ABOVE",
"_NET_WM_STATE_STAYS_ON_TOP");
539 else if (e->type() == QEvent::WindowDeactivate)
543 if (!_window->isVisible() || window()->isMinimized())
547 internal::xcb_update_prop(
false, _window->window()->winId(),
548 "_NET_WM_STATE",
"_NET_WM_STATE_ABOVE",
"_NET_WM_STATE_STAYS_ON_TOP");
554 if (e->type() == QEvent::WindowStateChange)
558 if (! _window->isVisible())
563 if (window()->isMinimized())
565 _window->showMinimized();
569 _window->setWindowState(_window->windowState() & (~Qt::WindowMinimized));
572 if (!window()->isMinimized())
574 QApplication::setActiveWindow(window());
577 return Super::eventFilter(obj, e);
607 if (
this != DockContainer)
653 QXmlStreamWriter s(&xmldata);
656 s.writeStartDocument();
657 s.writeStartElement(
"QtAdvancedDockingSystem");
659 s.writeAttribute(
"UserVersion", QString::number(version));
660 s.writeAttribute(
"Containers", QString::number(
d->
Containers.count()));
663 s.writeAttribute(
"CentralWidget",
d->
CentralWidget->objectName());
667 Container->saveState(s);
671 s.writeEndDocument();
674 ? qCompress(xmldata, 9) : xmldata;
696 bool IsHidden = this->isHidden();
726 FloatingWidget->resize(Dockwidget->size());
729 FloatingWidget->show();
736 return FloatingWidget;
743 Super::showEvent(event);
751 FloatingWidget->show();
762 auto Container = DockAreaWidget ? DockAreaWidget->
dockContainer():
this;
763 auto AreaOfAddedDockWidget = Container->
addDockWidget(area, Dockwidget, DockAreaWidget);
765 return AreaOfAddedDockWidget;
839 for (
auto Name : Names)
877 Settings.beginWriteArray(
"Perspectives",
d->
Perspectives.size());
881 Settings.setArrayIndex(i);
882 Settings.setValue(
"Name", it.key());
883 Settings.setValue(
"State", it.value());
894 int Size = Settings.beginReadArray(
"Perspectives");
901 for (
int i = 0; i < Size; ++i)
903 Settings.setArrayIndex(i);
904 QString Name = Settings.value(
"Name").toString();
905 QByteArray Data = Settings.value(
"State").toByteArray();
906 if (Name.isEmpty() || Data.isEmpty())
938 qWarning(
"Setting a central widget not possible because there is already a central widget.");
946 qWarning(
"Setting a central widget not possible - the central widget need to be the first " 947 "dock widget that is added to the dock manager.");
957 CentralArea->
setDockAreaFlag(CDockAreaWidget::eDockAreaFlag::HideSingleWidgetTitleBar,
true);
963 const QString& Group,
const QIcon& GroupIcon)
966 if (!Group.isEmpty())
971 GroupMenu =
new QMenu(Group,
this);
972 GroupMenu->setIcon(GroupIcon);
976 else if (GroupMenu->icon().isNull() && !GroupIcon.isNull())
978 GroupMenu->setIcon(GroupIcon);
982 return GroupMenu->menuAction();
987 return ToggleViewAction;
1016 return QApplication::startDragDistance() * 1.5;
1030 StaticConfigFlags = Flags;
1103 auto Splitter = internal::findParent<CDockSplitter*>(ContainedArea);
1106 return Splitter->sizes();
1120 auto Splitter = internal::findParent<CDockSplitter*>(ContainedArea);
1121 if (Splitter && Splitter->count() == sizes.count())
1123 Splitter->setSizes(sizes);
static bool testConfigFlag(eConfigFlag Flag)
void registerFloatingWidget(CFloatingDockContainer *FloatingWidget)
static const bool RestoreTesting
void floatingWidgetCreated(ads::CFloatingDockContainer *FloatingWidget)
CDockOverlay * DockAreaOverlay
CDockWidget * focusedDockWidget() const
void notifyFloatingWidgetDrop(CFloatingDockContainer *FloatingWidget)
If enabled, the XML output will be compressed and is not human readable anymore.
bool isRestoringState() const
the default configuration for non opaque operations
CDockManager::eViewMenuInsertionOrder MenuInsertionOrder
virtual void showEvent(QShowEvent *event) override
QAction * addToggleViewActionToMenu(QAction *ToggleViewAction, const QString &Group=QString(), const QIcon &GroupIcon=QIcon())
CDockOverlay * ContainerOverlay
void dockWidgetRemoved(ads::CDockWidget *DockWidget)
unsigned int zOrderIndex() const override
CDockWidget * CentralWidget
static ConfigFlags configFlags()
void perspectiveListChanged()
CDockAreaWidget * addDockWidget(DockWidgetArea area, CDockWidget *Dockwidget, CDockAreaWidget *DockAreaWidget=nullptr)
Declaration of CDockFocusController class.
void savePerspectives(QSettings &Settings) const
CDockWidget * centralWidget() const
CDockManager(QWidget *parent=nullptr)
enables styling of focused dock widget tabs or floating widget titlebar
Declaration of CFloatingDockContainer class.
void notifyFloatingWidgetDrop(CFloatingDockContainer *FloatingWidget)
static CDockManager::ConfigFlags StaticConfigFlags
QMap< QString, QByteArray > Perspectives
void registerDockContainer(CDockContainerWidget *DockContainer)
If enabled, the XML writer automatically adds line-breaks and indentation to empty sections between e...
QList< int > splitterSizes(CDockAreaWidget *ContainedArea) const
void emitTopLevelEvents()
const QList< CFloatingDockContainer * > floatingWidgets() const
void perspectivesRemoved()
void markDockWidgetsDirty()
bool restoreState(const QByteArray &state, int version=0)
bool restoreState(const QByteArray &state, int version)
static const char *const DirtyProperty
static void setConfigFlags(const ConfigFlags Flags)
bool checkFormat(const QByteArray &state, int version)
DockManagerPrivate(CDockManager *_public)
void setDockWidgetFocused(CDockWidget *DockWidget)
void setFileVersion(int FileVersion)
void setDockWidgetFocused(CDockWidget *focusedNow)
friend class CFloatingDockContainer
static CIconProvider & iconProvider()
void hideFloatingWidgets()
DockManagerPrivate * d
private data (pimpl)
CDockAreaWidget * addDockWidgetTabToArea(CDockWidget *Dockwidget, CDockAreaWidget *DockAreaWidget)
Declaration of CDockSplitter.
CDockAreaWidget * addDockWidgetTab(DockWidgetArea area, CDockWidget *Dockwidget)
const QList< CDockContainerWidget * > dockContainers() const
static void setConfigFlag(eConfigFlag Flag, bool On=true)
void removeDockWidget(CDockWidget *Dockwidget)
Declaration of CIconProvider.
void setFlag(T &Flags, typename T::enum_type flag, bool on=true)
CDockAreaWidget * setCentralWidget(CDockWidget *widget)
void notifyWidgetOrAreaRelocation(QWidget *RelocatedWidget)
CDockWidget * focusedDockWidget() const
virtual ~CDockManager() override
CDockFocusController * FocusController
void restoreDockAreasIndices()
void removePerspective(const QString &Name)
CFloatingDockContainer * addDockWidgetFloating(CDockWidget *Dockwidget)
QVector< CFloatingDockContainer * > UninitializedFloatingWidgets
Declaration of CDockingStateReader.
bool restoreState(CDockingStateReader &Stream, bool Testing)
QList< CFloatingDockContainer * > FloatingWidgets
void dockWidgetAdded(ads::CDockWidget *DockWidget)
CDockOverlay * containerOverlay() const
QMap< QString, CDockWidget * > dockWidgetsMap() const
void loadPerspectives(QSettings &Settings)
static const bool Restore
static int startDragDistance()
void restoreDockWidgetsOpenState()
QMap< QString, CDockWidget * > DockWidgetsMap
void perspectiveOpened(const QString &PerspectiveName)
bool restoreStateFromXml(const QByteArray &state, int version, bool Testing=internal::Restore)
void openPerspective(const QString &PerspectiveName)
void addActionToMenu(QAction *Action, QMenu *Menu, bool InsertSorted)
void setViewMenuInsertionOrder(eViewMenuInsertionOrder Order)
QStringList perspectiveNames() const
void dockWidgetAboutToBeRemoved(ads::CDockWidget *DockWidget)
QByteArray saveState(int version=0) const
Declaration of CDockManager class.
void removeFloatingWidget(CFloatingDockContainer *FloatingWidget)
CDockOverlay * dockAreaOverlay() const
void removePerspectives(const QStringList &Names)
QMap< QString, QMenu * > ViewMenuGroups
QList< CDockContainerWidget * > Containers
void openingPerspective(const QString &PerspectiveName)
CDockWidget * findDockWidget(const QString &ObjectName) const
Declaration of CDockAreaTitleBar class.
void removeDockContainer(CDockContainerWidget *DockContainer)
void setSplitterSizes(CDockAreaWidget *ContainedArea, const QList< int > &sizes)
static const char *const ClosedProperty
static void initResource()
void notifyWidgetOrAreaRelocation(QWidget *RelocatedWidget)
void addPerspective(const QString &UniquePrespectiveName)
bool restoreContainer(int Index, CDockingStateReader &stream, bool Testing)