File indexing completed on 2025-01-19 03:59:15
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2006-01-20 0007 * Description : core image editor GUI implementation 0008 * 0009 * SPDX-FileCopyrightText: 2006-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2009-2011 by Andi Clemens <andi dot clemens at gmail dot com> 0011 * SPDX-FileCopyrightText: 2015 by Mohamed_Anwer <m_dot_anwer at gmx dot com> 0012 * 0013 * SPDX-License-Identifier: GPL-2.0-or-later 0014 * 0015 * ============================================================ */ 0016 0017 #ifndef DIGIKAM_IMAGE_EDITOR_WINDOW_H 0018 #define DIGIKAM_IMAGE_EDITOR_WINDOW_H 0019 0020 // C++ includes 0021 0022 #include <queue> 0023 0024 // Qt includes 0025 0026 #include <QColor> 0027 #include <QPointer> 0028 #include <QRect> 0029 #include <QString> 0030 #include <QProgressDialog> 0031 #include <QUrl> 0032 0033 // Local includes 0034 0035 #include "digikam_export.h" 0036 #include "digikam_config.h" 0037 #include "thumbbardock.h" 0038 #include "previewtoolbar.h" 0039 #include "savingcontext.h" 0040 #include "dxmlguiwindow.h" 0041 0042 class QSplitter; 0043 class QMenu; 0044 class QAction; 0045 0046 class KSelectAction; 0047 class KToolBarPopupAction; 0048 0049 namespace Digikam 0050 { 0051 0052 class DAdjustableLabel; 0053 class DCategorizedView; 0054 class Canvas; 0055 class DImageHistory; 0056 class EditorTool; 0057 class EditorStackView; 0058 class ExposureSettingsContainer; 0059 class IOFileSettings; 0060 class ICCSettingsContainer; 0061 class Sidebar; 0062 class SidebarSplitter; 0063 class StatusProgressBar; 0064 class VersionManager; 0065 class VersionFileOperation; 0066 class IccProfile; 0067 0068 class DIGIKAM_EXPORT EditorWindow : public DXmlGuiWindow 0069 { 0070 Q_OBJECT 0071 0072 public: 0073 0074 enum TransformType 0075 { 0076 RotateLeft, 0077 RotateRight, 0078 FlipHorizontal, 0079 FlipVertical 0080 }; 0081 0082 const static QString CONFIG_GROUP_NAME; 0083 0084 public: 0085 0086 explicit EditorWindow(const QString& name, QWidget* const parent = nullptr); 0087 ~EditorWindow() override; 0088 0089 void registerExtraPluginsActions(QString& dom) override; 0090 void loadTool(EditorTool* const tool); 0091 bool actionEnabledState() const; 0092 0093 public Q_SLOTS: 0094 0095 void slotSetup() override = 0; 0096 virtual void slotSetupICC() = 0; 0097 0098 Q_SIGNALS: 0099 0100 void signalSelectionChanged(const QRect&); 0101 void signalNoCurrentItem(); 0102 void signalPreviewModeChanged(int); 0103 void signalToolApplied(); 0104 0105 protected: 0106 0107 bool m_nonDestructive; 0108 bool m_setExifOrientationTag; 0109 bool m_editingOriginalImage; 0110 bool m_actionEnabledState; 0111 0112 DAdjustableLabel* m_resLabel; 0113 0114 QColor m_bgColor; 0115 0116 SidebarSplitter* m_splitter; 0117 0118 QAction* m_openVersionAction; 0119 QAction* m_saveAction; 0120 QAction* m_saveAsAction; 0121 KToolBarPopupAction* m_saveNewVersionAction; 0122 QAction* m_saveCurrentVersionAction; 0123 QAction* m_saveNewVersionAsAction; 0124 QMenu* m_saveNewVersionInFormatAction; 0125 QAction* m_exportAction; 0126 QAction* m_revertAction; 0127 QAction* m_discardChangesAction; 0128 QAction* m_fileDeleteAction; 0129 QAction* m_forwardAction; 0130 QAction* m_backwardAction; 0131 0132 QAction* m_lastAction; 0133 QAction* m_firstAction; 0134 0135 QAction* m_applyToolAction; 0136 QAction* m_closeToolAction; 0137 0138 QAction* m_showBarAction; 0139 0140 KToolBarPopupAction* m_undoAction; 0141 KToolBarPopupAction* m_redoAction; 0142 0143 QMenu* m_contextMenu; 0144 QMenu* m_servicesMenu; 0145 QAction* m_serviceAction; 0146 0147 EditorStackView* m_stackView; 0148 Canvas* m_canvas; 0149 StatusProgressBar* m_nameLabel; 0150 IOFileSettings* m_IOFileSettings; 0151 QPointer<QProgressDialog> m_savingProgressDialog; 0152 0153 SavingContext m_savingContext; 0154 0155 QString m_formatForRAWVersioning; 0156 QString m_formatForSubversions; 0157 0158 /// NOTE: using QVector to store transforms 0159 QVector<TransformType> m_transformQue; 0160 0161 protected: 0162 0163 enum SaveAskMode 0164 { 0165 AskIfNeeded, 0166 OverwriteWithoutAsking, 0167 AlwaysSaveAs, 0168 SaveVersionWithoutAsking = OverwriteWithoutAsking, 0169 AlwaysNewVersion = AlwaysSaveAs 0170 }; 0171 0172 protected: 0173 0174 void saveStandardSettings(); 0175 void readStandardSettings(); 0176 void applyStandardSettings(); 0177 void applyIOSettings(); 0178 void applyColorManagementSettings(); 0179 0180 void setupStandardConnections(); 0181 void setupStandardActions(); 0182 void setupStatusBar(); 0183 void setupContextMenu(); 0184 void setupSelectToolsAction(); 0185 void toggleStandardActions(bool val); 0186 void toggleZoomActions(bool val); 0187 void toggleNonDestructiveActions(); 0188 void toggleToolActions(EditorTool* tool = nullptr); 0189 0190 bool promptForOverWrite(); 0191 0192 bool promptUserDelete(const QUrl& url); 0193 bool promptUserSave(const QUrl& url, SaveAskMode mode = AskIfNeeded, bool allowCancel = true); 0194 bool waitForSavingToComplete(); 0195 void startingSave(const QUrl& url); 0196 bool startingSaveAs(const QUrl& url); 0197 bool startingSaveCurrentVersion(const QUrl& url); 0198 bool startingSaveNewVersion(const QUrl& url); 0199 bool startingSaveNewVersionAs(const QUrl& url); 0200 bool startingSaveNewVersionInFormat(const QUrl& url, const QString& format); 0201 bool checkPermissions(const QUrl& url); 0202 bool checkOverwrite(const QUrl& url); 0203 bool moveLocalFile(const QString& src, const QString& dest); 0204 void movingSaveFileFinished(bool successful); 0205 void colorManage(); 0206 void execSavingProgressDialog(); 0207 0208 void resetOrigin(); 0209 void resetOriginSwitchFile(); 0210 0211 void addServicesMenuForUrl(const QUrl& url); 0212 void openWith(const QUrl& url, QAction* action); 0213 0214 SidebarSplitter* sidebarSplitter() const; 0215 EditorStackView* editorStackView() const; 0216 ExposureSettingsContainer* exposureSettings() const; 0217 0218 VersionFileOperation saveVersionFileOperation(const QUrl& url, bool fork); 0219 VersionFileOperation saveAsVersionFileOperation(const QUrl& url, const QUrl& saveLocation, const QString& format); 0220 VersionFileOperation saveInFormatVersionFileOperation(const QUrl& url, const QString& format); 0221 0222 virtual bool hasOriginalToRestore(); 0223 virtual DImageHistory resolvedImageHistory(const DImageHistory& history); 0224 0225 virtual void moveFile(); 0226 virtual void finishSaving(bool success); 0227 0228 virtual void readSettings(); 0229 virtual void saveSettings(); 0230 virtual void toggleActions(bool val); 0231 0232 virtual ThumbBarDock* thumbBar() const = 0; 0233 virtual Sidebar* rightSideBar() const = 0; 0234 0235 virtual void setupConnections() = 0; 0236 virtual void setupActions() = 0; 0237 virtual void setupUserArea() = 0; 0238 0239 virtual void addServicesMenu() = 0; 0240 0241 virtual VersionManager* versionManager() const; 0242 0243 /** 0244 * Hook method that subclasses must implement to return the destination url 0245 * of the image to save. This may also be a remote url. 0246 * 0247 * This method will only be called while saving. 0248 * 0249 * @return destination for the file that is currently being saved. 0250 */ 0251 virtual QUrl saveDestinationUrl() = 0; 0252 0253 virtual void saveIsComplete() = 0; 0254 virtual void saveAsIsComplete() = 0; 0255 virtual void saveVersionIsComplete() = 0; 0256 0257 protected Q_SLOTS: 0258 0259 void slotAboutToShowUndoMenu(); 0260 void slotAboutToShowRedoMenu(); 0261 0262 void slotSelected(bool); 0263 0264 void slotLoadingProgress(const QString& filePath, float progress); 0265 void slotSavingProgress(const QString& filePath, float progress); 0266 0267 void slotNameLabelCancelButtonPressed(); 0268 0269 void slotComponentsInfo() override; 0270 0271 virtual void slotPrepareToLoad(); 0272 virtual void slotLoadingStarted(const QString& filename); 0273 virtual void slotLoadingFinished(const QString& filename, bool success); 0274 virtual void slotSavingStarted(const QString& filename); 0275 virtual void slotFileOriginChanged(const QString& filePath); 0276 virtual void slotDiscardChanges(); 0277 virtual void slotOpenOriginal(); 0278 0279 virtual bool saveOrSaveAs(); 0280 0281 virtual bool saveAs() = 0; 0282 virtual bool save() = 0; 0283 virtual bool saveNewVersion() = 0; 0284 virtual bool saveCurrentVersion() = 0; 0285 virtual bool saveNewVersionAs() = 0; 0286 virtual bool saveNewVersionInFormat(const QString&) = 0; 0287 virtual void slotFileWithDefaultApplication() = 0; 0288 virtual void slotDeleteCurrentItem() = 0; 0289 virtual void slotBackward() = 0; 0290 virtual void slotForward() = 0; 0291 virtual void slotFirst() = 0; 0292 virtual void slotLast() = 0; 0293 virtual void slotUpdateItemInfo() = 0; 0294 virtual void slotChanged() = 0; 0295 virtual void slotContextMenu() = 0; 0296 virtual void slotRevert() = 0; 0297 virtual void slotAddedDropedItems(QDropEvent* e) = 0; 0298 virtual void slotOpenWith(QAction* action = nullptr) = 0; 0299 0300 private Q_SLOTS: 0301 0302 void slotSetUnderExposureIndicator(bool); 0303 void slotSetOverExposureIndicator(bool); 0304 void slotColorManagementOptionsChanged(); 0305 void slotToggleColorManagedView(); 0306 void slotSoftProofingOptions(); 0307 void slotUpdateSoftProofingState(); 0308 void slotSavingFinished(const QString& filename, bool success); 0309 void slotZoomTo100Percents(); 0310 void slotZoomChanged(bool isMax, bool isMin, double zoom); 0311 void slotSelectionChanged(const QRect& sel); 0312 void slotSelectionSetText(const QRect& sel); 0313 void slotToggleFitToWindow(); 0314 void slotToggleOffFitToWindow(); 0315 void slotFitToSelect(); 0316 void slotIncreaseZoom(); 0317 void slotDecreaseZoom(); 0318 void slotCloseTool(); 0319 void slotApplyTool(); 0320 void slotUndoStateChanged(); 0321 void slotThemeChanged(); 0322 void slotToggleRightSideBar() override; 0323 void slotPreviousRightSideBarTab() override; 0324 void slotNextRightSideBarTab() override; 0325 void slotToolDone(); 0326 0327 void slotRotateLeftIntoQue(); 0328 void slotRotateRightIntoQue(); 0329 void slotFlipHIntoQue(); 0330 void slotFlipVIntoQue(); 0331 0332 private: 0333 0334 void enterWaitingLoop(); 0335 void quitWaitingLoop(); 0336 void showSideBars(bool visible) override; 0337 void showThumbBar(bool visible) override; 0338 void customizedFullScreenMode(bool set) override; 0339 bool thumbbarVisibility() const override; 0340 void setColorManagedViewIndicatorToolTip(bool available, bool cmv); 0341 void setUnderExposureToolTip(bool uei); 0342 void setOverExposureToolTip(bool oei); 0343 0344 void setToolStartProgress(const QString& toolName); 0345 void setToolProgress(int progress); 0346 void setToolStopProgress(); 0347 0348 void setToolInfoMessage(const QString& txt); 0349 0350 bool startingSaveVersion(const QUrl& url, bool subversion, bool saveAs, const QString& format); 0351 0352 void setPreviewModeMask(int mask); 0353 PreviewToolBar::PreviewMode previewMode() const; 0354 0355 bool showFileSaveDialog(const QUrl& initialUrl, QUrl& newURL); 0356 0357 /** 0358 * Sets up a temp file to save image contents to and updates the saving 0359 * context to use this file 0360 * 0361 * @param url file to save the image to 0362 */ 0363 void setupTempSaveFile(const QUrl& url); 0364 0365 /** 0366 * Sets the format to use in the saving context. Therefore multiple sources 0367 * are used starting with the extension found in the save dialog. 0368 * 0369 * @param filter the filter selected in the dialog 0370 * @param targetUrl target url selected for the file to save 0371 * @return The valid extension which could be found, or a null string 0372 */ 0373 QString selectValidSavingFormat(const QUrl& targetUrl); 0374 0375 void addAction2ContextMenu(const QString& actionName, bool addDisabled = false); 0376 0377 private: 0378 0379 class Private; 0380 Private* const d; 0381 0382 friend class EditorToolIface; 0383 }; 0384 0385 } // namespace Digikam 0386 0387 #endif // DIGIKAM_IMAGE_EDITOR_WINDOW_H