1 /* 2 * This file is part of RawTherapee. 3 * 4 * Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com> 5 * 6 * RawTherapee is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * RawTherapee is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with RawTherapee. If not, see <https://www.gnu.org/licenses/>. 18 */ 19 #pragma once 20 21 #include <gtkmm.h> 22 23 #include <glibmm/ustring.h> 24 25 #include "guiutils.h" 26 #include "multilangmgr.h" 27 #include "paramsedited.h" 28 29 #include "../rtengine/noncopyable.h" 30 #include "../rtengine/rtengine.h" 31 32 namespace rtengine 33 { 34 class ProcEvent; 35 36 namespace procparams 37 { 38 39 class ProcParams; 40 } 41 } 42 43 class ToolPanelListener 44 { 45 public: 46 virtual ~ToolPanelListener() = default; 47 virtual void panelChanged(const rtengine::ProcEvent& event, const Glib::ustring& descr) = 0; 48 }; 49 50 /// @brief This class control the space around the group of tools inside a tab, as well as the space separating each tool. */ 51 class ToolVBox : 52 public Gtk::VBox 53 { 54 public: 55 ToolVBox(); 56 }; 57 58 /// @brief This class control the space around a tool's block of parameter. */ 59 class ToolParamBlock : 60 public Gtk::VBox 61 { 62 public: 63 ToolParamBlock(); 64 }; 65 66 class ToolPanel : 67 public rtengine::NonCopyable 68 { 69 70 protected: 71 Glib::ustring toolName; 72 ToolPanelListener* listener; 73 ToolPanelListener* tmp; 74 bool batchMode; // True if the ToolPanel is used in Batch mode 75 bool multiImage; // True if more than one image are being edited at the same time (also imply that batchMode=true), false otherwise 76 bool need100Percent; 77 78 public: 79 toolName(toolName)80 ToolPanel (Glib::ustring toolName = "", bool need11 = false) : toolName(toolName), listener(nullptr), tmp(nullptr), batchMode(false), multiImage(false), need100Percent(need11) {} ~ToolPanel()81 virtual ~ToolPanel() {} 82 setParent(Gtk::Box * parent)83 virtual void setParent (Gtk::Box* parent) {} getParent()84 virtual Gtk::Box* getParent () 85 { 86 return nullptr; 87 } getExpander()88 virtual MyExpander* getExpander () 89 { 90 return nullptr; 91 } setExpanded(bool expanded)92 virtual void setExpanded (bool expanded) {} getExpanded()93 virtual bool getExpanded () 94 { 95 return false; 96 } setMultiImage(bool m)97 void setMultiImage (bool m) 98 { 99 multiImage = m; 100 } setListener(ToolPanelListener * tpl)101 virtual void setListener (ToolPanelListener* tpl) 102 { 103 listener = tpl; 104 } setEditProvider(EditDataProvider * provider)105 virtual void setEditProvider (EditDataProvider *provider) {} 106 virtual void read (const rtengine::procparams::ProcParams* pp, const ParamsEdited* pedited = nullptr) {} 107 virtual void write (rtengine::procparams::ProcParams* pp, ParamsEdited* pedited = nullptr) {} trimValues(rtengine::procparams::ProcParams * pp)108 virtual void trimValues (rtengine::procparams::ProcParams* pp) 109 { 110 return; 111 } 112 virtual void setDefaults (const rtengine::procparams::ProcParams* defParams, const ParamsEdited* pedited = nullptr) {} autoOpenCurve()113 virtual void autoOpenCurve () {} 114 115 /** @brief Disable the event broadcasting mechanism 116 * 117 * @return Return the previous state of the broadcast (true: enabled ; false: disabled) 118 */ disableListener()119 bool disableListener () 120 { 121 if (tmp == nullptr) { 122 tmp = listener; 123 } 124 125 bool prevState = listener != nullptr; 126 listener = nullptr; 127 return prevState; 128 } 129 130 /** @brief Enable the event broadcasting mechanism 131 */ enableListener()132 void enableListener () 133 { 134 if (tmp != nullptr) { 135 listener = tmp; 136 } 137 138 tmp = nullptr; 139 } 140 setBatchMode(bool batchMode)141 virtual void setBatchMode (bool batchMode) 142 { 143 this->batchMode = batchMode; 144 } 145 getToolName()146 virtual Glib::ustring getToolName () { 147 return toolName; 148 } 149 }; 150 151 class FoldableToolPanel : 152 public ToolPanel 153 { 154 155 protected: 156 Gtk::Box* parentContainer; 157 MyExpander* exp; 158 bool lastEnabled; 159 sigc::connection enaConn; 160 void foldThemAll (GdkEventButton* event); 161 void enabled_toggled(); 162 163 public: 164 165 FoldableToolPanel(Gtk::Box* content, Glib::ustring toolName, Glib::ustring UILabel, bool need11 = false, bool useEnabled = false); 166 getExpander()167 MyExpander* getExpander() override 168 { 169 return exp; 170 } setExpanded(bool expanded)171 void setExpanded (bool expanded) override 172 { 173 if (exp) { 174 exp->set_expanded( expanded ); 175 } 176 } 177 hide()178 void hide() { 179 if (exp && !batchMode) { // conditional hide 180 exp->hide(); 181 } 182 } 183 show()184 void show() { 185 if (exp) { // always show 186 exp->show(); 187 } 188 } getExpanded()189 bool getExpanded () override 190 { 191 if (exp) { 192 return exp->get_expanded(); 193 } 194 195 return false; 196 } setParent(Gtk::Box * parent)197 void setParent (Gtk::Box* parent) override 198 { 199 parentContainer = parent; 200 } getParent()201 Gtk::Box* getParent () override 202 { 203 return parentContainer; 204 } 205 enabledChanged()206 virtual void enabledChanged () {} 207 getUseEnabled()208 bool getUseEnabled () 209 { 210 if (exp) { 211 return exp->getUseEnabled(); 212 } else { 213 return true; 214 } 215 } 216 bool getEnabled(); // related to the enabled/disabled state 217 void setEnabled(bool isActive); // related to the enabled/disabled state 218 void setEnabledTooltipMarkup(Glib::ustring tooltipMarkup); 219 void setEnabledTooltipText(Glib::ustring tooltipText); 220 bool get_inconsistent(); // related to the enabled/disabled state 221 void set_inconsistent(bool isInconsistent); // related to the enabled/disabled state 222 void setGrayedOut(bool doGrayOut); // Set whether the tool should be disabled, collapsed and grayed-out. 223 224 void setLevel (int level); 225 226 // Functions that want to receive an enabled/disabled event from this class 227 // will have to receive it from MyExpander directly, we do not create 228 // a relaying event signal_enabled_toggled()229 MyExpander::type_signal_enabled_toggled signal_enabled_toggled() 230 { 231 return exp->signal_enabled_toggled(); 232 } 233 }; 234