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 {
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
icon.color: enabled ? "transparent" : "lightgray"
onClicked: addon.update()
hoverEnabled: true
states: [
+34 -26
View File
@@ -19,9 +19,9 @@ import GitAddonsManager.engine 1.0
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.3
ColumnLayout {
ToolBar {
Page {
title: "Addons"
header: ToolBar {
Layout.fillWidth: true
RowLayout {
anchors.fill: parent
@@ -34,6 +34,7 @@ ColumnLayout {
ToolButton {
hoverEnabled: true
action: updateAllAction
icon.name: availableUpdates > 0 ? "update-high" : "update-none"
ToolTip.visible: hovered
ToolTip.text: "Upgrade all addons"
}
@@ -58,8 +59,8 @@ ColumnLayout {
}
}
RowLayout {
Layout.fillHeight: true
Layout.fillWidth: true
anchors.fill: parent
anchors.leftMargin: 4
spacing: 0
ListView {
ScrollBar.vertical: scrollBar
@@ -76,7 +77,6 @@ ColumnLayout {
hoverEnabled: true
id: ma
RowLayout {
spacing: 0
width: parent.width
id: row
Rectangle {
@@ -88,13 +88,18 @@ ColumnLayout {
Label {
id: addonName
text: addon.name
}
Item {
Layout.fillWidth: true
background: ProgressBar {
Layout.fillHeight: true
ProgressBar {
anchors.fill: parent
anchors.margins: 4
id: pBar
from: 0
to: addon.total
value: addon.progress
visible: addon.status == Addon.Status.Busy
visible: addon.status === Addon.Status.Busy
indeterminate: to == 0
}
}
@@ -105,26 +110,29 @@ ColumnLayout {
Component.onCompleted: currentIndex = find(addon.currentBranch)
onActivated: addon.currentBranch = currentText
}
AddonUpdateButton {
width: parent.width
}
ToolButton {
icon.name: "overflow-menu"
onClicked: if (!addonMenu.visible) addonMenu.visible = true
checked: addonMenu.visible
Menu {
x: -width
id: addonMenu
visible: false
MenuItem {
enabled: addon.status == Addon.Status.Ready
id: deleteButton
text: qsTr("delete")
icon.name: "delete"
onTriggered: addon.uninstall()
RowLayout {
spacing: 0
AddonUpdateButton {
}
ToolButton {
icon.name: "overflow-menu"
onClicked: if (!addonMenu.visible) addonMenu.visible = true
checked: addonMenu.visible
Menu {
x: -width
id: addonMenu
visible: false
MenuItem {
enabled: addon.status == Addon.Status.Ready
id: deleteButton
text: qsTr("delete")
icon.name: "delete"
onTriggered: addon.uninstall()
hoverEnabled: true
}
}
}
}
}
}
Dialog {
parent: window.overlay
+1 -1
View File
@@ -1,4 +1,4 @@
QT += quick widgets concurrent
QT += quick widgets concurrent quickcontrols2
CONFIG += c++1z
# 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 {
Frame {
RowLayout {
Layout.fillWidth: true
contentItem: RowLayout {
width: parent.width
TextField {
Layout.fillWidth: true
id: path
text: Engine.addonsPath
onAccepted: Engine.addonsPath = text
placeholderText: qsTr("Path to AddOns folder")
hoverEnabled: true
ToolTip.visible: hovered
ToolTip.text: qsTr("Path to the folder containing the addons")
enabled: Control.status == Control.Ready && addonsReady
}
Button {
enabled: Control.status == Control.Ready && addonsReady
text: qsTr("Browse")
onClicked: fileDialog.visible = true
hoverEnabled: true
ToolTip.visible: hovered
ToolTip.text: qsTr("Choose the folder containing the addons")
}
TextField {
Layout.fillWidth: true
id: path
text: Engine.addonsPath
onAccepted: Engine.addonsPath = text
placeholderText: qsTr("Path to AddOns folder")
hoverEnabled: true
ToolTip.visible: hovered
ToolTip.text: qsTr("Path to the folder containing the addons")
enabled: Control.status == Control.Ready && addonsReady
}
Button {
enabled: Control.status == Control.Ready && addonsReady
text: qsTr("Browse")
onClicked: fileDialog.visible = true
hoverEnabled: true
ToolTip.visible: hovered
ToolTip.text: qsTr("Choose the folder containing the addons")
}
}
CheckBox {
@@ -58,4 +55,33 @@ ColumnLayout {
ToolTip.visible: hovered
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 {
visible: true
iconName: "update-none"
iconName: availableUpdates > 0 ? "update-high" : "update-none"
onActivated: {
window.show()
window.raise()
+38 -1
View File
@@ -18,6 +18,8 @@
#include <QSettings>
#include <QDir>
#include <QFutureWatcher>
#include <QQuickStyle>
#include <QQuickStyle>
#include "addon.h"
#include <git2.h>
#include <QDebug>
@@ -26,7 +28,9 @@
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;
setAddonsPath(settings.value("addonsPath").toString());
@@ -81,6 +85,11 @@ void Control::delegate(QString taskname, auto work)
delegate(taskname, work, [](ret_t){});
}
Control::~Control()
{
m_instance = nullptr;
}
QList<QObject *> Control::addons() const
{
return m_addons;
@@ -128,6 +137,16 @@ Control::MinimizeToTray Control::minimizeToTray() const
return m_minimizeToTray;
}
QString Control::style() const
{
return m_style;
}
QStringList Control::availableStyles() const
{
return m_availableStyles;
}
void Control::setAddons(QList<QObject *> addons)
{
if (m_addons == addons)
@@ -289,3 +308,21 @@ void Control::setMinimizeToTray(MinimizeToTray minimizeToTray)
QSettings s;
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(QString statusMessage READ statusMessage WRITE setStatusMessage NOTIFY statusMessageChanged)
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 {
Error = -1,
@@ -77,6 +81,10 @@ public:
MinimizeToTray minimizeToTray() const;
QString style() const;
QStringList availableStyles() const;
private:
static Control *m_instance;
explicit Control(QObject *parent = nullptr);
@@ -98,6 +106,10 @@ private:
void delegate(QString message, auto work, auto callback);
void delegate(QString message, auto work);
QString m_style;
QStringList m_availableStyles;
signals:
void addonsChanged(QList<QObject *> addons);
@@ -115,6 +127,10 @@ signals:
void minimizeToTrayChanged(MinimizeToTray minimizeToTray);
void styleChanged(QString style);
void availableStylesChanged(QStringList availableStyles);
public slots:
void setAddons(QList<QObject *> addons);
void setAddonsPath(QString addonsPath);
@@ -127,6 +143,8 @@ public slots:
void setStatusMessage(QString statusMessage);
void setFirstBoot(bool firstBoot);
void setMinimizeToTray(MinimizeToTray minimizeToTray);
void setStyle(QString style);
void setAvailableStyles(QStringList availableStyles);
};
Q_DECLARE_METATYPE(Control::MinimizeToTray)
+4 -2
View File
@@ -86,5 +86,7 @@ FollowsColorScheme=true
Directories=svg
[svg]
Type=Fixed
Size=48
Type=Scalable
Size=22
MinSize=8
MaxSize=256
+25 -2
View File
@@ -20,9 +20,16 @@
#include "addon.h"
#include <QIcon>
#include <QQmlContext>
#include <QQuickStyle>
#include <QInputDialog>
#include <QSettings>
#include <QProcess>
int main(int argc, char *argv[])
{
int res;
qmlClearTypeRegistrations();
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
app.setApplicationDisplayName("Git Addons Manager");
@@ -30,8 +37,18 @@ int main(int argc, char *argv[])
QCoreApplication::setApplicationName("Git Addons Manager");
QIcon::setThemeName("breeze");
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*{
return Control::instance();
});
@@ -40,6 +57,12 @@ int main(int argc, char *argv[])
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
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 {
id: updateAllAction
icon.name: availableUpdates > 0 ? "update-high" : "update-none"
onTriggered: updateAll()
enabled: availableUpdates > 0
}
@@ -145,6 +144,8 @@ ApplicationWindow {
TextArea {
readOnly: true
text: gitVersion
selectByMouse: true
onFocusChanged: if (focus) selectAll()
}
}
}
@@ -165,6 +166,7 @@ ApplicationWindow {
visible: cloneHelpBtn.checked
x: (parent.width - width) / 2
y: (parent.height - height) / 2
standardButtons: Dialog.Close
title: qsTr("Clone URL Help")
ColumnLayout {
anchors.fill: parent
+4 -4
View File
@@ -5,7 +5,11 @@
<file>Options.qml</file>
<file>AddonUpdateButton.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/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/overflow-menu.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/COPYING-ICONS</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>
</RCC>