diff --git a/CMakeLists.txt b/CMakeLists.txt index 9acc5521..db269e94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,118 +1,122 @@ cmake_minimum_required(VERSION 3.0) set(KF5_VERSION "5.43.0") # handled by release scripts set(KF5_DEP_VERSION "5.42.0") # handled by release scripts project(kirigami2 VERSION ${KF5_VERSION}) set(REQUIRED_QT_VERSION "5.7.0") +SET(CMAKE_CXX_STANDARD 11) + ################# Disallow in-source build ################# if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") message(FATAL_ERROR "kirigami requires an out of source build. Please create a separate build directory and run 'cmake path_to_kirigami [options]' there.") endif() +option(BUILD_SHARED_LIBS "Build a shared module" ON) option(DESKTOP_ENABLED "Build and install The Desktop style" ON) -option(STATIC_LIBRARY "Build as a static library" OFF) +option(STATIC_LIBRARY "Build as a static library (deprecated, use BUILD_SHARED_LIBS instead)" OFF) option(BUILD_EXAMPLES "Build and install examples" OFF) +if(NOT BUILD_SHARED_LIBS) + set(STATIC_LIBRARY 1) +elseif(STATIC_LIBRARY) + set(BUILD_SHARED_LIBS 0) +endif() + # Make CPack available to easy generate binary packages include(CPack) include(FeatureSummary) -IF(STATIC_LIBRARY) - set(CMAKE_AUTOMOC ON) - set(CMAKE_INCLUDE_CURRENT_DIR ON) - ADD_DEFINITIONS(-DKIRIGAMI_BUILD_TYPE_STATIC) - find_package(Qt5 ${REQUIRED_QT_VERSION} REQUIRED NO_MODULE COMPONENTS Core Quick Test Gui Svg QuickControls2) - add_subdirectory(src) +find_package(Qt5 ${REQUIRED_QT_VERSION} REQUIRED NO_MODULE COMPONENTS Core Quick Gui Svg QuickControls2) +find_package(Qt5Test ${REQUIRED_QT_VERSION} CONFIG QUIET) -ELSE(STATIC_LIBRARY) +set(CMAKE_AUTOMOC ON) +set(AUTOMOC_MOC_OPTIONS -Muri=org.kde.kirigami) +set(CMAKE_INCLUDE_CURRENT_DIR ON) +if(STATIC_LIBRARY) + add_definitions(-DKIRIGAMI_BUILD_TYPE_STATIC) + add_definitions(-DQT_PLUGIN) + add_definitions(-DQT_STATICPLUGIN=1) +else(STATIC_LIBRARY) + add_subdirectory(autotests) +endif(STATIC_LIBRARY) ################# set KDE specific information ################# find_package(ECM 5.42.0 NO_MODULE) set_package_properties(ECM PROPERTIES TYPE REQUIRED DESCRIPTION "Extra CMake Modules." URL "https://projects.kde.org/projects/kdesupport/extra-cmake-modules") # where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) include(GenerateExportHeader) include(ECMSetupVersion) include(ECMGenerateHeaders) include(CMakePackageConfigHelpers) include(ECMPoQmTools) include(ECMQMLModules) include(KDEInstallDirs) include(KDECMakeSettings) include(ECMQtDeclareLoggingCategory) include(ECMAddQch) include(KDECompilerSettings NO_POLICY_SCOPE) set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5Kirigami2") option(BUILD_QCH "Build API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)" OFF) add_feature_info(QCH ${BUILD_QCH} "API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)") configure_package_config_file( - "${CMAKE_CURRENT_SOURCE_DIR}/KF5Kirigami2Config.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/KF5Kirigami2Config.cmake" - INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} - PATH_VARS KF5_INCLUDE_INSTALL_DIR CMAKE_INSTALL_PREFIX + "${CMAKE_CURRENT_SOURCE_DIR}/KF5Kirigami2Config.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/KF5Kirigami2Config.cmake" + INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} + PATH_VARS KF5_INCLUDE_INSTALL_DIR CMAKE_INSTALL_PREFIX ) install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/KF5Kirigami2Config.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/KF5Kirigami2ConfigVersion.cmake" - "${CMAKE_CURRENT_SOURCE_DIR}/KF5Kirigami2Macros.cmake" - DESTINATION "${CMAKECONFIG_INSTALL_DIR}" - COMPONENT Devel + "${CMAKE_CURRENT_BINARY_DIR}/KF5Kirigami2Config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/KF5Kirigami2ConfigVersion.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/KF5Kirigami2Macros.cmake" + DESTINATION "${CMAKECONFIG_INSTALL_DIR}" + COMPONENT Devel ) install(EXPORT KF5Kirigami2Targets - DESTINATION "${CMAKECONFIG_INSTALL_DIR}" - FILE KF5Kirigami2Targets.cmake - NAMESPACE KF5::) + DESTINATION "${CMAKECONFIG_INSTALL_DIR}" + FILE KF5Kirigami2Targets.cmake + NAMESPACE KF5:: +) ecm_setup_version(${KF5_VERSION} VARIABLE_PREFIX KIRIGAMI2 VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kirigami_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5Kirigami2ConfigVersion.cmake" - SOVERSION 5) - -find_package(Qt5 ${REQUIRED_QT_VERSION} REQUIRED NO_MODULE COMPONENTS Core Quick Test Gui Svg QuickControls2) + SOVERSION 5 +) if(BUILD_EXAMPLES AND CMAKE_SYSTEM_NAME STREQUAL "Android") -find_package(Qt5AndroidExtras ${REQUIRED_QT_VERSION} REQUIRED) + find_package(Qt5AndroidExtras ${REQUIRED_QT_VERSION} REQUIRED) endif() -ecm_find_qmlmodule(QtGraphicalEffects 1.0) - -################# Enable C++11 features for clang and gcc ################# - -if(UNIX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++0x") -endif() -######################################################################### +ecm_find_qmlmodule(QtGraphicalEffects 1.0) add_definitions(-DQT_NO_URL_CAST_FROM_STRING) -add_subdirectory(autotests) add_subdirectory(src) -if (BUILD_EXAMPLES) +if (BUILD_EXAMPLES AND NOT STATIC_LIBRARY) add_subdirectory(examples) endif() -ENDIF(STATIC_LIBRARY) - if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/po") ecm_install_po_files_as_qm(po) endif() feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index eb2ce20b..02338bb1 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -1,4 +1,9 @@ +if(NOT Qt5Test_FOUND) + message(STATUS "Qt5Test not found, autotests will not be built.") + return() +endif() + add_test(NAME qmltests COMMAND qmltestrunner WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) set_property(TEST qmltests PROPERTY ENVIRONMENT "QML2_IMPORT_PATH=${CMAKE_BINARY_DIR}/bin") diff --git a/examples/minimalqmake/minimalqmake.pro b/examples/minimalqmake/minimalqmake.pro index fdd0e182..fe95bd2c 100644 --- a/examples/minimalqmake/minimalqmake.pro +++ b/examples/minimalqmake/minimalqmake.pro @@ -1,35 +1,10 @@ -TEMPLATE = app +TEMPLATE = subdirs -QT += qml quick +SUBDIRS = \ + kirigami \ + src -android: { - include(3rdparty/kirigami/kirigami.pri) -} +src.subdir = src +kirigami.subdir = 3rdparty/kirigami -CONFIG += c++11 - -SOURCES += main.cpp - -RESOURCES += qml.qrc - -# Additional import path used to resolve QML modules in Qt Creator's code model -QML_IMPORT_PATH = - -# Additional import path used to resolve QML modules just for Qt Quick Designer -QML_DESIGNER_IMPORT_PATH = - -# The following define makes your compiler emit warnings if you use -# any feature of Qt which as been marked deprecated (the exact warnings -# depend on your compiler). Please consult the documentation of the -# deprecated API in order to know how to port your code away from it. -DEFINES += QT_DEPRECATED_WARNINGS - -# You can also make your code fail to compile if you use deprecated APIs. -# In order to do so, uncomment the following line. -# You can also select to disable deprecated APIs only up to a certain version of Qt. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - -# Default rules for deployment. -qnx: target.path = /tmp/$${TARGET}/bin -else: unix:!android: target.path = /opt/$${TARGET}/bin -!isEmpty(target.path): INSTALLS += target +src.depends = kirigami diff --git a/examples/minimalqmake/Page1.qml b/examples/minimalqmake/src/Page1.qml similarity index 100% copy from examples/minimalqmake/Page1.qml copy to examples/minimalqmake/src/Page1.qml diff --git a/examples/minimalqmake/Page1Form.ui.qml b/examples/minimalqmake/src/Page1Form.ui.qml similarity index 100% copy from examples/minimalqmake/Page1Form.ui.qml copy to examples/minimalqmake/src/Page1Form.ui.qml diff --git a/examples/minimalqmake/kirigami-icons.qrc b/examples/minimalqmake/src/kirigami-icons.qrc similarity index 100% rename from examples/minimalqmake/kirigami-icons.qrc rename to examples/minimalqmake/src/kirigami-icons.qrc diff --git a/examples/minimalqmake/main.cpp b/examples/minimalqmake/src/main.cpp similarity index 88% rename from examples/minimalqmake/main.cpp rename to examples/minimalqmake/src/main.cpp index 887d4ced..b8d79cf2 100644 --- a/examples/minimalqmake/main.cpp +++ b/examples/minimalqmake/src/main.cpp @@ -1,42 +1,40 @@ /* * Copyright 2017 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 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 Library General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include -#ifdef Q_OS_ANDROID -#include "./3rdparty/kirigami/src/kirigamiplugin.h" -#endif + + +#include + +Q_IMPORT_PLUGIN(KirigamiPlugin) int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); QQmlApplicationEngine engine; -#ifdef Q_OS_ANDROID - KirigamiPlugin::getInstance().registerTypes(); -#endif - engine.load(QUrl(QLatin1String("qrc:/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; return app.exec(); } diff --git a/examples/minimalqmake/main.qml b/examples/minimalqmake/src/main.qml similarity index 100% copy from examples/minimalqmake/main.qml copy to examples/minimalqmake/src/main.qml diff --git a/examples/minimalqmake/qml.qrc b/examples/minimalqmake/src/qml.qrc similarity index 100% copy from examples/minimalqmake/qml.qrc copy to examples/minimalqmake/src/qml.qrc diff --git a/examples/minimalqmake/qtquickcontrols2.conf b/examples/minimalqmake/src/qtquickcontrols2.conf similarity index 100% copy from examples/minimalqmake/qtquickcontrols2.conf copy to examples/minimalqmake/src/qtquickcontrols2.conf diff --git a/examples/minimalqmake/minimalqmake.pro b/examples/minimalqmake/src/src.pro similarity index 85% copy from examples/minimalqmake/minimalqmake.pro copy to examples/minimalqmake/src/src.pro index fdd0e182..0b7f4467 100644 --- a/examples/minimalqmake/minimalqmake.pro +++ b/examples/minimalqmake/src/src.pro @@ -1,35 +1,39 @@ TEMPLATE = app -QT += qml quick +QT += qml quick quickcontrols2 -android: { - include(3rdparty/kirigami/kirigami.pri) -} +#android: { +# include(3rdparty/kirigami/kirigami.pri) +#} CONFIG += c++11 SOURCES += main.cpp RESOURCES += qml.qrc +LIBS += ../3rdparty/kirigami/org/kde/kirigami.2/libkirigamiplugin.a + # Additional import path used to resolve QML modules in Qt Creator's code model QML_IMPORT_PATH = # Additional import path used to resolve QML modules just for Qt Quick Designer QML_DESIGNER_IMPORT_PATH = # The following define makes your compiler emit warnings if you use # any feature of Qt which as been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS +TARGET = minimalqmake + # You can also make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target diff --git a/examples/staticcmake/3rdparty/CMakeLists.txt b/examples/staticcmake/3rdparty/CMakeLists.txt new file mode 100644 index 00000000..e10afb24 --- /dev/null +++ b/examples/staticcmake/3rdparty/CMakeLists.txt @@ -0,0 +1,3 @@ +set(BUILD_SHARED_LIBS 0) + +add_subdirectory(kirigami) diff --git a/examples/staticcmake/3rdparty/README b/examples/staticcmake/3rdparty/README new file mode 100644 index 00000000..aad19dd4 --- /dev/null +++ b/examples/staticcmake/3rdparty/README @@ -0,0 +1,6 @@ +Add here, with either a script that does a git checkout +or as git submodules the two projects: + +git://anongit.kde.org/kirigami.git +git://anongit.kde.org/breeze-icons.git + diff --git a/examples/staticcmake/CMakeLists.txt b/examples/staticcmake/CMakeLists.txt new file mode 100644 index 00000000..4f362f2f --- /dev/null +++ b/examples/staticcmake/CMakeLists.txt @@ -0,0 +1,24 @@ +project(minimal) +cmake_minimum_required(VERSION 3.2) +if (POLICY CMP0063) + cmake_policy(SET CMP0063 NEW) +endif() + + +find_package(ECM REQUIRED CONFIG) +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/ ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH}) + +set(BREEZEICONS_DIR ${CMAKE_SOURCE_DIR}/3rdparty/breeze-icons/) + +find_package(Qt5 REQUIRED Core Quick Multimedia Test Widgets QuickControls2) + +include(KDEInstallDirs) +include(KDECompilerSettings) +include(KDECMakeSettings) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_EXTENSIONS OFF) + +add_subdirectory(3rdparty) +add_subdirectory(src) + diff --git a/examples/staticcmake/src/CMakeLists.txt b/examples/staticcmake/src/CMakeLists.txt new file mode 100644 index 00000000..4423d567 --- /dev/null +++ b/examples/staticcmake/src/CMakeLists.txt @@ -0,0 +1,27 @@ + +include_directories(${CMAKE_SOURCE_DIR}/3rdparty/kirigami/src) +include(${CMAKE_SOURCE_DIR}/3rdparty/kirigami/KF5Kirigami2Macros.cmake) + +set(minimal_SRCS + main.cpp + ) + +qt5_add_resources(RESOURCES kirigami-icons.qrc resources.qrc) + +if (CMAKE_SYSTEM_NAME STREQUAL "Android") + set(minimal_EXTRA_LIBS Qt5::AndroidExtras + #FIXME: we shouldn't have to link to it but otherwise the lib won't be packaged on Android + Qt5::QuickControls2) +else () +#qstyle-based qqc2 style needs a QApplication + set(minimal_EXTRA_LIBS Qt5::Widgets) +endif() + + +add_executable(minimal ${minimal_SRCS} ${RESOURCES}) +#kirigamiplugin is the static library built by us +target_link_libraries(minimal kirigamiplugin Qt5::Core Qt5::Qml Qt5::Quick Qt5::QuickControls2 ${minimal_EXTRA_LIBS}) + +#install(TARGETS minimal ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) + +kirigami_package_breeze_icons(ICONS application-menu document-decrypt folder-sync go-next go-previous go-up handle-left handle-right view-list-icons applications-graphics media-record-symbolic) diff --git a/examples/minimalqmake/Page1.qml b/examples/staticcmake/src/Page1.qml similarity index 100% rename from examples/minimalqmake/Page1.qml rename to examples/staticcmake/src/Page1.qml diff --git a/examples/minimalqmake/Page1Form.ui.qml b/examples/staticcmake/src/Page1Form.ui.qml similarity index 87% rename from examples/minimalqmake/Page1Form.ui.qml rename to examples/staticcmake/src/Page1Form.ui.qml index 5bd00845..ff587737 100644 --- a/examples/minimalqmake/Page1Form.ui.qml +++ b/examples/staticcmake/src/Page1Form.ui.qml @@ -1,45 +1,52 @@ /* * Copyright 2017 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 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 Library General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.7 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.3 import org.kde.kirigami 2.2 as Kirigami Kirigami.Page { title: qsTr("Page 1") property alias textField1: textField1 property alias button1: button1 + actions { + main: Kirigami.Action { + text: "Sync" + icon.name: "folder-sync" + onTriggered: showPassiveNotification("Action clicked") + } + } RowLayout { anchors.horizontalCenter: parent.horizontalCenter anchors.topMargin: 20 anchors.top: parent.top TextField { id: textField1 placeholderText: qsTr("Text Field") } Button { id: button1 text: qsTr("Press Me") } } } diff --git a/examples/staticcmake/src/kirigami-icons.qrc b/examples/staticcmake/src/kirigami-icons.qrc new file mode 100644 index 00000000..f8992e12 --- /dev/null +++ b/examples/staticcmake/src/kirigami-icons.qrc @@ -0,0 +1,15 @@ + + + ../3rdparty/breeze-icons/icons/actions/32/application-menu.svg + ../3rdparty/breeze-icons/icons/actions/32/document-decrypt.svg + ../3rdparty/breeze-icons/icons/actions/32/folder-sync.svg + ../3rdparty/breeze-icons/icons/actions/22/go-next.svg + ../3rdparty/breeze-icons/icons/actions/22/go-previous.svg + ../3rdparty/breeze-icons/icons/actions/22/go-up.svg + ../3rdparty/breeze-icons/icons/actions/22/handle-left.svg + ../3rdparty/breeze-icons/icons/actions/22/handle-right.svg + ../3rdparty/breeze-icons/icons/actions/32/view-list-icons.svg + ../3rdparty/breeze-icons/icons/categories/32/applications-graphics.svg + ../3rdparty/breeze-icons/icons/actions/symbolic/media-record-symbolic.svg + + diff --git a/examples/staticcmake/src/main.cpp b/examples/staticcmake/src/main.cpp new file mode 100644 index 00000000..57ac9d90 --- /dev/null +++ b/examples/staticcmake/src/main.cpp @@ -0,0 +1,78 @@ +/* + * Copyright 2017 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, 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 Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifdef Q_OS_ANDROID +#include +#else +#include +#endif + +#include +#include +#include +#include + +#ifdef Q_OS_ANDROID +#include + +// WindowManager.LayoutParams +#define FLAG_TRANSLUCENT_STATUS 0x04000000 +#define FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS 0x80000000 +// View +#define SYSTEM_UI_FLAG_LIGHT_STATUS_BAR 0x00002000 + +#endif + + + +Q_IMPORT_PLUGIN(KirigamiPlugin) + +Q_DECL_EXPORT int main(int argc, char *argv[]) +{ + QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); +//The desktop QQC2 style needs it to be a QApplication +#ifdef Q_OS_ANDROID + QGuiApplication app(argc, argv); +#else + QApplication app(argc, argv); +#endif + + //qputenv("QML_IMPORT_TRACE", "1"); + + QQmlApplicationEngine engine; + + engine.load(QUrl(QStringLiteral("qrc:///main.qml"))); + + if (engine.rootObjects().isEmpty()) { + return -1; + } + + //HACK to color the system bar on Android, use qtandroidextras and call the appropriate Java methods +#ifdef Q_OS_ANDROID + QtAndroid::runOnAndroidThread([=]() { + QAndroidJniObject window = QtAndroid::androidActivity().callObjectMethod("getWindow", "()Landroid/view/Window;"); + window.callMethod("addFlags", "(I)V", FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + window.callMethod("clearFlags", "(I)V", FLAG_TRANSLUCENT_STATUS); + window.callMethod("setStatusBarColor", "(I)V", QColor("#2196f3").rgba()); + window.callMethod("setNavigationBarColor", "(I)V", QColor("#2196f3").rgba()); + }); +#endif + + return app.exec(); +} diff --git a/examples/minimalqmake/main.qml b/examples/staticcmake/src/main.qml similarity index 100% rename from examples/minimalqmake/main.qml rename to examples/staticcmake/src/main.qml diff --git a/examples/minimalqmake/qtquickcontrols2.conf b/examples/staticcmake/src/qtquickcontrols2.conf similarity index 100% rename from examples/minimalqmake/qtquickcontrols2.conf rename to examples/staticcmake/src/qtquickcontrols2.conf diff --git a/examples/minimalqmake/qml.qrc b/examples/staticcmake/src/resources.qrc similarity index 100% rename from examples/minimalqmake/qml.qrc rename to examples/staticcmake/src/resources.qrc diff --git a/kirigami.pro b/kirigami.pro index ab61b2fe..78d38bad 100644 --- a/kirigami.pro +++ b/kirigami.pro @@ -1,35 +1,52 @@ TEMPLATE = lib -CONFIG += plugin - -QT += qml quick gui svg -HEADERS += $$PWD/src/kirigamiplugin.h $$PWD/src/enums.h $$PWD/src/settings.h -SOURCES += $$PWD/src/kirigamiplugin.cpp $$PWD/src/enums.cpp $$PWD/src/settings.cpp +CONFIG += static plugin + +QT += qml quick gui quickcontrols2 svg +URI = org.kde.kirigami +QMAKE_MOC_OPTIONS += -Muri=org.kde.kirigami +HEADERS += $$PWD/src/kirigamiplugin.h \ + $$PWD/src/enums.h \ + $$PWD/src/settings.h \ + $$PWD/src/mnemonicattached.h \ + $$PWD/src/formlayoutattached.h \ + $$PWD/src/libkirigami/basictheme_p.h \ + $$PWD/src/libkirigami/kirigamipluginfactory.h \ + $$PWD/src/libkirigami/platformtheme.h +SOURCES += $$PWD/src/kirigamiplugin.cpp \ + $$PWD/src/enums.cpp \ + $$PWD/src/settings.cpp \ + $$PWD/src/mnemonicattached.cpp \ + $$PWD/src/formlayoutattached.cpp \ + $$PWD/src/libkirigami/basictheme.cpp \ + $$PWD/src/libkirigami/kirigamipluginfactory.cpp \ + $$PWD/src/libkirigami/platformtheme.cpp RESOURCES += $$PWD/kirigami.qrc +DEFINES += KIRIGAMI_BUILD_TYPE_STATIC !ios:!android { message( "compiling for desktop" ) HEADERS += $$PWD/src/desktopicon.h SOURCES += $$PWD/src/desktopicon.cpp } API_VER=1.0 TARGET = $$qtLibraryTarget(org/kde/kirigami.2/kirigamiplugin) importPath = $$[QT_INSTALL_QML]/org/kde/kirigami.2 target.path = $${importPath} controls.path = $${importPath} controls.files += $$PWD/src/controls/* #For now ignore Desktop and Plasma stuff in qmake styles.path = $${importPath}/styles styles.files += $$PWD/src/styles/* INSTALLS += target controls styles diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2a6bea2d..1cf0b287 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,71 +1,88 @@ project(kirigami) if (NOT STATIC_LIBRARY) ecm_create_qm_loader(kirigami_QM_LOADER libkirigami2plugin_qt) else() set(KIRIGAMI_STATIC_FILES libkirigami/basictheme.cpp libkirigami/platformtheme.cpp libkirigami/kirigamipluginfactory.cpp) endif() include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libkirigami ${CMAKE_CURRENT_BINARY_DIR}/libkirigami) set(kirigami_SRCS kirigamiplugin.cpp enums.cpp desktopicon.cpp settings.cpp formlayoutattached.cpp mnemonicattached.cpp ${kirigami_QM_LOADER} ${KIRIGAMI_STATIC_FILES} ) -IF(STATIC_LIBRARY) - -qt5_add_resources(RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../kirigami.qrc) +add_subdirectory(libkirigami) -add_library(kirigamiplugin STATIC ${kirigami_SRCS} ${RESOURCES}) -target_link_libraries(kirigamiplugin Qt5::Core Qt5::Qml Qt5::Quick Qt5::QuickControls2) +if(STATIC_LIBRARY) + # When using the static library, all QML files need to be shipped within the + # .a file. + qt5_add_resources(RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../kirigami.qrc) +endif(STATIC_LIBRARY) -ELSE(STATIC_LIBRARY) -add_subdirectory(libkirigami) -add_library(kirigamiplugin SHARED ${kirigami_SRCS}) +add_library(kirigamiplugin ${kirigami_SRCS} ${RESOURCES}) -set_target_properties(kirigamiplugin PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/org/kde/kirigami.2) -target_link_libraries(kirigamiplugin KF5::Kirigami2 Qt5::Core Qt5::Qml Qt5::Quick Qt5::QuickControls2) +if(STATIC_LIBRARY) + SET_TARGET_PROPERTIES(kirigamiplugin PROPERTIES + AUTOMOC_MOC_OPTIONS -Muri=org.kde.kirigami) + set(Kirigami_EXTRA_LIBS "") +else(STATIC_LIBRARY) + set(Kirigami_EXTRA_LIBS KF5::Kirigami2) +endif(STATIC_LIBRARY) -add_custom_target(copy) +target_link_libraries(kirigamiplugin + PUBLIC + Qt5::Core + PRIVATE + ${Kirigami_EXTRA_LIBS} Qt5::Qml Qt5::Quick Qt5::QuickControls2 + ) -file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin/org/kde/kirigami.2) -add_custom_command(TARGET copy PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E - copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/controls ${CMAKE_BINARY_DIR}/bin/org/kde/kirigami.2/) -add_custom_command(TARGET copy PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E - copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/styles ${CMAKE_BINARY_DIR}/bin/org/kde/kirigami.2/styles) +if (NOT STATIC_LIBRARY) -add_dependencies(kirigamiplugin copy) + add_custom_target(copy) + file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin/org/kde/kirigami.2) + add_custom_command(TARGET copy PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E + copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/controls ${CMAKE_BINARY_DIR}/bin/org/kde/kirigami.2/) + add_custom_command(TARGET copy PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E + copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/styles ${CMAKE_BINARY_DIR}/bin/org/kde/kirigami.2/styles) -install(TARGETS kirigamiplugin DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/kirigami.2) + add_dependencies(kirigamiplugin copy) -install(DIRECTORY controls/ DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/kirigami.2) + install(DIRECTORY controls/ DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/kirigami.2) -if (DESKTOP_ENABLED) - install(DIRECTORY styles/org.kde.desktop DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/kirigami.2/styles) -endif() + if (PLASMA_ENABLED) + install(DIRECTORY styles/Plasma DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/kirigami.2/styles) + endif() + if (DESKTOP_ENABLED) + install(DIRECTORY styles/org.kde.desktop DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/kirigami.2/styles) + endif() + if (PLASMA_ENABLED AND DESKTOP_ENABLED) + install(DIRECTORY styles/org.kde.desktop.plasma DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/kirigami.2/styles) + endif() + install(DIRECTORY styles/Material DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/kirigami.2/styles) -install(DIRECTORY styles/Material DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/kirigami.2/styles) + install(FILES ${platformspecific} DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/kirigami.2) -install(FILES ${platformspecific} DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/kirigami.2) + include(ECMGeneratePriFile) + ecm_generate_pri_file(BASE_NAME Kirigami2 LIB_NAME KF5Kirigami2 DEPS "core qml quick svg" FILENAME_VAR PRI_FILENAME ) + install(FILES ${PRI_FILENAME} + DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) -include(ECMGeneratePriFile) -ecm_generate_pri_file(BASE_NAME Kirigami2 LIB_NAME KF5Kirigami2 DEPS "core qml quick svg" FILENAME_VAR PRI_FILENAME ) -install(FILES ${PRI_FILENAME} - DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) +endif(NOT STATIC_LIBRARY) -ENDIF(STATIC_LIBRARY) +install(TARGETS kirigamiplugin DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/kirigami.2) diff --git a/src/controls/Theme.qml b/src/controls/Theme.qml index 40fdad85..2af4a4b1 100644 --- a/src/controls/Theme.qml +++ b/src/controls/Theme.qml @@ -1,77 +1,77 @@ /* * Copyright 2015 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, 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 Library General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.4 -//pragma Singleton +pragma Singleton /** * A set of named colors for the application * @inherit QtQuick.QtObject */ QtObject { id: theme property color textColor: "#31363b" property color disabledTextColor: "#9931363b" property color highlightColor: "#2196F3" property color highlightedTextColor: "#eff0fa" property color backgroundColor: "#eff0f1" property color activeTextColor: "#0176D3" property color linkColor: "#2196F3" property color visitedLinkColor: "#2196F3" property color negativeTextColor: "#DA4453" property color neutralTextColor: "#F67400" property color positiveTextColor: "#27AE60" property color buttonTextColor: "#31363b" property color buttonBackgroundColor: "#eff0f1" property color buttonHoverColor: "#2196F3" property color buttonFocusColor: "#2196F3" property color viewTextColor: "#31363b" property color viewBackgroundColor: "#fcfcfc" property color viewHoverColor: "#2196F3" property color viewFocusColor: "#2196F3" property color selectionTextColor: "#eff0fa" property color selectionBackgroundColor: "#2196F3" property color selectionHoverColor: "#2196F3" property color selectionFocusColor: "#2196F3" property color tooltipTextColor: "#eff0f1" property color tooltipBackgroundColor: "#31363b" property color tooltipHoverColor: "#2196F3" property color tooltipFocusColor: "#2196F3" property color complementaryTextColor: "#eff0f1" property color complementaryBackgroundColor: "#31363b" property color complementaryHoverColor: "#2196F3" property color complementaryFocusColor: "#2196F3" property font defaultFont: fontMetrics.font property list children: [ TextMetrics { id: fontMetrics } ] } diff --git a/src/controls/templates/qmldir b/src/controls/templates/qmldir new file mode 100644 index 00000000..295c78c3 --- /dev/null +++ b/src/controls/templates/qmldir @@ -0,0 +1,10 @@ +module org.kde.kirigami.templates + +OverlaySheet 2.2 OverlaySheet.qml +FormLayout 2.2 FormLayout.qml +SwipeListItem 2.2 SwipeListItem.qml +AbstractListItem 2.2 AbstractListItem.qml +ApplicationHeader 2.2 ApplicationHeader.qml +AbstractApplicationHeader 2.2 AbstractApplicationHeader.qml +OverlayDrawer 2.2 OverlayDrawer.qml + diff --git a/src/desktopicon.cpp b/src/desktopicon.cpp index 1e6c6ad5..dd16a081 100644 --- a/src/desktopicon.cpp +++ b/src/desktopicon.cpp @@ -1,484 +1,484 @@ /* * Copyright 2011 Marco Martin * Copyright 2014 Aleix Pol Gonzalez * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, 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 Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "desktopicon.h" -#include "platformtheme.h" +#include "libkirigami/platformtheme.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include class ManagedTextureNode : public QSGSimpleTextureNode { Q_DISABLE_COPY(ManagedTextureNode) public: ManagedTextureNode(); void setTexture(QSharedPointer texture); private: QSharedPointer m_texture; }; ManagedTextureNode::ManagedTextureNode() {} void ManagedTextureNode::setTexture(QSharedPointer texture) { m_texture = texture; QSGSimpleTextureNode::setTexture(texture.data()); } typedef QHash > > TexturesCache; struct ImageTexturesCachePrivate { TexturesCache cache; }; class ImageTexturesCache { public: ImageTexturesCache(); ~ImageTexturesCache(); /** * @returns the texture for a given @p window and @p image. * * If an @p image id is the same as one already provided before, we won't create * a new texture and return a shared pointer to the existing texture. */ QSharedPointer loadTexture(QQuickWindow *window, const QImage &image, QQuickWindow::CreateTextureOptions options); QSharedPointer loadTexture(QQuickWindow *window, const QImage &image); private: QScopedPointer d; }; ImageTexturesCache::ImageTexturesCache() : d(new ImageTexturesCachePrivate) { } ImageTexturesCache::~ImageTexturesCache() { } QSharedPointer ImageTexturesCache::loadTexture(QQuickWindow *window, const QImage &image, QQuickWindow::CreateTextureOptions options) { qint64 id = image.cacheKey(); QSharedPointer texture = d->cache.value(id).value(window).toStrongRef(); if (!texture) { auto cleanAndDelete = [this, window, id](QSGTexture* texture) { QHash >& textures = (d->cache)[id]; textures.remove(window); if (textures.isEmpty()) d->cache.remove(id); delete texture; }; texture = QSharedPointer(window->createTextureFromImage(image, options), cleanAndDelete); (d->cache)[id][window] = texture.toWeakRef(); } //if we have a cache in an atlas but our request cannot use an atlassed texture //create a new texture and use that //don't use removedFromAtlas() as that requires keeping a reference to the non atlased version if (!(options & QQuickWindow::TextureCanUseAtlas) && texture->isAtlasTexture()) { texture = QSharedPointer(window->createTextureFromImage(image, options)); } return texture; } QSharedPointer ImageTexturesCache::loadTexture(QQuickWindow *window, const QImage &image) { return loadTexture(window, image, 0); } Q_GLOBAL_STATIC(ImageTexturesCache, s_iconImageCache) DesktopIcon::DesktopIcon(QQuickItem *parent) : QQuickItem(parent), m_smooth(false), m_changed(false), m_active(false), m_selected(false), m_isMask(false) { setFlag(ItemHasContents, true); //FIXME: not necessary anymore connect(qApp, &QGuiApplication::paletteChanged, this, [this]() { m_changed = true; update(); }); } DesktopIcon::~DesktopIcon() { } void DesktopIcon::setSource(const QVariant &icon) { if (m_source == icon) { return; } m_source = icon; m_changed = true; if (!m_theme) { m_theme = static_cast(qmlAttachedPropertiesObject(this, true)); Q_ASSERT(m_theme); connect(m_theme, &Kirigami::PlatformTheme::colorsChanged, this, [this]() { m_changed = true; update(); }); } update(); emit sourceChanged(); } QVariant DesktopIcon::source() const { return m_source; } void DesktopIcon::setEnabled(const bool enabled) { if (enabled == QQuickItem::isEnabled()) { return; } QQuickItem::setEnabled(enabled); m_changed = true; update(); emit enabledChanged(); } void DesktopIcon::setActive(const bool active) { if (active == m_active) { return; } m_active = active; m_changed = true; update(); emit activeChanged(); } bool DesktopIcon::active() const { return m_active; } bool DesktopIcon::valid() const { return !m_source.isNull(); } void DesktopIcon::setSelected(const bool selected) { if (selected == m_selected) { return; } m_selected = selected; m_changed = true; update(); emit selectedChanged(); } bool DesktopIcon::selected() const { return m_selected; } void DesktopIcon::setIsMask(bool mask) { if (m_isMask == mask) { return; } m_isMask = mask; emit isMaskChanged(); } bool DesktopIcon::isMask() const { return m_isMask; } void DesktopIcon::setColor(const QColor &color) { if (m_color == color) { return; } m_color = color; emit colorChanged(); } QColor DesktopIcon::color() const { return m_color; } int DesktopIcon::implicitWidth() const { return 32; } int DesktopIcon::implicitHeight() const { return 32; } void DesktopIcon::setSmooth(const bool smooth) { if (smooth == m_smooth) { return; } m_smooth = smooth; m_changed = true; update(); emit smoothChanged(); } bool DesktopIcon::smooth() const { return m_smooth; } QSGNode* DesktopIcon::updatePaintNode(QSGNode* node, QQuickItem::UpdatePaintNodeData* /*data*/) { if (m_source.isNull()) { delete node; return Q_NULLPTR; } if (m_changed || node == 0) { QImage img; const QSize itemSize(width(), height()); QRect nodeRect(QPoint(0,0), itemSize); if (itemSize.width() != 0 && itemSize.height() != 0) { const QSize size = itemSize * (window() ? window()->devicePixelRatio() : qApp->devicePixelRatio()); switch(m_source.type()){ case QVariant::Pixmap: img = m_source.value().toImage(); break; case QVariant::Image: img = m_source.value(); break; case QVariant::Bitmap: img = m_source.value().toImage(); break; case QVariant::Icon: img = m_source.value().pixmap(size, iconMode(), QIcon::On).toImage(); break; case QVariant::Url: case QVariant::String: img = findIcon(size); break; case QVariant::Brush: //todo: fill here too? case QVariant::Color: img = QImage(size, QImage::Format_Alpha8); img.fill(m_source.value()); break; default: break; } if (img.isNull()){ img = QImage(size, QImage::Format_Alpha8); img.fill(Qt::transparent); } if (img.size() != size){ // At this point, the image will already be scaled, but we need to output it in // the correct aspect ratio, painted centered in the viewport. So: QRect destination(QPoint(0, 0), img.size().scaled(itemSize, Qt::KeepAspectRatio)); destination.moveCenter(nodeRect.center()); nodeRect = destination; } } m_changed = false; ManagedTextureNode* mNode = dynamic_cast(node); if (!mNode) { delete node; mNode = new ManagedTextureNode; } mNode->setTexture(s_iconImageCache->loadTexture(window(), img)); mNode->setRect(nodeRect); node = mNode; } return node; } void DesktopIcon::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { if (newGeometry.size() != oldGeometry.size()) { m_changed = true; update(); } QQuickItem::geometryChanged(newGeometry, oldGeometry); } void DesktopIcon::handleFinished(QNetworkAccessManager* qnam, QNetworkReply* reply) { if (reply->error() == QNetworkReply::NoError) { const QUrl possibleRedirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); if (!possibleRedirectUrl.isEmpty()) { const QUrl redirectUrl = reply->url().resolved(possibleRedirectUrl); if (redirectUrl == reply->url()) { // no infinite redirections thank you very much reply->deleteLater(); return; } reply->deleteLater(); QNetworkRequest request(possibleRedirectUrl); request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); QNetworkReply* newReply = qnam->get(request); connect(newReply, &QNetworkReply::readyRead, this, [this, newReply](){ handleReadyRead(newReply); }); connect(newReply, &QNetworkReply::finished, this, [this, qnam, newReply](){ handleFinished(qnam, newReply); }); return; } } } void DesktopIcon::handleReadyRead(QNetworkReply* reply) { if (reply->attribute(QNetworkRequest::RedirectionTargetAttribute).isNull()) { // We're handing the event loop back while doing network work, and it turns out // this fairly regularly results in things being deleted under us. So, just // handle that and crash less :) QPointer me(this); QByteArray data; do { data.append(reply->read(32768)); // Because we are in the main thread, this could be potentially very expensive, so let's not block qApp->processEvents(); if(!me) { return; } } while(!reply->atEnd()); m_loadedImage = QImage::fromData(data); if (m_loadedImage.isNull()) { // broken image from data, inform the user of this with some useful broken-image thing... const QSize size = QSize(width(), height()) * (window() ? window()->devicePixelRatio() : qApp->devicePixelRatio()); m_loadedImage = QIcon::fromTheme("unknown").pixmap(size, iconMode(), QIcon::On).toImage(); } m_changed = true; update(); } } QImage DesktopIcon::findIcon(const QSize &size) { QImage img; QString iconSource = m_source.toString(); if (iconSource.startsWith("image://")){ QUrl iconUrl(iconSource); QString iconProviderId = iconUrl.host(); QString iconId = iconUrl.path(); QSize actualSize; QQuickImageProvider* imageProvider = dynamic_cast( qmlEngine(this)->imageProvider(iconProviderId)); if (!imageProvider) return img; switch(imageProvider->imageType()){ case QQmlImageProviderBase::Image: img = imageProvider->requestImage(iconId, &actualSize, size); break; case QQmlImageProviderBase::Pixmap: img = imageProvider->requestPixmap(iconId, &actualSize, size).toImage(); break; case QQmlImageProviderBase::Texture: case QQmlImageProviderBase::Invalid: case QQmlImageProviderBase::ImageResponse: //will have to investigate this more break; } } else if(iconSource.startsWith("http://") || iconSource.startsWith("https://")) { if(!m_loadedImage.isNull()) { return m_loadedImage.scaled(size, Qt::KeepAspectRatio, m_smooth ? Qt::SmoothTransformation : Qt::FastTransformation ); } QQmlEngine* engine = qmlEngine(this); QNetworkAccessManager* qnam; if (engine && (qnam = qmlEngine(this)->networkAccessManager())) { QNetworkRequest request(m_source.toUrl()); request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); QNetworkReply* reply = qnam->get(request); connect(reply, &QNetworkReply::readyRead, this, [this, reply](){ handleReadyRead(reply); }); connect(reply, &QNetworkReply::finished, this, [this, qnam, reply](){ handleFinished(qnam, reply); }); } // Temporary icon while we wait for the real image to load... img = QIcon::fromTheme("image-x-icon").pixmap(size, iconMode(), QIcon::On).toImage(); } else { if (iconSource.startsWith("qrc:/")){ iconSource = iconSource.mid(3); } QIcon icon(iconSource); if (icon.availableSizes().isEmpty()) { icon = m_theme->iconFromTheme(iconSource, m_color); } if (!icon.availableSizes().isEmpty()){ img = icon.pixmap(size, iconMode(), QIcon::On).toImage(); if (m_isMask || icon.isMask()) { QPainter p(&img); p.setCompositionMode(QPainter::CompositionMode_SourceIn); p.fillRect(img.rect(), m_theme->textColor()); p.end(); } } } return img; } QIcon::Mode DesktopIcon::iconMode() const { if (!isEnabled()) { return QIcon::Disabled; } else if (m_selected) { return QIcon::Selected; } else if (m_active) { return QIcon::Active; } return QIcon::Normal; } diff --git a/src/kirigamiplugin.cpp b/src/kirigamiplugin.cpp index 2020209c..6bfb2350 100644 --- a/src/kirigamiplugin.cpp +++ b/src/kirigamiplugin.cpp @@ -1,153 +1,163 @@ /* * Copyright 2009 by Alan Alpert * Copyright 2010 by Ménard Alexis * Copyright 2010 by Marco Martin * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, 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 Library General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kirigamiplugin.h" #include "enums.h" #include "desktopicon.h" #include "settings.h" #include "formlayoutattached.h" #include "mnemonicattached.h" #include #include #include #include -#ifdef KIRIGAMI_BUILD_TYPE_STATIC #include "libkirigami/platformtheme.h" -#else -#include -#endif static QString s_selectedStyle; +//Q_INIT_RESOURCE(kirigami); +#ifdef KIRIGAMI_BUILD_TYPE_STATIC +#include +#endif + QUrl KirigamiPlugin::componentUrl(const QString &fileName) const { foreach (const QString &style, m_stylesFallbackChain) { const QString candidate = QStringLiteral("styles/") + style + QLatin1Char('/') + fileName; if (QFile::exists(resolveFilePath(candidate))) { +#ifdef KIRIGAMI_BUILD_TYPE_STATIC + return QUrl(QStringLiteral("qrc:/org/kde/kirigami/styles/") + style + QLatin1Char('/') + fileName); +#else return QUrl(resolveFileUrl(candidate)); +#endif } } + +#ifdef KIRIGAMI_BUILD_TYPE_STATIC + return QUrl(QStringLiteral("qrc:/org/kde/kirigami/") + fileName); +#else return QUrl(resolveFileUrl(fileName)); +#endif } void KirigamiPlugin::registerTypes(const char *uri) { Q_ASSERT(uri == QLatin1String("org.kde.kirigami")); const QString style = QQuickStyle::name(); //org.kde.desktop.plasma is a couple of files that fall back to desktop by purpose if ((style.isEmpty() || style == QStringLiteral("org.kde.desktop.plasma")) && QFile::exists(resolveFilePath(QStringLiteral("/styles/org.kde.desktop")))) { #if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS) m_stylesFallbackChain.prepend(QStringLiteral("org.kde.desktop")); #elif defined(Q_OS_ANDROID) m_stylesFallbackChain.prepend(QStringLiteral("Material")); #else // do we have an iOS specific style? m_stylesFallbackChain.prepend(QStringLiteral("Material")); #endif } if (!style.isEmpty() && QFile::exists(resolveFilePath(QStringLiteral("/styles/") + style))) { m_stylesFallbackChain.prepend(style); //if we have plasma deps installed, use them for extra integration if (style == QStringLiteral("org.kde.desktop") && QFile::exists(resolveFilePath(QStringLiteral("/styles/org.kde.desktop.plasma")))) { m_stylesFallbackChain.prepend("org.kde.desktop.plasma"); } } else { m_stylesFallbackChain.prepend(QStringLiteral("org.kde.desktop")); } //At this point the fallback chain will be selected->org.kde.desktop->Fallback s_selectedStyle = m_stylesFallbackChain.first(); qmlRegisterSingletonType(uri, 2, 0, "Settings", [](QQmlEngine*, QJSEngine*) -> QObject* { Settings *settings = new Settings; settings->setStyle(s_selectedStyle); return settings; } ); qmlRegisterUncreatableType(uri, 2, 0, "ApplicationHeaderStyle", "Cannot create objects of type ApplicationHeaderStyle"); //old legacy retrocompatible Theme qmlRegisterSingletonType(componentUrl(QStringLiteral("Theme.qml")), uri, 2, 0, "Theme"); qmlRegisterSingletonType(componentUrl(QStringLiteral("Units.qml")), uri, 2, 0, "Units"); qmlRegisterType(componentUrl(QStringLiteral("Action.qml")), uri, 2, 0, "Action"); qmlRegisterType(componentUrl(QStringLiteral("AbstractApplicationHeader.qml")), uri, 2, 0, "AbstractApplicationHeader"); qmlRegisterType(componentUrl(QStringLiteral("AbstractApplicationWindow.qml")), uri, 2, 0, "AbstractApplicationWindow"); qmlRegisterType(componentUrl(QStringLiteral("AbstractListItem.qml")), uri, 2, 0, "AbstractListItem"); qmlRegisterType(componentUrl(QStringLiteral("ApplicationHeader.qml")), uri, 2, 0, "ApplicationHeader"); qmlRegisterType(componentUrl(QStringLiteral("ToolBarApplicationHeader.qml")), uri, 2, 0, "ToolBarApplicationHeader"); qmlRegisterType(componentUrl(QStringLiteral("ApplicationWindow.qml")), uri, 2, 0, "ApplicationWindow"); qmlRegisterType(componentUrl(QStringLiteral("BasicListItem.qml")), uri, 2, 0, "BasicListItem"); qmlRegisterType(componentUrl(QStringLiteral("OverlayDrawer.qml")), uri, 2, 0, "OverlayDrawer"); qmlRegisterType(componentUrl(QStringLiteral("ContextDrawer.qml")), uri, 2, 0, "ContextDrawer"); qmlRegisterType(componentUrl(QStringLiteral("GlobalDrawer.qml")), uri, 2, 0, "GlobalDrawer"); qmlRegisterType(componentUrl(QStringLiteral("Heading.qml")), uri, 2, 0, "Heading"); qmlRegisterType(componentUrl(QStringLiteral("Separator.qml")), uri, 2, 0, "Separator"); qmlRegisterType(componentUrl(QStringLiteral("PageRow.qml")), uri, 2, 0, "PageRow"); //The icon is "special: we have to use a wrapper class to QIcon on org.kde.desktops #if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS) //we know that we want a different implementation with Material and Plasma styles if (s_selectedStyle == QStringLiteral("Material") || s_selectedStyle == QStringLiteral("Plasma")) { qmlRegisterType(componentUrl(QStringLiteral("Icon.qml")), uri, 2, 0, "Icon"); } else { qmlRegisterType(uri, 2, 0, "Icon"); } #else qmlRegisterType(componentUrl(QStringLiteral("Icon.qml")), uri, 2, 0, "Icon"); #endif qmlRegisterType(componentUrl(QStringLiteral("Label.qml")), uri, 2, 0, "Label"); //TODO: uncomment for 2.3 release //qmlRegisterTypeNotAvailable(uri, 2, 3, "Label", "Label type not supported anymore, use QtQuick.Controls.Label 2.0 instead"); qmlRegisterType(componentUrl(QStringLiteral("OverlaySheet.qml")), uri, 2, 0, "OverlaySheet"); qmlRegisterType(componentUrl(QStringLiteral("Page.qml")), uri, 2, 0, "Page"); qmlRegisterType(componentUrl(QStringLiteral("ScrollablePage.qml")), uri, 2, 0, "ScrollablePage"); qmlRegisterType(componentUrl(QStringLiteral("SplitDrawer.qml")), uri, 2, 0, "SplitDrawer"); qmlRegisterType(componentUrl(QStringLiteral("SwipeListItem.qml")), uri, 2, 0, "SwipeListItem"); //2.1 qmlRegisterType(componentUrl(QStringLiteral("AbstractItemViewHeader.qml")), uri, 2, 1, "AbstractItemViewHeader"); qmlRegisterType(componentUrl(QStringLiteral("ItemViewHeader.qml")), uri, 2, 1, "ItemViewHeader"); qmlRegisterType(componentUrl(QStringLiteral("AbstractApplicationItem.qml")), uri, 2, 1, "AbstractApplicationItem"); qmlRegisterType(componentUrl(QStringLiteral("ApplicationItem.qml")), uri, 2, 1, "ApplicationItem"); //2.2 //Theme changed from a singleton to an attached property qmlRegisterUncreatableType(uri, 2, 2, "Theme", "Cannot create objects of type Theme, use it as an attached poperty"); //2.3 qmlRegisterType(componentUrl(QStringLiteral("FormLayout.qml")), uri, 2, 3, "FormLayout"); qmlRegisterUncreatableType(uri, 2, 3, "FormData", "Cannot create objects of type FormData, use it as an attached poperty"); qmlRegisterUncreatableType(uri, 2, 3, "MnemonicData", "Cannot create objects of type MnemonicData, use it as an attached poperty"); qmlProtectModule(uri, 2); } #include "moc_kirigamiplugin.cpp" diff --git a/src/kirigamiplugin.h b/src/kirigamiplugin.h index c2581153..f5df1f34 100644 --- a/src/kirigamiplugin.h +++ b/src/kirigamiplugin.h @@ -1,96 +1,67 @@ /* * Copyright 2009 by Alan Alpert * Copyright 2010 by Ménard Alexis * Copyright 2010 by Marco Martin * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, 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 Library General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef MOBILECOMPONENTSPLUGIN_H #define MOBILECOMPONENTSPLUGIN_H -#ifdef KIRIGAMI_BUILD_TYPE_STATIC -#include -#include #include -#else + #include #include -#include -#endif - - -#ifdef KIRIGAMI_BUILD_TYPE_STATIC - -class KirigamiPlugin : public QObject -{ -public: - static KirigamiPlugin& getInstance() - { - static KirigamiPlugin instance; - return instance; - } - KirigamiPlugin(KirigamiPlugin const&) = delete; - void operator=(KirigamiPlugin const&) = delete; - void registerTypes(const char *uri); - static void registerTypes() - { - getInstance().registerTypes("org.kde.kirigami"); - } - -private: - KirigamiPlugin() {} - QUrl componentUrl(const QString &fileName) const; - QString resolveFilePath(const QString &path) const - { - return QStringLiteral(":/org/kde/kirigami/") + path; - } - QString resolveFileUrl(const QString &filePath) const - { - if (filePath.startsWith(QLatin1Char(':'))) { - return QStringLiteral("qrc:") + filePath.right(filePath.length() - 1); - } - return QStringLiteral("qrc:/org/kde/kirigami/") + filePath; - } - QStringList m_stylesFallbackChain; -}; - -#else class KirigamiPlugin : public QQmlExtensionPlugin { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") public: void registerTypes(const char *uri) Q_DECL_OVERRIDE; +#ifdef KIRIGAMI_BUILD_TYPE_STATIC + static void registerTypes() + { + static KirigamiPlugin instance; + instance.registerTypes("org.kde.kirigami"); + } +#endif + private: QUrl componentUrl(const QString &fileName) const; QString resolveFilePath(const QString &path) const { +#ifdef KIRIGAMI_BUILD_TYPE_STATIC + return QStringLiteral(":/org/kde/kirigami/") + path; +#else return baseUrl().toLocalFile() + QLatin1Char('/') + path; +#endif } QString resolveFileUrl(const QString &filePath) const { +#ifdef KIRIGAMI_BUILD_TYPE_STATIC + return filePath; +#else return baseUrl().toString() + QLatin1Char('/') + filePath; +#endif } QStringList m_stylesFallbackChain; }; #endif - -#endif diff --git a/src/qmldir b/src/qmldir index 0a60a80a..f262452b 100644 --- a/src/qmldir +++ b/src/qmldir @@ -1,24 +1,39 @@ module org.kde.kirigami -AbstractApplicationHeader 2.0 templates/AbstractApplicationHeader.qml -AbstractApplicationWindow 2.0 templates/AbstractApplicationWindow.qml -AbstractListItem 2.0 templates/AbstractListItem.qml -Action 2.0 templates/Action.qml -ApplicationHeader 2.0 templates/ApplicationHeader.qml -ApplicationWindow 2.0 templates/ApplicationWindow.qml -OverlayDrawer 2.0 templates/OverlayDrawer.qml -OverlaySheet 2.0 templates/OverlaySheet.qml -Page 2.0 templates/Page.qml -SplitDrawer 2.0 templates/SplitDrawer.qml -SwipeListItem 2.0 templates/SwipeListItem.qml +classname KirigamiPlugin +depends QtQuick.Controls 1.4 +depends QtQuick.Controls.Private 1.0 +depends QtQuick.Controls 2.0 +depends QtGraphicalEffects 1.0 +designersupported + +typeinfo plugins.qmltypes + +singleton Theme 2.2 Theme.qml + +OverlaySheet 2.0 OverlaySheet.qml +ApplicationItem 2.1 ApplicationItem.qml +AbstractApplicationWindow 2.0 AbstractApplicationWindow.qml +FormLayout 2.3 FormLayout.qml +GlobalDrawer 2.0 GlobalDrawer.qml +BasicListItem 2.0 BasicListItem.qml +AbstractItemViewHeader 2.1 AbstractItemViewHeader.qml +Heading 2.0 Heading.qml +Action 2.0 Action.qml +Separator 2.0 Separator.qml +ItemViewHeader 2.1 ItemViewHeader.qml +SwipeListItem 2.0 SwipeListItem.qml +AbstractListItem 2.0 AbstractListItem.qml +Icon 2.0 Icon.qml +Units 2.0 Units.qml +Page 2.0 Page.qml +Label 2.0 Label.qml +AbstractApplicationItem 2.1 AbstractApplicationItem.qml +ToolBarApplicationHeader 2.0 ToolBarApplicationHeader.qml +ScrollablePage 2.0 ScrollablePage.qml +ApplicationHeader 2.0 ApplicationHeader.qml +AbstractApplicationHeader 2.0 AbstractApplicationHeader.qml +ContextDrawer 2.0 ContextDrawer.qml +ApplicationWindow 2.0 ApplicationWindow.qml +PageRow 2.0 PageRow.qml -PageRow 2.0 controls/PageRow.qml -BasicListItem 2.0 controls/BasicListItem.qml -ContextDrawer 2.0 controls/ContextDrawer.qml -GlobalDrawer 2.0 controls/GlobalDrawer.qml -Heading 2.0 controls/Heading.qml -Icon 2.0 controls/Icon.qml -Label 2.0 controls/Label.qml -ScrollablePage 2.0 controls/ScrollablePage.qml -Theme 2.0 controls/Theme.qml -Units 2.0 controls/Units.qml