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