diff --git a/matrique.pro b/matrique.pro
index d1ed1dd..f107b4e 100644
--- a/matrique.pro
+++ b/matrique.pro
@@ -32,7 +32,7 @@ RESOURCES += \
res.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
-QML_IMPORT_PATH =
+QML_IMPORT_PATH += qml/MatriqueSettings
# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =
diff --git a/qml/MatriqueSettings/MatriqueSettings.qml b/qml/MatriqueSettings/MatriqueSettings.qml
new file mode 100644
index 0000000..32edabe
--- /dev/null
+++ b/qml/MatriqueSettings/MatriqueSettings.qml
@@ -0,0 +1,13 @@
+pragma Singleton
+import QtQuick 2.9
+import Qt.labs.settings 1.0
+
+Settings {
+ property bool lazyLoad: true
+ property bool asyncMessageDelegate
+ property bool richText
+ property bool pressAndHold
+
+ property bool darkTheme
+ property bool miniMode
+}
diff --git a/qml/MatriqueSettings/plugins.qmltypes b/qml/MatriqueSettings/plugins.qmltypes
new file mode 100644
index 0000000..904ebd9
--- /dev/null
+++ b/qml/MatriqueSettings/plugins.qmltypes
@@ -0,0 +1,26 @@
+import QtQuick.tooling 1.2
+
+// This file describes the plugin-supplied types contained in the library.
+// It is used for QML tooling purposes only.
+//
+// This file was auto-generated by:
+// 'qmlplugindump -nonrelocatable MatriqueSettings 0.1 qml/'
+
+Module {
+ dependencies: ["Qt.labs.settings 1.0", "QtQuick 2.9"]
+ Component {
+ prototype: "QQmlSettings"
+ name: "MatriqueSettings 0.1"
+ exports: ["MatriqueSettings 0.1"]
+ exportMetaObjectRevisions: [1]
+ isComposite: true
+ isCreatable: false
+ isSingleton: true
+ Property { name: "lazyLoad"; type: "bool" }
+ Property { name: "asyncMessageDelegate"; type: "bool" }
+ Property { name: "richText"; type: "bool" }
+ Property { name: "pressAndHold"; type: "bool" }
+ Property { name: "darkTheme"; type: "bool" }
+ Property { name: "miniMode"; type: "bool" }
+ }
+}
diff --git a/qml/MatriqueSettings/qmldir b/qml/MatriqueSettings/qmldir
new file mode 100644
index 0000000..8ce28a2
--- /dev/null
+++ b/qml/MatriqueSettings/qmldir
@@ -0,0 +1,2 @@
+module MatriqueSettings
+singleton MatriqueSettings 0.1 MatriqueSettings.qml
diff --git a/qml/Room.qml b/qml/Room.qml
index 448cd86..a777ffb 100644
--- a/qml/Room.qml
+++ b/qml/Room.qml
@@ -2,6 +2,7 @@ import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import Matrique 0.1
+import MatriqueSettings 0.1
import "qrc:/qml/form"
@@ -13,7 +14,7 @@ Page {
RoomListModel {
id: roomListModel
- onRoomAdded: setting.lazyLoad ? {} : room.getPreviousContent(20)
+ onRoomAdded: MatriqueSettings.lazyLoad ? {} : room.getPreviousContent(20)
onNewMessage: window.active ? {} : matriqueController.showMessage(roomName, content, icon)
}
@@ -25,7 +26,7 @@ Page {
id: roomListForm
Layout.fillHeight: true
- Layout.preferredWidth: setting.miniMode ? 80 : page.width * 0.35
+ Layout.preferredWidth: MatriqueSettings.miniMode ? 80 : page.width * 0.35
Layout.minimumWidth: 80
Layout.maximumWidth: 360
diff --git a/qml/Setting.qml b/qml/Setting.qml
index 1411e51..d6ead88 100644
--- a/qml/Setting.qml
+++ b/qml/Setting.qml
@@ -7,13 +7,6 @@ import "component"
import "form"
Page {
- property alias lazyLoad: generalForm.lazyLoad
- property alias asyncMessageDelegate: generalForm.asyncMessageDelegate
- property alias richText: generalForm.richText
-
- property alias darkTheme: appearanceForm.darkTheme
- property alias miniMode: appearanceForm.miniMode
-
property var connection
SettingAccountForm {
diff --git a/qml/component/AutoMouseArea.qml b/qml/component/AutoMouseArea.qml
new file mode 100644
index 0000000..23e3657
--- /dev/null
+++ b/qml/component/AutoMouseArea.qml
@@ -0,0 +1,12 @@
+import QtQuick 2.9
+import MatriqueSettings 0.1
+
+MouseArea {
+ signal primaryClicked()
+ signal secondaryClicked()
+
+ propagateComposedEvents: true
+ acceptedButtons: MatriqueSettings.pressAndHold ? Qt.LeftButton : (Qt.LeftButton | Qt.RightButton)
+ onClicked: mouse.button == Qt.RightButton ? secondaryClicked() : primaryClicked()
+ onPressAndHold: MatriqueSettings.pressAndHold ? secondaryClicked() : {}
+}
diff --git a/qml/component/MessageDelegate.qml b/qml/component/MessageDelegate.qml
index 6e52651..014e8f5 100644
--- a/qml/component/MessageDelegate.qml
+++ b/qml/component/MessageDelegate.qml
@@ -2,6 +2,7 @@ import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.2
import Matrique 0.1
+import MatriqueSettings 0.1
Item {
readonly property bool hidden: marks === EventStatus.Redacted || marks === EventStatus.Hidden
@@ -21,15 +22,15 @@ Item {
anchors.right: !isState && sentByMe ? parent.right : undefined
anchors.horizontalCenter: isState ? parent.horizontalCenter : undefined
- MouseArea {
+ AutoMouseArea {
anchors.fill: parent
- onPressAndHold: Qt.createComponent("MessageContextMenu.qml").createObject(this)
+ onSecondaryClicked: Qt.createComponent("MessageContextMenu.qml").createObject(this)
}
Loader {
id: delegateLoader
- asynchronous: setting.asyncMessageDelegate
+ asynchronous: MatriqueSettings.asyncMessageDelegate
source: {
if (eventType == "redaction" || hidden) return ""
diff --git a/qml/component/TextDelegate.qml b/qml/component/TextDelegate.qml
index eb5b177..d2dd443 100644
--- a/qml/component/TextDelegate.qml
+++ b/qml/component/TextDelegate.qml
@@ -2,6 +2,7 @@ import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.2
import QtQuick.Layouts 1.3
+import MatriqueSettings 0.1
Rectangle {
property bool flat: false
@@ -45,7 +46,7 @@ Rectangle {
wrapMode: Label.Wrap
linkColor: darkBackground ? "white" : Material.accent
- textFormat: setting.richText ? Text.RichText : Text.StyledText
+ textFormat: MatriqueSettings.richText ? Text.RichText : Text.StyledText
onLinkActivated: Qt.openUrlExternally(link)
}
diff --git a/qml/form/RoomListForm.qml b/qml/form/RoomListForm.qml
index a9bd3bd..aa43fea 100644
--- a/qml/form/RoomListForm.qml
+++ b/qml/form/RoomListForm.qml
@@ -6,6 +6,7 @@ import QtQuick.Controls.Material 2.2
import QtQml.Models 2.3
import Matrique 0.1
import SortFilterProxyModel 0.2
+import MatriqueSettings 0.1
import "qrc:/qml/component"
@@ -13,7 +14,7 @@ Item {
property alias listModel: roomListProxyModel.sourceModel
readonly property int currentIndex: roomListProxyModel.mapToSource(listView.currentIndex)
readonly property var currentRoom: currentIndex != -1 ? listModel.roomAt(currentIndex) : null
- readonly property bool mini: setting.miniMode // Used as an indicator of whether the listform should be displayed as "Mini mode".
+ readonly property bool mini: MatriqueSettings.miniMode // Used as an indicator of whether the listform should be displayed as "Mini mode".
signal enterRoom()
ColumnLayout {
@@ -121,9 +122,14 @@ Item {
delegate: ItemDelegate {
width: parent.width
height: 80
- onPressed: listView.currentIndex = index
- onPressAndHold: roomListMenu.popup()
- onClicked: category === RoomType.Invited ? inviteDialog.open() : enterRoom()
+
+ AutoMouseArea {
+ anchors.fill: parent
+
+ onPressed: listView.currentIndex = index
+ onSecondaryClicked: roomListMenu.popup()
+ onPrimaryClicked: category === RoomType.Invited ? inviteDialog.open() : enterRoom()
+ }
ToolTip.visible: mini && hovered
ToolTip.text: name
@@ -209,7 +215,7 @@ Item {
contentItem: Label { text: "Accept this invitation?" }
onAccepted: currentRoom.acceptInvitation()
- onRejected: currentRoom.rejectInvitation()
+ onRejected: currentRoom.forget()
}
Menu {
diff --git a/qml/form/SettingAppearanceForm.qml b/qml/form/SettingAppearanceForm.qml
index 55c4fd5..315360c 100644
--- a/qml/form/SettingAppearanceForm.qml
+++ b/qml/form/SettingAppearanceForm.qml
@@ -1,19 +1,21 @@
import QtQuick 2.9
import QtQuick.Controls 2.2
+import MatriqueSettings 0.1
Page {
- property alias darkTheme: themeSwitch.checked
- property alias miniMode: miniModeSwitch.checked
-
Column {
Switch {
id: themeSwitch
text: "Dark theme"
+ checked: MatriqueSettings.darkTheme
+ onCheckedChanged: MatriqueSettings.darkTheme = checked
}
Switch {
id: miniModeSwitch
text: "Mini Room List"
+ checked: MatriqueSettings.miniMode
+ onCheckedChanged: MatriqueSettings.miniMode = checked
}
}
}
diff --git a/qml/form/SettingGeneralForm.qml b/qml/form/SettingGeneralForm.qml
index 71650d8..40c4d27 100644
--- a/qml/form/SettingGeneralForm.qml
+++ b/qml/form/SettingGeneralForm.qml
@@ -1,24 +1,32 @@
import QtQuick 2.9
import QtQuick.Controls 2.2
+import MatriqueSettings 0.1
Page {
- property alias lazyLoad: lazyLoadSwitch.checked
- property alias asyncMessageDelegate: asyncMessageDelegateSwitch.checked
- property alias richText: richTextSwitch.checked
-
Column {
Switch {
id: lazyLoadSwitch
text: "Lazy load at initial sync"
- checked: true
+ checked: MatriqueSettings.lazyLoad
+ onCheckedChanged: MatriqueSettings.lazyLoad = checked
}
Switch {
id: asyncMessageDelegateSwitch
text: "Force loading message delegates asynchronously"
+ checked: MatriqueSettings.asyncMessageDelegate
+ onCheckedChanged: MatriqueSettings.asyncMessageDelegate = checked
}
Switch {
id: richTextSwitch
text: "Use RichText instead of StyledText"
+ checked: MatriqueSettings.richText
+ onCheckedChanged: MatriqueSettings.richText = checked
+ }
+ Switch {
+ id: pressAndHoldSwitch
+ text: "Use press and hold instead of right click"
+ checked: MatriqueSettings.pressAndHold
+ onCheckedChanged: MatriqueSettings.pressAndHold = checked
}
Button {
diff --git a/qml/main.qml b/qml/main.qml
index 1914640..22b8af2 100644
--- a/qml/main.qml
+++ b/qml/main.qml
@@ -2,9 +2,10 @@ import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import QtQuick.Controls.Material 2.2
+import Qt.labs.settings 1.0 as Labs
import QtGraphicalEffects 1.0
-import Qt.labs.settings 1.0 as Settings
import Matrique 0.1
+import MatriqueSettings 0.1
import "component"
import "form"
@@ -20,25 +21,16 @@ ApplicationWindow {
minimumHeight: 480
title: qsTr("Matrique")
- Material.theme: setting.darkTheme ? Material.Dark : Material.Light
-
- FontLoader { id: materialFont; source: "qrc:/asset/font/material.ttf" }
-
- Settings.Settings {
- id: setting
+ Material.theme: MatriqueSettings.darkTheme ? Material.Dark : Material.Light
+ Labs.Settings {
property alias homeserver: matriqueController.homeserver
property alias userID: matriqueController.userID
property alias token: matriqueController.token
-
- property alias lazyLoad: settingPage.lazyLoad
- property alias asyncMessageDelegate: settingPage.asyncMessageDelegate
- property alias richText: settingPage.richText
-
- property alias darkTheme: settingPage.darkTheme
- property alias miniMode: settingPage.miniMode
}
+ FontLoader { id: materialFont; source: "qrc:/asset/font/material.ttf" }
+
Controller {
id: matriqueController
diff --git a/res.qrc b/res.qrc
index 51bec6a..e0a2235 100644
--- a/res.qrc
+++ b/res.qrc
@@ -34,5 +34,9 @@
qml/component/AutoImage.qml
asset/img/icon.ico
asset/img/icon.icns
+ qml/component/AutoMouseArea.qml
+ qml/MatriqueSettings/MatriqueSettings.qml
+ qml/MatriqueSettings/qmldir
+ qml/MatriqueSettings/plugins.qmltypes
diff --git a/src/main.cpp b/src/main.cpp
index 1427376..ddff03c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -38,6 +38,7 @@ int main(int argc, char *argv[]) {
qmlRegisterUncreatableType("Matrique", 0, 1, "RoomType", "ENUM");
QQmlApplicationEngine engine;
+ engine.addImportPath("qrc:/qml");
ImageProvider *m_provider = new ImageProvider();
diff --git a/src/matriqueroom.cpp b/src/matriqueroom.cpp
index 76f4a80..c7a13e4 100644
--- a/src/matriqueroom.cpp
+++ b/src/matriqueroom.cpp
@@ -69,12 +69,7 @@ void MatriqueRoom::saveFileAs(QString eventId) {
if (!fileName.isEmpty()) downloadFile(eventId, QUrl::fromLocalFile(fileName));
}
-void MatriqueRoom::acceptInvitation() { setJoinState(JoinState::Join); }
-
-void MatriqueRoom::rejectInvitation() {
- setJoinState(JoinState::Leave);
- forget();
-}
+void MatriqueRoom::acceptInvitation() { connection()->joinRoom(id()); }
void MatriqueRoom::forget() { connection()->forgetRoom(id()); }
diff --git a/src/matriqueroom.h b/src/matriqueroom.h
index 21f85e8..6047985 100644
--- a/src/matriqueroom.h
+++ b/src/matriqueroom.h
@@ -57,7 +57,6 @@ class MatriqueRoom : public Room {
void chooseAndUploadFile();
void saveFileAs(QString eventId);
void acceptInvitation();
- void rejectInvitation();
void forget();
void sendTypingNotification(bool isTyping);
};