implemented the basis for the ability to restore position of the note input bar

This commit is contained in:
Roman Pudashkin 2021-05-07 12:47:25 +02:00 committed by Igor Korsukov
parent 58b54e0b2b
commit f6f15611b1
12 changed files with 110 additions and 19 deletions

View file

@ -37,4 +37,11 @@ Dock.DockPage {
anchors.fill: parent
}
}
toolBarsDockingHelper: Dock.DockToolBar {
objectName: root.objectName + "_toolbarsDockingHelper"
visible: false
Rectangle { color: ui.theme.backgroundPrimaryColor }
}
}

View file

@ -79,7 +79,18 @@ QList<DockToolBar*> DockPage::mainToolBars() const
QList<DockToolBar*> DockPage::toolBars() const
{
return m_toolBars.list();
auto list = m_toolBars.list();
if (m_toolBarsDockingHelper) {
list << m_toolBarsDockingHelper;
}
return list;
}
DockToolBar* DockPage::toolBarsDockingHelper() const
{
return m_toolBarsDockingHelper;
}
DockCentral* DockPage::centralDock() const
@ -118,6 +129,16 @@ void DockPage::setUri(const QString& uri)
emit uriChanged(uri);
}
void DockPage::setToolBarsDockingHelper(DockToolBar* helper)
{
if (helper == m_toolBarsDockingHelper) {
return;
}
m_toolBarsDockingHelper = helper;
emit toolBarsDockingHelperChanged(helper);
}
void DockPage::setCentralDock(DockCentral* central)
{
if (central == m_central) {
@ -133,7 +154,7 @@ void DockPage::close()
TRACEFUNC;
for (DockBase* dock : allDocks()) {
dock->close();
dock->hide();
}
}

View file

@ -40,6 +40,7 @@ class DockPage : public QQuickItem
Q_PROPERTY(QString uri READ uri WRITE setUri NOTIFY uriChanged)
Q_PROPERTY(QQmlListProperty<mu::dock::DockToolBar> mainToolBars READ mainToolBarsProperty)
Q_PROPERTY(QQmlListProperty<mu::dock::DockToolBar> toolBars READ toolBarsProperty)
Q_PROPERTY(mu::dock::DockToolBar* toolBarsDockingHelper READ toolBarsDockingHelper WRITE setToolBarsDockingHelper NOTIFY toolBarsDockingHelperChanged)
Q_PROPERTY(QQmlListProperty<mu::dock::DockPanel> panels READ panelsProperty)
Q_PROPERTY(mu::dock::DockCentral* centralDock READ centralDock WRITE setCentralDock NOTIFY centralDockChanged)
Q_PROPERTY(QQmlListProperty<mu::dock::DockStatusBar> statusBars READ statusBarsProperty)
@ -48,6 +49,7 @@ public:
explicit DockPage(QQuickItem* parent = nullptr);
void init();
void close();
QString uri() const;
@ -58,29 +60,32 @@ public:
QList<DockToolBar*> mainToolBars() const;
QList<DockToolBar*> toolBars() const;
DockToolBar* toolBarsDockingHelper() const;
DockCentral* centralDock() const;
QList<DockPanel*> panels() const;
QList<DockStatusBar*> statusBars() const;
QList<DockBase*> allDocks() const;
DockBase* dockByName(const QString& dockName) const;
void close();
public slots:
void setUri(const QString& uri);
void setToolBarsDockingHelper(DockToolBar* helper);
void setCentralDock(DockCentral* central);
signals:
void uriChanged(const QString& uri);
void toolBarsDockingHelperChanged(DockToolBar* helper);
void centralDockChanged(DockCentral* central);
private:
void componentComplete() override;
QList<DockBase*> allDocks() const;
QString m_uri;
uicomponents::QmlListProperty<DockToolBar> m_mainToolBars;
uicomponents::QmlListProperty<DockToolBar> m_toolBars;
DockToolBar* m_toolBarsDockingHelper = nullptr;
uicomponents::QmlListProperty<DockPanel> m_panels;
DockCentral* m_central = nullptr;
uicomponents::QmlListProperty<DockStatusBar> m_statusBars;

View file

@ -66,6 +66,21 @@ void DockWindow::componentComplete()
toolBar->setOrientation(static_cast<Qt::Orientation>(orientation.second));
}
});
mainWindow()->dockingHelperVisibleChanged().onReceive(this, [this](bool visible) {
DockPage* page = pageByUri(m_currentPageUri);
DockBase* helper = page ? page->toolBarsDockingHelper() : nullptr;
if (!helper) {
return;
}
if (visible) {
helper->show();
} else {
helper->hide();
}
});
}
QString DockWindow::currentPageUri() const
@ -156,20 +171,27 @@ void DockWindow::loadPageContent(const DockPage* page)
}
unitePanelsToTabs(page);
for (DockBase* dock : page->allDocks()) {
if (!dock->isVisible()) {
dock->hide();
}
}
}
void DockWindow::unitePanelsToTabs(const DockPage* page)
{
for (const DockPanel* panel : page->panels()) {
const DockPanel* tab = panel->tabifyPanel();
if (!tab) {
continue;
}
if (tab) {
panel->dockWidget()->addDockWidgetAsTab(tab->dockWidget());
panel->dockWidget()->addDockWidgetAsTab(tab->dockWidget());
KDDockWidgets::Frame* frame = panel->dockWidget()->frame();
if (frame) {
frame->setCurrentTabIndex(0);
}
KDDockWidgets::Frame* frame = panel->dockWidget()->frame();
if (frame) {
frame->setCurrentTabIndex(0);
}
}
}

View file

@ -33,6 +33,7 @@
#include "async/asyncable.h"
#include "ui/iuiconfiguration.h"
#include "ui/imainwindow.h"
#include "async/asyncable.h"
namespace KDDockWidgets {
class MainWindowBase;

View file

@ -180,7 +180,16 @@ void DockBase::init()
applySizeConstraints();
}
void DockBase::close()
void DockBase::show()
{
IF_ASSERT_FAILED(m_dockWidget) {
return;
}
m_dockWidget->show();
}
void DockBase::hide()
{
IF_ASSERT_FAILED(m_dockWidget) {
return;

View file

@ -55,16 +55,16 @@ public:
int minimumHeight() const;
int maximumWidth() const;
int maximumHeight() const;
QSize preferredSize() const;
Qt::DockWidgetAreas allowedAreas() const;
bool floating() const;
virtual void init();
void close();
bool floating() const;
void show();
void hide();
public slots:
void setTitle(const QString& title);

View file

@ -249,7 +249,8 @@ void DropIndicators::updateVisibility()
} else {
m_rubberBand->setVisible(false);
m_indicatorsWindow->setVisible(false);
}
mainWindow()->setDockingHelperVisible(false);
}
m_draggedDockProperties = readPropertiesFromObject(draggedDock());
@ -274,7 +275,7 @@ void DropIndicators::showDropAreaIfNeed(const QPoint& hoveredGlobalPos)
return;
}
QRect dropAreaRect = hoveredDock->geometry();
QRect dropAreaRect = hoveredFrameRect();
int distanceToLeftCorner = std::abs(dropAreaRect.x() - hoveredGlobalPos.x());
int distanceToRightCorner = std::abs(dropAreaRect.x() + dropAreaRect.width() - hoveredGlobalPos.x());
@ -286,12 +287,16 @@ void DropIndicators::showDropAreaIfNeed(const QPoint& hoveredGlobalPos)
dropLocation = DropLocation_Right;
}
dropAreaRect.setWidth(draggedDock->width());
if (draggedDock->width() <= hoveredDock->width() / 2) {
dropAreaRect.setWidth(draggedDock->width());
}
mainWindow()->setDockingHelperVisible(true);
m_rubberBand->setGeometry(dropAreaRect);
m_rubberBand->setVisible(true);
setDropLocation(dropLocation);
setCurrentDropLocation(dropLocation);
}
void DropIndicators::setDropLocation(DropLocation location)

