From 3409d00193e14b756cb2d4e9f1ab1dacdeb452c2 Mon Sep 17 00:00:00 2001 From: Ming Rui Zhang <mingrui.zhang@savoirfairelinux.com> Date: Thu, 17 Sep 2020 14:17:56 -0400 Subject: [PATCH] dialog: remove MessageDialog to jami customized style Change-Id: I67230d9395a1f25214692a24f099d4306b6b1dc9 --- qml.qrc | 2 +- src/commoncomponents/MessageBox.qml | 40 ------ src/commoncomponents/SimpleMessageDialog.qml | 128 ++++++++++++++++++ src/mainapplication.cpp | 2 + src/mainview/MainView.qml | 2 +- .../components/CurrentAccountSettings.qml | 15 +- src/settingsview/components/LinkedDevices.qml | 13 +- .../components/PluginListPreferencesView.qml | 34 ++--- 8 files changed, 161 insertions(+), 75 deletions(-) delete mode 100644 src/commoncomponents/MessageBox.qml create mode 100644 src/commoncomponents/SimpleMessageDialog.qml diff --git a/qml.qrc b/qml.qrc index e6f7b8c67..06ff49145 100644 --- a/qml.qrc +++ b/qml.qrc @@ -61,7 +61,6 @@ <file>src/commoncomponents/LookupStatusLabel.qml</file> <file>src/commoncomponents/ListViewJami.qml</file> <file>src/commoncomponents/DeleteAccountDialog.qml</file> - <file>src/commoncomponents/MessageBox.qml</file> <file>src/wizardview/WizardView.qml</file> <file>src/wizardview/components/WelcomePage.qml</file> <file>src/wizardview/components/CreateAccountPage.qml</file> @@ -140,5 +139,6 @@ <file>src/mainview/components/UserInfoCallPage.qml</file> <file>src/commoncomponents/BaseDialog.qml</file> <file>src/commoncomponents/ModalPopup.qml</file> + <file>src/commoncomponents/SimpleMessageDialog.qml</file> </qresource> </RCC> diff --git a/src/commoncomponents/MessageBox.qml b/src/commoncomponents/MessageBox.qml deleted file mode 100644 index 16225a0c6..000000000 --- a/src/commoncomponents/MessageBox.qml +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2020 by Savoir-faire Linux - * Author: Yang Wang <yang.wang@savoirfairelinux.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - */ - -import QtQuick 2.15 -import QtQuick.Controls 2.14 -import QtQuick.Layouts 1.14 -import QtQuick.Controls.Styles 1.4 -import QtQuick.Dialogs 1.3 - -MessageDialog { - id: messageBox - - visible: false - modality: Qt.NonModal - width: 300 - height: 200 - - function openWithParameters(titleToDisplay, infoToDisplay, infoIconMode = StandardIcon.Information, buttons = StandardButton.Ok){ - title = titleToDisplay - text = infoToDisplay - icon = infoIconMode - standardButtons = buttons - messageBox.open() - } -} diff --git a/src/commoncomponents/SimpleMessageDialog.qml b/src/commoncomponents/SimpleMessageDialog.qml new file mode 100644 index 000000000..01a0c72b0 --- /dev/null +++ b/src/commoncomponents/SimpleMessageDialog.qml @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2020 by Savoir-faire Linux + * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +import QtQuick 2.15 +import QtQuick.Controls 2.14 +import QtQuick.Layouts 1.14 +import net.jami.Models 1.0 +import net.jami.Adapters 1.0 + +BaseDialog { + id: root + + // TODO: make MaterialButton ButtonStyle + enum ButtonStyle { + TintedBlue, + TintedBlack, + TintedRed + } + + property var buttonTitles: [] + property var buttonCallBacks: [] + property var buttonStyles: [] + property alias description: descriptionText.text + + function openWithParameters(title, info) { + root.title = title + descriptionText.text = info + open() + } + + contentItem: Rectangle { + id: simpleMessageDialogContentRect + + implicitWidth: Math.max(JamiTheme.preferredDialogWidth, + buttonTitles.length * (JamiTheme.preferredFieldWidth / 2 + + JamiTheme.preferredMarginSize)) + implicitHeight: JamiTheme.preferredDialogHeight / 2 + + ColumnLayout { + anchors.fill: parent + + Label { + id: descriptionText + + Layout.alignment: Qt.AlignCenter + Layout.preferredWidth: JamiTheme.preferredDialogWidth - JamiTheme.preferredMarginSize + Layout.topMargin: JamiTheme.preferredMarginSize + + font.pointSize: JamiTheme.menuFontSize - 2 + wrapMode: Text.WordWrap + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + + RowLayout { + spacing: JamiTheme.preferredMarginSize + + Layout.fillWidth: true + Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom + Layout.bottomMargin: JamiTheme.preferredMarginSize + + Repeater { + model: buttonTitles.length + MaterialButton { + Layout.alignment: Qt.AlignVCenter + Layout.preferredWidth: JamiTheme.preferredFieldWidth / 2 + Layout.preferredHeight: JamiTheme.preferredFieldHeight + + color: { + switch(buttonStyles[modelData]) { + case SimpleMessageDialog.ButtonStyle.TintedBlue: + return JamiTheme.buttonTintedBlue + case SimpleMessageDialog.ButtonStyle.TintedBlack: + return JamiTheme.buttonTintedBlack + case SimpleMessageDialog.ButtonStyle.TintedRed: + return JamiTheme.buttonTintedRed + } + } + hoveredColor: { + switch(buttonStyles[modelData]) { + case SimpleMessageDialog.ButtonStyle.TintedBlue: + return JamiTheme.buttonTintedBlueHovered + case SimpleMessageDialog.ButtonStyle.TintedBlack: + return JamiTheme.buttonTintedBlackHovered + case SimpleMessageDialog.ButtonStyle.TintedRed: + return JamiTheme.buttonTintedRedHovered + } + } + pressedColor: { + switch(buttonStyles[modelData]) { + case SimpleMessageDialog.ButtonStyle.TintedBlue: + return JamiTheme.buttonTintedBluePressed + case SimpleMessageDialog.ButtonStyle.TintedBlack: + return JamiTheme.buttonTintedBlackPressed + case SimpleMessageDialog.ButtonStyle.TintedRed: + return JamiTheme.buttonTintedRedPressed + } + } + outlined: true + + text: buttonTitles[modelData] + + onClicked: { + if (buttonCallBacks[modelData]) + buttonCallBacks[modelData]() + close() + } + } + } + } + } + } +} diff --git a/src/mainapplication.cpp b/src/mainapplication.cpp index 1c37de9e6..e27965c1a 100644 --- a/src/mainapplication.cpp +++ b/src/mainapplication.cpp @@ -113,6 +113,8 @@ MainApplication::MainApplication(int& argc, char** argv) void MainApplication::init() { + setWindowIcon(QIcon(":images/jami.ico")); + #ifdef Q_OS_LINUX if (!getenv("QT_QPA_PLATFORMTHEME")) setenv("QT_QPA_PLATFORMTHEME", "gtk3", true); diff --git a/src/mainview/MainView.qml b/src/mainview/MainView.qml index 13a3acf79..195e38c01 100644 --- a/src/mainview/MainView.qml +++ b/src/mainview/MainView.qml @@ -549,7 +549,7 @@ Window { onSettingsViewWindowNeedToShowMainViewWindow: { mainViewWindowSidePanel.refreshAccountComboBox(0) - AccountAdapter.accountChanged(index) + AccountAdapter.accountChanged(0) toggleSettingsView() } diff --git a/src/settingsview/components/CurrentAccountSettings.qml b/src/settingsview/components/CurrentAccountSettings.qml index a286317a2..13846c095 100644 --- a/src/settingsview/components/CurrentAccountSettings.qml +++ b/src/settingsview/components/CurrentAccountSettings.qml @@ -98,12 +98,12 @@ Rectangle { JamiStrings.setPassword } - MessageBox { + SimpleMessageDialog { id: msgDialog - onAccepted: { - setPasswordButtonText() - } + buttonTitles: [qsTr("Ok")] + buttonStyles: [SimpleMessageDialog.ButtonStyle.TintedBlue] + buttonCallBacks: [setPasswordButtonText] } DeleteAccountDialog { @@ -125,7 +125,6 @@ Rectangle { onDoneSignal: { var title = success ? qsTr("Success") : qsTr("Error") - var iconMode = success ? StandardIcon.Information : StandardIcon.Critical var info switch(currentPurpose) { @@ -141,7 +140,7 @@ Rectangle { break } - msgDialog.openWithParameters(title,info, iconMode, StandardButton.Ok) + msgDialog.openWithParameters(title, info) } } @@ -166,9 +165,9 @@ Rectangle { if (exportPath.length > 0) { var isSuccessful = AccountAdapter.model.exportToFile(UtilsAdapter.getCurrAccId(), exportPath,"") var title = isSuccessful ? qsTr("Success") : qsTr("Error") - var iconMode = isSuccessful ? StandardIcon.Information : StandardIcon.Critical var info = isSuccessful ? JamiStrings.backupSuccessful : JamiStrings.backupFailed - msgDialog.openWithParameters(title,info, iconMode, StandardButton.Ok) + + msgDialog.openWithParameters(title,info) } } } diff --git a/src/settingsview/components/LinkedDevices.qml b/src/settingsview/components/LinkedDevices.qml index 76e4127ce..759843d23 100644 --- a/src/settingsview/components/LinkedDevices.qml +++ b/src/settingsview/components/LinkedDevices.qml @@ -88,17 +88,18 @@ ColumnLayout { onRevokeDeviceWithPassword: revokeDeviceWithIDAndPassword(idOfDevice, password) } - MessageBox { + SimpleMessageDialog { id: revokeDeviceMessageBox property string idOfDev: "" - title:qsTr("Remove Device") - text :qsTr("Are you sure you wish to remove this device?") - icon :StandardIcon.Information - standardButtons: StandardButton.Ok | StandardButton.Cancel + title: qsTr("Remove Device") + description: qsTr("Are you sure you wish to remove this device?") - onAccepted: revokeDeviceWithIDAndPassword(idOfDev,"") + buttonTitles: [qsTr("Ok"), qsTr("Cancel")] + buttonStyles: [SimpleMessageDialog.ButtonStyle.TintedBlue, + SimpleMessageDialog.ButtonStyle.TintedBlack] + buttonCallBacks: [function() {revokeDeviceWithIDAndPassword(idOfDev, "")}] } Label { diff --git a/src/settingsview/components/PluginListPreferencesView.qml b/src/settingsview/components/PluginListPreferencesView.qml index ec066e288..54c88078a 100644 --- a/src/settingsview/components/PluginListPreferencesView.qml +++ b/src/settingsview/components/PluginListPreferencesView.qml @@ -46,7 +46,10 @@ Rectangle { signal uninstalled function resetPluginSlot() { - resetPluginMessageBox.open() + msgDialog.buttonCallBacks = [function () {resetPlugin()}] + msgDialog.openWithParameters(qsTr("Reset preferences"), + qsTr("Are you sure you wish to reset "+ pluginName + + " preferences?")) } function resetPlugin() { @@ -61,7 +64,12 @@ Rectangle { } function uninstallPluginSlot() { - uninstallPluginMessageBox.open() + msgDialog.buttonCallBacks = [function () { + uninstallPlugin() + root.visible = false + }] + msgDialog.openWithParameters(qsTr("Uninstall plugin"), + qsTr("Are you sure you wish to uninstall " + pluginName + " ?")) } function uninstallPlugin() { @@ -79,13 +87,12 @@ Rectangle { PluginModel.setPluginPreference(pluginId, preferenceKey, preferenceNewValue) } - MessageDialog { - id: uninstallPluginMessageBox + SimpleMessageDialog { + id: msgDialog - title:qsTr("Uninstall plugin") - text :qsTr("Are you sure you wish to uninstall " + pluginName + " ?") - icon: StandardIcon.Warning - standardButtons: StandardButton.Ok | StandardButton.Cancel + buttonTitles: [qsTr("Ok"), qsTr("Cancel")] + buttonStyles: [SimpleMessageDialog.ButtonStyle.TintedBlue, + SimpleMessageDialog.ButtonStyle.TintedBlack] onAccepted: { uninstallPlugin() @@ -93,17 +100,6 @@ Rectangle { } } - MessageDialog { - id: resetPluginMessageBox - - title:qsTr("Reset preferences") - text :qsTr("Are you sure you wish to reset "+ pluginName + " preferences?") - icon: StandardIcon.Warning - standardButtons: StandardButton.Ok | StandardButton.Cancel - - onAccepted: resetPlugin() - } - ColumnLayout { anchors.left: root.left anchors.right: root.right -- GitLab