diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e9e18f..a11b96e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) \ No newline at end of file +add_subdirectory(theme) +add_subdirectory(lib) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt new file mode 100644 index 0000000..352cdd7 --- /dev/null +++ b/lib/CMakeLists.txt @@ -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) diff --git a/lib/configuration.cpp b/lib/configuration.cpp new file mode 100644 index 0000000..9803548 --- /dev/null +++ b/lib/configuration.cpp @@ -0,0 +1,87 @@ +#include "configuration.h" +#include +#include +#include +#include + + +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(); +} diff --git a/lib/configuration.h b/lib/configuration.h new file mode 100644 index 0000000..aaebda6 --- /dev/null +++ b/lib/configuration.h @@ -0,0 +1,33 @@ +#ifndef CONFIGURATION_H +#define CONFIGURATION_H + +#include +#include + +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 + diff --git a/lib/openvoiceshellplugin.cpp b/lib/openvoiceshellplugin.cpp new file mode 100644 index 0000000..4521a82 --- /dev/null +++ b/lib/openvoiceshellplugin.cpp @@ -0,0 +1,35 @@ +/* + * Copyright 2021 Aditya Mehra + * + * 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 +#include + +static QObject *configSingletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine) +{ + Q_UNUSED(engine) + Q_UNUSED(scriptEngine) + + return new Configuration; +} + + +void OpenVoiceShellPlugin::registerTypes(const char *uri) +{ + qmlRegisterSingletonType(uri, 1, 0, "Configuration", configSingletonProvider); +} diff --git a/lib/openvoiceshellplugin.h b/lib/openvoiceshellplugin.h new file mode 100644 index 0000000..7f93df8 --- /dev/null +++ b/lib/openvoiceshellplugin.h @@ -0,0 +1,33 @@ +/* + * Copyright 2022 Aditya Mehra + * + * 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 + +class OpenVoiceShellPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) + +public: + void registerTypes(const char *uri) override; +}; + +#endif + diff --git a/lib/plugins.qmltypes b/lib/plugins.qmltypes new file mode 100644 index 0000000..61ef031 --- /dev/null +++ b/lib/plugins.qmltypes @@ -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" } + } +} + diff --git a/lib/qmldir b/lib/qmldir new file mode 100644 index 0000000..7bfc0b5 --- /dev/null +++ b/lib/qmldir @@ -0,0 +1,5 @@ +module OVOSPlugin +plugin openvoiceshellplugin +classname OpenVoiceShellPlugin + +typeinfo plugins.qmltypes