diff --git a/CMakeLists.txt b/CMakeLists.txt index b63bdbb..284dd2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,77 +1,78 @@ cmake_minimum_required(VERSION 3.0) set(KF5_VERSION "5.50.0") # handled by release scripts project(KWidgetsAddons VERSION ${KF5_VERSION}) include(FeatureSummary) find_package(ECM 5.49.0 NO_MODULE) set_package_properties(ECM PROPERTIES TYPE REQUIRED DESCRIPTION "Extra CMake Modules." URL "https://projects.kde.org/projects/kdesupport/extra-cmake-modules") feature_summary(WHAT REQUIRED_PACKAGES_NOT_FOUND FATAL_ON_MISSING_REQUIRED_PACKAGES) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) include(KDEInstallDirs) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(KDECMakeSettings) set(REQUIRED_QT_VERSION 5.8.0) find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Widgets) include(GenerateExportHeader) include(CMakePackageConfigHelpers) include(ECMSetupVersion) include(ECMGenerateHeaders) include(ECMAddQch) include(ECMPoQmTools) include(ECMQtDeclareLoggingCategory) ecm_setup_version(PROJECT VARIABLE_PREFIX KWIDGETSADDONS VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kwidgetsaddons_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5WidgetsAddonsConfigVersion.cmake" SOVERSION 5) 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)") if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/po") ecm_install_po_files_as_qm(po) endif() add_subdirectory(src) if (BUILD_TESTING) add_subdirectory(autotests) add_subdirectory(tests) + add_subdirectory(examples) endif() # create a Config.cmake and a ConfigVersion.cmake file and install them set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5WidgetsAddons") if (BUILD_QCH) ecm_install_qch_export( TARGETS KF5WidgetsAddons_QCH FILE KF5WidgetsAddonsQchTargets.cmake DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) set(PACKAGE_INCLUDE_QCHTARGETS "include(\"\${CMAKE_CURRENT_LIST_DIR}/KF5WidgetsAddonsQchTargets.cmake\")") endif() configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/KF5WidgetsAddonsConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/KF5WidgetsAddonsConfig.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KF5WidgetsAddonsConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/KF5WidgetsAddonsConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) install(EXPORT KF5WidgetsAddonsTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KF5WidgetsAddonsTargets.cmake NAMESPACE KF5:: ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kwidgetsaddons_version.h DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5} COMPONENT Devel ) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..0b0a6dd --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(kmessagebox) diff --git a/examples/kmessagebox/CMakeLists.txt b/examples/kmessagebox/CMakeLists.txt new file mode 100644 index 0000000..f3e6d42 --- /dev/null +++ b/examples/kmessagebox/CMakeLists.txt @@ -0,0 +1,11 @@ +set(SRCS main.cpp) + +add_executable(kwidgetaddons-example-kmessagebox ${SRCS}) + +target_link_libraries(kwidgetaddons-example-kmessagebox + Qt5::Widgets + KF5::WidgetsAddons +) + +# We don't want to install the tutorial +#install(TARGETS kwidgetaddons-example-kmessagebox ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/examples/kmessagebox/main.cpp b/examples/kmessagebox/main.cpp new file mode 100644 index 0000000..99691d2 --- /dev/null +++ b/examples/kmessagebox/main.cpp @@ -0,0 +1,56 @@ +/* This file is part of the KDE project + * + * Copyright (C) 2018 Friedrich W. H. Kossebau + * Copyright (C) 2018 Olivier Churlaud + * Copyright (C) 2016 by Juan Carlos Torres + * + * This library 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 3 of the License, or (at your option) any later version. + * + * This library 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 library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include +#include + +#include + +int main (int argc, char *argv[]) +{ + QApplication app(argc, argv); + + // Define a button + KGuiItem yesButton( + QStringLiteral("Hello"), // the button label + QStringLiteral("view-filter"), // iconName, can be empty to fallback to default + QStringLiteral("This is a tooltip"), + QStringLiteral("This is a WhatsThis help text.") + ); + + KMessageBox::ButtonCode res = KMessageBox::questionYesNo( + nullptr, // Parent, here none + // The description can contain HTML + QStringLiteral("Description to tell you to click
on either button"), + QStringLiteral("My Title"), + yesButton + /*noButton not explicitely set, falls back to default*/ + ); + + if (res == KMessageBox::Yes) { + std::cout << "You clicked Hello\n"; + return EXIT_SUCCESS; + } else { + std::cout << "You clicked No\n"; + return EXIT_FAILURE; + } +}