Skip to content

Commit 37dc845

Browse files
authored
Docking is made non-mandatory (#3578)
1 parent 9ac6c75 commit 37dc845

File tree

6 files changed

+65
-2
lines changed

6 files changed

+65
-2
lines changed

src/dialogs/preferences/ShortcutOptionsWidget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ void ShortcutOptionsWidget::populateShortcutTree()
3232
{ "Debug", tr("Debug") }, { "Functions", tr("Functions") },
3333
{ "Omnibar", tr("Omnibar") }, { "Exports", tr("Exports") },
3434
{ "Imports", tr("Imports") }, { "Overview", tr("Graph Overview") },
35+
{ "Docking", tr("Docking") },
3536
};
3637

3738
QHash<QString, QTreeWidgetItem *> prefixToItem;

src/shortcuts/DefaultShortcuts.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,12 @@ const QHash<QString, Shortcut> &getDefaultShortcuts()
329329
QT_TRANSLATE_NOOP("SearchBarWidget", "Show Search Bar Options Menu"),
330330
"SearchBarWidget" } },
331331

332+
// Docking
333+
{ "Docking.toggle",
334+
{ { Qt::Key_Alt },
335+
QT_TRANSLATE_NOOP("CutterDockWidget", "Enable/Disable Docking"),
336+
"CutterDockWidget" } },
337+
332338
};
333339
return defaultShortcuts;
334340
}

src/shortcuts/ShortcutManager.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "ShortcutManager.h"
22
#include <QCoreApplication>
33
#include <QDebug>
4+
#include <qglobal.h>
45

56
Q_GLOBAL_STATIC(ShortcutManager, uniqueInstance)
67

@@ -33,6 +34,36 @@ QKeySequence ShortcutManager::getKeySequence(const QString &id)
3334
return sequences.isEmpty() ? QKeySequence() : sequences.first();
3435
}
3536

37+
Qt::KeyboardModifier ShortcutManager::convertKeyToModifer(const QKeySequence &sequence)
38+
{
39+
if (sequence.isEmpty())
40+
return Qt::NoModifier;
41+
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
42+
Qt::Key key = static_cast<Qt::Key>(sequence[0] & ~Qt::KeyboardModifierMask);
43+
#else
44+
QKeyCombination combo = sequence[0];
45+
Qt::Key key = combo.key();
46+
#endif
47+
switch (key) {
48+
case Qt::Key_Alt:
49+
return Qt::AltModifier;
50+
case Qt::Key_Shift:
51+
return Qt::ShiftModifier;
52+
53+
case Qt::Key_Control:
54+
return Qt::ControlModifier;
55+
56+
case Qt::Key_Meta:
57+
return Qt::MetaModifier;
58+
case Qt::Key_AltGr:
59+
return Qt::GroupSwitchModifier;
60+
61+
default:
62+
return Qt::NoModifier;
63+
}
64+
return Qt::NoModifier;
65+
}
66+
3667
Shortcut ShortcutManager::getShortcut(const QString &id)
3768
{
3869
const auto &defaultShortcuts = getDefaultShortcuts();

src/shortcuts/ShortcutManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class ShortcutManager : public QObject
1717

1818
Shortcut getShortcut(const QString &id);
1919
QKeySequence getKeySequence(const QString &id);
20+
Qt::KeyboardModifier convertKeyToModifer(const QKeySequence &sequence);
2021
QList<QKeySequence> getKeySequences(const QString &id);
2122
QHash<QString, Shortcut> getAllShortcuts();
2223

src/widgets/CutterDockWidget.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <QEvent>
55
#include <QShortcut>
6+
#include <QApplication>
67

78
CutterDockWidget::CutterDockWidget(MainWindow *parent, QAction *) : CutterDockWidget(parent) {}
89

@@ -14,6 +15,24 @@ CutterDockWidget::CutterDockWidget(MainWindow *parent) : QDockWidget(parent), ma
1415
connect(toggleViewAction(), &QAction::triggered, this, &QWidget::raise);
1516
}
1617

18+
bool CutterDockWidget::event(QEvent *event)
19+
{
20+
21+
if (event->type() == QEvent::Move || event->type() == QEvent::MouseMove) {
22+
23+
Qt::KeyboardModifiers mods = QApplication::keyboardModifiers();
24+
Qt::KeyboardModifier mod =
25+
Shortcuts()->convertKeyToModifer(Shortcuts()->getKeySequence("Docking.toggle"));
26+
27+
if (mods & mod) {
28+
setAllowedAreas(Qt::NoDockWidgetArea);
29+
} else {
30+
setAllowedAreas(Qt::AllDockWidgetAreas);
31+
}
32+
}
33+
return QDockWidget::event(event);
34+
}
35+
1736
CutterDockWidget::~CutterDockWidget() = default;
1837

1938
bool CutterDockWidget::eventFilter(QObject *object, QEvent *event)

src/widgets/CutterDockWidget.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "core/CutterCommon.h"
55
#include "common/RefreshDeferrer.h"
6-
6+
#include "shortcuts/ShortcutManager.h"
77
#include <QDockWidget>
88

99
class MainWindow;
@@ -107,8 +107,13 @@ public slots:
107107

108108
protected:
109109
virtual QWidget *widgetToFocusOnRaise();
110-
111110
void closeEvent(QCloseEvent *event) override;
111+
112+
/**
113+
* @brief On any event(targeting windowMove event) if the altmodifer is
114+
* pressed then the dock will be non dockable.
115+
*/
116+
bool event(QEvent *event) override;
112117
QString getDockNumber();
113118

114119
MainWindow *mainWindow;

0 commit comments

Comments
 (0)