diff --git a/CMakeLists.txt b/CMakeLists.txt index dbdae165..2d8e085c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,363 +1,363 @@ # KDE Application Version, managed by release script set(KDE_APPLICATIONS_VERSION_MAJOR "20") set(KDE_APPLICATIONS_VERSION_MINOR "03") set(KDE_APPLICATIONS_VERSION_MICRO "70") set(KDE_APPLICATIONS_VERSION "${KDE_APPLICATIONS_VERSION_MAJOR}.${KDE_APPLICATIONS_VERSION_MINOR}.${KDE_APPLICATIONS_VERSION_MICRO}") cmake_minimum_required(VERSION 3.10.0 FATAL_ERROR) project(kolourpaint VERSION ${KDE_APPLICATIONS_VERSION}) set(QT_MIN_VERSION "5.11.0") set(KF5_MIN_VERSION "5.58.0") find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) add_definitions(-DTRANSLATION_DOMAIN="kolourpaint") include(KDEInstallDirs) include(KDECompilerSettings NO_POLICY_SCOPE) include(KDECMakeSettings) include(ECMInstallIcons) include(ECMAddAppIcon) include(ECMSetupVersion) include(FeatureSummary) find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core Widgets PrintSupport ) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS DocTools I18n GuiAddons WidgetsAddons KIO XmlGui IconThemes TextWidgets - KDELibs4Support #kio::netaccess + JobWidgets ) add_definitions(-DQT_USE_QSTRINGBUILDER) find_package(KF5Sane) if(KF5Sane_FOUND) add_definitions(-DHAVE_KSANE=1) set(KSANE_LIBRARIES KF5::Sane) else(KF5Sane_FOUND) add_definitions(-DHAVE_KSANE=0) endif(KF5Sane_FOUND) include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ) ## Generate header with version number ecm_setup_version(${KDE_APPLICATIONS_VERSION} VARIABLE_PREFIX KOLOURPAINT VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kpVersion.h" ) add_subdirectory( pics ) add_subdirectory( doc ) ########### next target ############### macro(CREATE_LICENSE _in_FILE _out_FILE) FILE(READ ${_in_FILE} _contents) FILE(WRITE ${_out_FILE} "static const char * const kpLicenseText =") STRING(REGEX REPLACE "\"" "\\\\\"" _contents "${_contents}" ) STRING(REGEX REPLACE "\n" "\\\\n\"\n\"" _contents "${_contents}" ) FILE(APPEND ${_out_FILE} "\"${_contents}\"") FILE(APPEND ${_out_FILE} ";\n") endmacro(CREATE_LICENSE) #macro_additional_clean_files( ${CMAKE_CURRENT_BINARY_DIR}/kolourpaintlicense.h ) create_license(${CMAKE_CURRENT_SOURCE_DIR}/COPYING ${CMAKE_CURRENT_BINARY_DIR}/kolourpaintlicense.h) # GENERATED BY ./gen_cmake_srcs | fgrep -v /lgpl/ set(kolourpaint_lib1_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/commands/imagelib/effects/kpEffectBalanceCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/imagelib/effects/kpEffectBlurSharpenCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/imagelib/effects/kpEffectClearCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/imagelib/effects/kpEffectCommandBase.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/imagelib/effects/kpEffectEmbossCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/imagelib/effects/kpEffectFlattenCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/imagelib/effects/kpEffectGrayscaleCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/imagelib/effects/kpEffectHSVCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/imagelib/effects/kpEffectInvertCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/imagelib/effects/kpEffectReduceColorsCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/imagelib/effects/kpEffectToneEnhanceCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/imagelib/kpDocumentMetaInfoCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/imagelib/transforms/kpTransformFlipCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/imagelib/transforms/kpTransformResizeScaleCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/imagelib/transforms/kpTransformRotateCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/imagelib/transforms/kpTransformSkewCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/kpCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/kpCommandHistoryBase.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/kpCommandHistory.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/kpCommandSize.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/kpMacroCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/kpNamedCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/tools/flow/kpToolFlowCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/tools/kpToolColorPickerCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/tools/kpToolFloodFillCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/tools/polygonal/kpToolPolygonalCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/tools/rectangular/kpToolRectangularCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/tools/selection/kpAbstractSelectionContentCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/tools/selection/kpToolImageSelectionTransparencyCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/tools/selection/kpToolSelectionCreateCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/tools/selection/kpToolSelectionDestroyCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/tools/selection/kpToolSelectionMoveCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/tools/selection/kpToolSelectionPullFromDocumentCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/tools/selection/kpToolSelectionResizeScaleCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/tools/selection/text/kpToolTextBackspaceCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/tools/selection/text/kpToolTextChangeStyleCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/tools/selection/text/kpToolTextDeleteCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/tools/selection/text/kpToolTextEnterCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/tools/selection/text/kpToolTextGiveContentCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/commands/tools/selection/text/kpToolTextInsertCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/cursors/kpCursorLightCross.cpp ${CMAKE_CURRENT_SOURCE_DIR}/cursors/kpCursorProvider.cpp ${CMAKE_CURRENT_SOURCE_DIR}/dialogs/imagelib/effects/kpEffectsDialog.cpp ${CMAKE_CURRENT_SOURCE_DIR}/dialogs/imagelib/kpDocumentMetaInfoDialog.cpp ${CMAKE_CURRENT_SOURCE_DIR}/dialogs/imagelib/transforms/kpTransformPreviewDialog.cpp ${CMAKE_CURRENT_SOURCE_DIR}/dialogs/imagelib/transforms/kpTransformResizeScaleDialog.cpp ${CMAKE_CURRENT_SOURCE_DIR}/dialogs/imagelib/transforms/kpTransformRotateDialog.cpp ${CMAKE_CURRENT_SOURCE_DIR}/dialogs/imagelib/transforms/kpTransformSkewDialog.cpp ${CMAKE_CURRENT_SOURCE_DIR}/dialogs/kpColorSimilarityDialog.cpp ${CMAKE_CURRENT_SOURCE_DIR}/dialogs/kpDocumentSaveOptionsPreviewDialog.cpp ${CMAKE_CURRENT_SOURCE_DIR}/document/kpDocument.cpp ${CMAKE_CURRENT_SOURCE_DIR}/document/kpDocument_Open.cpp ${CMAKE_CURRENT_SOURCE_DIR}/document/kpDocument_Save.cpp ${CMAKE_CURRENT_SOURCE_DIR}/document/kpDocumentSaveOptions.cpp ${CMAKE_CURRENT_SOURCE_DIR}/document/kpDocument_Selection.cpp ${CMAKE_CURRENT_SOURCE_DIR}/environments/commands/kpCommandEnvironment.cpp ${CMAKE_CURRENT_SOURCE_DIR}/environments/dialogs/imagelib/transforms/kpTransformDialogEnvironment.cpp ${CMAKE_CURRENT_SOURCE_DIR}/environments/document/kpDocumentEnvironment.cpp ${CMAKE_CURRENT_SOURCE_DIR}/environments/kpEnvironmentBase.cpp ${CMAKE_CURRENT_SOURCE_DIR}/environments/tools/kpToolEnvironment.cpp ${CMAKE_CURRENT_SOURCE_DIR}/environments/tools/selection/kpToolSelectionEnvironment.cpp ${CMAKE_CURRENT_SOURCE_DIR}/generic/kpSetOverrideCursorSaver.cpp ${CMAKE_CURRENT_SOURCE_DIR}/generic/kpWidgetMapper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/generic/widgets/kpResizeSignallingLabel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/generic/widgets/kpSubWindow.cpp ${CMAKE_CURRENT_SOURCE_DIR}/imagelib/effects/blitz.cpp ${CMAKE_CURRENT_SOURCE_DIR}/imagelib/effects/kpEffectBalance.cpp ${CMAKE_CURRENT_SOURCE_DIR}/imagelib/effects/kpEffectBlurSharpen.cpp ${CMAKE_CURRENT_SOURCE_DIR}/imagelib/effects/kpEffectEmboss.cpp ${CMAKE_CURRENT_SOURCE_DIR}/imagelib/effects/kpEffectFlatten.cpp ${CMAKE_CURRENT_SOURCE_DIR}/imagelib/effects/kpEffectGrayscale.cpp ${CMAKE_CURRENT_SOURCE_DIR}/imagelib/effects/kpEffectHSV.cpp ${CMAKE_CURRENT_SOURCE_DIR}/imagelib/effects/kpEffectInvert.cpp ${CMAKE_CURRENT_SOURCE_DIR}/imagelib/effects/kpEffectReduceColors.cpp ${CMAKE_CURRENT_SOURCE_DIR}/imagelib/effects/kpEffectToneEnhance.cpp ${CMAKE_CURRENT_SOURCE_DIR}/imagelib/kpColor_Constants.cpp ${CMAKE_CURRENT_SOURCE_DIR}/imagelib/kpColor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/imagelib/kpDocumentMetaInfo.cpp ${CMAKE_CURRENT_SOURCE_DIR}/imagelib/kpFloodFill.cpp ${CMAKE_CURRENT_SOURCE_DIR}/imagelib/kpPainter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/imagelib/transforms/kpTransformAutoCrop.cpp ${CMAKE_CURRENT_SOURCE_DIR}/imagelib/transforms/kpTransformCrop.cpp ${CMAKE_CURRENT_SOURCE_DIR}/imagelib/transforms/kpTransformCrop_ImageSelection.cpp ${CMAKE_CURRENT_SOURCE_DIR}/imagelib/transforms/kpTransformCrop_TextSelection.cpp ) # kolourpaint_lib1_SRCS set(kolourpaint_lib2_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/kpLogCategories.cpp ${CMAKE_CURRENT_SOURCE_DIR}/kolourpaint.cpp ${CMAKE_CURRENT_SOURCE_DIR}/kpThumbnail.cpp ${CMAKE_CURRENT_SOURCE_DIR}/kpViewScrollableContainer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/layers/selections/image/kpAbstractImageSelection.cpp ${CMAKE_CURRENT_SOURCE_DIR}/layers/selections/image/kpEllipticalImageSelection.cpp ${CMAKE_CURRENT_SOURCE_DIR}/layers/selections/image/kpFreeFormImageSelection.cpp ${CMAKE_CURRENT_SOURCE_DIR}/layers/selections/image/kpImageSelectionTransparency.cpp ${CMAKE_CURRENT_SOURCE_DIR}/layers/selections/image/kpRectangularImageSelection.cpp ${CMAKE_CURRENT_SOURCE_DIR}/layers/selections/kpAbstractSelection.cpp ${CMAKE_CURRENT_SOURCE_DIR}/layers/selections/kpSelectionDrag.cpp ${CMAKE_CURRENT_SOURCE_DIR}/layers/selections/kpSelectionFactory.cpp ${CMAKE_CURRENT_SOURCE_DIR}/layers/selections/text/kpTextSelection.cpp ${CMAKE_CURRENT_SOURCE_DIR}/layers/selections/text/kpTextSelection_Cursor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/layers/selections/text/kpTextSelection_Paint.cpp ${CMAKE_CURRENT_SOURCE_DIR}/layers/selections/text/kpTextStyle.cpp ${CMAKE_CURRENT_SOURCE_DIR}/layers/selections/text/kpPreeditText.cpp ${CMAKE_CURRENT_SOURCE_DIR}/layers/tempImage/kpTempImage.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_Colors.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_Edit.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_File.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_Image.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_Settings.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_StatusBar.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_Text.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_Tools.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_View.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_View_Thumbnail.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_View_Zoom.cpp ${CMAKE_CURRENT_SOURCE_DIR}/pixmapfx/kpPixmapFX_DrawShapes.cpp ${CMAKE_CURRENT_SOURCE_DIR}/pixmapfx/kpPixmapFX_GetSetPixmapParts.cpp ${CMAKE_CURRENT_SOURCE_DIR}/pixmapfx/kpPixmapFX_Transforms.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/flow/kpToolBrush.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/flow/kpToolColorEraser.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/flow/kpToolEraser.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/flow/kpToolFlowBase.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/flow/kpToolFlowPixmapBase.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/flow/kpToolPen.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/flow/kpToolSpraycan.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpToolAction.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpToolColorPicker.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpTool.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpTool_Drawing.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpToolFloodFill.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpTool_KeyboardEvents.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpTool_MouseEvents.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpTool_OtherEvents.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpTool_UserNotifications.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpTool_Utilities.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpToolZoom.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/polygonal/kpToolCurve.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/polygonal/kpToolLine.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/polygonal/kpToolPolygonalBase.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/polygonal/kpToolPolygon.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/polygonal/kpToolPolyline.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/rectangular/kpToolEllipse.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/rectangular/kpToolRectangle.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/rectangular/kpToolRectangularBase.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/rectangular/kpToolRoundedRectangle.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/selection/image/kpAbstractImageSelectionTool.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/selection/image/kpAbstractImageSelectionTool_Transparency.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/selection/image/kpToolEllipticalSelection.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/selection/image/kpToolFreeFormSelection.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/selection/image/kpToolRectSelection.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/selection/kpAbstractSelectionTool.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/selection/kpAbstractSelectionTool_Create.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/selection/kpAbstractSelectionTool_KeyboardEvents.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/selection/kpAbstractSelectionTool_Move.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/selection/kpAbstractSelectionTool_ResizeScale.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/selection/text/kpToolText_Commands.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/selection/text/kpToolText.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/selection/text/kpToolText_Create.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/selection/text/kpToolText_CursorCalc.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/selection/text/kpToolText_InputMethodEvents.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/selection/text/kpToolText_KeyboardEvents.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/selection/text/kpToolText_KeyboardEvents_HandleArrowKeys.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/selection/text/kpToolText_KeyboardEvents_HandleTypingKeys.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/selection/text/kpToolText_Move.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/selection/text/kpToolText_ResizeScale.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/selection/text/kpToolText_SelectText.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/selection/text/kpToolText_TextStyle.cpp ) # kolourpaint_lib2_SRCS if(KF5Sane_FOUND) set(kolourpaint_lib2_SRCS ${kolourpaint_lib2_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/scan/sanedialog.cpp ) endif(KF5Sane_FOUND) set(kolourpaint_app_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/views/kpThumbnailView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/views/kpUnzoomedThumbnailView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/views/kpView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/views/kpView_Events.cpp ${CMAKE_CURRENT_SOURCE_DIR}/views/kpView_Paint.cpp ${CMAKE_CURRENT_SOURCE_DIR}/views/kpView_Selections.cpp ${CMAKE_CURRENT_SOURCE_DIR}/views/kpZoomedThumbnailView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/views/kpZoomedView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/views/manager/kpViewManager.cpp ${CMAKE_CURRENT_SOURCE_DIR}/views/manager/kpViewManager_TextCursor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/views/manager/kpViewManager_ViewUpdates.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/colorSimilarity/kpColorSimilarityCubeRenderer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/colorSimilarity/kpColorSimilarityFrame.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/colorSimilarity/kpColorSimilarityHolder.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/colorSimilarity/kpColorSimilarityToolBarItem.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/imagelib/effects/kpNumInput.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/imagelib/effects/kpEffectBalanceWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/imagelib/effects/kpEffectBlurSharpenWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/imagelib/effects/kpEffectEmbossWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/imagelib/effects/kpEffectFlattenWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/imagelib/effects/kpEffectHSVWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/imagelib/effects/kpEffectInvertWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/imagelib/effects/kpEffectReduceColorsWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/imagelib/effects/kpEffectToneEnhanceWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/imagelib/effects/kpEffectWidgetBase.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/kpColorCells.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/kpColorPalette.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/kpDefaultColorCollection.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/kpDocumentSaveOptionsWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/kpDualColorButton.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/kpPrintDialogPage.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/kpTransparentColorCell.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/toolbars/kpColorToolBar.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/toolbars/kpToolToolBar.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/toolbars/options/kpToolWidgetBase.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/toolbars/options/kpToolWidgetBrush.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/toolbars/options/kpToolWidgetEraserSize.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/toolbars/options/kpToolWidgetFillStyle.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/toolbars/options/kpToolWidgetLineWidth.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/toolbars/options/kpToolWidgetOpaqueOrTransparent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/toolbars/options/kpToolWidgetSpraycanSize.cpp ) # set(kolourpaint_app_SRCS set(kolourpaint_SRCS ${kolourpaint_lib1_SRCS} ${kolourpaint_lib2_SRCS} ${kolourpaint_app_SRCS} ) add_subdirectory(lgpl) qt5_add_resources(kolourpaint_SRCS kolourpaint.qrc) # # Executable # ecm_add_app_icon(kolourpaint_SRCS ICONS pics/app/16-apps-kolourpaint.png pics/app/22-apps-kolourpaint.png pics/app/32-apps-kolourpaint.png pics/app/48-apps-kolourpaint.png ) add_executable(kolourpaint ${kolourpaint_SRCS}) target_link_libraries(kolourpaint KF5::XmlGui KF5::IconThemes KF5::TextWidgets Qt5::PrintSupport ${KSANE_LIBRARIES} kolourpaint_lgpl ) if(KSANE_FOUND) target_link_libraries(kolourpaint ${KSANE_LIBRARY} ) endif(KSANE_FOUND) install(TARGETS kolourpaint ${INSTALL_TARGETS_DEFAULT_ARGS}) ########### install files ############### install(PROGRAMS org.kde.kolourpaint.desktop DESTINATION ${XDG_APPS_INSTALL_DIR}) install(FILES org.kde.kolourpaint.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR}) install(FILES kolourpaintui.rc DESTINATION ${KXMLGUI_INSTALL_DIR}/kolourpaint) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/lgpl/CMakeLists.txt b/lgpl/CMakeLists.txt index fa018b79..c78fc0a5 100644 --- a/lgpl/CMakeLists.txt +++ b/lgpl/CMakeLists.txt @@ -1,36 +1,36 @@ # # LGPL Library # # This MUST be a dynamic link library to avoid LGPL license infection. # include(GenerateExportHeader) set(kolourpaint_lgpl_SRCS generic/kpUrlFormatter.cpp generic/kpColorCollection.cpp generic/widgets/kpColorCellsBase.cpp ) add_library(kolourpaint_lgpl SHARED ${kolourpaint_lgpl_SRCS}) set(kolourpaint_lgpl_version 5) target_link_libraries(kolourpaint_lgpl - KF5::KDELibs4Support # kio::network KF5::I18n KF5::GuiAddons KF5::WidgetsAddons KF5::KIOCore + KF5::JobWidgets Qt5::Widgets ) set_target_properties(kolourpaint_lgpl PROPERTIES VERSION ${kolourpaint_lgpl_version} DEFINE_SYMBOL MAKE_KOLOURPAINT4_LGPL_LIB ) generate_export_header(kolourpaint_lgpl BASE_NAME kolourpaint_lgpl) install(TARGETS kolourpaint_lgpl ${INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/lgpl/generic/kpColorCollection.cpp b/lgpl/generic/kpColorCollection.cpp index 56452219..514a3d18 100644 --- a/lgpl/generic/kpColorCollection.cpp +++ b/lgpl/generic/kpColorCollection.cpp @@ -1,519 +1,520 @@ // REFACT0R: Remote open/save file logic is duplicated in kpDocument. // HITODO: Test when remote file support in KDE 4 stabilizes /* This file is part of the KDE libraries Copyright (C) 1999 Waldo Bastian (bastian@kde.org) Copyright (C) 2007 Clarence Dang (dang@kde.org) 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 2 of the License. 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. */ //----------------------------------------------------------------------------- // KDE color collection #define DEBUG_KP_COLOR_COLLECTION 0 #include "kpColorCollection.h" #include "kpUrlFormatter.h" #include #include +#include #include #include #include "kpLogCategories.h" #include #include #include #include #include #include #include #include struct ColorNode { ColorNode(const QColor &c, const QString &n) : color(c), name(n) {} QColor color; QString name; }; //--------------------------------------------------------------------- Q_LOGGING_CATEGORY(kpLogColorCollection, "kp.colorCollection") //BEGIN kpColorCollectionPrivate class kpColorCollectionPrivate { public: kpColorCollectionPrivate(); kpColorCollectionPrivate(const kpColorCollectionPrivate&); QList colorList; QString name; QString desc; kpColorCollection::Editable editable; }; kpColorCollectionPrivate::kpColorCollectionPrivate() : editable(kpColorCollection::Yes) { } kpColorCollectionPrivate::kpColorCollectionPrivate(const kpColorCollectionPrivate& p) : colorList(p.colorList), name(p.name), desc(p.desc), editable(p.editable) { } //END kpColorCollectionPrivate //--------------------------------------------------------------------- QStringList kpColorCollection::installedCollections() { QStringList paletteList; QStringList paths = QStandardPaths::locateAll(QStandardPaths::GenericConfigLocation, QStringLiteral("colors"), QStandardPaths::LocateDirectory); for (const auto &path : paths) { paletteList.append(QDir(path).entryList(QStringList(), QDir::Files)); } return paletteList; } kpColorCollection::kpColorCollection() { d = new kpColorCollectionPrivate(); } kpColorCollection::kpColorCollection(const kpColorCollection &p) { d = new kpColorCollectionPrivate(*p.d); } kpColorCollection::~kpColorCollection() { // Need auto-save? delete d; } static void CouldNotOpenDialog (const QUrl &url, QWidget *parent) { KMessageBox::sorry (parent, i18n ("Could not open color palette \"%1\".", kpUrlFormatter::PrettyFilename (url))); } // TODO: Set d->editable? bool kpColorCollection::open(const QUrl &url, QWidget *parent) { if (url.isEmpty()) { return false; } KIO::StoredTransferJob *job = KIO::storedGet (url); KJobWidgets::setWindow (job, parent); if (!job->exec ()) { #if DEBUG_KP_COLOR_COLLECTION qCDebug(kpLogColorCollection) << "\tcould not download"; #endif ::CouldNotOpenDialog (url, parent); return false; } const QByteArray &data = job->data(); QTextStream stream(data); // Read first line // Expected "GIMP Palette" QString line = stream.readLine(); if (line.indexOf(QLatin1String(" Palette")) == -1) { KMessageBox::sorry (parent, i18n ("Could not open color palette \"%1\" - unsupported format.\n" "The file may be corrupt.", kpUrlFormatter::PrettyFilename (url))); return false; } QList newColorList; QString newDesc; while( !stream.atEnd() ) { line = stream.readLine(); if (line[0] == '#') { // This is a comment line line = line.mid(1); // Strip '#' line = line.trimmed(); // Strip remaining white space.. if (!line.isEmpty()) { newDesc += line+'\n'; // Add comment to description } } else { // This is a color line, hopefully line = line.trimmed(); if (line.isEmpty()) continue; int r, g, b; int pos = 0; if (sscanf(line.toLatin1(), "%d %d %d%n", &r, &g, &b, &pos) >= 3) { r = qBound(0, r, 255); g = qBound(0, g, 255); b = qBound(0, b, 255); QString name = line.mid(pos).trimmed(); newColorList.append(ColorNode(QColor(r, g, b), name)); } } } d->colorList = newColorList; d->name.clear (); d->desc = newDesc; return true; } static void CouldNotOpenKDEDialog (const QString &name, QWidget *parent) { KMessageBox::sorry (parent, i18n ("Could not open KDE color palette \"%1\".", name)); } bool kpColorCollection::openKDE(const QString &name, QWidget *parent) { #if DEBUG_KP_COLOR_COLLECTION qCDebug(kpLogColorCollection) << "name=" << name; #endif if (name.isEmpty()) { #if DEBUG_KP_COLOR_COLLECTION qCDebug(kpLogColorCollection) << "name.isEmpty"; #endif ::CouldNotOpenKDEDialog (name, parent); return false; } QString filename = QStandardPaths::locate(QStandardPaths::GenericConfigLocation, "colors/" + name); if (filename.isEmpty()) { #if DEBUG_KP_COLOR_COLLECTION qCDebug(kpLogColorCollection) << "could not find file"; #endif ::CouldNotOpenKDEDialog (name, parent); return false; } // (this will pop up an error dialog on failure) if (!open (QUrl::fromLocalFile (filename), parent)) { #if DEBUG_KP_COLOR_COLLECTION qCDebug(kpLogColorCollection) << "could not open"; #endif return false; } d->name = name; #if DEBUG_KP_COLOR_COLLECTION qCDebug(kpLogColorCollection) << "opened"; #endif return true; } static void CouldNotSaveDialog (const QUrl &url, QWidget *parent) { // TODO: use file.errorString() KMessageBox::error (parent, i18n ("Could not save color palette as \"%1\".", kpUrlFormatter::PrettyFilename (url))); } static void SaveToFile (kpColorCollectionPrivate *d, QIODevice *device) { // HITODO: QTextStream can fail but does not report errors. // Bug in KColorCollection too. QTextStream str (device); QString description = d->desc.trimmed(); description = '#'+description.split( '\n', QString::KeepEmptyParts).join(QLatin1String("\n#")); str << "KDE RGB Palette\n"; str << description << "\n"; for (const auto &node : d->colorList) { // Added for KolourPaint. if(!node.color.isValid ()) continue; int r,g,b; node.color.getRgb(&r, &g, &b); str << r << " " << g << " " << b << " " << node.name << "\n"; } str.flush(); } bool kpColorCollection::saveAs(const QUrl &url, QWidget *parent) const { if (url.isLocalFile ()) { const QString filename = url.toLocalFile (); // sync: All failure exit paths _must_ call QSaveFile::cancelWriting() or // else, the QSaveFile destructor will overwrite the file, // , despite the failure. QSaveFile atomicFileWriter (filename); { if (!atomicFileWriter.open (QIODevice::WriteOnly)) { // We probably don't need this as has not been // opened. atomicFileWriter.cancelWriting (); #if DEBUG_KP_COLOR_COLLECTION qCDebug(kpLogColorCollection) << "\treturning false because could not open QSaveFile" << " error=" << atomicFileWriter.error (); #endif ::CouldNotSaveDialog (url, parent); return false; } // Write to local temporary file. ::SaveToFile (d, &atomicFileWriter); // Atomically overwrite local file with the temporary file // we saved to. if (!atomicFileWriter.commit ()) { atomicFileWriter.cancelWriting (); #if DEBUG_KP_COLOR_COLLECTION qCDebug(kpLogColorCollection) << "\tcould not close QSaveFile"; #endif ::CouldNotSaveDialog (url, parent); return false; } } // sync QSaveFile.cancelWriting() } // Remote file? else { // Create temporary file that is deleted when the variable goes // out of scope. QTemporaryFile tempFile; if (!tempFile.open ()) { #if DEBUG_KP_COLOR_COLLECTION qCDebug(kpLogColorCollection) << "\treturning false because could not open tempFile"; #endif ::CouldNotSaveDialog (url, parent); return false; } // Write to local temporary file. ::SaveToFile (d, &tempFile); // Collect name of temporary file now, as QTemporaryFile::fileName() // stops working after close() is called. const QString tempFileName = tempFile.fileName (); #if DEBUG_KP_COLOR_COLLECTION qCDebug(kpLogColorCollection) << "\ttempFileName='" << tempFileName << "'"; #endif Q_ASSERT (!tempFileName.isEmpty ()); tempFile.close (); if (tempFile.error () != QFile::NoError) { #if DEBUG_KP_COLOR_COLLECTION qCDebug(kpLogColorCollection) << "\treturning false because could not close"; #endif ::CouldNotSaveDialog (url, parent); return false; } // Copy local temporary file to overwrite remote. KIO::FileCopyJob *job = KIO::file_copy (QUrl::fromLocalFile (tempFileName), url, -1, KIO::Overwrite); KJobWidgets::setWindow (job, parent); if (!job->exec ()) { #if DEBUG_KP_COLOR_COLLECTION qCDebug(kpLogColorCollection) << "\treturning false because could not upload"; #endif ::CouldNotSaveDialog (url, parent); return false; } } d->name.clear (); return true; } bool kpColorCollection::saveKDE(QWidget *parent) const { const QString name = d->name; QString filename = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "colors/" + name; const bool ret = saveAs (QUrl::fromLocalFile (filename), parent); // (d->name is wiped by saveAs()). d->name = name; return ret; } QString kpColorCollection::description() const { return d->desc; } void kpColorCollection::setDescription(const QString &desc) { d->desc = desc; } QString kpColorCollection::name() const { return d->name; } void kpColorCollection::setName(const QString &name) { d->name = name; } kpColorCollection::Editable kpColorCollection::editable() const { return d->editable; } void kpColorCollection::setEditable(Editable editable) { d->editable = editable; } int kpColorCollection::count() const { return (int) d->colorList.count(); } void kpColorCollection::resize(int newCount) { if (newCount == count()) return; else if (newCount < count()) { d->colorList.erase(d->colorList.begin() + newCount, d->colorList.end()); } else if (newCount > count()) { while(newCount > count()) { const int ret = addColor(QColor(), QString()/*color name*/); Q_ASSERT(ret == count() - 1); } } } kpColorCollection& kpColorCollection::operator=( const kpColorCollection &p) { if (&p == this) return *this; d->colorList = p.d->colorList; d->name = p.d->name; d->desc = p.d->desc; d->editable = p.d->editable; return *this; } QColor kpColorCollection::color(int index) const { if ((index < 0) || (index >= count())) return {}; return d->colorList[index].color; } int kpColorCollection::findColor(const QColor &color) const { for (int i = 0; i < d->colorList.size(); ++i) { if (d->colorList[i].color == color) return i; } return -1; } QString kpColorCollection::name(int index) const { if ((index < 0) || (index >= count())) return {}; return d->colorList[index].name; } QString kpColorCollection::name(const QColor &color) const { return name(findColor(color)); } int kpColorCollection::addColor(const QColor &newColor, const QString &newColorName) { d->colorList.append(ColorNode(newColor, newColorName)); return count() - 1; } int kpColorCollection::changeColor(int index, const QColor &newColor, const QString &newColorName) { if ((index < 0) || (index >= count())) return -1; ColorNode& node = d->colorList[index]; node.color = newColor; node.name = newColorName; return index; } int kpColorCollection::changeColor(const QColor &oldColor, const QColor &newColor, const QString &newColorName) { return changeColor( findColor(oldColor), newColor, newColorName); } diff --git a/mainWindow/kpMainWindow_File.cpp b/mainWindow/kpMainWindow_File.cpp index 290c40f0..5fb057e5 100644 --- a/mainWindow/kpMainWindow_File.cpp +++ b/mainWindow/kpMainWindow_File.cpp @@ -1,1514 +1,1508 @@ /* Copyright (c) 2003-2007 Clarence Dang Copyright (c) 2007 John Layt Copyright (c) 2007,2011,2015 Martin Koller All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "kpMainWindow.h" #include "kpMainWindowPrivate.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include -#include // kdelibs4support #include "kpLogCategories.h" #include "commands/kpCommandHistory.h" #include "kpDefs.h" #include "document/kpDocument.h" #include "commands/imagelib/kpDocumentMetaInfoCommand.h" #include "dialogs/imagelib/kpDocumentMetaInfoDialog.h" #include "widgets/kpDocumentSaveOptionsWidget.h" #include "pixmapfx/kpPixmapFX.h" #include "widgets/kpPrintDialogPage.h" #include "views/kpView.h" #include "views/manager/kpViewManager.h" #if HAVE_KSANE #include "../scan/sanedialog.h" #endif // HAVE_KSANE // private void kpMainWindow::setupFileMenuActions () { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "kpMainWindow::setupFileMenuActions()"; #endif KActionCollection *ac = actionCollection (); d->actionNew = KStandardAction::openNew (this, SLOT (slotNew()), ac); d->actionOpen = KStandardAction::open (this, SLOT (slotOpen()), ac); d->actionOpenRecent = KStandardAction::openRecent(this, &kpMainWindow::slotOpenRecent, ac); connect(d->actionOpenRecent, &KRecentFilesAction::recentListCleared, this, &kpMainWindow::slotRecentListCleared); d->actionOpenRecent->loadEntries (KSharedConfig::openConfig ()->group (kpSettingsGroupRecentFiles)); #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\trecent URLs=" << d->actionOpenRecent->items (); #endif d->actionSave = KStandardAction::save (this, SLOT (slotSave()), ac); d->actionSaveAs = KStandardAction::saveAs (this, SLOT (slotSaveAs()), ac); d->actionExport = ac->addAction(QStringLiteral("file_export")); d->actionExport->setText (i18n ("E&xport...")); d->actionExport->setIcon(QIcon::fromTheme(QStringLiteral("document-export"))); connect (d->actionExport, &QAction::triggered, this, &kpMainWindow::slotExport); d->actionScan = ac->addAction(QStringLiteral("file_scan")); d->actionScan->setText(i18n ("Scan...")); d->actionScan->setIcon(QIcon::fromTheme("scanner")); #if HAVE_KSANE connect (d->actionScan, &QAction::triggered, this, &kpMainWindow::slotScan); #else d->actionScan->setEnabled(false); #endif // HAVE_KSANE d->actionScreenshot = ac->addAction(QStringLiteral("file_screenshot")); d->actionScreenshot->setText(i18n("Acquire Screenshot")); connect (d->actionScreenshot, &QAction::triggered, this, &kpMainWindow::slotScreenshot); d->actionProperties = ac->addAction (QStringLiteral("file_properties")); d->actionProperties->setText (i18n ("Properties")); d->actionProperties->setIcon(QIcon::fromTheme(QStringLiteral("document-properties"))); connect (d->actionProperties, &QAction::triggered, this, &kpMainWindow::slotProperties); //d->actionRevert = KStandardAction::revert (this, SLOT (slotRevert()), ac); d->actionReload = ac->addAction (QStringLiteral("file_revert")); d->actionReload->setText (i18n ("Reloa&d")); d->actionReload->setIcon(QIcon::fromTheme(QStringLiteral("view-refresh"))); connect (d->actionReload, &QAction::triggered, this, &kpMainWindow::slotReload); ac->setDefaultShortcuts (d->actionReload, KStandardShortcut::reload ()); slotEnableReload (); d->actionPrint = KStandardAction::print (this, SLOT (slotPrint()), ac); d->actionPrintPreview = KStandardAction::printPreview (this, SLOT (slotPrintPreview()), ac); d->actionMail = KStandardAction::mail (this, SLOT (slotMail()), ac); d->actionClose = KStandardAction::close (this, SLOT (slotClose()), ac); d->actionQuit = KStandardAction::quit (this, SLOT (slotQuit()), ac); d->scanDialog = nullptr; enableFileMenuDocumentActions (false); } //--------------------------------------------------------------------- // private void kpMainWindow::enableFileMenuDocumentActions (bool enable) { // d->actionNew // d->actionOpen // d->actionOpenRecent d->actionSave->setEnabled (enable); d->actionSaveAs->setEnabled (enable); d->actionExport->setEnabled (enable); // d->actionScan d->actionProperties->setEnabled (enable); // d->actionReload d->actionPrint->setEnabled (enable); d->actionPrintPreview->setEnabled (enable); d->actionMail->setEnabled (enable); d->actionClose->setEnabled (enable); // d->actionQuit->setEnabled (enable); } //--------------------------------------------------------------------- // private void kpMainWindow::addRecentURL (const QUrl &url_) { // HACK: KRecentFilesAction::loadEntries() clears the KRecentFilesAction::d->urls // map. // // So afterwards, the URL ref, our method is given, points to an // element in this now-cleared map (see KRecentFilesAction::urlSelected(QAction*)). // Accessing it would result in a crash. // // To avoid the crash, make a copy of it before calling // loadEntries() and use this copy, instead of the to-be-dangling // ref. const QUrl url = url_; // DO NOT MAKE IT A REFERENCE, THE CALL BELOW TO loadEntries DESTROYS url_ #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "kpMainWindow::addRecentURL(" << url << ")"; #endif if (url.isEmpty ()) return; KSharedConfig::Ptr cfg = KSharedConfig::openConfig(); // KConfig::readEntry() does not actually reread from disk, hence doesn't // realize what other processes have done e.g. Settings / Show Path cfg->reparseConfiguration (); #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\trecent URLs=" << d->actionOpenRecent->items (); #endif // HACK: Something might have changed interprocess. // If we could PROPAGATE: interprocess, then this wouldn't be required. d->actionOpenRecent->loadEntries (cfg->group (kpSettingsGroupRecentFiles)); #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\tafter loading config=" << d->actionOpenRecent->items (); #endif d->actionOpenRecent->addUrl (url); d->actionOpenRecent->saveEntries (cfg->group (kpSettingsGroupRecentFiles)); cfg->sync (); #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\tnew recent URLs=" << d->actionOpenRecent->items (); #endif // TODO: PROPAGATE: interprocess // TODO: Is this loop safe since a KMainWindow later along in the list, // could be closed as the code in the body almost certainly re-enters // the event loop? Problem for KDE 3 as well, I think. for (auto *kmw : KMainWindow::memberList ()) { Q_ASSERT (dynamic_cast (kmw)); auto *mw = dynamic_cast (kmw); #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\t\tmw=" << mw; #endif if (mw != this) { // WARNING: Do not use KRecentFilesAction::setItems() // - it does not work since only its superclass, // KSelectAction, implements setItems() and can't // update KRecentFilesAction's URL list. // Avoid URL memory leak in KRecentFilesAction::loadEntries(). mw->d->actionOpenRecent->clear (); mw->d->actionOpenRecent->loadEntries (cfg->group (kpSettingsGroupRecentFiles)); #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\t\t\tcheck recent URLs=" << mw->d->actionOpenRecent->items (); #endif } } } //--------------------------------------------------------------------- // private slot // TODO: Disable action if // (d->configOpenImagesInSameWindow && d->document && d->document->isEmpty()) // as it does nothing if this is true. void kpMainWindow::slotNew () { toolEndShape (); if (d->document && !d->configOpenImagesInSameWindow) { // A document -- empty or otherwise -- is open. // Force open a new window. In contrast, open() might not open // a new window in this case. auto *win = new kpMainWindow (); win->show (); } else { open (QUrl (), true/*create an empty doc*/); } } //--------------------------------------------------------------------- // private QSize kpMainWindow::defaultDocSize () const { // KConfig::readEntry() does not actually reread from disk, hence doesn't // realize what other processes have done e.g. Settings / Show Path KSharedConfig::openConfig ()->reparseConfiguration (); KConfigGroup cfg (KSharedConfig::openConfig (), kpSettingsGroupGeneral); QSize docSize = cfg.readEntry (kpSettingLastDocSize, QSize ()); if (docSize.isEmpty ()) { docSize = QSize (400, 300); } else { // Don't get too big or you'll thrash (or even lock up) the computer // just by opening a window docSize = QSize (qMin (2048, docSize.width ()), qMin (2048, docSize.height ())); } return docSize; } //--------------------------------------------------------------------- // private void kpMainWindow::saveDefaultDocSize (const QSize &size) { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\tCONFIG: saving Last Doc Size = " << size; #endif KConfigGroup cfg (KSharedConfig::openConfig (), kpSettingsGroupGeneral); cfg.writeEntry (kpSettingLastDocSize, size); cfg.sync (); } //--------------------------------------------------------------------- // private bool kpMainWindow::shouldOpen () { if (d->configOpenImagesInSameWindow) { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\topenImagesInSameWindow"; #endif // (this brings up a dialog and might save the current doc) if (!queryCloseDocument ()) { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\t\tqueryCloseDocument() aborts open"; #endif return false; } } return true; } //--------------------------------------------------------------------- // private void kpMainWindow::setDocumentChoosingWindow (kpDocument *doc) { // Want new window? if (d->document && !d->document->isEmpty () && !d->configOpenImagesInSameWindow) { // Send doc to new window. auto *win = new kpMainWindow (doc); win->show (); } else { // (sets up views, doc signals) setDocument (doc); } } //--------------------------------------------------------------------- // private kpDocument *kpMainWindow::openInternal (const QUrl &url, const QSize &fallbackDocSize, bool newDocSameNameIfNotExist) { // If using OpenImagesInSameWindow mode, ask whether to close the // current document. if (!shouldOpen ()) return nullptr; // Create/open doc. auto *newDoc = new kpDocument (fallbackDocSize.width (), fallbackDocSize.height (), documentEnvironment ()); if (!newDoc->open (url, newDocSameNameIfNotExist)) { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\topen failed"; #endif delete newDoc; return nullptr; } #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\topen OK"; #endif // Send document to current or new window. setDocumentChoosingWindow (newDoc); return newDoc; } //--------------------------------------------------------------------- // private bool kpMainWindow::open (const QUrl &url, bool newDocSameNameIfNotExist) { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "kpMainWindow::open(" << url << ",newDocSameNameIfNotExist=" << newDocSameNameIfNotExist << ")"; #endif kpDocument *newDoc = openInternal (url, defaultDocSize (), newDocSameNameIfNotExist); if (newDoc) { if (newDoc->isFromExistingURL ()) addRecentURL (url); return true; } return false; } //--------------------------------------------------------------------- // private QList kpMainWindow::askForOpenURLs(const QString &caption, bool allowMultipleURLs) { QMimeDatabase db; QStringList filterList; QString filter; for (const auto &type : QImageReader::supportedMimeTypes()) { if ( !filter.isEmpty() ) { filter += QLatin1Char(' '); } QMimeType mime(db.mimeTypeForName(QString::fromLatin1(type))); if ( mime.isValid() ) { QString glob = mime.globPatterns().join(QLatin1Char(' ')); filter += glob; // I want to show the mime comment AND the file glob pattern, // but to avoid that the "All Supported Files" entry shows ALL glob patterns, // I must add the pattern here a second time so that QFileDialog::HideNameFilterDetails // can hide the first pattern and I still see the second one filterList << mime.comment() + QStringLiteral(" (%1)(%2)").arg(glob).arg(glob); } } filterList.prepend(i18n("All Supported Files (%1)", filter)); QFileDialog fd(this); fd.setNameFilters(filterList); fd.setOption(QFileDialog::HideNameFilterDetails); fd.setWindowTitle(caption); if ( allowMultipleURLs ) { fd.setFileMode(QFileDialog::ExistingFiles); } if ( fd.exec() ) { return fd.selectedUrls(); } return {}; } //--------------------------------------------------------------------- // private slot void kpMainWindow::slotOpen () { toolEndShape (); const QList urls = askForOpenURLs(i18nc("@title:window", "Open Image")); for (const auto & url : urls) { open (url); } } //--------------------------------------------------------------------- // private slot void kpMainWindow::slotOpenRecent (const QUrl &url) { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "kpMainWindow::slotOpenRecent(" << url << ")"; qCDebug(kpLogMainWindow) << "\titems=" << d->actionOpenRecent->items (); #endif toolEndShape (); open (url); // If the open is successful, addRecentURL() would have bubbled up the // URL in the File / Open Recent action. As a side effect, the URL is // deselected. // // If the open fails, we should deselect the URL: // // 1. for consistency // // 2. because it has not been opened. // d->actionOpenRecent->setCurrentItem (-1); } //--------------------------------------------------------------------- void kpMainWindow::slotRecentListCleared() { d->actionOpenRecent->saveEntries(KSharedConfig::openConfig()->group(kpSettingsGroupRecentFiles)); } //--------------------------------------------------------------------- #if HAVE_KSANE // private slot void kpMainWindow::slotScan () { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "kpMainWindow::slotScan() scanDialog=" << d->scanDialog; #endif toolEndShape (); if (!d->scanDialog) { // Create scan dialog d->scanDialog = new SaneDialog(this); // No scanning support (kdegraphics/libkscan) installed? if (!d->scanDialog) { KMessageBox::sorry (this, i18n("Failed to open scanning dialog."), i18nc("@title:window", "Scanning Failed")); return; } #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\tcreated scanDialog=" << d->scanDialog; #endif connect (d->scanDialog, &SaneDialog::finalImage, this, &kpMainWindow::slotScanned); } // If using OpenImagesInSameWindow mode, ask whether to close the // current document. // // Do this after scan support is detected. Because if it's not, what // would be the point of closing the document? // // Ideally, we would do this after the user presses "Final Scan" in // the scan dialog and before the scan begins (if the user wants to // cancel the scan operation, it would be annoying to offer this choice // only after the slow scan is completed) but the KScanDialog API does // not allow this. So we settle for doing this before any // scan dialogs are shown. We don't do this between KScanDialog::setup() // and KScanDialog::exec() as it could be confusing alternating between // scanning and KolourPaint dialogs. if (!shouldOpen ()) { return; } #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\tcalling setup"; #endif // Bring up dialog to select scan device. // If there is no scanner, we find that this does not bring up a dialog // but still returns true. if (d->scanDialog->setup ()) { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\t\tOK - showing dialog"; #endif // Called only if scanner configured/available. // // In reality, this seems to be called even if you press "Cancel" in // the KScanDialog::setup() dialog! // // We use exec() to make sure it's modal. show() seems to work too // but better safe than sorry. d->scanDialog->exec (); } else { // Have never seen this code path execute even if "Cancel" is pressed. #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\t\tFAIL"; #endif } } //--------------------------------------------------------------------- // private slot void kpMainWindow::slotScanned (const QImage &image, int) { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "kpMainWindow::slotScanned() image.rect=" << image.rect (); #endif #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\thiding dialog"; #endif // (KScanDialog does not close itself after a scan is made) // // Close the dialog, first thing: // // 1. This means that any dialogs we bring up won't be nested on top. // // 2. We don't want to return from this method but forget to close // the dialog. So do it before anything else. d->scanDialog->hide (); // (just in case there's some drawing between slotScan() exiting and // us being called) toolEndShape (); // TODO: Maybe this code should be moved into kpdocument.cpp - // since it resembles the responsibilities of kpDocument::open(). kpDocumentSaveOptions saveOptions; kpDocumentMetaInfo metaInfo; kpDocument::getDataFromImage(image, saveOptions, metaInfo); // Create document from image and meta info. auto *doc = new kpDocument (image.width (), image.height (), documentEnvironment ()); doc->setImage (image); doc->setSaveOptions (saveOptions); doc->setMetaInfo (metaInfo); // Send document to current or new window. setDocumentChoosingWindow (doc); } #endif // HAVE_KSANE //--------------------------------------------------------------------- void kpMainWindow::slotScreenshot() { toolEndShape(); auto *dialog = new QDialog(this); auto *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, dialog); connect (buttons, &QDialogButtonBox::accepted, dialog, &QDialog::accept); connect (buttons, &QDialogButtonBox::rejected, dialog, &QDialog::reject); auto *label = new QLabel(i18n("Snapshot Delay")); auto *seconds = new KPluralHandlingSpinBox; seconds->setRange(0, 99); seconds->setSuffix(ki18np(" second", " seconds")); seconds->setSpecialValueText(i18n("No delay")); auto *hideWindow = new QCheckBox(i18n("Hide Main Window")); hideWindow->setChecked(true); auto *vbox = new QVBoxLayout(dialog); vbox->addWidget(label); vbox->addWidget(seconds); vbox->addWidget(hideWindow); vbox->addWidget(buttons); if ( dialog->exec() == QDialog::Rejected ) { delete dialog; return; } if ( hideWindow->isChecked() ) { hide(); } // at least 1 seconds to make sure the window is hidden and the hide effect already stopped QTimer::singleShot((seconds->value() + 1) * 1000, this, &kpMainWindow::slotMakeScreenshot); delete dialog; } //--------------------------------------------------------------------- void kpMainWindow::slotMakeScreenshot() { QCoreApplication::processEvents(); QPixmap pixmap = QGuiApplication::primaryScreen()->grabWindow(QApplication::desktop()->winId()); auto *doc = new kpDocument(pixmap.width(), pixmap.height(), documentEnvironment()); doc->setImage(pixmap.toImage()); // Send document to current or new window. setDocumentChoosingWindow(doc); show(); // in case we hid the mainwindow, show it again } //--------------------------------------------------------------------- // private slot void kpMainWindow::slotProperties () { toolEndShape (); kpDocumentMetaInfoDialog dialog (document ()->metaInfo (), this); if (dialog.exec () && !dialog.isNoOp ()) { commandHistory ()->addCommand ( new kpDocumentMetaInfoCommand ( i18n ("Document Properties"), dialog.metaInfo ()/*new*/, *document ()->metaInfo ()/*old*/, commandEnvironment ())); } } //--------------------------------------------------------------------- // private slot bool kpMainWindow::save (bool localOnly) { if (d->document->url ().isEmpty () || !QImageWriter::supportedMimeTypes() .contains(d->document->saveOptions ()->mimeType().toLatin1()) || // SYNC: kpDocument::getPixmapFromFile() can't determine quality // from file so it has been set initially to an invalid value. (d->document->saveOptions ()->mimeTypeHasConfigurableQuality () && d->document->saveOptions ()->qualityIsInvalid ()) || (localOnly && !d->document->url ().isLocalFile ())) { return saveAs (localOnly); } if (d->document->save (!d->document->savedAtLeastOnceBefore ()/*lossy prompt*/)) { addRecentURL (d->document->url ()); return true; } return false; } //--------------------------------------------------------------------- // private slot bool kpMainWindow::slotSave () { toolEndShape (); return save (); } //--------------------------------------------------------------------- // private QUrl kpMainWindow::askForSaveURL (const QString &caption, const QString &startURL, const kpImage &imageToBeSaved, const kpDocumentSaveOptions &startSaveOptions, const kpDocumentMetaInfo &docMetaInfo, const QString &forcedSaveOptionsGroup, bool localOnly, kpDocumentSaveOptions *chosenSaveOptions, bool isSavingForFirstTime, bool *allowLossyPrompt) { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "kpMainWindow::askForURL() startURL=" << startURL; startSaveOptions.printDebug ("\tstartSaveOptions"); #endif bool reparsedConfiguration = false; // KConfig::readEntry() does not actually reread from disk, hence doesn't // realize what other processes have done e.g. Settings / Show Path // so reparseConfiguration() must be called #define SETUP_READ_CFG() \ if (!reparsedConfiguration) \ { \ KSharedConfig::openConfig ()->reparseConfiguration (); \ reparsedConfiguration = true; \ } \ \ KConfigGroup cfg (KSharedConfig::openConfig (), forcedSaveOptionsGroup); if (chosenSaveOptions) { *chosenSaveOptions = kpDocumentSaveOptions (); } if (allowLossyPrompt) { *allowLossyPrompt = true; // play it safe for now } kpDocumentSaveOptions fdSaveOptions = startSaveOptions; QStringList mimeTypes; for (const auto &type : QImageWriter::supportedMimeTypes()) { mimeTypes << QString::fromLatin1(type); } #if DEBUG_KP_MAIN_WINDOW QStringList sortedMimeTypes = mimeTypes; sortedMimeTypes.sort (); qCDebug(kpLogMainWindow) << "\tmimeTypes=" << mimeTypes << "\tsortedMimeTypes=" << sortedMimeTypes; #endif if (mimeTypes.isEmpty ()) { qCCritical(kpLogMainWindow) << "No output mimetypes!"; return {}; } #define MIME_TYPE_IS_VALID() (!fdSaveOptions.mimeTypeIsInvalid () && \ mimeTypes.contains (fdSaveOptions.mimeType ())) if (!MIME_TYPE_IS_VALID ()) { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\tmimeType=" << fdSaveOptions.mimeType () << " not valid, get default"; #endif SETUP_READ_CFG (); fdSaveOptions.setMimeType (kpDocumentSaveOptions::defaultMimeType (cfg)); if (!MIME_TYPE_IS_VALID ()) { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\tmimeType=" << fdSaveOptions.mimeType () << " not valid, get hardcoded"; #endif if (mimeTypes.contains(QLatin1String("image/png"))) { fdSaveOptions.setMimeType (QStringLiteral("image/png")); } else if (mimeTypes.contains(QLatin1String("image/bmp"))) { fdSaveOptions.setMimeType (QStringLiteral("image/bmp")); } else { fdSaveOptions.setMimeType (mimeTypes.first ()); } } } #undef MIME_TYPE_IS_VALID if (fdSaveOptions.colorDepthIsInvalid ()) { SETUP_READ_CFG (); fdSaveOptions.setColorDepth (kpDocumentSaveOptions::defaultColorDepth (cfg)); fdSaveOptions.setDither (kpDocumentSaveOptions::defaultDither (cfg)); } if (fdSaveOptions.qualityIsInvalid ()) { SETUP_READ_CFG (); fdSaveOptions.setQuality (kpDocumentSaveOptions::defaultQuality (cfg)); } #if DEBUG_KP_MAIN_WINDOW fdSaveOptions.printDebug ("\tcorrected saveOptions passed to fileDialog"); #endif auto *saveOptionsWidget = new kpDocumentSaveOptionsWidget (imageToBeSaved, fdSaveOptions, docMetaInfo, this); QFileDialog fd(this); fd.setAcceptMode (QFileDialog::AcceptSave); fd.setOption (QFileDialog::DontUseNativeDialog); fd.setDirectoryUrl (QUrl (startURL)); fd.setWindowTitle (caption); fd.setMimeTypeFilters (mimeTypes); fd.selectMimeTypeFilter (fdSaveOptions.mimeType ()); if (localOnly) { fd.setSupportedSchemes ({QStringLiteral("file")}); } // insert the checkbox below the filter box if (QGridLayout* gl = qobject_cast(fd.layout ())) { gl->addWidget (saveOptionsWidget, gl->rowCount (), 0, 1, gl->columnCount ()); } saveOptionsWidget->setVisualParent (&fd); connect (&fd, &QFileDialog::filterSelected, this, [saveOptionsWidget, &fd]() { saveOptionsWidget->setMimeType(fd.selectedMimeTypeFilter()); }); if ( fd.exec() == QDialog::Accepted ) { kpDocumentSaveOptions newSaveOptions = saveOptionsWidget->documentSaveOptions (); #if DEBUG_KP_MAIN_WINDOW newSaveOptions.printDebug ("\tnewSaveOptions"); #endif KConfigGroup cfg (KSharedConfig::openConfig (), forcedSaveOptionsGroup); // Save options user forced - probably want to use them in future kpDocumentSaveOptions::saveDefaultDifferences (cfg, fdSaveOptions, newSaveOptions); cfg.sync (); if (chosenSaveOptions) { *chosenSaveOptions = newSaveOptions; } const QList selectedUrls = fd.selectedUrls (); if (selectedUrls.isEmpty()) { // shouldn't happen return {}; } const QUrl selectedUrl = selectedUrls.at(0); if (allowLossyPrompt) { // SYNC: kpDocumentSaveOptions elements - everything except quality // (one quality setting is "just as lossy" as another so no // need to continually warn due to quality change) *allowLossyPrompt = (isSavingForFirstTime || selectedUrl != QUrl (startURL) || newSaveOptions.mimeType () != startSaveOptions.mimeType () || newSaveOptions.colorDepth () != startSaveOptions.colorDepth () || newSaveOptions.dither () != startSaveOptions.dither ()); #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\tallowLossyPrompt=" << *allowLossyPrompt; #endif } #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\tselectedUrl=" << selectedUrl; #endif return selectedUrl; } return {}; #undef SETUP_READ_CFG } //--------------------------------------------------------------------- // private slot bool kpMainWindow::saveAs (bool localOnly) { kpDocumentSaveOptions chosenSaveOptions; bool allowLossyPrompt; QUrl chosenURL = askForSaveURL (i18nc ("@title:window", "Save Image As"), d->document->url ().url (), d->document->imageWithSelection (), *d->document->saveOptions (), *d->document->metaInfo (), kpSettingsGroupFileSaveAs, localOnly, &chosenSaveOptions, !d->document->savedAtLeastOnceBefore (), &allowLossyPrompt); if (chosenURL.isEmpty ()) { return false; } if (!d->document->saveAs (chosenURL, chosenSaveOptions, allowLossyPrompt)) { return false; } addRecentURL (chosenURL); return true; } //--------------------------------------------------------------------- // private slot bool kpMainWindow::slotSaveAs () { toolEndShape (); return saveAs (); } //--------------------------------------------------------------------- // private slot bool kpMainWindow::slotExport () { toolEndShape (); kpDocumentSaveOptions chosenSaveOptions; bool allowLossyPrompt; QUrl chosenURL = askForSaveURL (i18nc ("@title:window", "Export"), d->lastExportURL.url (), d->document->imageWithSelection (), d->lastExportSaveOptions, *d->document->metaInfo (), kpSettingsGroupFileExport, false/*allow remote files*/, &chosenSaveOptions, d->exportFirstTime, &allowLossyPrompt); if (chosenURL.isEmpty ()) { return false; } if (!kpDocument::savePixmapToFile (d->document->imageWithSelection (), chosenURL, chosenSaveOptions, *d->document->metaInfo (), allowLossyPrompt, this)) { return false; } addRecentURL (chosenURL); d->lastExportURL = chosenURL; d->lastExportSaveOptions = chosenSaveOptions; d->exportFirstTime = false; return true; } //--------------------------------------------------------------------- // private slot void kpMainWindow::slotEnableReload () { d->actionReload->setEnabled (d->document); } //--------------------------------------------------------------------- // private slot bool kpMainWindow::slotReload () { toolEndShape (); Q_ASSERT (d->document); QUrl oldURL = d->document->url (); if (d->document->isModified ()) { int result = KMessageBox::Cancel; if (d->document->isFromExistingURL () && !oldURL.isEmpty ()) { result = KMessageBox::warningContinueCancel (this, i18n ("The document \"%1\" has been modified.\n" "Reloading will lose all changes since you last saved it.\n" "Are you sure?", d->document->prettyFilename ()), QString()/*caption*/, KGuiItem(i18n ("&Reload"))); } else { result = KMessageBox::warningContinueCancel (this, i18n ("The document \"%1\" has been modified.\n" "Reloading will lose all changes.\n" "Are you sure?", d->document->prettyFilename ()), QString()/*caption*/, KGuiItem(i18n ("&Reload"))); } if (result != KMessageBox::Continue) { return false; } } kpDocument *doc = nullptr; // If it's _supposed to_ come from an existing URL or it actually exists if (d->document->isFromExistingURL () || d->document->urlExists (oldURL)) { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "kpMainWindow::slotReload() reloading from disk!"; #endif doc = new kpDocument (1, 1, documentEnvironment ()); if (!doc->open (oldURL)) { delete doc; doc = nullptr; return false; } addRecentURL (oldURL); } else { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "kpMainWindow::slotReload() create doc"; #endif doc = new kpDocument (d->document->constructorWidth (), d->document->constructorHeight (), documentEnvironment ()); doc->setURL (oldURL, false/*not from URL*/); } setDocument (doc); return true; } // private void kpMainWindow::sendDocumentNameToPrinter (QPrinter *printer) { QUrl url = d->document->url (); if (!url.isEmpty ()) { int dot; QString fileName = url.fileName (); dot = fileName.lastIndexOf ('.'); // file.ext but not .hidden-file? if (dot > 0) { fileName.truncate (dot); } #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "kpMainWindow::sendDocumentNameToPrinter() fileName=" << fileName << " dir=" << url.path(); #endif printer->setDocName (fileName); } } //-------------------------------------------------------------------------------- void kpMainWindow::sendPreviewToPrinter(QPrinter *printer) { sendImageToPrinter(printer, false); } //-------------------------------------------------------------------------------- // private void kpMainWindow::sendImageToPrinter (QPrinter *printer, bool showPrinterSetupDialog) { // Get image to be printed. kpImage image = d->document->imageWithSelection (); // Get image DPI. auto imageDotsPerMeterX = double (d->document->metaInfo ()->dotsPerMeterX ()); auto imageDotsPerMeterY = double (d->document->metaInfo ()->dotsPerMeterY ()); #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "kpMainWindow::sendImageToPrinter() image:" << " width=" << image.width () << " height=" << image.height () << " dotsPerMeterX=" << imageDotsPerMeterX << " dotsPerMeterY=" << imageDotsPerMeterY; #endif // Image DPI invalid (e.g. new image, could not read from file // or Qt3 doesn't implement DPI for JPEG)? if (imageDotsPerMeterX <= 0 || imageDotsPerMeterY <= 0) { // Even if just one DPI dimension is invalid, mutate both DPI // dimensions as we have no information about the intended // aspect ratio anyway (and other dimension likely to be invalid). // When rendering text onto a document, the fonts are rasterised // according to the screen's DPI. // TODO: I think we should use the image's DPI. Technically // possible? // // So no matter what computer you draw text on, you get // the same pixels. // // So we must print at the screen's DPI to get the right text size. // // Unfortunately, this means that moving to a different screen DPI // affects printing. If you edited the image at a different screen // DPI than when you print, you get incorrect results. Furthermore, // this is bogus if you don't have text in your image. Worse still, // what if you have multiple screens connected to the same computer // with different DPIs? // TODO: mysteriously, someone else is setting this to 96dpi always. QPixmap arbitraryScreenElement(1, 1); const QPaintDevice *screenDevice = &arbitraryScreenElement; const auto dpiX = screenDevice->logicalDpiX (); const auto dpiY = screenDevice->logicalDpiY (); #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\tusing screen dpi: x=" << dpiX << " y=" << dpiY; #endif imageDotsPerMeterX = dpiX * KP_INCHES_PER_METER; imageDotsPerMeterY = dpiY * KP_INCHES_PER_METER; } // Get page size (excluding margins). // Coordinate (0,0) is the X here: // mmmmm // mX m // m m m = margin // m m // mmmmm const auto printerWidthMM = printer->widthMM (); const auto printerHeightMM = printer->heightMM (); auto dpiX = imageDotsPerMeterX / KP_INCHES_PER_METER; auto dpiY = imageDotsPerMeterY / KP_INCHES_PER_METER; #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\tprinter: widthMM=" << printerWidthMM << " heightMM=" << printerHeightMM; qCDebug(kpLogMainWindow) << "\timage: dpiX=" << dpiX << " dpiY=" << dpiY; #endif // // If image doesn't fit on page at intended DPI, change the DPI. // const auto scaleDpiX = (image.width () / (printerWidthMM / KP_MILLIMETERS_PER_INCH)) / dpiX; const auto scaleDpiY = (image.height () / (printerHeightMM / KP_MILLIMETERS_PER_INCH)) / dpiY; const auto scaleDpi = qMax (scaleDpiX, scaleDpiY); #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\t\tscaleDpi: x=" << scaleDpiX << " y=" << scaleDpiY << " --> scale at " << scaleDpi << " to fit?"; #endif // Need to increase resolution to fit page? if (scaleDpi > 1.0) { dpiX *= scaleDpi; dpiY *= scaleDpi; #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\t\t\tto fit page, scaled to:" << " dpiX=" << dpiX << " dpiY=" << dpiY; #endif } // Make sure DPIs are equal as that's all QPrinter::setResolution() // supports. We do this in such a way that we only ever stretch an // image, to avoid losing information. Don't antialias as the printer // will do that to translate our DPI to its physical resolution and // double-antialiasing looks bad. if (dpiX > dpiY) { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\tdpiX > dpiY; stretching image height to equalise DPIs to dpiX=" << dpiX; #endif kpPixmapFX::scale (&image, image.width (), qMax (1, qRound (image.height () * dpiX / dpiY)), false/*don't antialias*/); dpiY = dpiX; } else if (dpiY > dpiX) { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\tdpiY > dpiX; stretching image width to equalise DPIs to dpiY=" << dpiY; #endif kpPixmapFX::scale (&image, qMax (1, qRound (image.width () * dpiY / dpiX)), image.height (), false/*don't antialias*/); dpiX = dpiY; } Q_ASSERT (dpiX == dpiY); // QPrinter::setResolution() has to be called before QPrinter::setup(). printer->setResolution (qMax (1, qRound (dpiX))); sendDocumentNameToPrinter (printer); if (showPrinterSetupDialog) { auto *optionsPage = new kpPrintDialogPage (this); optionsPage->setPrintImageCenteredOnPage (d->configPrintImageCenteredOnPage); - QPrintDialog *printDialog = - KdePrint::createPrintDialog ( - printer, - QList () << optionsPage, - this); - printDialog->setWindowTitle (i18nc ("@title:window", "Print Image")); + QPrintDialog printDialog (printer, this); + printDialog.setOptionTabs ({optionsPage}); + printDialog.setWindowTitle (i18nc ("@title:window", "Print Image")); // Display dialog. - const bool wantToPrint = printDialog->exec (); + const bool wantToPrint = printDialog.exec (); if (optionsPage->printImageCenteredOnPage () != d->configPrintImageCenteredOnPage) { // Save config option even if the dialog was cancelled. d->configPrintImageCenteredOnPage = optionsPage->printImageCenteredOnPage (); KConfigGroup cfg (KSharedConfig::openConfig (), kpSettingsGroupGeneral); cfg.writeEntry (kpSettingPrintImageCenteredOnPage, d->configPrintImageCenteredOnPage); cfg.sync (); } - delete printDialog; - if (!wantToPrint) { return; } } // Send image to printer. QPainter painter; painter.begin(printer); double originX = 0, originY = 0; // Center image on page? if (d->configPrintImageCenteredOnPage) { originX = (printer->width() - image.width ()) / 2; originY = (printer->height() - image.height ()) / 2; } painter.drawImage(qRound(originX), qRound(originY), image); painter.end(); } //--------------------------------------------------------------------- // private slot void kpMainWindow::slotPrint () { toolEndShape (); QPrinter printer; sendImageToPrinter (&printer, true/*showPrinterSetupDialog*/); } //--------------------------------------------------------------------- // private slot void kpMainWindow::slotPrintPreview () { toolEndShape (); QPrintPreviewDialog printPreview(this); connect(&printPreview, &QPrintPreviewDialog::paintRequested, this, &kpMainWindow::sendPreviewToPrinter); printPreview.exec (); } //--------------------------------------------------------------------- // private slot void kpMainWindow::slotMail () { toolEndShape (); if (d->document->url ().isEmpty ()/*no name*/ || !(d->document->isFromExistingURL () && d->document->urlExists (d->document->url ())) || d->document->isModified ()/*needs to be saved*/) { int result = KMessageBox::questionYesNo (this, i18n ("You must save this image before sending it.\n" "Do you want to save it?"), QString(), KStandardGuiItem::save (), KStandardGuiItem::cancel ()); if (result == KMessageBox::Yes) { if (!save ()) { // save failed or aborted - don't email return; } } else { // don't want to save - don't email return; } } KToolInvocation::invokeMailer ( QString()/*to*/, QString()/*cc*/, QString()/*bcc*/, d->document->prettyFilename()/*subject*/, QString()/*body*/, QString()/*messageFile*/, QStringList(d->document->url().url())/*attachments*/); } //--------------------------------------------------------------------- // private bool kpMainWindow::queryCloseDocument () { toolEndShape (); if (!d->document || !d->document->isModified ()) { return true; // ok to close current doc } int result = KMessageBox::warningYesNoCancel (this, i18n ("The document \"%1\" has been modified.\n" "Do you want to save it?", d->document->prettyFilename ()), QString()/*caption*/, KStandardGuiItem::save (), KStandardGuiItem::discard ()); switch (result) { case KMessageBox::Yes: return slotSave (); // close only if save succeeds case KMessageBox::No: return true; // close without saving default: return false; // don't close current doc } } //--------------------------------------------------------------------- // private virtual [base KMainWindow] bool kpMainWindow::queryClose () { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "kpMainWindow::queryClose()"; #endif toolEndShape (); if (!queryCloseDocument ()) { return false; } if (!queryCloseColors ()) { return false; } return true; } //--------------------------------------------------------------------- // private slot void kpMainWindow::slotClose () { toolEndShape (); if (!queryCloseDocument ()) { return; } setDocument (nullptr); } //--------------------------------------------------------------------- // private slot void kpMainWindow::slotQuit () { toolEndShape (); close (); // will call queryClose() } //---------------------------------------------------------------------