"Fossies" - the Fresh Open Source Software Archive

Member "rawtherapee-5.7/rtgui/toolbar.cc" (10 Sep 2019, 13213 Bytes) of package /linux/misc/rawtherapee-5.7.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "toolbar.cc" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 5.6_vs_5.7.

    1 
    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 <https://www.gnu.org/licenses/>.
   19  */
   20 #include "toolbar.h"
   21 #include "multilangmgr.h"
   22 #include "guiutils.h"
   23 
   24 ToolBar::ToolBar () : showColPickers(true), listener (nullptr), pickerListener(nullptr)
   25 {
   26 
   27     editingMode = false;
   28 
   29     handimg.reset(new RTImage("hand-open.png"));
   30     editinghandimg.reset(new RTImage("crosshair-adjust.png"));
   31 
   32     handTool = Gtk::manage (new Gtk::ToggleButton ());
   33     handTool->add (*handimg);
   34     handimg->show ();
   35     handTool->set_relief(Gtk::RELIEF_NONE);
   36     handTool->show ();
   37 
   38     pack_start (*handTool);
   39 
   40     wbTool = Gtk::manage (new Gtk::ToggleButton ());
   41     Gtk::Image* wbimg = Gtk::manage (new RTImage ("color-picker.png"));
   42     wbTool->add (*wbimg);
   43     wbimg->show ();
   44     wbTool->set_relief(Gtk::RELIEF_NONE);
   45     wbTool->show ();
   46 
   47     pack_start (*wbTool);
   48 
   49     showcolpickersimg.reset(new RTImage("color-picker-bars.png"));
   50     hidecolpickersimg.reset(new RTImage("color-picker-hide.png"));
   51 
   52     colPickerTool = Gtk::manage (new Gtk::ToggleButton ());
   53     colPickerTool->add (*showcolpickersimg);
   54     showcolpickersimg->show ();
   55     colPickerTool->set_relief(Gtk::RELIEF_NONE);
   56     colPickerTool->show ();
   57 
   58     pack_start (*colPickerTool);
   59 
   60     cropTool = Gtk::manage (new Gtk::ToggleButton ());
   61     Gtk::Image* cropimg = Gtk::manage (new RTImage ("crop.png"));
   62     cropTool->add (*cropimg);
   63     cropimg->show ();
   64     cropTool->set_relief(Gtk::RELIEF_NONE);
   65     cropTool->show ();
   66 
   67     pack_start (*cropTool);
   68 
   69     straTool = Gtk::manage (new Gtk::ToggleButton ());
   70     Gtk::Image* straimg = Gtk::manage (new RTImage ("rotate-straighten.png"));
   71     straTool->add (*straimg);
   72     straimg->show ();
   73     straTool->set_relief(Gtk::RELIEF_NONE);
   74     straTool->show ();
   75 
   76     pack_start (*straTool);
   77 
   78 
   79     handTool->set_active (true);
   80     current = TMHand;
   81     allowNoTool = false;
   82 
   83     handConn = handTool->signal_toggled().connect( sigc::mem_fun(*this, &ToolBar::hand_pressed));
   84     wbConn   = wbTool->signal_toggled().connect( sigc::mem_fun(*this, &ToolBar::wb_pressed));
   85     cpConn   = colPickerTool->signal_button_press_event().connect_notify( sigc::mem_fun(*this, &ToolBar::colPicker_pressed));
   86     cropConn = cropTool->signal_toggled().connect( sigc::mem_fun(*this, &ToolBar::crop_pressed));
   87     straConn = straTool->signal_toggled().connect( sigc::mem_fun(*this, &ToolBar::stra_pressed));
   88 
   89     handTool->set_tooltip_markup (M("TOOLBAR_TOOLTIP_HAND"));
   90     wbTool->set_tooltip_markup (M("TOOLBAR_TOOLTIP_WB"));
   91     colPickerTool->set_tooltip_markup (M("TOOLBAR_TOOLTIP_COLORPICKER"));
   92     cropTool->set_tooltip_markup (M("TOOLBAR_TOOLTIP_CROP"));
   93     straTool->set_tooltip_markup (M("TOOLBAR_TOOLTIP_STRAIGHTEN"));
   94 }
   95 
   96 //
   97 // Selects the desired tool without notifying the listener
   98 //
   99 void ToolBar::setTool (ToolMode tool)
  100 {
  101 
  102     bool stopEdit;
  103 
  104     {
  105     ConnectionBlocker handBlocker(handConn);
  106     ConnectionBlocker straBlocker(straConn);
  107     ConnectionBlocker cropBlocker(cropConn);
  108     ConnectionBlocker wbWasBlocked(wbTool, wbConn), cpWasBlocked(colPickerTool, cpConn);
  109 
  110     stopEdit = tool == TMHand && handTool->get_active() && editingMode;
  111 
  112     handTool->set_active (false);
  113 
  114     if (wbTool) {
  115         wbTool->set_active (false);
  116     }
  117 
  118     cropTool->set_active (false);
  119     straTool->set_active (false);
  120     if (colPickerTool) {
  121         colPickerTool->set_active (false);
  122     }
  123 
  124     if (tool == TMHand) {
  125         handTool->set_active (true);
  126         handTool->grab_focus(); // switch focus to the handTool button
  127     } else if (tool == TMSpotWB) {
  128         if (wbTool) {
  129             wbTool->set_active (true);
  130         }
  131     } else if (tool == TMCropSelect) {
  132         cropTool->set_active (true);
  133     } else if (tool == TMStraighten) {
  134         straTool->set_active (true);
  135     } else if (tool == TMColorPicker) {
  136         if (colPickerTool) {
  137             colPickerTool->set_active (true);
  138         }
  139     }
  140 
  141     current = tool;
  142 
  143     }
  144 
  145     if (stopEdit) {
  146         stopEditMode();
  147 
  148         if (listener) {
  149             listener->editModeSwitchedOff();
  150         }
  151     }
  152 }
  153 
  154 void ToolBar::startEditMode()
  155 {
  156     if (!editingMode) {
  157         {
  158         ConnectionBlocker handBlocker(handConn);
  159         ConnectionBlocker straBlocker(straConn);
  160         ConnectionBlocker cropBlocker(cropConn);
  161         ConnectionBlocker wbWasBlocked(wbTool, wbConn), cpWasBlocked(colPickerTool, cpConn);
  162 
  163         if (current != TMHand) {
  164             if (colPickerTool) {
  165                 colPickerTool->set_active(false);
  166             }
  167             if (wbTool) {
  168                 wbTool->set_active (false);
  169             }
  170 
  171             cropTool->set_active (false);
  172             straTool->set_active (false);
  173             current = TMHand;
  174         }
  175         handTool->set_active (true);
  176 
  177         }
  178 
  179         editingMode = true;
  180         handTool->set_image(*editinghandimg);
  181     }
  182 
  183 #ifndef NDEBUG
  184     else {
  185         printf("Editing mode already active!\n");
  186     }
  187 
  188 #endif
  189 }
  190 
  191 void ToolBar::stopEditMode()
  192 {
  193     if (editingMode) {
  194         editingMode = false;
  195         handTool->set_image(*handimg);
  196     }
  197 }
  198 
  199 void ToolBar::hand_pressed ()
  200 {
  201     {
  202     ConnectionBlocker handBlocker(handConn);
  203     ConnectionBlocker straBlocker(straConn);
  204     ConnectionBlocker cropBlocker(cropConn);
  205     ConnectionBlocker wbWasBlocked(wbTool, wbConn), cpWasBlocked(colPickerTool, cpConn);
  206 
  207     if (editingMode) {
  208         stopEditMode();
  209         if (listener) {
  210             listener->editModeSwitchedOff ();
  211         }
  212     }
  213 
  214     if (colPickerTool) {
  215         colPickerTool->set_active(false);
  216     }
  217     if (wbTool) {
  218         wbTool->set_active (false);
  219     }
  220 
  221     cropTool->set_active (false);
  222     straTool->set_active (false);
  223     handTool->set_active (true);
  224 
  225     if (current != TMHand) {
  226         current = TMHand;
  227     } else if (allowNoTool) {
  228         current = TMNone;
  229         handTool->set_active(false);
  230     }
  231 
  232     }
  233 
  234     if (listener) {
  235         listener->toolSelected (current);
  236     }
  237 }
  238 
  239 void ToolBar::wb_pressed ()
  240 {
  241     {
  242     ConnectionBlocker handBlocker(handConn);
  243     ConnectionBlocker straBlocker(straConn);
  244     ConnectionBlocker cropBlocker(cropConn);
  245     ConnectionBlocker wbWasBlocked(wbTool, wbConn), cpWasBlocked(colPickerTool, cpConn);
  246 
  247     if (current != TMSpotWB) {
  248         if (editingMode) {
  249             stopEditMode();
  250             if (listener) {
  251                 listener->editModeSwitchedOff ();
  252             }
  253         }
  254         handTool->set_active (false);
  255         cropTool->set_active (false);
  256         straTool->set_active (false);
  257         if (colPickerTool) {
  258             colPickerTool->set_active(false);
  259         }
  260         current = TMSpotWB;
  261     }
  262 
  263     if (wbTool) {
  264         wbTool->set_active (true);
  265     }
  266 
  267     }
  268 
  269     if (listener) {
  270         listener->toolSelected (TMSpotWB);
  271     }
  272 }
  273 
  274 void ToolBar::colPicker_pressed (GdkEventButton* event)
  275 {
  276 
  277     if (event->button == 1) {
  278         {
  279         ConnectionBlocker handBlocker(handConn);
  280         ConnectionBlocker straBlocker(straConn);
  281         ConnectionBlocker cropBlocker(cropConn);
  282         ConnectionBlocker wbWasBlocked(wbTool, wbConn);
  283 
  284         cropTool->set_active (false);
  285         if (wbTool) {
  286             wbTool->set_active (false);
  287         }
  288         straTool->set_active (false);
  289 
  290         if (current != TMColorPicker) {
  291             // Disabling all other tools, enabling the Picker tool and entering the "visible pickers" mode
  292             if (editingMode) {
  293                 stopEditMode();
  294                 if (listener) {
  295                     listener->editModeSwitchedOff ();
  296                 }
  297             }
  298             handTool->set_active (false);
  299             showColorPickers(true);
  300             current = TMColorPicker;
  301             if (pickerListener) {
  302                 pickerListener->switchPickerVisibility (showColPickers);
  303             }
  304         } else {
  305             // Disabling the picker tool, enabling the Hand tool and keeping the "visible pickers" mode
  306             handTool->set_active (true);
  307             //colPickerTool->set_active (false);  Done by the standard event handler
  308             current = TMHand;
  309         }
  310 
  311         }
  312 
  313         if (listener) {
  314             listener->toolSelected (current);
  315         }
  316     } else if (event->button == 3) {
  317         if (current == TMColorPicker) {
  318             // Disabling the Picker tool and entering into the "invisible pickers" mode
  319             ConnectionBlocker handBlocker(handConn);
  320             ConnectionBlocker cpWasBlocked(cpConn);
  321             handTool->set_active (true);
  322             colPickerTool->set_active (false);
  323             current = TMHand;
  324             showColorPickers(false);
  325         } else {
  326             // The Picker tool is already disabled, entering into the "invisible pickers" mode
  327             switchColorPickersVisibility();
  328         }
  329         if (pickerListener) {
  330             pickerListener->switchPickerVisibility (showColPickers);
  331         }
  332     }
  333 }
  334 
  335 bool ToolBar::showColorPickers(bool showCP)
  336 {
  337     if (showColPickers != showCP) {
  338         // Inverting the state
  339         colPickerTool->set_image(showCP ? *showcolpickersimg : *hidecolpickersimg);
  340         showColPickers = showCP;
  341         return true;
  342     }
  343 
  344     return false;
  345 }
  346 
  347 void ToolBar::switchColorPickersVisibility()
  348 {
  349     // Inverting the state
  350     showColPickers = !showColPickers;
  351     colPickerTool->set_image(showColPickers ? *showcolpickersimg : *hidecolpickersimg);
  352 }
  353 
  354 void ToolBar::crop_pressed ()
  355 {
  356     {
  357     ConnectionBlocker handBlocker(handConn);
  358     ConnectionBlocker straBlocker(straConn);
  359     ConnectionBlocker cropBlocker(cropConn);
  360     ConnectionBlocker wbWasBlocked(wbTool, wbConn), cpWasBlocked(colPickerTool, cpConn);
  361 
  362     if (editingMode) {
  363         stopEditMode();
  364         if (listener) {
  365             listener->editModeSwitchedOff ();
  366         }
  367     }
  368     handTool->set_active (false);
  369     if (colPickerTool) {
  370         colPickerTool->set_active(false);
  371     }
  372     if (wbTool) {
  373         wbTool->set_active (false);
  374     }
  375 
  376     straTool->set_active (false);
  377     cropTool->set_active (true);
  378 
  379     if (current != TMCropSelect) {
  380         current = TMCropSelect;
  381         cropTool->grab_focus ();
  382     } else if (allowNoTool) {
  383         current = TMNone;
  384         cropTool->set_active(false);
  385     }
  386 
  387     }
  388 
  389     if (listener) {
  390         listener->toolSelected (current);
  391     }
  392 }
  393 
  394 void ToolBar::stra_pressed ()
  395 {
  396     {
  397     ConnectionBlocker handBlocker(handConn);
  398     ConnectionBlocker straBlocker(straConn);
  399     ConnectionBlocker cropBlocker(cropConn);
  400     ConnectionBlocker wbWasBlocked(wbTool, wbConn), cpWasBlocked(colPickerTool, cpConn);
  401 
  402     if (editingMode) {
  403         stopEditMode();
  404         if (listener) {
  405             listener->editModeSwitchedOff ();
  406         }
  407     }
  408     handTool->set_active (false);
  409     if (colPickerTool) {
  410         colPickerTool->set_active(false);
  411     }
  412     if (wbTool) {
  413         wbTool->set_active (false);
  414     }
  415 
  416     cropTool->set_active (false);
  417     straTool->set_active (true);
  418 
  419     if (current != TMStraighten) {
  420         current = TMStraighten;
  421     } else if (allowNoTool) {
  422         current = TMNone;
  423         straTool->set_active(false);
  424     }
  425 
  426     }
  427 
  428     if (listener) {
  429         listener->toolSelected (current);
  430     }
  431 }
  432 
  433 bool ToolBar::handleShortcutKey (GdkEventKey* event)
  434 {
  435 
  436     bool ctrl = event->state & GDK_CONTROL_MASK;
  437     //bool shift = event->state & GDK_SHIFT_MASK;
  438     bool alt = event->state & GDK_MOD1_MASK;
  439 
  440     if (!ctrl && !alt) {
  441         switch(event->keyval) {
  442         case GDK_KEY_w:
  443         case GDK_KEY_W:
  444             if(wbTool) {
  445                 wb_pressed ();
  446                 return true;
  447             }
  448 
  449             return false;
  450 
  451         case GDK_KEY_c:
  452         case GDK_KEY_C:
  453             crop_pressed ();
  454             return true;
  455 
  456         case GDK_KEY_s:
  457         case GDK_KEY_S:
  458             stra_pressed ();
  459             return true;
  460 
  461         case GDK_KEY_h:
  462         case GDK_KEY_H:
  463             hand_pressed ();
  464             return true;
  465         }
  466     } else {
  467         switch (event->keyval) {
  468         }
  469     }
  470 
  471     return false;
  472 }
  473 
  474 void ToolBar::setBatchMode()
  475 {
  476     if (wbTool) {
  477         wbConn.disconnect();
  478         removeIfThere(this, wbTool, false);
  479         wbTool = nullptr;
  480     }
  481     if (colPickerTool) {
  482         cpConn.disconnect();
  483         removeIfThere(this, colPickerTool, false);
  484         colPickerTool = nullptr;
  485     }
  486 
  487     allowNoTool = true;
  488     switch (current) {
  489     case TMHand:
  490         hand_pressed();
  491         break;
  492     case TMCropSelect:
  493         crop_pressed();
  494         break;
  495     case TMStraighten:
  496         stra_pressed();
  497         break;
  498     default:
  499         break;
  500     }
  501 }
  502