1 /******************************************************************************* 2 ** 3 ** Photivo 4 ** 5 ** Copyright (C) 2012 Bernd Schoeler <brjohn@brother-john.net> 6 ** Copyright (C) 2012 Michael Munzert <mail@mm-log.com> 7 ** 8 ** This file is part of Photivo. 9 ** 10 ** Photivo is free software: you can redistribute it and/or modify 11 ** it under the terms of the GNU General Public License version 3 12 ** as published by the Free Software Foundation. 13 ** 14 ** Photivo is distributed in the hope that it will be useful, 15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 ** GNU General Public License for more details. 18 ** 19 ** You should have received a copy of the GNU General Public License 20 ** along with Photivo. If not, see <http://www.gnu.org/licenses/>. 21 ** 22 *******************************************************************************/ 23 #ifndef PTFILTERBASE_H 24 #define PTFILTERBASE_H 25 26 #include "ptFilterConfig.h" 27 #include "ptTempFilterBase.h" 28 #include <QObject> 29 #include <QList> 30 #include <QVariant> 31 #include <QFlags> 32 #include <QLabel> 33 #include <QComboBox> 34 #include <QCheckBox> 35 #include <QToolButton> 36 37 class ptImage; 38 class ptWidget; 39 class ptToolBox; 40 class QWidget; 41 class QSettings; 42 43 //------------------------------------------------------------------------------ 44 /*! Base class for all filters. Must not be instantiated directly. */ 45 class ptFilterBase: /*public QObject,*/ public ptTempFilterBase { 46 Q_OBJECT 47 48 public: 49 /*! The TFilterFlag enum describes the capabilites of a filter. 50 The flags determine which entries appear in the toolbox context menu. 51 IMPORTANT: When you change TFilterFlag do not forget to change the default implementation 52 of flags() as well! 53 */ 54 enum TFilterFlag { 55 NoFilterFlags = 0, 56 FilterIsBlockable = 1, 57 FilterHasDefault = 2, 58 FilterIsSaveable = 4, 59 FilterIsFavouriteable = 8, 60 FilterIsHideable = 16, 61 }; 62 63 /*! Standard Qt typedef to make OR combinations of \c TFilterFlag possible. */ 64 typedef QFlags<TFilterFlag> TFilterFlags; 65 66 public: 67 virtual ~ptFilterBase(); //!< Destroys a ptFilterBase object. 68 69 virtual TFilterFlags flags() const; //!< Returns the filter’s capabilities as an OR combination of \c TFilterFlag values. 70 ptToolBox* gui(); //!< Returns the GUI toolbox. 71 72 void exportPreset(QSettings *APreset, const bool AIncludeFlags = true) const; 73 void importPreset(QSettings *APreset, const bool ARequestPipeRun = false); 74 void init(const QString &AUniqueName, const QString &AGuiNamePostfix); 75 void reset(const bool ARequestPipeRun = false); 76 void runFilter(ptImage *AImage); 77 78 79 /*! \name Status getters and setters *//*! @{*/ 80 bool hasActiveCfg() const; 81 bool isActive() const; 82 bool isBlocked() const; 83 bool setBlocked(const bool AIsBlocked); 84 bool isHidden() const; 85 bool setHidden(const bool AIsHidden); 86 /*! @}*/ 87 88 /*! \name Other getters and setters *//*! @{*/ 89 QString caption() const; //!< \see init() 90 bool hasHelp() const; //!< Returns \c true if the filter has a help URL. 91 QString helpUri() const; //!< Valid URL to the help page for this filter on photivo.org. 92 bool isFavourite() const; //!< Returns \c true when the filter is in the favourites list, \c false otherwise. 93 bool setFavourite(bool AIsFavourite); //!< Adds or removes the filter from the list of favourites. 94 bool isSlow() const; //!< If \c true the toolbox header will get an icon marking the filter as computationally expensive. 95 int idxInParentTab() const; //!< \see init() 96 int parentTabIdx() const; //!< \see init() 97 void setPos(int ATab, int AIdx); //!< Sets the filter’s position in the pipe 98 QString uniqueName() const; //!< Returns the filter’s unique name. 99 /*! @}*/ 100 101 /*! Deprecated! These functions are strictly for compatibility with old ptGroupBox specific code. 102 Will disappear once the old groupbox system is gone. DO NOT USE except for said compatibility 103 stuff. You have been warned! *//*! @{*/ 104 QWidget* guiWidget(); 105 bool canHide() const; 106 /*! @}*/ 107 108 signals: 109 void activityChanged(); //!< Emitted whenever the filter’s isActive() status changes. 110 111 protected: 112 static ptWidget* createWidgetByType(const ptCfgItem &ACfgItem, QWidget *AParent); 113 114 protected: 115 ptFilterBase(); //!< Ctor is only usable by derived classes. 116 117 bool checkActiveChanged(const bool ANoSignal = false); 118 void connectCommonDispatch(); 119 int cfgIdx(const QString &AId) const; 120 void initDesignerGui(QWidget *AGuiBody); 121 void internalInit(); 122 ptWidget* findPtWidget(const QString &AId, QWidget* AWidget); 123 void requestPipeRun(const bool AUnconditional = false); 124 void updateGui(const bool ARequestPipeRun = true); 125 126 // Pragmas are here to stop the compiler complaining about unused parameters in the default 127 // implementations. Removing the parameter names would work too but be too obscure. 128 #pragma GCC diagnostic push 129 #pragma GCC diagnostic ignored "-Wunused-parameter" doAfterInit()130 virtual void doAfterInit() {} doCreateGui()131 virtual QWidget *doCreateGui() { return nullptr; } //!< Derived classes must reimplement this method when they use a custom GUI layout, e.g. created via an .ui file. The result has to be \c true if a gui is created. 132 virtual bool doCheckHasActiveCfg() = 0; //!< Determines if the filter is active in the pipe. Derived classes should reimplement this function to determine the activity status of the filter. doExportCustomConfig(QSettings * APreset,const bool AIncludeFlags)133 virtual void doExportCustomConfig(QSettings *APreset, const bool AIncludeFlags) const {} doImportCustomConfig(QSettings * APreset)134 virtual void doImportCustomConfig(QSettings *APreset) {} doUpdateGui()135 virtual void doUpdateGui() {} //!< Update for the children. 136 virtual void doRunFilter(ptImage *AImage) = 0; //!< Children should do the work. doReset()137 virtual void doReset() {} //!< Reset for the children 138 virtual void doDefineControls() = 0; //!< Children know which controls they need. 139 #pragma GCC diagnostic pop 140 141 ptFilterConfig FConfig; 142 QString FFilterName; 143 QString FCaption; 144 QString FHelpUri; 145 bool FHasActiveCfg; 146 bool FIsSlow; 147 ptToolBox* FGuiContainer; 148 149 protected slots: 150 void commonDispatch(const QString AId, const QVariant ANewValue); 151 152 private: 153 void performCommonConnect(const ptCfgItem &ACfgItem, QObject *AObject); 154 void createGui(); 155 156 QString FUniqueName; 157 QString FCaptionPostfix; 158 bool FIsActive; 159 int FParentTabIdx; 160 int FIdxInParentTab; 161 bool FIsBlocked; 162 bool FPreventPipeRun; 163 }; 164 165 //------------------------------------------------------------------------------ 166 167 /*! Qt macro that defines \c operator|() for \c TFilterFlags. */ 168 Q_DECLARE_OPERATORS_FOR_FLAGS(ptFilterBase::TFilterFlags) 169 170 /*! \typedef ptFilterFactoryMethod 171 Type to encapsulate the function pointers to the static factory classes. */ 172 typedef ptFilterBase* (*ptFilterFactoryMethod)(); 173 174 /*! \class RegisterHelper 175 Just a little helper to get the registering done automatically. */ 176 class RegisterHelper { 177 public: 178 RegisterHelper(const ptFilterFactoryMethod AMethod, 179 const QString AName); ~RegisterHelper()180 ~RegisterHelper() {} 181 }; 182 183 //============================================================================== 184 185 #endif // PTFILTERBASE_H 186