diff --git a/CMakeLists.txt b/CMakeLists.txt index 16066f2..8008156 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,127 +1,128 @@ project(kblocks) cmake_minimum_required (VERSION 3.5 FATAL_ERROR) set (QT_MIN_VERSION "5.7.0") set (KF5_MIN_VERSION "5.30.0") find_package(ECM ${KF5_MIN_VERSION} REQUIRED CONFIG) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) find_package(Qt5 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS Widgets Svg Network) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Config ConfigWidgets CoreAddons Crash DocTools DBusAddons I18n WidgetsAddons XmlGui ) find_package(KF5KDEGames 4.9.0 REQUIRED) include(FeatureSummary) include(ECMInstallIcons) include(KDEInstallDirs) include(KDECompilerSettings NO_POLICY_SCOPE) include(KDECMakeSettings) include(ECMAddAppIcon) include(ECMQtDeclareLoggingCategory) add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS) if (${KF5Config_VERSION} STRGREATER "5.56.0") add_definitions(-DQT_NO_FOREACH) MESSAGE(STATUS "compile without foreach") endif() +add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000) add_subdirectory(themes) add_subdirectory(sounds) add_subdirectory(doc) ########### next target ############### set(kblocks_SRCS main.cpp KBlocksDefine.cpp KBlocksNetServer.cpp KBlocksNetClient.cpp KBlocksConfigManager.cpp KBlocksWin.cpp KBlocksDisplay.cpp KBlocksRepWin.cpp KBlocksAppThread.cpp KBlocksScene.cpp KBlocksView.cpp KBlocksScore.cpp KBlocksGraphics.cpp KBlocksSound.cpp KBlocksItemGroup.cpp KBlocksSvgItem.cpp KBlocksAnimator.cpp KBlocksAnimFade.cpp KBlocksAnimDrop.cpp KBlocksPlayManager.cpp KBlocksPlayNetwork.cpp KBlocksSinglePlayer.cpp KBlocksNetPlayer.cpp KBlocksKeyboardPlayer.cpp KBlocksDummyAI.cpp KBlocksLayout.cpp KBlocksGameLogic.cpp KBlocksSingleGame.cpp KBlocksField.cpp KBlocksPiece.cpp KBlocksPieceGenerator.cpp KBlocksGameMessage.cpp KBlocksGameRecorder.cpp KBlocksGameReplayer.cpp AI/KBlocksAIPlayer.cpp AI/KBlocksAIPlanner.cpp AI/KBlocksAIPlannerExtend.cpp AI/KBlocksAIEvaluation.cpp AI/KBlocksAIFeature.cpp AI/KBlocksAILog.cpp ) ecm_qt_declare_logging_category(kblocks_SRCS HEADER kblocks_ai_debug.h IDENTIFIER KBlocksAI CATEGORY_NAME KBlocks.AI) ecm_qt_declare_logging_category(kblocks_SRCS HEADER kblocks_sound_debug.h IDENTIFIER KBSound CATEGORY_NAME KBlocks.Sound) ecm_qt_declare_logging_category(kblocks_SRCS HEADER kblocks_replay_debug.h IDENTIFIER KBReplay CATEGORY_NAME KBlocks.Replay) ecm_qt_declare_logging_category(kblocks_SRCS HEADER kblocks_graphics_debug.h IDENTIFIER KBGraphics CATEGORY_NAME KBlocks.Graphics) kconfig_add_kcfg_files(kblocks_SRCS settings.kcfgc ) file(GLOB ICONS_SRCS "*-apps-kblocks.png") ecm_add_app_icon(kblocks_SRCS ICONS ${ICONS_SRCS}) add_executable(kblocks ${kblocks_SRCS}) target_link_libraries(kblocks KF5KDEGames KF5KDEGamesPrivate Qt5::Network KF5::Crash KF5::DBusAddons KF5::XmlGui KF5::I18n Qt5::Svg ) install(TARGETS kblocks ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} ) ########### install files ############### install(PROGRAMS org.kde.kblocks.desktop DESTINATION ${KDE_INSTALL_APPDIR}) install(FILES org.kde.kblocks.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR}) install(FILES kblocks.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR}) install(FILES kblocksui.rc DESTINATION ${KDE_INSTALL_KXMLGUI5DIR}/kblocks) install(FILES kblocks.knsrc DESTINATION ${KDE_INSTALL_CONFDIR}) ecm_install_icons(ICONS 128-apps-kblocks.png 16-apps-kblocks.png 22-apps-kblocks.png 32-apps-kblocks.png 48-apps-kblocks.png 64-apps-kblocks.png DESTINATION ${KDE_INSTALL_ICONDIR} THEME hicolor) install( FILES kblocks.categories DESTINATION ${KDE_INSTALL_CONFDIR} ) feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/KBlocksRepWin.cpp b/KBlocksRepWin.cpp index 0ae010b..85b34ba 100644 --- a/KBlocksRepWin.cpp +++ b/KBlocksRepWin.cpp @@ -1,171 +1,171 @@ /*************************************************************************** * KBlocks, a falling blocks game by KDE * * Copyright (C) 2010 Zhongjie Cai * * * * 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. * ***************************************************************************/ #include "KBlocksRepWin.h" #include #include #include #include #include "kblocks_replay_debug.h" KBlocksRepWin::KBlocksRepWin(const char *replayFile, bool binaryMode) : KMainWindow() { //Use up to 3MB for global application pixmap cache QPixmapCache::setCacheLimit(3 * 1024); mUpdateInterval = 1000; mpGameReplayer = new KBlocksGameReplayer(replayFile, binaryMode); mGameCount = mpGameReplayer->getGameCount(); if (mGameCount == 0) { mpGameScene = nullptr; mpGameView = nullptr; mpGameLogic = nullptr; return; } mpGameLogic = new KBlocksGameLogic(mpGameReplayer); if (mpGameReplayer->isSameSeed()) { mpGameLogic->setGameSeed(mpGameReplayer->getGameSeed()); } else { mpGameLogic->setGameSeed(-mpGameReplayer->getGameSeed()); } mpGameLogic->setGamePunish(false); mpGameLogic->setGameStandbyMode(false); mpGameLogic->setInitInterval(0); mpGameLogic->setLevelUpInterval(0); mpGameScene = new KBlocksScene(mpGameLogic, mGameCount); mpGameView = new KBlocksView(mpGameScene, this); mpGameView->show(); setCentralWidget(mpGameView); mUpdateTimer.setInterval(mUpdateInterval); connect(&mUpdateTimer, &QTimer::timeout, this, &KBlocksRepWin::replayOneStep); mUpdateTimer.stop(); mSnapshotFilename = QLatin1String(""); mSnapshotFolder = QStringLiteral("./snapshot/"); } KBlocksRepWin::~KBlocksRepWin() { delete mpGameView; delete mpGameScene; delete mpGameLogic; delete mpGameReplayer; } void KBlocksRepWin::setGamesPerLine(int count) { if (mpGameScene) { mpGameScene->setGamesPerLine(count); } } void KBlocksRepWin::setUpdateInterval(int interval) { if (mpGameScene) { mUpdateInterval = interval; mUpdateTimer.setInterval(mUpdateInterval); mpGameScene->setUpdateInterval(interval); } } void KBlocksRepWin::setReplayStepLength(int stepLen) { mpGameReplayer->setStepLength(stepLen); } void KBlocksRepWin::setSnapshotFolder(const QString &folder) { mSnapshotFolder = folder; } void KBlocksRepWin::setSnapshotFilename(const QString &fileName) { mSnapshotFilename = fileName; } bool KBlocksRepWin::replayLoaded() { return (mGameCount != 0); } void KBlocksRepWin::startReplay() { if (mpGameLogic) { mpGameLogic->startGame(mGameCount); } if (mpGameScene) { mpGameScene->createGameItemGroups(mGameCount); mpGameScene->startGame(); } mUpdateTimer.start(); } void KBlocksRepWin::stopReplay() { mUpdateTimer.stop(); if (mpGameScene) { mpGameScene->stopGame(); mpGameScene->deleteGameItemGroups(); } if (mpGameLogic) { mpGameLogic->stopGame(); } } QString KBlocksRepWin::getTimeString() { QDate tmpDate = QDate::currentDate(); QTime tmpTime = QTime::currentTime(); QString result; result = QStringLiteral("%1-%2-%3_%4-%5-%6_%7") .arg(tmpDate.year(), 4, 10, QLatin1Char('0')) .arg(tmpDate.month(), 2, 10, QLatin1Char('0')) .arg(tmpDate.day(), 2, 10, QLatin1Char('0')) .arg(tmpTime.hour(), 2, 10, QLatin1Char('0')) .arg(tmpTime.minute(), 2, 10, QLatin1Char('0')) .arg(tmpTime.second(), 2, 10, QLatin1Char('0')) .arg(tmpTime.msec(), 3, 10, QLatin1Char('0')); return result; } void KBlocksRepWin::snapshotView() { if (!mSnapshotFilename.isEmpty()) { //mSnapshoter = QPixmap::grabWindow(mpGameView->winId()); - mSnapshoter = QPixmap::grabWidget(this); + mSnapshoter = grab(); QString tmpFilename = mSnapshotFolder + mSnapshotFilename + QStringLiteral("_") + getTimeString() + QStringLiteral(".png"); mSnapshoter.save(tmpFilename); } } void KBlocksRepWin::replayOneStep() { int tmpPieceChanged = 0; if (!mpGameLogic->playRecordOneStep(&tmpPieceChanged)) { qCDebug(KBReplay) << "Finished Replay!"; mUpdateTimer.stop(); } if (tmpPieceChanged != 0) { snapshotView(); } }