Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OpenVoice shell plugin to support color configuration #4

Merged
merged 1 commit into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0)
add_definitions(-DQT_NO_URL_CAST_FROM_STRING -DQT_USE_QSTRINGBUILDER -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII)

add_subdirectory(application)
add_subdirectory(theme)
add_subdirectory(theme)
add_subdirectory(lib)
18 changes: 18 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
set(openvoiceshell_SRCS openvoiceshellplugin.cpp configuration.cpp)

include_directories(${CMAKE_CURRENT_BINARY_DIR})

add_library(openvoiceshellplugin SHARED ${openvoiceshell_SRCS} ${RESOURCES})

target_link_libraries(openvoiceshellplugin
Qt5::Core
Qt5::Quick
Qt5::Qml
KF5::GuiAddons
KF5::ConfigWidgets
)

########### install files ###############
install(TARGETS openvoiceshellplugin DESTINATION ${KDE_INSTALL_QMLDIR}/OVOSPlugin)
install(FILES qmldir DESTINATION ${KDE_INSTALL_QMLDIR}/OVOSPlugin)
install(FILES plugins.qmltypes DESTINATION ${KDE_INSTALL_QMLDIR}/OVOSPlugin)
87 changes: 87 additions & 0 deletions lib/configuration.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include "configuration.h"
#include <KConfigGroup>
#include <KSharedConfig>
#include <KUser>
#include <QColor>


Configuration &Configuration::self()
{
static Configuration c;
return c;
}

QColor Configuration::primaryColor() const
{
static KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("OvosTheme"));
static KConfigGroup grp(config, QLatin1String("ColorScheme"));

if (grp.isValid()) {
return grp.readEntry(QLatin1String("primaryColor"), "#313131");
}

return "#313131";
}

void Configuration::setPrimaryColor(const QColor &mPrimaryColor)
{
static KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("OvosTheme"));
static KConfigGroup grp(config, QLatin1String("ColorScheme"));

if (primaryColor() == mPrimaryColor)
return;

grp.writeEntry(QLatin1String("primaryColor"), mPrimaryColor.name(QColor::HexArgb));
grp.sync();
emit primaryColorChanged();
}

QColor Configuration::secondaryColor() const
{
static KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("OvosTheme"));
static KConfigGroup grp(config, QLatin1String("ColorScheme"));

if (grp.isValid()) {
return grp.readEntry(QLatin1String("primaryColor"), "#F70D1A");
}

return "#F70D1A";
}

void Configuration::setSecondaryColor(const QColor &mSecondaryColor)
{
static KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("OvosTheme"));
static KConfigGroup grp(config, QLatin1String("ColorScheme"));

if (secondaryColor() == mSecondaryColor)
return;

grp.writeEntry(QLatin1String("secondaryColor"), mSecondaryColor.name(QColor::HexArgb));
grp.sync();
emit secondaryColorChanged();
}

QColor Configuration::textColor() const
{
static KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("OvosTheme"));
static KConfigGroup grp(config, QLatin1String("ColorScheme"));

if (grp.isValid()) {
return grp.readEntry(QLatin1String("textColor"), "#F1F1F1");
}

return "#F1F1F1";
}

void Configuration::setTextColor(const QColor &mTextColor)
{
static KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("OvosTheme"));
static KConfigGroup grp(config, QLatin1String("ColorScheme"));

if (textColor() == mTextColor)
return;

grp.writeEntry(QLatin1String("textColor"), mTextColor.name(QColor::HexArgb));
grp.sync();
emit textColorChanged();
}
33 changes: 33 additions & 0 deletions lib/configuration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef CONFIGURATION_H
#define CONFIGURATION_H

#include <QObject>
#include <QColor>

class Q_DECL_EXPORT Configuration : public QObject
{
Q_OBJECT
Q_PROPERTY(QColor primaryColor READ primaryColor WRITE setPrimaryColor NOTIFY primaryColorChanged)
Q_PROPERTY(QColor secondaryColor READ secondaryColor WRITE setSecondaryColor NOTIFY secondaryColorChanged)
Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor NOTIFY textColorChanged)

public:
QColor primaryColor() const;
void setPrimaryColor(const QColor &mPrimaryColor);

QColor secondaryColor() const;
void setSecondaryColor(const QColor &mSecondaryColor);

QColor textColor() const;
void setTextColor(const QColor &mTextColor);

static Configuration &self();

Q_SIGNALS:
void primaryColorChanged();
void secondaryColorChanged();
void textColorChanged();
};

#endif // CONFIGURATION_H

35 changes: 35 additions & 0 deletions lib/openvoiceshellplugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2021 Aditya Mehra <aix.m@outlook.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include "openvoiceshellplugin.h"
#include "configuration.h"
#include <QQmlContext>
#include <QQmlEngine>

static QObject *configSingletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
{
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)

return new Configuration;
}


void OpenVoiceShellPlugin::registerTypes(const char *uri)
{
qmlRegisterSingletonType<Configuration>(uri, 1, 0, "Configuration", configSingletonProvider);
}
33 changes: 33 additions & 0 deletions lib/openvoiceshellplugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2022 Aditya Mehra <aix.m@outlook.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#ifndef QMYCROFTPLUGIN_H
#define QMYCROFTPLUGIN_H

#include <QQmlExtensionPlugin>

class OpenVoiceShellPlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)

public:
void registerTypes(const char *uri) override;
};

#endif

23 changes: 23 additions & 0 deletions lib/plugins.qmltypes
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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 OVOSPlugin 1.0'

Module {
dependencies: ["QtQuick 2.0"]
Component {
name: "Configuration"
prototype: "QObject"
exports: ["OVOSPlugin/Configuration 1.0"]
isCreatable: false
isSingleton: true
exportMetaObjectRevisions: [0]
Property { name: "primaryColor"; type: "QColor" }
Property { name: "secondaryColor"; type: "QColor" }
Property { name: "textColor"; type: "QColor" }
}
}

5 changes: 5 additions & 0 deletions lib/qmldir
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module OVOSPlugin
plugin openvoiceshellplugin
classname OpenVoiceShellPlugin

typeinfo plugins.qmltypes