Skip to content

Commit f7d1739

Browse files
committed
Add snap preference options
1 parent a7ca960 commit f7d1739

File tree

5 files changed

+107
-0
lines changed

5 files changed

+107
-0
lines changed

src/plugins/visualeditor/internal/EditorPreference.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ namespace VisualEditor::Internal {
1515
EditorPreference::ScrollModifier pageModifier{};
1616
bool usePageModifierAsAlternateAxisZoom{};
1717
bool middleButtonAutoScroll{};
18+
int autoDurationPositionAlignment{48};
19+
bool enableTemporarySnapOff{true};
1820
};
1921

2022
static EditorPreference *m_instance = nullptr;
@@ -46,6 +48,10 @@ namespace VisualEditor::Internal {
4648
emit usePageModifierAsAlternateAxisZoomChanged();
4749
d->middleButtonAutoScroll = settings->value("middleButtonAutoScroll", false).toBool();
4850
emit middleButtonAutoScrollChanged();
51+
d->autoDurationPositionAlignment = settings->value("autoDurationPositionAlignment", 48).toInt();
52+
emit autoDurationPositionAlignmentChanged();
53+
d->enableTemporarySnapOff = settings->value("enableTemporarySnapOff", true).toBool();
54+
emit enableTemporarySnapOffChanged();
4955
settings->endGroup();
5056
}
5157

@@ -58,6 +64,8 @@ namespace VisualEditor::Internal {
5864
settings->setValue("pageModifier", static_cast<int>(d->pageModifier));
5965
settings->setValue("usePageModifierAsAlternateAxisZoom", d->usePageModifierAsAlternateAxisZoom);
6066
settings->setValue("middleButtonAutoScroll", d->middleButtonAutoScroll);
67+
settings->setValue("autoDurationPositionAlignment", d->autoDurationPositionAlignment);
68+
settings->setValue("enableTemporarySnapOff", d->enableTemporarySnapOff);
6169
settings->endGroup();
6270
}
6371

@@ -130,4 +138,30 @@ namespace VisualEditor::Internal {
130138
emit m_instance->middleButtonAutoScrollChanged();
131139
}
132140

141+
int EditorPreference::autoDurationPositionAlignment() {
142+
M_INSTANCE_D;
143+
return d->autoDurationPositionAlignment;
144+
}
145+
146+
void EditorPreference::setAutoDurationPositionAlignment(int autoDurationPositionAlignment) {
147+
M_INSTANCE_D;
148+
if (d->autoDurationPositionAlignment == autoDurationPositionAlignment)
149+
return;
150+
d->autoDurationPositionAlignment = autoDurationPositionAlignment;
151+
emit m_instance->autoDurationPositionAlignmentChanged();
152+
}
153+
154+
bool EditorPreference::enableTemporarySnapOff() {
155+
M_INSTANCE_D;
156+
return d->enableTemporarySnapOff;
157+
}
158+
159+
void EditorPreference::setEnableTemporarySnapOff(bool enableTemporarySnapOff) {
160+
M_INSTANCE_D;
161+
if (d->enableTemporarySnapOff == enableTemporarySnapOff)
162+
return;
163+
d->enableTemporarySnapOff = enableTemporarySnapOff;
164+
emit m_instance->enableTemporarySnapOffChanged();
165+
}
166+
133167
}

