1 /******************************************************************************* 2 ** 3 ** Photivo 4 ** 5 ** Copyright (C) 2008 Jos De Laender <jos.de_laender@telenet.be> 6 ** Copyright (C) 2010 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 24 #ifndef DLSETTINGS_H 25 #define DLSETTINGS_H 26 27 #include "ptConstants.h" 28 #include "ptGuiOptions.h" 29 #include "ptInput.h" 30 #include "ptChoice.h" 31 #include "ptCheck.h" 32 33 #include <QtCore> 34 #include <QComboBox> 35 #include <QToolButton> 36 #include <QCheckBox> 37 #include <QLabel> 38 39 //============================================================================== 40 41 class ptDcRaw; 42 43 //////////////////////////////////////////////////////////////////////////////// 44 // 45 // ptSettingItem 46 // Description of any setting. 47 // Gui elements will be attached and handled via the setting. 48 // Remark that one never will use this class directly but only 49 // via its friend class ptSettings. So nothing public. 50 // 51 //////////////////////////////////////////////////////////////////////////////// 52 53 // Some forward declarations. 54 struct ptGuiInputItem; 55 struct ptGuiChoiceItem; 56 struct ptGuiCheckItem; 57 struct ptItem; 58 59 class ptSettingItem { 60 // All will be accessed via ptSettings 61 friend class ptSettings; 62 63 short InitLevel; // the smaller, the longer coming from ini fle 64 QVariant DefaultValue; // Give always one. Maybe nonsensical. 65 QVariant Value; 66 short InJobFile; // Should be in job file ? 67 short GuiType; // Associated gui type 68 short HasDefaultValue; // For gui : is the default sensical. 69 // Remainder is gui related stuff. 70 QVariant MinimumValue; 71 QVariant MaximumValue; 72 QVariant Step; 73 short NrDecimals; 74 QString Label; 75 QString ToolTip; 76 const ptGuiOptionsItem * InitialOptions; // For choice (combo) gui elements. 77 78 // Reference to the associated Gui stuff 79 ptInput* GuiInput; 80 ptChoice* GuiChoice; 81 ptCheck* GuiCheck; 82 83 // Constructor of an item : 84 // Make sure non QVariants all have sensible defaults. ptSettingsItem()85 void ptSettingsItem() { 86 InitLevel = 9; // Never reached. 87 InJobFile = 0; 88 GuiType = ptGT_None; 89 HasDefaultValue = 0; 90 NrDecimals = 0; 91 InitialOptions = NULL; 92 GuiInput = NULL; 93 GuiCheck = NULL; 94 GuiChoice = NULL; 95 } 96 }; // End ptSettingItem class. 97 98 99 //////////////////////////////////////////////////////////////////////////////// 100 // 101 // ptSettings 102 // This class finally works on underlying ptSettingItem, which 103 // are shielded. All access and changes via this one. 104 // 105 //////////////////////////////////////////////////////////////////////////////// 106 107 class ptSettings { 108 Q_DECLARE_TR_FUNCTIONS(ptSettings) 109 110 //------------------------------------- 111 112 private: 113 // We have this private section on top for being able 114 // referring to m_Hash already during declaration of class. 115 // Hash with the items. 116 QHash <QString,ptSettingItem*> m_Hash; 117 118 //------------------------------------- 119 120 public: 121 // First of all a number of simple accessors to the ptSettingItem 122 // characterized by 'Key' GetKeys()123 const QStringList GetKeys() { return m_Hash.keys(); } GetGuiType(const QString Key)124 short GetGuiType(const QString Key) { return m_Hash[Key]->GuiType;} GetHasDefaultValue(const QString Key)125 short GetHasDefaultValue(const QString Key) { return m_Hash[Key]->HasDefaultValue;} GetDefaultValue(const QString Key)126 const QVariant GetDefaultValue(const QString Key) { return m_Hash[Key]->DefaultValue;} GetMinimumValue(const QString Key)127 const QVariant GetMinimumValue(const QString Key) { return m_Hash[Key]->MinimumValue;} GetMaximumValue(const QString Key)128 const QVariant GetMaximumValue(const QString Key) { return m_Hash[Key]->MaximumValue;} GetStep(const QString Key)129 const QVariant GetStep(const QString Key) { return m_Hash[Key]->Step;} GetNrDecimals(const QString Key)130 short GetNrDecimals(const QString Key) { return m_Hash[Key]->NrDecimals;} GetLabel(const QString Key)131 const QString GetLabel(const QString Key) { return m_Hash[Key]->Label;} GetToolTip(const QString Key)132 const QString GetToolTip(const QString Key) { return m_Hash[Key]->ToolTip;} GetInitialOptions(const QString Key)133 const ptGuiOptionsItem* GetInitialOptions(const QString Key) { return m_Hash[Key]->InitialOptions;} GetInJobFile(const QString Key)134 short GetInJobFile(const QString Key) { return m_Hash[Key]->InJobFile;} 135 136 // Low level access to the underlying QWidget 137 QWidget* GetGuiWidget(const QString Key); 138 139 // Constructor 140 // The InitLevel determines how much of the .ini information is preserved. 141 // If InitLevel > InitLevelOfItem the initialization of that Item is 142 // preserved from the .ini. 143 // So ptSettings(0) would keep no setting at all. As InitLevelOfItem > 0. 144 // If InitLevelOfItem = 9 then the item will never be initialized from 145 // the .ini as InitLevel<9 (asserted). 146 ptSettings(const short InitLevel, const QString Path); 147 148 // Destructor 149 ~ptSettings(); 150 151 // Accessors to the Value part of a setting. 152 // Selfexplaining. 153 int GetInt(const QString Key) const; 154 double GetDouble(const QString Key) const; 155 const QString GetString(const QString Key) const; 156 const QStringList GetStringList(const QString Key) const; 157 // This should be avoided as much as possible and replaced by above. 158 // It is needed though, for instance while writing a job file. 159 const QVariant GetValue(const QString Key) const; 160 161 // Setting of value. Implies update for gui element, if one. 162 void SetValue(const QString Key, const QVariant Value); 163 // Other selfexplaining settings. Make only sense for gui elements. 164 void SetEnabled(const QString Key, const short Enabled); 165 void SetMaximum(const QString Key, const QVariant Maximum); 166 void Show(const QString Key, const short Show); 167 168 // Some accessors by GuiName 169 QString ToolGetName (const QString GuiName) const; 170 int ToolAlwaysVisible(const QString GuiName) const; 171 int ToolIsActive (const QString GuiName) const; 172 int ToolIsBlocked (const QString GuiName) const; 173 int ToolIsHidden (const QString GuiName) const; 174 175 // Methods specific for choice (combo) type of gui elements. 176 177 // Keeps Value unique in the choice. 178 void AddOrReplaceOption(const QString Key, 179 const QString Text, 180 const QVariant Value); 181 void ClearOptions(const QString Key, const short WithDefault = 0); 182 int GetNrOptions(const QString Key); 183 // Value of the combobox at a certain index position. 184 const QVariant GetOptionsValue(const QString Key, const int Index); 185 // Current text of the combobox. 186 const QString GetCurrentText(const QString Key); 187 188 // Following are only used by ptMainWindow when inserting 189 // the gui elements in the ptMainWindow. They provide an access 190 // to one of the underlying gui elements. 191 void SetGuiInput(const QString Key, ptInput* Input); 192 void SetGuiChoice(const QString Key, ptChoice* Choice); 193 void SetGuiCheck(const QString Key, ptCheck* Check); 194 195 // Interface to update the settings to/from dcraw 196 void ToDcRaw(ptDcRaw* TheDcRaw); 197 void FromDcRaw(ptDcRaw* TheDcRaw); 198 199 // Helper function to decide, if we start with a bitmap or a RAW 200 bool useRAWHandling() const; 201 202 // Persistent Settings. Initialization code in ptMain 203 // will access it directly. 204 QSettings* m_IniSettings; 205 }; // end class ptSettings 206 207 // And we will instantiate one toplevel. 208 extern ptSettings* Settings; 209 210 //////////////////////////////////////////////////////////////////////////////// 211 // 212 // ptGui*Item 213 // Initial description (from .i files) of items. 214 // 215 //////////////////////////////////////////////////////////////////////////////// 216 217 // Initial description of a numerical input gui element. 218 struct ptGuiInputItem { 219 QString KeyName; 220 short GuiType; 221 short InitLevel; 222 short InJobFile; 223 short HasDefaultValue; 224 QVariant DefaultValue; 225 QVariant MinimumValue; 226 QVariant MaximumValue; 227 QVariant Step; 228 short NrDecimals; 229 QString Label; 230 QString ToolTip; 231 }; 232 233 // Initial description of a choice (combobox) input gui element. 234 struct ptGuiChoiceItem { 235 QString KeyName; 236 short GuiType; 237 short InitLevel; 238 short InJobFile; 239 short HasDefaultValue; 240 QVariant DefaultValue; 241 const ptGuiOptionsItem* InitialOptions; 242 QString ToolTip; 243 }; 244 245 // Initial description of a check input gui element. 246 struct ptGuiCheckItem { 247 QString KeyName; 248 short GuiType; 249 short InitLevel; 250 short InJobFile; 251 QVariant DefaultValue; 252 QString Label; 253 QString ToolTip; 254 }; 255 256 // Initial description of a simple setting element. 257 struct ptItem { 258 QString KeyName; 259 short InitLevel; 260 QVariant DefaultValue; 261 short InJobFile; 262 }; 263 264 #endif 265 266 //////////////////////////////////////////////////////////////////////////////// 267