View file

@ -27,6 +27,9 @@
#include "../docktypes.h"
#include "ui/imainwindow.h"
#include "modularity/ioc.h"
#include "ui/imainwindow.h"
#include "thirdparty/KDDockWidgets/src/private/DropIndicatorOverlayInterface_p.h"
namespace mu::dock {

View file

@ -27,6 +27,7 @@
#include "thirdparty/KDDockWidgets/src/private/DockRegistry_p.h"
using namespace mu::dock;
using namespace mu::async;
inline QWindow* mainWindow()
{
@ -86,3 +87,13 @@ mu::async::Channel<std::pair<QString, mu::framework::Orientation> > MainWindowPr
{
return m_dockOrientationChanged;
}
void MainWindowProvider::setDockingHelperVisible(bool visible)
{
m_dockingHelperVisibleChanged.send(visible);
}
Channel<bool> MainWindowProvider::dockingHelperVisibleChanged() const
{
return m_dockingHelperVisibleChanged;
}

View file

@ -39,8 +39,12 @@ public:
void requestChangeToolBarOrientation(const QString& toolBarName, framework::Orientation orientation) override;
async::Channel<std::pair<QString, framework::Orientation> > toolBarOrientationChangeRequested() const override;
void setDockingHelperVisible(bool visible) override;
async::Channel<bool> dockingHelperVisibleChanged() const override;
private:
async::Channel<std::pair<QString, framework::Orientation> > m_dockOrientationChanged;
async::Channel<bool> m_dockingHelperVisibleChanged;
};
}

View file

@ -48,6 +48,9 @@ public:
virtual void requestChangeToolBarOrientation(const QString& toolBarName, framework::Orientation orientation) = 0;
virtual async::Channel<std::pair<QString, framework::Orientation> > toolBarOrientationChangeRequested() const = 0;
virtual void setDockingHelperVisible(bool visible) = 0;
virtual async::Channel<bool> dockingHelperVisibleChanged() const = 0;
};
}