src/plugins/visualeditor/internal/EditorPreference.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ namespace VisualEditor::Internal {
2424
Q_PROPERTY(EditorPreference::ScrollModifier pageModifier READ pageModifier WRITE setPageModifier NOTIFY pageModifierChanged)
2525
Q_PROPERTY(bool usePageModifierAsAlternateAxisZoom READ usePageModifierAsAlternateAxisZoom WRITE setUsePageModifierAsAlternateAxisZoom NOTIFY usePageModifierAsAlternateAxisZoomChanged)
2626
Q_PROPERTY(bool middleButtonAutoScroll READ middleButtonAutoScroll WRITE setMiddleButtonAutoScroll NOTIFY middleButtonAutoScrollChanged)
27+
Q_PROPERTY(int autoDurationPositionAlignment READ autoDurationPositionAlignment WRITE setAutoDurationPositionAlignment NOTIFY autoDurationPositionAlignmentChanged)
28+
Q_PROPERTY(bool enableTemporarySnapOff READ enableTemporarySnapOff WRITE setEnableTemporarySnapOff NOTIFY enableTemporarySnapOffChanged)
2729

2830
public:
2931
~EditorPreference() override;
@@ -59,12 +61,20 @@ namespace VisualEditor::Internal {
5961
static bool middleButtonAutoScroll();
6062
static void setMiddleButtonAutoScroll(bool middleButtonAutoScroll);
6163

64+
static int autoDurationPositionAlignment();
65+
static void setAutoDurationPositionAlignment(int autoDurationPositionAlignment);
66+
67+
static bool enableTemporarySnapOff();
68+
static void setEnableTemporarySnapOff(bool enableTemporarySnapOff);
69+
6270
Q_SIGNALS:
6371
void alternateAxisModifierChanged();
6472
void zoomModifierChanged();
6573
void pageModifierChanged();
6674
void usePageModifierAsAlternateAxisZoomChanged();
6775
void middleButtonAutoScrollChanged();
76+
void autoDurationPositionAlignmentChanged();
77+
void enableTemporarySnapOffChanged();
6878

6979
private:
7080
friend class VisualEditorPlugin;

src/plugins/visualeditor/internal/settings/EditorPage.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ namespace VisualEditor::Internal {
5555
qCDebug(lcEditorPage) << m_widget->property("usePageModifierAsAlternateAxisZoom");
5656
m_widget->setProperty("middleButtonAutoScroll", EditorPreference::instance()->property("middleButtonAutoScroll"));
5757
qCDebug(lcEditorPage) << m_widget->property("middleButtonAutoScroll");
58+
m_widget->setProperty("autoDurationPositionAlignment", EditorPreference::instance()->property("autoDurationPositionAlignment"));
59+
qCDebug(lcEditorPage) << m_widget->property("autoDurationPositionAlignment");
60+
m_widget->setProperty("enableTemporarySnapOff", EditorPreference::instance()->property("enableTemporarySnapOff"));
61+
qCDebug(lcEditorPage) << m_widget->property("enableTemporarySnapOff");
5862
m_widget->setProperty("started", true);
5963
Core::ISettingPage::beginSetting();
6064
}
@@ -71,6 +75,10 @@ namespace VisualEditor::Internal {
7175
EditorPreference::instance()->setProperty("usePageModifierAsAlternateAxisZoom", m_widget->property("usePageModifierAsAlternateAxisZoom"));
7276
qCDebug(lcEditorPage) << "middleButtonAutoScroll" << m_widget->property("middleButtonAutoScroll");
7377
EditorPreference::instance()->setProperty("middleButtonAutoScroll", m_widget->property("middleButtonAutoScroll"));
78+
qCDebug(lcEditorPage) << "autoDurationPositionAlignment" << m_widget->property("autoDurationPositionAlignment");
79+
EditorPreference::instance()->setProperty("autoDurationPositionAlignment", m_widget->property("autoDurationPositionAlignment"));
80+
qCDebug(lcEditorPage) << "enableTemporarySnapOff" << m_widget->property("enableTemporarySnapOff");
81+
EditorPreference::instance()->setProperty("enableTemporarySnapOff", m_widget->property("enableTemporarySnapOff"));
7482
EditorPreference::instance()->save();
7583
return Core::ISettingPage::accept();
7684
}
@@ -89,6 +97,10 @@ namespace VisualEditor::Internal {
8997
};
9098
}
9199

100+
QString EditorPage::shiftText() {
101+
return QKeySequence(Qt::Key_Shift).toString(QKeySequence::NativeText);
102+
}
103+
92104
bool EditorPage::widgetMatches(const QString &word) {
93105
widget();
94106
auto matcher = m_widget->property("matcher").value<QObject *>();

src/plugins/visualeditor/internal/settings/EditorPage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace VisualEditor::Internal {
88
class EditorPage : public Core::ISettingPage {
99
Q_OBJECT
1010
Q_PROPERTY(QStringList scrollModifierTexts READ scrollModifierTexts CONSTANT)
11+
Q_PROPERTY(QString shiftText READ shiftText CONSTANT)
1112
public:
1213
explicit EditorPage(QObject *parent = nullptr);
1314
~EditorPage() override;
@@ -20,6 +21,7 @@ namespace VisualEditor::Internal {
2021
void endSetting() override;
2122

2223
static QStringList scrollModifierTexts();
24+
static QString shiftText();
2325

2426
private:
2527
bool widgetMatches(const QString &word);

src/plugins/visualeditor/qml/settings/EditorPage.qml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ ScrollView {
1818
property int pageModifier: 0
1919
property bool usePageModifierAsAlternateAxisZoom: false
2020
property bool middleButtonAutoScroll: false
21+
property int autoDurationPositionAlignment: 20
22+
property bool enableTemporarySnapOff: false
2123

2224
onAlternateAxisModifierChanged: if (started) pageHandle.markDirty()
2325
onZoomModifierChanged: if (started) pageHandle.markDirty()
2426
onPageModifierChanged: if (started) pageHandle.markDirty()
2527
onUsePageModifierAsAlternateAxisZoomChanged: if (started) pageHandle.markDirty()
2628
onMiddleButtonAutoScrollChanged: if (started) pageHandle.markDirty()
29+
onAutoDurationPositionAlignmentChanged: if (started) pageHandle.markDirty()
30+
onEnableTemporarySnapOffChanged: if (started) pageHandle.markDirty()
2731

2832
anchors.fill: parent
2933
contentWidth: availableWidth
@@ -109,6 +113,51 @@ ScrollView {
109113
}
110114
}
111115

116+
GroupBox {
117+
title: qsTr("Snap")
118+
TextMatcherItem on title {
119+
matcher: page.matcher
120+
}
121+
Layout.fillWidth: true
122+
123+
GridLayout {
124+
anchors.fill: parent
125+
columns: 3
126+
127+
Label {
128+
text: qsTr("Auto-snap length")
129+
TextMatcherItem on text {
130+
matcher: page.matcher
131+
}
132+
}
133+
Slider {
134+
Layout.fillWidth: true
135+
from: 0
136+
to: 80
137+
138+
stepSize: 1
139+
snapMode: Slider.SnapAlways
140+
value: page.autoDurationPositionAlignment - 20
141+
onMoved: page.autoDurationPositionAlignment = value + 20
142+
}
143+
SpinBox {
144+
from: 20
145+
to: 100
146+
stepSize: 1
147+
value: page.autoDurationPositionAlignment
148+
onValueModified: page.autoDurationPositionAlignment = value
149+
}
150+
151+
CheckBox {
152+
text: qsTr("Temporarily disable snap when pressing %1").arg(page.pageHandle.shiftText)
153+
Layout.columnSpan: 3
154+
checked: page.enableTemporarySnapOff
155+
onClicked: page.enableTemporarySnapOff = checked
156+
}
157+
158+
}
159+
}
160+
112161
}
113162
}
114163
}

0 commit comments

Comments
 (0)