diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 25a5f63..74b087e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,153 +1,154 @@ ecm_setup_version(${KDE_APPLICATIONS_VERSION} VARIABLE_PREFIX KTOUCH VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KTouchConfigVersion.cmake" ) find_package(X11) add_feature_info("X11-Xkbfile" X11_Xkbfile_FOUND "required for automatic keyboard layout detection") find_package(XCB OPTIONAL_COMPONENTS XCB XKB) add_feature_info("XCB-XKB" XCB_XKB_FOUND "required for automatic keyboard layout detection") ecm_optional_add_subdirectory(schemata) # set include directories include_directories( ${CMAKE_CURRENT_BINARY_DIR} ${ktouch_SOURCE_DIR} ) # configure the local configuration file configure_file(ktouch_build_config.h.in ktouch_build_config.h) # set the source code files from which KTouch is compiled set(ktouch_SRCS main.cpp application.cpp mainwindow.cpp bindings/utils.cpp bindings/stringformatter.cpp declarativeitems/griditem.cpp + declarativeitems/kcolorschemeproxy.cpp declarativeitems/lessonpainter.cpp declarativeitems/preferencesproxy.cpp declarativeitems/scalebackgrounditem.cpp declarativeitems/traininglinecore.cpp core/resource.cpp core/keyboardlayoutbase.cpp core/keyboardlayout.cpp core/abstractkey.cpp core/key.cpp core/keychar.cpp core/specialkey.cpp core/coursebase.cpp core/course.cpp core/lesson.cpp core/trainingstats.cpp core/profile.cpp core/dataindex.cpp core/dataaccess.cpp core/dbaccess.cpp core/profiledataaccess.cpp core/resourcedataaccess.cpp core/userdataaccess.cpp undocommands/coursecommands.cpp undocommands/keyboardlayoutcommands.cpp models/resourcemodel.cpp models/lessonmodel.cpp models/charactersmodel.cpp models/categorizedresourcesortfilterproxymodel.cpp models/errorsmodel.cpp models/learningprogressmodel.cpp editor/resourceeditor.cpp editor/resourceeditorwidget.cpp editor/newresourceassistant.cpp editor/resourcetypeswidget.cpp editor/newcoursewidget.cpp editor/newkeyboardlayoutwidget.cpp editor/resourcetemplatewidget.cpp editor/abstracteditor.cpp editor/courseeditor.cpp editor/keyboardlayoutcombobox.cpp editor/lessontexteditor.cpp editor/lessontexthighlighter.cpp editor/keyboardlayouteditor.cpp editor/keyboardlayouteditorview.cpp editor/keyboardlayoutpropertieswidget.cpp editor/charactersviewdelegate.cpp trainingconfigwidget.cpp colorsconfigwidget.cpp customlessoneditordialog.cpp ktouchcontext.cpp ) qt5_add_resources(ktouch_SRCS qml/qml.qrc) # compile UI files ki18n_wrap_ui(ktouch_SRCS ui/colorsconfigwidget.ui ui/trainingconfigwidget.ui ui/resourceeditorwidget.ui ui/resourcetypeswidget.ui ui/newcoursewidget.ui ui/newkeyboardlayoutwidget.ui ui/resourcetemplatewidget.ui ui/courseeditor.ui ui/lessontexteditor.ui ui/keyboardlayouteditor.ui ui/keyboardlayoutpropertieswidget.ui ui/customlessoneditordialog.ui ) set (KTOUCH_BUILD_WITH_X11 X11_Xkbfile_FOUND AND XCB_XKB_FOUND AND XCB_FOUND) if (KTOUCH_BUILD_WITH_X11) add_definitions(-DKTOUCH_BUILD_WITH_X11) include_directories(${X11_Xkbfile_INCLUDE_PATH}) set(ktouch_SRCS ${ktouch_SRCS} x11_helper.cpp) else (KTOUCH_BUILD_WITH_X11) set(ktouch_SRCS ${ktouch_SRCS} keyboardlayoutmenu.cpp) endif (KTOUCH_BUILD_WITH_X11) kconfig_add_kcfg_files(ktouch_SRCS preferences.kcfgc) add_executable(ktouch ${ktouch_SRCS}) set(ktouch_X11_DEPS "") if (KTOUCH_BUILD_WITH_X11) set(ktouch_X11_DEPS ${X11_Xkbfile_LIB} ${X11_LIBRARIES} XCB::XCB XCB::XKB) endif (KTOUCH_BUILD_WITH_X11) #uncomment this if oxygen icons for ktouch are available target_link_libraries(ktouch LINK_PUBLIC Qt5::Qml Qt5::Quick Qt5::QuickWidgets Qt5::Script Qt5::Sql Qt5::XmlPatterns Qt5::X11Extras KF5::Completion KF5::ConfigWidgets KF5::Declarative KF5::ItemViews KF5::XmlGui KF5::I18n KF5::KCMUtils KF5::TextWidgets KF5::WindowSystem KF5::CoreAddons ${ktouch_X11_DEPS} ) #kde4_add_app_icon(ktouch_SRCS "${KDE4_ICON_DIR}/oxygen/*/apps/ktouch.png") #kde4_add_app_icon(ktouch_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/../icons/hi*-app-ktouch.png") install(TARGETS ktouch ${INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES ktouch.kcfg DESTINATION ${KCFG_INSTALL_DIR}) diff --git a/src/application.cpp b/src/application.cpp index 4ef411e..823a907 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -1,154 +1,156 @@ /* * Copyright 2012 Sebastian Gottfried * * 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 2 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 . */ #include "application.h" #include #include #include #include #include #include #include #include #include "bindings/utils.h" #include "bindings/stringformatter.h" #include "declarativeitems/griditem.h" +#include "declarativeitems/kcolorschemeproxy.h" #include "declarativeitems/lessonpainter.h" #include "declarativeitems/preferencesproxy.h" #include "declarativeitems/scalebackgrounditem.h" #include "declarativeitems/traininglinecore.h" #include "core/keyboardlayout.h" #include "core/key.h" #include "core/specialkey.h" #include "core/keychar.h" #include "core/course.h" #include "core/lesson.h" #include "core/profile.h" #include "core/trainingstats.h" #include "core/dataindex.h" #include "core/dataaccess.h" #include "core/profiledataaccess.h" #include "models/resourcemodel.h" #include "models/lessonmodel.h" #include "models/categorizedresourcesortfilterproxymodel.h" #include "models/learningprogressmodel.h" #include "models/errorsmodel.h" Application::Application(int& argc, char** argv, int flags): QApplication(argc, argv, flags), m_dataIndex(new DataIndex(this)) { registerQmlTypes(); migrateKde4Files(); DataAccess dataAccess; dataAccess.loadDataIndex(m_dataIndex); } DataIndex* Application::dataIndex() { Application* app = qobject_cast(QCoreApplication::instance()); return app->m_dataIndex; } QPointer& Application::resourceEditorRef() { Application* app = qobject_cast(QCoreApplication::instance()); return app->m_resourceEditorRef; } void Application::setupDeclarativeBindings(QQmlEngine* qmlEngine) { KDeclarative::KDeclarative kDeclarative; kDeclarative.setDeclarativeEngine(qmlEngine); kDeclarative.setupBindings(); Application* app = static_cast(Application::instance()); foreach (const QString& path, app->m_qmlImportPaths) { qmlEngine->addImportPath(path); } QQmlContext* rootContext = qmlEngine->rootContext(); rootContext->setContextProperty("utils", new Utils()); rootContext->setContextProperty("strFormatter", new StringFormatter()); } QStringList& Application::qmlImportPaths() { return m_qmlImportPaths; } void Application::registerQmlTypes() { qmlRegisterType("ktouch", 1, 0, "KeyboardLayout"); qmlRegisterType("ktouch", 1, 0, "AbstractKey"); qmlRegisterType("ktouch", 1, 0, "Key"); qmlRegisterType("ktouch", 1, 0, "SpecialKey"); qmlRegisterType("ktouch", 1, 0, "KeyChar"); qmlRegisterType("ktouch", 1, 0, "Course"); qmlRegisterType("ktouch", 1, 0, "Lesson"); qmlRegisterType("ktouch", 1, 0, "TrainingStats"); qmlRegisterType("ktouch", 1, 0, "Profile"); qmlRegisterType("ktouch", 1, 0, "DataIndex"); qmlRegisterType("ktouch", 1, 0, "DataIndexCourse"); qmlRegisterType("ktouch", 1, 0, "DataIndexKeyboardLayout"); qmlRegisterType("ktouch", 1, 0, "Preferences"); qmlRegisterType("ktouch", 1, 0, "DataAccess"); qmlRegisterType("ktouch", 1, 0, "ProfileDataAccess"); qmlRegisterType("ktouch", 1, 0, "ResourceModel"); qmlRegisterType("ktouch", 1, 0, "LessonModel"); qmlRegisterType("ktouch", 1, 0, "CategorizedResourceSortFilterProxyModel"); qmlRegisterType("ktouch", 1, 0, "LearningProgressModel"); qmlRegisterType("ktouch", 1, 0, "ErrorsModel"); qmlRegisterType("ktouch", 1, 0 , "Grid"); qmlRegisterType("ktouch", 1, 0, "ScaleBackgroundItem"); qmlRegisterType("ktouch", 1, 0, "LessonPainter"); qmlRegisterType("ktouch", 1, 0, "TrainingLineCore"); + qmlRegisterType("ktouch", 1, 0, "KColorScheme"); } void Application::migrateKde4Files() { QStringList configFiles; configFiles << QLatin1String("ktouchrc"); Kdelibs4ConfigMigrator confMigrator(QLatin1String("ktouch")); confMigrator.setConfigFiles(configFiles); confMigrator.migrate(); Kdelibs4Migration migration; const QDir dataDir = QDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation)); if (!dataDir.exists()) { dataDir.mkpath(dataDir.path()); } const QString dbPath = dataDir.filePath("profiles.db"); const QString oldDbPath = migration.locateLocal("data", QStringLiteral("ktouch/profiles.db")); if (!QFile(dbPath).exists() && !oldDbPath.isEmpty()) { QFile(oldDbPath).copy(dbPath); } } diff --git a/src/declarativeitems/kcolorschemeproxy.cpp b/src/declarativeitems/kcolorschemeproxy.cpp new file mode 100644 index 0000000..48d8d2f --- /dev/null +++ b/src/declarativeitems/kcolorschemeproxy.cpp @@ -0,0 +1,175 @@ +#include "kcolorschemeproxy.h" + +#include + +KColorSchemeProxy::KColorSchemeProxy(QObject* parent) : + QObject(parent), + m_colorGroup(QPalette::Active), + m_colorSet(KColorScheme::View), + m_colorScheme(m_colorGroup, m_colorSet) +{ + auto app = qobject_cast(QCoreApplication::instance()); + if (app) + { + connect(app, SIGNAL(paletteChanged(QPalette)), SIGNAL(paletteChanged())); + } +} + +KColorSchemeProxy::ColorGroup KColorSchemeProxy::colorGroup() const +{ + return static_cast(m_colorGroup); +} + +void KColorSchemeProxy::setColorGroup(ColorGroup group) +{ + auto newColorGroup = static_cast(group); + if (newColorGroup != m_colorGroup) + { + m_colorGroup = newColorGroup; + emit colorGroupChanged(); + m_colorScheme = KColorScheme(m_colorGroup, m_colorSet); + emit paletteChanged(); + } +} + +KColorSchemeProxy::ColorSet KColorSchemeProxy::colorSet() const +{ + return static_cast(m_colorSet); +} + +void KColorSchemeProxy::setColorSet(ColorSet colorSet) +{ + auto newColorSet = static_cast(colorSet); + if (newColorSet != m_colorSet) + { + m_colorSet = newColorSet; + emit colorSetChanged(); + m_colorScheme = KColorScheme(m_colorGroup, m_colorSet); + emit paletteChanged(); + } +} + +QColor KColorSchemeProxy::normalBackground() const +{ + return m_colorScheme.background(KColorScheme::NormalBackground).color(); +} + +QColor KColorSchemeProxy::alternateBackground() const +{ + return m_colorScheme.background(KColorScheme::AlternateBackground).color(); +} + +QColor KColorSchemeProxy::activeBackground() const +{ + return m_colorScheme.background(KColorScheme::ActiveBackground).color(); +} + +QColor KColorSchemeProxy::linkBackground() const +{ + return m_colorScheme.background(KColorScheme::LinkBackground).color(); +} + +QColor KColorSchemeProxy::visitedBackground() const +{ + return m_colorScheme.background(KColorScheme::VisitedBackground).color(); +} + +QColor KColorSchemeProxy::negativeBackground() const +{ + return m_colorScheme.background(KColorScheme::NegativeBackground).color(); +} + +QColor KColorSchemeProxy::neutralBackground() const +{ + return m_colorScheme.background(KColorScheme::NeutralBackground).color(); +} + +QColor KColorSchemeProxy::positiveBackground() const +{ + return m_colorScheme.background(KColorScheme::PositiveBackground).color(); +} + +QColor KColorSchemeProxy::focusDecoration() const +{ + return m_colorScheme.decoration(KColorScheme::FocusColor).color(); +} + +QColor KColorSchemeProxy::hoverDecoration() const +{ + return m_colorScheme.decoration(KColorScheme::HoverColor).color(); +} + +QColor KColorSchemeProxy::normalText() const +{ + return m_colorScheme.foreground(KColorScheme::NormalText).color(); +} + +QColor KColorSchemeProxy::activeText() const +{ + return m_colorScheme.foreground(KColorScheme::ActiveText).color(); +} + +QColor KColorSchemeProxy::linkText() const +{ + return m_colorScheme.foreground(KColorScheme::LinkText).color(); +} + +QColor KColorSchemeProxy::visitedText() const +{ + return m_colorScheme.foreground(KColorScheme::VisitedText).color(); +} + +QColor KColorSchemeProxy::negativeText() const +{ + return m_colorScheme.foreground(KColorScheme::NegativeText).color(); +} + +QColor KColorSchemeProxy::neutralText() const +{ + return m_colorScheme.foreground(KColorScheme::NeutralText).color(); +} + +QColor KColorSchemeProxy::positiveText() const +{ + return m_colorScheme.foreground(KColorScheme::PositiveText).color(); +} + +QColor KColorSchemeProxy::lightShade() const +{ + return m_colorScheme.shade(KColorScheme::LightShade); +} + +QColor KColorSchemeProxy::midlightShade() const +{ + return m_colorScheme.shade(KColorScheme::MidlightShade); +} + +QColor KColorSchemeProxy::midShade() const +{ + return m_colorScheme.shade(KColorScheme::MidShade); +} + +QColor KColorSchemeProxy::darkShade() const +{ + return m_colorScheme.shade(KColorScheme::DarkShade); +} + +QColor KColorSchemeProxy::shadowShade() const +{ + return m_colorScheme.shade(KColorScheme::ShadowShade); +} + +qreal KColorSchemeProxy::contrast() const +{ + return KColorScheme::contrastF(); +} + +QColor KColorSchemeProxy::shade(const QColor& color, ShadeRole role) const +{ + return KColorScheme::shade(color, static_cast(role)); +} + +QColor KColorSchemeProxy::shade(const QColor& color, ShadeRole role, qreal contrast, qreal chromaAdjust) const +{ + return KColorScheme::shade(color, static_cast(role), contrast, chromaAdjust); +} diff --git a/src/declarativeitems/kcolorschemeproxy.h b/src/declarativeitems/kcolorschemeproxy.h new file mode 100644 index 0000000..314b5e6 --- /dev/null +++ b/src/declarativeitems/kcolorschemeproxy.h @@ -0,0 +1,118 @@ +#ifndef KCOLORSCHEMEPROXY_H +#define KCOLORSCHEMEPROXY_H + +#include +#include +#include + +class KColorSchemeProxy : public QObject +{ + Q_OBJECT + Q_ENUMS(ColorGroup) + Q_ENUMS(ColorSet) + Q_ENUMS(ShadeRole) + + Q_PROPERTY(ColorGroup colorGroup READ colorGroup WRITE setColorGroup NOTIFY colorGroupChanged) + Q_PROPERTY(ColorSet colorSet READ colorSet WRITE setColorSet NOTIFY colorSetChanged) + + Q_PROPERTY(QColor normalBackground READ normalBackground NOTIFY paletteChanged) + Q_PROPERTY(QColor alternateBackground READ alternateBackground NOTIFY paletteChanged) + Q_PROPERTY(QColor activeBackground READ activeBackground NOTIFY paletteChanged) + Q_PROPERTY(QColor linkBackground READ linkBackground NOTIFY paletteChanged) + Q_PROPERTY(QColor visitedBackground READ visitedBackground NOTIFY paletteChanged) + Q_PROPERTY(QColor negativeBackground READ negativeBackground NOTIFY paletteChanged) + Q_PROPERTY(QColor neutralBackground READ neutralBackground NOTIFY paletteChanged) + Q_PROPERTY(QColor positiveBackground READ positiveBackground NOTIFY paletteChanged) + + Q_PROPERTY(QColor focusDecoration READ focusDecoration NOTIFY paletteChanged) + Q_PROPERTY(QColor hoverDecoration READ hoverDecoration NOTIFY paletteChanged) + + Q_PROPERTY(QColor normalText READ normalText NOTIFY paletteChanged) + Q_PROPERTY(QColor activeText READ activeText NOTIFY paletteChanged) + Q_PROPERTY(QColor linkText READ linkText NOTIFY paletteChanged) + Q_PROPERTY(QColor visitedText READ visitedText NOTIFY paletteChanged) + Q_PROPERTY(QColor negativeText READ negativeText NOTIFY paletteChanged) + Q_PROPERTY(QColor neutralText READ neutralText NOTIFY paletteChanged) + Q_PROPERTY(QColor positiveText READ positiveText NOTIFY paletteChanged) + + Q_PROPERTY(QColor lightShade READ lightShade NOTIFY paletteChanged) + Q_PROPERTY(QColor midlightShade READ midlightShade NOTIFY paletteChanged) + Q_PROPERTY(QColor midShade READ midShade NOTIFY paletteChanged) + Q_PROPERTY(QColor darkShade READ darkShade NOTIFY paletteChanged) + Q_PROPERTY(QColor shadowShade READ shadowShade NOTIFY paletteChanged) + + Q_PROPERTY(qreal contrast READ contrast NOTIFY paletteChanged) + +public: + enum ColorGroup { Active, Disabled, Inactive, NColorGroups, Current, All, Normal = Active }; + + enum ColorSet { + View, + Window, + Button, + Selection, + Tooltip, + Complementary + }; + + enum ShadeRole { + LightShade, + MidlightShade, + MidShade, + DarkShade, + ShadowShade + }; + + explicit KColorSchemeProxy(QObject* parent = 0); + + ColorGroup colorGroup() const; + void setColorGroup(ColorGroup group); + + + ColorSet colorSet() const; + void setColorSet(ColorSet colorSet); + + QColor normalBackground() const; + QColor alternateBackground() const; + QColor activeBackground() const; + QColor linkBackground() const; + QColor visitedBackground() const; + QColor negativeBackground() const; + QColor neutralBackground() const; + QColor positiveBackground() const; + + QColor focusDecoration() const; + QColor hoverDecoration() const; + + QColor normalText() const; + QColor inactiveText() const; + QColor activeText() const; + QColor linkText() const; + QColor visitedText() const; + QColor negativeText() const; + QColor neutralText() const; + QColor positiveText() const; + + QColor lightShade() const; + QColor midlightShade() const; + QColor midShade() const; + QColor darkShade() const; + QColor shadowShade() const; + + qreal contrast() const; + + Q_INVOKABLE QColor shade(const QColor &color, ShadeRole role) const; + Q_INVOKABLE QColor shade(const QColor &color, ShadeRole role, qreal contrast, qreal chromaAdjust = 0.0) const; + +signals: + void colorGroupChanged(); + void colorSetChanged(); + void paletteChanged(); + +private: + QPalette::ColorGroup m_colorGroup; + KColorScheme::ColorSet m_colorSet; + KColorScheme m_colorScheme; +}; + +#endif // KCOLORSCHEMEPROXY_H