Skip to content

Commit 3479ec4

Browse files
committed
14088: Double-click on a toolbar grip will dock/undock it
1 parent 0b66869 commit 3479ec4

File tree

4 files changed

+42
-13
lines changed

4 files changed

+42
-13
lines changed

src/framework/dockwindow/internal/dockbase.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ public slots:
184184
DockType type() const;
185185
KDDockWidgets::DockWidgetQuick* dockWidget() const;
186186

187+
void doSetFloating(bool floating);
188+
187189
protected slots:
188190
void applySizeConstraints();
189191

@@ -193,7 +195,6 @@ private slots:
193195

194196
private:
195197
void setUpFrameConnections();
196-
void doSetFloating(bool floating);
197198

198199
void writeProperties();
199200

src/framework/dockwindow/qml/Muse/Dock/DockToolBar.qml

+15-12
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,17 @@ DockToolBarView {
4242
minimumHeight: root.inited ? Math.min(root.contentHeight, root.maximumHeight) : prv.minimumLength
4343

4444
onFloatingChanged: {
45-
if (!root.floating) {
46-
//! NOTE: The dock widgets system determines the position of a toolbar
47-
// when inserting the toolbar into the app window.
48-
// It may be that the grip button can be moved to a different
49-
// location from where a user wanted to place it.
50-
// Because of this, the mouse area does not emit a signal
51-
// that the user has moved the mouse outside the grip button.
52-
// Therefore, the hover state of the grip button is not reset.
53-
// The hack is to hide and show the grip button to reset the hover state.
54-
gripButton.visible = false
55-
gripButton.visible = true
56-
}
45+
//! NOTE: The dock widgets system determines the position of a toolbar
46+
// when inserting the toolbar into the app window.
47+
// It may be that the grip button can be moved to a different
48+
// location from where a user wanted to place it.
49+
// Because of this, the mouse area does not emit a signal
50+
// that the user has moved the mouse outside the grip button.
51+
// Therefore, the hover state of the grip button is not reset.
52+
// Disabling and enabling the mousearea does not reset the hover state.
53+
// The hack is to hide and show the grip button's mousearea to reset the hover state.
54+
gripButton.mouseArea.visible = false
55+
gripButton.mouseArea.visible = true
5756
}
5857

5958
QtObject {
@@ -93,6 +92,10 @@ DockToolBarView {
9392
Component.onCompleted: {
9493
root.setDraggableMouseArea(gripButton.mouseArea)
9594
}
95+
96+
mouseArea.onDoubleClicked: {
97+
root.onGripDoubleClicked()
98+
}
9699
}
97100

98101
Loader {

src/framework/dockwindow/view/docktoolbarview.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,27 @@ void DockToolBarView::resetToDefault()
201201

202202
setOrientation(Qt::Horizontal);
203203
}
204+
205+
void DockToolBarView::onGripDoubleClicked()
206+
{
207+
if (KDDockWidgets::DockWidgetBase* dw = m_draggableArea->singleDockWidget()) {
208+
bool isFloating = dw->isFloating();
209+
210+
// If the toolbar is floating, first make it think it is docked so it can update itself
211+
// for the docked state and then actually dock it. This is a hack for toolbars that
212+
// change their size between the docked and undocked state, e.g. the Playback toolbar.
213+
// Otheriwse docking a toolbar that will shrink itself after docking will leave gaps.
214+
if (isFloating) {
215+
doSetFloating(false);
216+
}
217+
218+
dw->setFloating(!isFloating);
219+
220+
if (isFloating) {
221+
if (dw->isFloating()) { // If it didn't dock for some reason, undo our hack above
222+
doSetFloating(true);
223+
}
224+
emit floatingChanged();
225+
}
226+
}
227+
}

src/framework/dockwindow/view/docktoolbarview.h

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class DockToolBarView : public DockBase
5656
int alignment() const;
5757

5858
Q_INVOKABLE void setDraggableMouseArea(QQuickItem* mouseArea);
59+
Q_INVOKABLE void onGripDoubleClicked();
5960

6061
void init() override;
6162
void resetToDefault() override;

0 commit comments

Comments
 (0)