diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fc0513..0f7e7db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,137 +1,142 @@ project(libkmahjongg) cmake_minimum_required (VERSION 3.5 FATAL_ERROR) set(QT_MIN_VERSION "5.9.0") set (KF5_MIN_VERSION "5.46.0") find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) #if(ENABLE_CLAZY) # set(CMAKE_CXX_COMPILER clazy) #endif() set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) find_package(Qt5 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS Core Gui Svg) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS CoreAddons Config ConfigWidgets WidgetsAddons Completion I18n ) include(FeatureSummary) include(GenerateExportHeader) include(ECMPackageConfigHelpers) include(ECMSetupVersion) include(ECMGenerateHeaders) include(ECMMarkNonGuiExecutable) include(KDEInstallDirs) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(KDECMakeSettings) include(ECMQtDeclareLoggingCategory) add_definitions(-DTRANSLATION_DOMAIN="libkmahjongg5") +add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000) +if (${KF5Config_VERSION} STRGREATER "5.56.0") + add_definitions(-DQT_NO_FOREACH) + MESSAGE(STATUS "compile without foreach") +endif() add_subdirectory(tilesets) add_subdirectory(backgrounds) ########### next target ############### set(KMAHJONGGLIB_VERSION 5.0.0) set(KMAHJONGGLIB_SOVERSION 5) set(kmahjongg_LIB_SRCS kmahjonggtileset.cpp kmahjonggbackground.cpp kmahjonggtilesetselector.cpp kmahjonggbackgroundselector.cpp kmahjonggconfigdialog.cpp ) ecm_qt_declare_logging_category(kmahjongg_LIB_SRCS HEADER libkmahjongg_debug.h IDENTIFIER LIBKMAHJONGG_LOG CATEGORY_NAME log_libkmahjongg) ki18n_wrap_ui(kmahjongg_LIB_SRCS kmahjonggtilesetselector.ui kmahjonggbackgroundselector.ui ) add_library(KF5KMahjongglib SHARED ${kmahjongg_LIB_SRCS}) generate_export_header(KF5KMahjongglib BASE_NAME libkmahjongg) target_link_libraries(KF5KMahjongglib PRIVATE Qt5::Core Qt5::Svg KF5::WidgetsAddons KF5::I18n KF5::Completion KF5::ConfigGui PUBLIC Qt5::Gui KF5::ConfigWidgets ) target_include_directories(KF5KMahjongglib INTERFACE "$" INTERFACE "$") set_target_properties(KF5KMahjongglib PROPERTIES VERSION ${KMAHJONGGLIB_VERSION} SOVERSION ${KMAHJONGGLIB_SOVERSION} EXPORT_NAME KF5KMahjongglib) ecm_setup_version(${KMAHJONGGLIB_VERSION} VARIABLE_PREFIX KF5KMAHJONGGLIB VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kmahjongglib_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5KMahjongglibConfigVersion.cmake" SOVERSION 6) install(TARGETS KF5KMahjongglib EXPORT KF5KMahjonggLibraryDepends ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) ########### install files ############### install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libkmahjongg_export.h kmahjonggtileset.h kmahjonggbackground.h kmahjonggconfigdialog.h DESTINATION ${KF5_INCLUDE_INSTALL_DIR}/KF5KMahjongg COMPONENT Devel ) ########### generate exports ############### # add libraries to the build-tree export set export(TARGETS KF5KMahjongglib FILE "${PROJECT_BINARY_DIR}/KF5KMahjonggLibraryDepends.cmake") # define the installation directory for the CMake files set(CMAKECONFIG_INSTALL_DIR "${CMAKECONFIG_INSTALL_PREFIX}/KF5KMahjongglib") # create the Config.cmake and ConfigVersion.cmake files ecm_configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/KF5KMahjongglibConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/KF5KMahjongglibConfig.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KF5KMahjongglibConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/KF5KMahjongglibConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) # install the export set for use with the install-tree install(EXPORT KF5KMahjonggLibraryDepends DESTINATION ${CMAKECONFIG_INSTALL_DIR} COMPONENT Devel ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kmahjongglib_version.h DESTINATION ${KF5_INCLUDE_INSTALL_DIR}/KF5KMahjongg COMPONENT Devel ) install( FILES libkmahjongg.categories DESTINATION ${KDE_INSTALL_CONFDIR} ) ########### Display Summary ############### feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/kmahjonggbackgroundselector.cpp b/kmahjonggbackgroundselector.cpp index 66f52c3..d706859 100644 --- a/kmahjonggbackgroundselector.cpp +++ b/kmahjonggbackgroundselector.cpp @@ -1,125 +1,125 @@ /* Copyright (C) 2006 Mauricio Piacentini Libkmahjongg 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ // own #include "kmahjonggbackgroundselector.h" // Qt #include #include // KDE #include // LibKMahjongg #include "kmahjonggbackground.h" KMahjonggBackgroundSelector::KMahjonggBackgroundSelector(QWidget * parent, KConfigSkeleton * aconfig) : QWidget(parent) { setupUi(this); setupData(aconfig); } KMahjonggBackgroundSelector::~KMahjonggBackgroundSelector() { qDeleteAll(backgroundMap); } void KMahjonggBackgroundSelector::setupData(KConfigSkeleton * aconfig) { //Get our currently configured background entry KConfig * config = aconfig->config(); KConfigGroup group = config->group("General"); QString initialGroup = group.readEntry("Background_file"); //The lineEdit widget holds our bg path, but the user does not manipulate it directly kcfg_Background->hide(); KMahjonggBackground bg; //Now get our backgrounds into a list QStringList bgsAvailable; const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("kmahjongglib/backgrounds"), QStandardPaths::LocateDirectory); - Q_FOREACH (const QString & dir, dirs) { + for (const QString & dir : dirs) { const QStringList fileNames = QDir(dir).entryList(QStringList() << QStringLiteral("*.desktop")); - Q_FOREACH (const QString & file, fileNames) { + for (const QString & file : fileNames) { bgsAvailable.append(dir + QLatin1Char('/') + file); } } QLatin1String namestr("Name"); int numvalidentries = 0; for (int i = 0; i < bgsAvailable.size(); ++i) { KMahjonggBackground * abg = new KMahjonggBackground(); QString bgpath = bgsAvailable.at(i); if (abg->load(bgpath, backgroundPreview->width(), backgroundPreview->height())) { backgroundMap.insert(abg->authorProperty(namestr), abg); backgroundList->addItem(abg->authorProperty(namestr)); //Find if this is our currently configured background if (bgpath == initialGroup) { //Select current entry backgroundList->setCurrentRow(numvalidentries); backgroundChanged(); } ++numvalidentries; } else { delete abg; } } connect(backgroundList, &QListWidget::currentItemChanged, this, &KMahjonggBackgroundSelector::backgroundChanged); } void KMahjonggBackgroundSelector::backgroundChanged() { KMahjonggBackground * selBG = backgroundMap.value(backgroundList->currentItem()->text()); //Sanity checkings. Should not happen. if (selBG == nullptr) { return; } if (selBG->path() == kcfg_Background->text()) { return; } QLatin1String authstr("Author"); QLatin1String contactstr("AuthorEmail"); QLatin1String descstr("Description"); kcfg_Background->setText(selBG->path()); backgroundAuthor->setText(selBG->authorProperty(authstr)); backgroundContact->setText(selBG->authorProperty(contactstr)); backgroundDescription->setText(selBG->authorProperty(descstr)); if (selBG->authorProperty(QStringLiteral("Plain")) == QLatin1String("1")) { backgroundPreview->setPixmap(QPixmap()); return; } //Make sure SVG is loaded when graphics is selected if (!selBG->loadGraphics()) { return; } //Draw the preview //TODO here: add code to load and keep proportions for non-tiled content? QImage qiRend(backgroundPreview->size(), QImage::Format_ARGB32_Premultiplied); qiRend.fill(0); QPainter p(&qiRend); p.fillRect(p.viewport(), selBG->getBackground()); p.end(); backgroundPreview->setPixmap(QPixmap::fromImage(qiRend)); } diff --git a/kmahjonggtilesetselector.cpp b/kmahjonggtilesetselector.cpp index 89d82ef..dff561f 100644 --- a/kmahjonggtilesetselector.cpp +++ b/kmahjonggtilesetselector.cpp @@ -1,127 +1,127 @@ /* Copyright (C) 2006 Mauricio Piacentini Libkmahjongg 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ // own #include "kmahjonggtilesetselector.h" // Qt #include #include #include // KDE #include // LibKMahjongg #include "kmahjonggtileset.h" KMahjonggTilesetSelector::KMahjonggTilesetSelector(QWidget * parent, KConfigSkeleton * aconfig) : QWidget(parent) { setupUi(this); setupData(aconfig); } KMahjonggTilesetSelector::~KMahjonggTilesetSelector() { tilesetMap.clear(); } void KMahjonggTilesetSelector::setupData(KConfigSkeleton * aconfig) { //Get our currently configured Tileset entry KConfig * config = aconfig->config(); KConfigGroup group = config->group("General"); QString initialGroup = group.readEntry("Tileset_file"); //The lineEdit widget holds our tileset path, but the user does not manipulate it directly kcfg_TileSet->hide(); //This will also load our resourcedir if it is not done already KMahjonggTileset tile; //Now get our tilesets into a list QStringList tilesAvailable; const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("kmahjongglib/tilesets"), QStandardPaths::LocateDirectory); - Q_FOREACH (const QString & dir, dirs) { + for (const QString & dir : dirs) { const QStringList fileNames = QDir(dir).entryList(QStringList() << QStringLiteral("*.desktop")); - Q_FOREACH (const QString & file, fileNames) { + for (const QString & file : fileNames) { tilesAvailable.append(dir + QLatin1Char('/') + file); } } QLatin1String namestr("Name"); int numvalidentries = 0; for (int i = 0; i < tilesAvailable.size(); ++i) { KMahjonggTileset * aset = new KMahjonggTileset(); QString atileset = tilesAvailable.at(i); if (aset->loadTileset(atileset)) { tilesetMap.insert(aset->authorProperty(namestr), aset); tilesetList->addItem(aset->authorProperty(namestr)); //Find if this is our currently configured Tileset if (atileset == initialGroup) { //Select current entry tilesetList->setCurrentRow(numvalidentries); tilesetChanged(); } ++numvalidentries; } else { delete aset; } } connect(tilesetList, &QListWidget::currentItemChanged, this, &KMahjonggTilesetSelector::tilesetChanged); } void KMahjonggTilesetSelector::tilesetChanged() { KMahjonggTileset * selTileset = tilesetMap.value(tilesetList->currentItem()->text()); //Sanity checkings. Should not happen. if (selTileset == nullptr) { return; } if (selTileset->path() == kcfg_TileSet->text()) { return; } QLatin1String authstr("Author"); QLatin1String contactstr("AuthorEmail"); QLatin1String descstr("Description"); kcfg_TileSet->setText(selTileset->path()); tilesetAuthor->setText(selTileset->authorProperty(authstr)); tilesetContact->setText(selTileset->authorProperty(contactstr)); tilesetDescription->setText(selTileset->authorProperty(descstr)); //Make sure SVG is loaded when graphics is selected if (!selTileset->loadGraphics()) { return; } //Let the tileset calculate its ideal size for the preview area, but reduce the margins a bit (pass oversized drawing area) QSize tilesize = selTileset->preferredTileSize(tilesetPreview->size() * 1.3, 1, 1); selTileset->reloadTileset(tilesize); //Draw the preview QImage qiRend(tilesetPreview->size(), QImage::Format_ARGB32_Premultiplied); qiRend.fill(0); QPainter p(&qiRend); //Calculate the margins to center the tile QSize margin = tilesetPreview->size() - tilesize; //Draw unselected tile and first tileface p.drawPixmap(margin.width() / 2, margin.height() / 2, selTileset->unselectedTile(1)); p.drawPixmap(margin.width() / 2, margin.height() / 2, selTileset->tileface(0)); p.end(); tilesetPreview->setPixmap(QPixmap::fromImage(qiRend)); }