Skip to content

Commit

Permalink
fix musescore#10477: introduced a new way to determine if panels can …
Browse files Browse the repository at this point in the history
…be combined into tabs
  • Loading branch information
RomanPudashkin committed Mar 23, 2022
1 parent a4c9b9f commit 57d2b1d
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 95 deletions.
19 changes: 13 additions & 6 deletions src/appshell/qml/NotationPage/NotationPage.qml
Expand Up @@ -95,6 +95,9 @@ DockPage {
readonly property int horizontalPanelMinHeight: 100
readonly property int horizontalPanelMaxHeight: 520

readonly property string verticalPanelsGroup: "VERTICAL_PANELS"
readonly property string horizontalPanelsGroup: "HORIZONTAL_PANELS"

readonly property var verticalPanelDropDestinations: [
{ "dock": root.centralDock, "dropLocation": Location.Left, "dropDistance": root.verticalPanelDefaultWidth },
{ "dock": root.centralDock, "dropLocation": Location.Right, "dropDistance": root.verticalPanelDefaultWidth }
Expand Down Expand Up @@ -213,7 +216,7 @@ DockPage {
minimumWidth: root.verticalPanelDefaultWidth
maximumWidth: root.verticalPanelDefaultWidth

tabifyPanel: instrumentsPanel
groupName: root.verticalPanelsGroup

dropDestinations: root.verticalPanelDropDestinations

Expand All @@ -238,7 +241,7 @@ DockPage {
minimumWidth: root.verticalPanelDefaultWidth
maximumWidth: root.verticalPanelDefaultWidth

tabifyPanel: inspectorPanel
groupName: root.verticalPanelsGroup

dropDestinations: root.verticalPanelDropDestinations

Expand All @@ -262,8 +265,8 @@ DockPage {
width: root.verticalPanelDefaultWidth
minimumWidth: root.verticalPanelDefaultWidth
maximumWidth: root.verticalPanelDefaultWidth
tabifyPanel: selectionFilterPanel

groupName: root.verticalPanelsGroup

dropDestinations: root.verticalPanelDropDestinations

Expand All @@ -284,6 +287,8 @@ DockPage {
minimumWidth: root.verticalPanelDefaultWidth
maximumWidth: root.verticalPanelDefaultWidth

groupName: root.verticalPanelsGroup

//! NOTE: hidden by default
visible: false

Expand All @@ -308,7 +313,7 @@ DockPage {
minimumHeight: root.horizontalPanelMinHeight
maximumHeight: root.horizontalPanelMaxHeight

tabifyPanel: pianoRollPanel
groupName: root.horizontalPanelsGroup

//! NOTE: hidden by default
visible: false
Expand Down Expand Up @@ -342,7 +347,7 @@ DockPage {
minimumHeight: root.horizontalPanelMinHeight
maximumHeight: root.horizontalPanelMaxHeight

tabifyPanel: timelinePanel
groupName: root.horizontalPanelsGroup

//! NOTE: hidden by default
visible: false
Expand All @@ -367,6 +372,8 @@ DockPage {
minimumHeight: root.horizontalPanelMinHeight
maximumHeight: root.horizontalPanelMaxHeight

groupName: root.horizontalPanelsGroup

//! NOTE: hidden by default
visible: false

Expand Down
69 changes: 9 additions & 60 deletions src/appshell/view/dockwindow/dockpageview.cpp
Expand Up @@ -153,51 +153,17 @@ DockingHolderView* DockPageView::holder(DockType type, Location location) const
return nullptr;
}

QList<DockPanelView*> DockPageView::possibleTabs(const DockPanelView* panel) const
QList<DockPanelView*> DockPageView::possiblePanelsForTab(const DockPanelView* tab) const
{
QList<DockPanelView*> tabs;
QList<DockPanelView*> result;

auto isPanelAllowedAsTab = [panel](const DockPanelView* p) {
if (!p || p == panel) {
return false;
}

return p->isOpen() && !p->floating();
};

DockPanelView* rootPanel = findRootPanel(panel);
DockPanelView* nextPanel = rootPanel ? rootPanel->tabifyPanel() : nullptr;

while (nextPanel) {
if (isPanelAllowedAsTab(nextPanel)) {
tabs << nextPanel;
}

nextPanel = nextPanel->tabifyPanel();
}

if (!tabs.contains(rootPanel) && isPanelAllowedAsTab(rootPanel)) {
tabs.prepend(rootPanel);
}

return tabs;
}

DockPanelView* DockPageView::findRootPanel(const DockPanelView* panel) const
{
for (DockPanelView* panel_ : panels()) {
DockPanelView* tabifyPanel = panel_->tabifyPanel();

while (tabifyPanel) {
if (tabifyPanel == panel) {
return panel_;
}

tabifyPanel = tabifyPanel->tabifyPanel();
for (DockPanelView* panel : panels()) {
if (panel->isTabAllowed(tab)) {
result << panel;
}
}

return const_cast<DockPanelView*>(panel);
return result;
}

bool DockPageView::isDockOpen(const QString& dockName) const
Expand Down Expand Up @@ -229,31 +195,14 @@ void DockPageView::setDockOpen(const QString& dockName, bool open)
return;
}

DockPanelView* destinationPanel = findPanelForTab(panel);
if (destinationPanel) {
destinationPanel->addPanelAsTab(panel);
QList<DockPanelView*> panels = possiblePanelsForTab(panel);
if (!panels.isEmpty()) {
panels.first()->addPanelAsTab(panel);
} else {
panel->open();
}
}

DockPanelView* DockPageView::findPanelForTab(const DockPanelView* tab) const
{
for (DockPanelView* panel : panels()) {
if (panel->tabifyPanel() != tab) {
continue;
}

if (panel->isOpen() && !panel->floating()) {
return panel;
}

return findPanelForTab(panel);
}

return nullptr;
}

bool DockPageView::isDockFloating(const QString& dockName) const
{
const DockBase* dock = dockByName(dockName);
Expand Down
5 changes: 1 addition & 4 deletions src/appshell/view/dockwindow/dockpageview.h
Expand Up @@ -75,7 +75,7 @@ class DockPageView : public QQuickItem

DockBase* dockByName(const QString& dockName) const;
DockingHolderView* holder(DockType type, Location location) const;
QList<DockPanelView*> possibleTabs(const DockPanelView* panel) const;
QList<DockPanelView*> possiblePanelsForTab(const DockPanelView* tab) const;

bool isDockOpen(const QString& dockName) const;
void toggleDock(const QString& dockName);
Expand All @@ -99,9 +99,6 @@ public slots:
private:
void componentComplete() override;

DockPanelView* findPanelForTab(const DockPanelView* tab) const;
DockPanelView* findRootPanel(const DockPanelView* panel) const;

QString m_uri;
uicomponents::QmlListProperty<DockToolBarView> m_mainToolBars;
uicomponents::QmlListProperty<DockToolBarView> m_toolBars;
Expand Down
41 changes: 35 additions & 6 deletions src/appshell/view/dockwindow/dockpanelview.cpp
Expand Up @@ -164,19 +164,19 @@ DockPanelView::~DockPanelView()
dockWidget->setProperty(CONTEXT_MENU_MODEL_PROPERTY, QVariant::fromValue(nullptr));
}

DockPanelView* DockPanelView::tabifyPanel() const
QString DockPanelView::groupName() const
{
return m_tabifyPanel;
return m_groupName;
}

void DockPanelView::setTabifyPanel(DockPanelView* panel)
void DockPanelView::setGroupName(const QString& name)
{
if (panel == m_tabifyPanel) {
if (m_groupName == name) {
return;
}

m_tabifyPanel = panel;
emit tabifyPanelChanged(panel);
m_groupName = name;
emit groupNameChanged();
}

DockType DockPanelView::type() const
Expand Down Expand Up @@ -236,12 +236,41 @@ void DockPanelView::setContextMenuModel(AbstractMenuModel* model)
emit contextMenuModelChanged();
}

bool DockPanelView::isTabAllowed(const DockPanelView* tab) const
{
IF_ASSERT_FAILED(tab) {
return false;
}

if (tab == this) {
return false;
}

if (!isOpen()) {
return false;
}

if (floating()) {
return false;
}

if (m_groupName.isEmpty() || tab->m_groupName.isEmpty()) {
return false;
}

return m_groupName == tab->m_groupName;
}

void DockPanelView::addPanelAsTab(DockPanelView* tab)
{
IF_ASSERT_FAILED(tab && dockWidget()) {
return;
}

if (!isTabAllowed(tab)) {
return;
}

dockWidget()->addDockWidgetAsTab(tab->dockWidget());
tab->setVisible(true);
}
Expand Down
13 changes: 7 additions & 6 deletions src/appshell/view/dockwindow/dockpanelview.h
Expand Up @@ -38,38 +38,39 @@ class DockPanelView : public DockBase
{
Q_OBJECT

Q_PROPERTY(DockPanelView * tabifyPanel READ tabifyPanel WRITE setTabifyPanel NOTIFY tabifyPanelChanged)
Q_PROPERTY(QString groupName READ groupName WRITE setGroupName NOTIFY groupNameChanged)
Q_PROPERTY(QObject * navigationSection READ navigationSection WRITE setNavigationSection NOTIFY navigationSectionChanged)
Q_PROPERTY(
mu::uicomponents::AbstractMenuModel
* contextMenuModel READ contextMenuModel WRITE setContextMenuModel NOTIFY contextMenuModelChanged)

public:
explicit DockPanelView(QQuickItem* parent = nullptr);
~DockPanelView();
~DockPanelView() override;

DockPanelView* tabifyPanel() const;
QString groupName() const;
QObject* navigationSection() const;
uicomponents::AbstractMenuModel* contextMenuModel() const;

bool isTabAllowed(const DockPanelView* tab) const;
void addPanelAsTab(DockPanelView* tab);
void setCurrentTabIndex(int index);

public slots:
void setTabifyPanel(DockPanelView* panel);
void setGroupName(const QString& name);
void setNavigationSection(QObject* newNavigation);
void setContextMenuModel(uicomponents::AbstractMenuModel* model);

signals:
void tabifyPanelChanged(DockPanelView* panel);
void groupNameChanged();
void navigationSectionChanged();
void contextMenuModelChanged();

private:
DockType type() const override;
void componentComplete() override;

DockPanelView* m_tabifyPanel = nullptr;
QString m_groupName;
QObject* m_navigationSection = nullptr;

class DockPanelMenuModel;
Expand Down
8 changes: 2 additions & 6 deletions src/appshell/view/dockwindow/dockwindow.cpp
Expand Up @@ -346,13 +346,9 @@ void DockWindow::loadPanels(const DockPageView* page)
{
TRACEFUNC;

auto canAddAsTab = [](const DockPanelView* panel, const DockPanelView* destination) {
return panel->isVisible() && destination->isOpen() && destination->tabifyPanel() == panel;
};

auto addPanel = [this, page, canAddAsTab](DockPanelView* panel, Location location) {
auto addPanel = [this, page](DockPanelView* panel, Location location) {
for (DockPanelView* destinationPanel : page->panels()) {
if (canAddAsTab(panel, destinationPanel)) {
if (destinationPanel->isTabAllowed(panel)) {
registerDock(panel);

destinationPanel->addPanelAsTab(panel);
Expand Down
12 changes: 6 additions & 6 deletions src/appshell/view/dockwindow/internal/dropcontroller.cpp
Expand Up @@ -252,7 +252,7 @@ DropDestination DropController::resolveDropDestination(const DockBase* draggedDo
if (draggedDock->type() == DockType::Panel) {
DropDestination destination;

destination.dock = resolveTabifyPanel(dynamic_cast<const DockPanelView*>(draggedDock), localPos);
destination.dock = resolvePanelForDrop(dynamic_cast<const DockPanelView*>(draggedDock), localPos);
destination.dropLocation = resolveDropLocation(destination.dock, localPos);

if (destination.isValid()) {
Expand Down Expand Up @@ -304,13 +304,13 @@ DockingHolderView* DropController::resolveDockingHolder(DockType draggedDockType
return nullptr;
}

DockPanelView* DropController::resolveTabifyPanel(const DockPanelView* panel, const QPoint& localPos) const
DockPanelView* DropController::resolvePanelForDrop(const DockPanelView* panel, const QPoint& localPos) const
{
QList<DockPanelView*> tabs = currentPage()->possibleTabs(panel);
QList<DockPanelView*> panels = currentPage()->possiblePanelsForTab(panel);

for (DockPanelView* tab : tabs) {
if (isMouseOverDock(localPos, tab)) {
return tab;
for (DockPanelView* p : panels) {
if (isMouseOverDock(localPos, p)) {
return p;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/appshell/view/dockwindow/internal/dropcontroller.h
Expand Up @@ -56,7 +56,7 @@ class DropController : public KDDockWidgets::DropIndicatorOverlayInterface

DropDestination resolveDropDestination(const DockBase* draggedDock, const QPoint& localPos) const;
DockingHolderView* resolveDockingHolder(DockType draggedDockType, const QPoint& localPos) const;
DockPanelView* resolveTabifyPanel(const DockPanelView* panel, const QPoint& localPos) const;
DockPanelView* resolvePanelForDrop(const DockPanelView* panel, const QPoint& localPos) const;
Location resolveDropLocation(const DockBase* hoveredDock, const QPoint& localPos) const;
QRect resolveHighlightingRect(const DockBase* draggedDock, const DropDestination& destination) const;

Expand Down

0 comments on commit 57d2b1d

Please sign in to comment.