implemented the ability to hide some separators

This commit is contained in:
Roman Pudashkin 2021-10-25 18:24:18 +02:00
parent 1c8e76e16c
commit ac46a41bef
12 changed files with 121 additions and 29 deletions

View file

@ -39,6 +39,8 @@ ApplicationWindow {
visible: true
color: ui.theme.backgroundPrimaryColor
MainWindowTitleProvider {
id: titleProvider
}

View file

@ -102,6 +102,7 @@ DockPage {
floatable: false
resizable: false
padding: 0
separatorsVisible: false
alignment: DockToolBarAlignment.Center
NotationToolBar {
@ -122,6 +123,7 @@ DockPage {
objectName: pageModel.playbackToolBarName()
title: qsTrc("appshell", "Playback controls")
separatorsVisible: false
alignment: DockToolBarAlignment.Right
PlaybackToolBar {

View file

@ -55,8 +55,10 @@ DockPage {
objectName: root.objectName + "_notationToolBar"
title: qsTrc("appshell", "Notation toolbar")
movable: false
floatable: false
resizable: false
padding: 0
separatorsVisible: false
alignment: DockToolBarAlignment.Center
NotationToolBar {
@ -77,6 +79,7 @@ DockPage {
objectName: root.objectName + "_playbackToolBar"
title: qsTrc("appshell", "Playback controls")
separatorsVisible: false
alignment: DockToolBarAlignment.Right
PlaybackToolBar {

View file

@ -33,6 +33,8 @@ Rectangle {
readonly property QtObject separatorCpp: parent
visible: separatorCpp && separatorCpp.isSeparatorVisible
MouseArea {
anchors.fill: parent
anchors.margins: -5 //! NOTE: extra space for user convenience

View file

@ -56,18 +56,6 @@ DockToolBarView {
color: ui.theme.backgroundPrimaryColor
function printInfo() {
console.debug("------------------------------")
console.debug("obj: " + objectName)
console.debug("contentSize: " + Qt.size(contentLoader.width, contentLoader.height))
console.debug("bakgroundSize: " + Qt.size(contentBackground.width, contentBackground.height))
console.debug("------------------------------\n")
}
Component.onCompleted: {
Qt.callLater(printInfo)
}
Item {
id: content

View file

@ -44,6 +44,12 @@ struct DockProperties
{
DockType type = DockType::Undefined;
Qt::DockWidgetAreas allowedAreas = Qt::NoDockWidgetArea;
bool separatorsVisible = false;
bool isValid() const
{
return type != DockType::Undefined;
}
};
inline void writePropertiesToObject(const DockProperties& properties, QObject& obj)
@ -52,6 +58,7 @@ inline void writePropertiesToObject(const DockProperties& properties, QObject& o
propertiesObj->setObjectName("properties");
propertiesObj->setProperty("dockType", QVariant::fromValue(static_cast<int>(properties.type)));
propertiesObj->setProperty("allowedAreas", QVariant::fromValue(static_cast<int>(properties.allowedAreas)));
propertiesObj->setProperty("separatorsVisible", properties.separatorsVisible);
}
inline DockProperties readPropertiesFromObject(const QObject* obj)
@ -68,6 +75,7 @@ inline DockProperties readPropertiesFromObject(const QObject* obj)
DockProperties result;
result.type = static_cast<DockType>(properties->property("dockType").toInt());
result.allowedAreas = static_cast<Qt::DockWidgetAreas>(properties->property("allowedAreas").toInt());
result.separatorsVisible = properties->property("separatorsVisible").toBool();
return result;
}

View file

@ -68,7 +68,7 @@ void DockWindow::componentComplete()
connect(qApp, &QCoreApplication::aboutToQuit, this, &DockWindow::onQuit);
connect(this, &QQuickItem::widthChanged, this, [this]() {
alignToolBars();
alignToolBars(currentPage());
});
uiConfiguration()->windowGeometryChanged().onNotify(this, [this]() {
@ -84,7 +84,9 @@ void DockWindow::componentComplete()
void DockWindow::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry)
{
for (DockToolBarView* toolBar : topLevelToolBars()) {
QList<DockToolBarView*> topToolBars = topLevelToolBars(currentPage());
for (DockToolBarView* toolBar : topToolBars) {
toolBar->setMinimumWidth(toolBar->contentWidth());
}
@ -146,8 +148,6 @@ void DockWindow::loadPage(const QString& uri)
KDDockWidgets::DockRegistry::self()->clear();
}
m_currentPageUri = uri;
loadPageContent(newPage);
restorePageState(newPage->objectName());
initDocks(newPage);
@ -158,7 +158,9 @@ void DockWindow::loadPage(const QString& uri)
allDockNames << dock->objectName();
}
m_currentPageUri = uri;
emit currentPageUriChanged(uri);
m_docksOpenStatusChanged.send(allDockNames);
}
@ -385,8 +387,10 @@ void DockWindow::loadPagePanels(const DockPageView* page)
}
}
void DockWindow::alignToolBars()
void DockWindow::alignToolBars(const DockPageView* page)
{
QList<DockToolBarView*> topToolBars = topLevelToolBars(page);
DockToolBarView* lastLeftToolBar = nullptr;
DockToolBarView* lastCentralToolBar = nullptr;
@ -394,7 +398,7 @@ void DockWindow::alignToolBars()
int centralToolBarsWidth = 0;
int rightToolBarsWidth = 0;
for (DockToolBarView* toolBar : topLevelToolBars()) {
for (DockToolBarView* toolBar : topToolBars) {
if (toolBar->floating() || !toolBar->isVisible()) {
continue;
}
@ -551,20 +555,20 @@ void DockWindow::initDocks(DockPageView* page)
page->init();
}
alignToolBars();
alignToolBars(page);
for (DockToolBarView* toolbar : page->mainToolBars()) {
connect(toolbar, &DockToolBarView::floatingChanged, this, [this]() {
alignToolBars();
connect(toolbar, &DockToolBarView::floatingChanged, this, [this, page]() {
alignToolBars(page);
}, Qt::UniqueConnection);
}
}
QList<DockToolBarView*> DockWindow::topLevelToolBars() const
QList<DockToolBarView*> DockWindow::topLevelToolBars(const DockPageView* page) const
{
QList<DockToolBarView*> toolBars = m_toolBars.list();
if (auto page = currentPage()) {
if (page) {
toolBars << page->mainToolBars();
}

View file

@ -112,8 +112,7 @@ private:
void unitePanelsToTabs(const DockPageView* page);
void loadPageToolbars(const DockPageView* page);
void loadPagePanels(const DockPageView* page);
void alignToolBars();
void alignToolBars(const DockPageView* page);
void addDock(DockBase* dock, KDDockWidgets::Location location, const DockBase* relativeTo = nullptr);
@ -130,7 +129,7 @@ private:
void initDocks(DockPageView* page);
QList<DockToolBarView*> topLevelToolBars() const;
QList<DockToolBarView*> topLevelToolBars(const DockPageView* page) const;
DockToolBarHolder* resolveToolbarDockingHolder(const QPoint& localPos) const;
void showToolBarDockingHolder(const QPoint& globalPos);

View file

@ -55,7 +55,7 @@ public:
using namespace mu::dock;
DockBase::DockBase(QQuickItem* parent)
: QQuickItem(parent), m_resizable(true)
: QQuickItem(parent), m_resizable(true), m_separatorsVisible(true)
{
}
@ -114,6 +114,11 @@ bool DockBase::resizable() const
return m_resizable;
}
bool DockBase::separatorsVisible() const
{
return m_separatorsVisible;
}
KDDockWidgets::DockWidgetQuick* DockBase::dockWidget() const
{
return m_dockWidget;
@ -229,6 +234,16 @@ void DockBase::setResizable(bool resizable)
emit resizableChanged();
}
void DockBase::setSeparatorsVisible(bool visible)
{
if (visible == m_separatorsVisible) {
return;
}
m_separatorsVisible = visible;
emit separatorsVisibleChanged();
}
DockType DockBase::type() const
{
return DockType::Undefined;
@ -298,6 +313,7 @@ void DockBase::componentComplete()
DockProperties properties;
properties.type = type();
properties.allowedAreas = allowedAreas();
properties.separatorsVisible = separatorsVisible();
writePropertiesToObject(properties, *m_dockWidget);

View file

@ -52,6 +52,7 @@ class DockBase : public QQuickItem
Q_PROPERTY(DockLocation location READ location WRITE setLocation NOTIFY locationChanged)
Q_PROPERTY(bool resizable READ resizable WRITE setResizable NOTIFY resizableChanged)
Q_PROPERTY(bool separatorsVisible READ separatorsVisible WRITE setSeparatorsVisible NOTIFY separatorsVisibleChanged)
public:
explicit DockBase(QQuickItem* parent = nullptr);
@ -91,6 +92,7 @@ public:
DockLocation location() const;
bool resizable() const;
bool separatorsVisible() const;
public slots:
void setTitle(const QString& title);
@ -110,6 +112,7 @@ public slots:
void setLocation(DockLocation location);
void setResizable(bool resizable);
void setSeparatorsVisible(bool visible);
signals:
void titleChanged();
@ -123,6 +126,7 @@ signals:
void locationChanged(DockLocation location);
void resizableChanged();
void separatorsVisibleChanged();
protected:
friend class DockWindow;
@ -153,6 +157,7 @@ private:
bool m_floating = false;
DockLocation m_location = DockLocation::Undefined;
bool m_resizable = false;
bool m_separatorsVisible = false;
};
}

View file

@ -23,22 +23,73 @@
#include "dockseparator.h"
#include "log.h"
#include "../docktypes.h"
#include "thirdparty/KDDockWidgets/src/private/multisplitter/Rubberband_quick.h"
#include "thirdparty/KDDockWidgets/src/DockWidgetBase.h"
#include "thirdparty/KDDockWidgets/src/private/DockRegistry_p.h"
#include <QTimer>
using namespace mu::dock;
namespace mu::dock {
static const KDDockWidgets::DockWidgetBase* findNearestDock(const DockSeparator* separator)
{
const Layouting::ItemBoxContainer* container = separator->parentContainer();
if (!container) {
return nullptr;
}
int separatorPos = separator->Layouting::Separator::position();
Qt::Orientation orientation = separator->orientation();
Layouting::Item::List children = container->visibleChildren();
const Layouting::Item* nearestItem = nullptr;
int minPosDiff = std::numeric_limits<int>::max();
for (const Layouting::Item* child : children) {
int childPos = child->pos(orientation);
int diff = std::abs(childPos - separatorPos);
if (diff < minPosDiff) {
nearestItem = child;
minPosDiff = diff;
}
}
if (!nearestItem) {
return nullptr;
}
auto frame = dynamic_cast<KDDockWidgets::Frame*>(nearestItem->guestAsQObject());
return frame ? frame->currentDockWidget() : nullptr;
}
}
DockSeparator::DockSeparator(Layouting::Widget* parent)
: QQuickItem(qobject_cast<QQuickItem*>(parent->asQObject())),
Layouting::Separator(parent),
Layouting::Widget_quick(this)
Layouting::Widget_quick(this), m_isSeparatorVisible(true)
{
createQQuickItem("qrc:/qml/dockwindow/DockSeparator.qml", this);
// Only set on Separator::init(), so single-shot
QTimer::singleShot(0, this, &DockSeparator::isVerticalChanged);
QTimer::singleShot(0, this, [this]() {
initAvailability();
});
}
void DockSeparator::initAvailability()
{
const QObject* dock = findNearestDock(this);
DockProperties properties = readPropertiesFromObject(dock);
if (properties.isValid()) {
m_isSeparatorVisible = properties.separatorsVisible;
emit isSeparatorVisibleChanged();
}
}
bool DockSeparator::isVertical() const
@ -46,6 +97,11 @@ bool DockSeparator::isVertical() const
return Layouting::Separator::isVertical();
}
bool DockSeparator::isSeparatorVisible() const
{
return m_isSeparatorVisible;
}
Layouting::Widget* DockSeparator::createRubberBand(Layouting::Widget* parent)
{
if (!parent) {

View file

@ -34,11 +34,13 @@ class DockSeparator : public QQuickItem, public Layouting::Separator, public Lay
Q_OBJECT
Q_PROPERTY(bool isVertical READ isVertical NOTIFY isVerticalChanged)
Q_PROPERTY(bool isSeparatorVisible READ isSeparatorVisible NOTIFY isSeparatorVisibleChanged)
public:
explicit DockSeparator(Layouting::Widget* parent = nullptr);
bool isVertical() const;
bool isSeparatorVisible() const;
Q_INVOKABLE void onMousePressed();
Q_INVOKABLE void onMouseMoved(QPointF localPos);
@ -47,10 +49,15 @@ public:
signals:
void isVerticalChanged();
void isSeparatorVisibleChanged();
private:
void initAvailability();
Widget* createRubberBand(Widget* parent) override;
Widget* asWidget() override;
bool m_isSeparatorVisible = false;
};
}