Add an option to change qqc2 style

This commit is contained in:
woblight
2018-07-12 18:59:07 +02:00
parent 1899e107cc
commit a0be5f7c0d
11 changed files with 177 additions and 63 deletions
+1 -2
View File
@@ -21,9 +21,8 @@ import QtQuick.Layouts 1.3
ToolButton { ToolButton {
id: upBtn id: upBtn
enabled: addon.status == Addon.Ready && (addon.gitStatus != Addon.UpToDate && addon.gitStatus != Addon.Error) enabled: addon.status === Addon.Ready && (addon.gitStatus !== Addon.UpToDate && addon.gitStatus !== Addon.Error)
state: addon.gitStatus & ~Addon.MergeStatusMask state: addon.gitStatus & ~Addon.MergeStatusMask
icon.color: enabled ? "transparent" : "lightgray"
onClicked: addon.update() onClicked: addon.update()
hoverEnabled: true hoverEnabled: true
states: [ states: [
+34 -26
View File
@@ -19,9 +19,9 @@ import GitAddonsManager.engine 1.0
import QtQuick.Controls 2.4 import QtQuick.Controls 2.4
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
ColumnLayout { Page {
title: "Addons"
ToolBar { header: ToolBar {
Layout.fillWidth: true Layout.fillWidth: true
RowLayout { RowLayout {
anchors.fill: parent anchors.fill: parent
@@ -34,6 +34,7 @@ ColumnLayout {
ToolButton { ToolButton {
hoverEnabled: true hoverEnabled: true
action: updateAllAction action: updateAllAction
icon.name: availableUpdates > 0 ? "update-high" : "update-none"
ToolTip.visible: hovered ToolTip.visible: hovered
ToolTip.text: "Upgrade all addons" ToolTip.text: "Upgrade all addons"
} }
@@ -58,8 +59,8 @@ ColumnLayout {
} }
} }
RowLayout { RowLayout {
Layout.fillHeight: true anchors.fill: parent
Layout.fillWidth: true anchors.leftMargin: 4
spacing: 0 spacing: 0
ListView { ListView {
ScrollBar.vertical: scrollBar ScrollBar.vertical: scrollBar
@@ -76,7 +77,6 @@ ColumnLayout {
hoverEnabled: true hoverEnabled: true
id: ma id: ma
RowLayout { RowLayout {
spacing: 0
width: parent.width width: parent.width
id: row id: row
Rectangle { Rectangle {
@@ -88,13 +88,18 @@ ColumnLayout {
Label { Label {
id: addonName id: addonName
text: addon.name text: addon.name
}
Item {
Layout.fillWidth: true Layout.fillWidth: true
background: ProgressBar { Layout.fillHeight: true
ProgressBar {
anchors.fill: parent
anchors.margins: 4
id: pBar id: pBar
from: 0 from: 0
to: addon.total to: addon.total
value: addon.progress value: addon.progress
visible: addon.status == Addon.Status.Busy visible: addon.status === Addon.Status.Busy
indeterminate: to == 0 indeterminate: to == 0
} }
} }
@@ -105,26 +110,29 @@ ColumnLayout {
Component.onCompleted: currentIndex = find(addon.currentBranch) Component.onCompleted: currentIndex = find(addon.currentBranch)
onActivated: addon.currentBranch = currentText onActivated: addon.currentBranch = currentText
} }
AddonUpdateButton { RowLayout {
width: parent.width spacing: 0
} AddonUpdateButton {
ToolButton { }
icon.name: "overflow-menu" ToolButton {
onClicked: if (!addonMenu.visible) addonMenu.visible = true icon.name: "overflow-menu"
checked: addonMenu.visible onClicked: if (!addonMenu.visible) addonMenu.visible = true
Menu { checked: addonMenu.visible
x: -width Menu {
id: addonMenu x: -width
visible: false id: addonMenu
MenuItem { visible: false
enabled: addon.status == Addon.Status.Ready MenuItem {
id: deleteButton enabled: addon.status == Addon.Status.Ready
text: qsTr("delete") id: deleteButton
icon.name: "delete" text: qsTr("delete")
onTriggered: addon.uninstall() icon.name: "delete"
onTriggered: addon.uninstall()
hoverEnabled: true
}
}
} }
} }
}
} }
Dialog { Dialog {
parent: window.overlay parent: window.overlay
+1 -1
View File
@@ -1,4 +1,4 @@
QT += quick widgets concurrent QT += quick widgets concurrent quickcontrols2
CONFIG += c++1z CONFIG += c++1z
# The following define makes your compiler emit warnings if you use # The following define makes your compiler emit warnings if you use
+48 -22
View File
@@ -21,29 +21,26 @@ import QtQuick.Layouts 1.3
ColumnLayout { ColumnLayout {
Frame { RowLayout {
Layout.fillWidth: true Layout.fillWidth: true
contentItem: RowLayout { TextField {
width: parent.width Layout.fillWidth: true
TextField { id: path
Layout.fillWidth: true text: Engine.addonsPath
id: path onAccepted: Engine.addonsPath = text
text: Engine.addonsPath placeholderText: qsTr("Path to AddOns folder")
onAccepted: Engine.addonsPath = text hoverEnabled: true
placeholderText: qsTr("Path to AddOns folder") ToolTip.visible: hovered
hoverEnabled: true ToolTip.text: qsTr("Path to the folder containing the addons")
ToolTip.visible: hovered enabled: Control.status == Control.Ready && addonsReady
ToolTip.text: qsTr("Path to the folder containing the addons") }
enabled: Control.status == Control.Ready && addonsReady Button {
} enabled: Control.status == Control.Ready && addonsReady
Button { text: qsTr("Browse")
enabled: Control.status == Control.Ready && addonsReady onClicked: fileDialog.visible = true
text: qsTr("Browse") hoverEnabled: true
onClicked: fileDialog.visible = true ToolTip.visible: hovered
hoverEnabled: true ToolTip.text: qsTr("Choose the folder containing the addons")
ToolTip.visible: hovered
ToolTip.text: qsTr("Choose the folder containing the addons")
}
} }
} }
CheckBox { CheckBox {
@@ -58,4 +55,33 @@ ColumnLayout {
ToolTip.visible: hovered ToolTip.visible: hovered
ToolTip.text: qsTr("Minimize to System Tray when the main window is closed.") ToolTip.text: qsTr("Minimize to System Tray when the main window is closed.")
} }
RowLayout {
Label {
text: qsTr("Style")
}
ComboBox {
model: Engine.availableStyles
currentIndex: Engine.availableStyles.indexOf(Engine.style)
onActivated: {
Engine.style = Engine.availableStyles[currentIndex]
restartDialog.visible = true
}
ToolTip.text: qsTr("Requires restart")
ToolTip.visible: hovered
hoverEnabled: true
}
}
Dialog {
id: restartDialog
parent: overlay
x: (parent.width - width) / 2
y: (parent.height - height) / 2
standardButtons: Dialog.Yes | Dialog.No
Label {
anchors.fill: parent
text: qsTr("The application must be restarted for this change to take effect.\nRestart now?")
wrapMode: Text.WordWrap
}
onAccepted: Qt.exit(1)
}
} }
+1 -2
View File
@@ -21,8 +21,7 @@ import GitAddonsManager.engine 1.0
SystemTrayIcon { SystemTrayIcon {
visible: true visible: true
iconName: "update-none" iconName: availableUpdates > 0 ? "update-high" : "update-none"
onActivated: { onActivated: {
window.show() window.show()
window.raise() window.raise()
+38 -1
View File
@@ -18,6 +18,8 @@
#include <QSettings> #include <QSettings>
#include <QDir> #include <QDir>
#include <QFutureWatcher> #include <QFutureWatcher>
#include <QQuickStyle>
#include <QQuickStyle>
#include "addon.h" #include "addon.h"
#include <git2.h> #include <git2.h>
#include <QDebug> #include <QDebug>
@@ -26,7 +28,9 @@
Control *Control::m_instance = nullptr; Control *Control::m_instance = nullptr;
Control::Control(QObject *parent) : QObject(parent), m_progress(0), m_total(0), m_status(Status::Ready), m_statusMessage(""), m_pool(new QThreadPool(this)) Control::Control(QObject *parent) : QObject(parent),
m_progress(0), m_total(0), m_status(Status::Ready), m_statusMessage(""), m_pool(new QThreadPool(this)),
m_style(QQuickStyle::name()),m_availableStyles(QQuickStyle::availableStyles())
{ {
QSettings settings; QSettings settings;
setAddonsPath(settings.value("addonsPath").toString()); setAddonsPath(settings.value("addonsPath").toString());
@@ -81,6 +85,11 @@ void Control::delegate(QString taskname, auto work)
delegate(taskname, work, [](ret_t){}); delegate(taskname, work, [](ret_t){});
} }
Control::~Control()
{
m_instance = nullptr;
}
QList<QObject *> Control::addons() const QList<QObject *> Control::addons() const
{ {
return m_addons; return m_addons;
@@ -128,6 +137,16 @@ Control::MinimizeToTray Control::minimizeToTray() const
return m_minimizeToTray; return m_minimizeToTray;
} }
QString Control::style() const
{
return m_style;
}
QStringList Control::availableStyles() const
{
return m_availableStyles;
}
void Control::setAddons(QList<QObject *> addons) void Control::setAddons(QList<QObject *> addons)
{ {
if (m_addons == addons) if (m_addons == addons)
@@ -289,3 +308,21 @@ void Control::setMinimizeToTray(MinimizeToTray minimizeToTray)
QSettings s; QSettings s;
s.setValue("minimizeToTray",(int)minimizeToTray); s.setValue("minimizeToTray",(int)minimizeToTray);
} }
void Control::setStyle(QString theme)
{
if (m_style == theme)
return;
m_style = theme;
emit styleChanged(m_style);
}
void Control::setAvailableStyles(QStringList availableStyles)
{
if (m_availableStyles == availableStyles)
return;
m_availableStyles = availableStyles;
emit availableStylesChanged(m_availableStyles);
}
+18
View File
@@ -42,6 +42,10 @@ public:
Q_PROPERTY(int total READ total WRITE setTotal NOTIFY totalChanged) Q_PROPERTY(int total READ total WRITE setTotal NOTIFY totalChanged)
Q_PROPERTY(QString statusMessage READ statusMessage WRITE setStatusMessage NOTIFY statusMessageChanged) Q_PROPERTY(QString statusMessage READ statusMessage WRITE setStatusMessage NOTIFY statusMessageChanged)
Q_PROPERTY(bool firstBoot READ firstBoot WRITE setFirstBoot NOTIFY firstBootChanged) Q_PROPERTY(bool firstBoot READ firstBoot WRITE setFirstBoot NOTIFY firstBootChanged)
Q_PROPERTY(QString style READ style WRITE setStyle NOTIFY styleChanged)
Q_PROPERTY(QStringList availableStyles READ availableStyles WRITE setAvailableStyles NOTIFY availableStylesChanged)
~Control();
enum class Status { enum class Status {
Error = -1, Error = -1,
@@ -77,6 +81,10 @@ public:
MinimizeToTray minimizeToTray() const; MinimizeToTray minimizeToTray() const;
QString style() const;
QStringList availableStyles() const;
private: private:
static Control *m_instance; static Control *m_instance;
explicit Control(QObject *parent = nullptr); explicit Control(QObject *parent = nullptr);
@@ -98,6 +106,10 @@ private:
void delegate(QString message, auto work, auto callback); void delegate(QString message, auto work, auto callback);
void delegate(QString message, auto work); void delegate(QString message, auto work);
QString m_style;
QStringList m_availableStyles;
signals: signals:
void addonsChanged(QList<QObject *> addons); void addonsChanged(QList<QObject *> addons);
@@ -115,6 +127,10 @@ signals:
void minimizeToTrayChanged(MinimizeToTray minimizeToTray); void minimizeToTrayChanged(MinimizeToTray minimizeToTray);
void styleChanged(QString style);
void availableStylesChanged(QStringList availableStyles);
public slots: public slots:
void setAddons(QList<QObject *> addons); void setAddons(QList<QObject *> addons);
void setAddonsPath(QString addonsPath); void setAddonsPath(QString addonsPath);
@@ -127,6 +143,8 @@ public slots:
void setStatusMessage(QString statusMessage); void setStatusMessage(QString statusMessage);
void setFirstBoot(bool firstBoot); void setFirstBoot(bool firstBoot);
void setMinimizeToTray(MinimizeToTray minimizeToTray); void setMinimizeToTray(MinimizeToTray minimizeToTray);
void setStyle(QString style);
void setAvailableStyles(QStringList availableStyles);
}; };
Q_DECLARE_METATYPE(Control::MinimizeToTray) Q_DECLARE_METATYPE(Control::MinimizeToTray)
+4 -2
View File
@@ -86,5 +86,7 @@ FollowsColorScheme=true
Directories=svg Directories=svg
[svg] [svg]
Type=Fixed Type=Scalable
Size=48 Size=22
MinSize=8
MaxSize=256
+25 -2
View File
@@ -20,9 +20,16 @@
#include "addon.h" #include "addon.h"
#include <QIcon> #include <QIcon>
#include <QQmlContext> #include <QQmlContext>
#include <QQuickStyle>
#include <QInputDialog>
#include <QSettings>
#include <QProcess>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int res;
qmlClearTypeRegistrations();
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv); QApplication app(argc, argv);
app.setApplicationDisplayName("Git Addons Manager"); app.setApplicationDisplayName("Git Addons Manager");
@@ -30,8 +37,18 @@ int main(int argc, char *argv[])
QCoreApplication::setApplicationName("Git Addons Manager"); QCoreApplication::setApplicationName("Git Addons Manager");
QIcon::setThemeName("breeze"); QIcon::setThemeName("breeze");
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
bool ok;
QSettings setts;
QStringList styles = QQuickStyle::availableStyles();
QString style = setts.value("style").toString();
if (style.isNull())
style = QInputDialog::getItem(nullptr, "Choose a style", "", styles, styles.indexOf(QQuickStyle::name()), false, &ok);
QQuickStyle::setStyle(style);
if (ok) {
setts.setValue("style", style);
setts.sync();
}
qmlRegisterSingletonType<Control>("GitAddonsManager.engine",1,0,"Engine",[](QQmlEngine *, QJSEngine *)->QObject*{ qmlRegisterSingletonType<Control>("GitAddonsManager.engine",1,0,"Engine",[](QQmlEngine *, QJSEngine *)->QObject*{
return Control::instance(); return Control::instance();
}); });
@@ -40,6 +57,12 @@ int main(int argc, char *argv[])
engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty()) if (engine.rootObjects().isEmpty())
return -1; return -1;
QObject::connect(Control::instance(), &Control::styleChanged,[&setts](const QString &style){
setts.setValue("style", style);
});
return app.exec(); res = app.exec();
if (res == 1)
QProcess().startDetached(app.arguments()[0],app.arguments().mid(1));
return res;
} }
+3 -1
View File
@@ -89,7 +89,6 @@ ApplicationWindow {
} }
Action { Action {
id: updateAllAction id: updateAllAction
icon.name: availableUpdates > 0 ? "update-high" : "update-none"
onTriggered: updateAll() onTriggered: updateAll()
enabled: availableUpdates > 0 enabled: availableUpdates > 0
} }
@@ -145,6 +144,8 @@ ApplicationWindow {
TextArea { TextArea {
readOnly: true readOnly: true
text: gitVersion text: gitVersion
selectByMouse: true
onFocusChanged: if (focus) selectAll()
} }
} }
} }
@@ -165,6 +166,7 @@ ApplicationWindow {
visible: cloneHelpBtn.checked visible: cloneHelpBtn.checked
x: (parent.width - width) / 2 x: (parent.width - width) / 2
y: (parent.height - height) / 2 y: (parent.height - height) / 2
standardButtons: Dialog.Close
title: qsTr("Clone URL Help") title: qsTr("Clone URL Help")
ColumnLayout { ColumnLayout {
anchors.fill: parent anchors.fill: parent
+4 -4
View File
@@ -5,7 +5,11 @@
<file>Options.qml</file> <file>Options.qml</file>
<file>AddonUpdateButton.qml</file> <file>AddonUpdateButton.qml</file>
<file>AddonsPanel.qml</file> <file>AddonsPanel.qml</file>
<file>github_clone_url.jpg</file>
<file>gitlab_clone_url.jpg</file>
<file>icons/breeze/svg/delete.svg</file> <file>icons/breeze/svg/delete.svg</file>
<file>icons/breeze/svg/go-parent-folder.svg</file>
<file>icons/breeze/svg/help-whatsthis.svg</file>
<file>icons/breeze/svg/list-add.svg</file> <file>icons/breeze/svg/list-add.svg</file>
<file>icons/breeze/svg/overflow-menu.svg</file> <file>icons/breeze/svg/overflow-menu.svg</file>
<file>icons/breeze/svg/update-high.svg</file> <file>icons/breeze/svg/update-high.svg</file>
@@ -15,9 +19,5 @@
<file>icons/breeze/svg/view-refresh.svg</file> <file>icons/breeze/svg/view-refresh.svg</file>
<file>icons/breeze/COPYING-ICONS</file> <file>icons/breeze/COPYING-ICONS</file>
<file>icons/breeze/index.theme</file> <file>icons/breeze/index.theme</file>
<file>icons/breeze/svg/go-parent-folder.svg</file>
<file>icons/breeze/svg/help-whatsthis.svg</file>
<file>github_clone_url.jpg</file>
<file>gitlab_clone_url.jpg</file>
</qresource> </qresource>
</RCC> </RCC>