"Fossies" - the Fresh Open Source Software Archive

Member "rawtherapee-5.7/rtgui/history.cc" (10 Sep 2019, 15202 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 "history.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  *  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 #include "history.h"
   20 
   21 #include "eventmapper.h"
   22 #include "guiutils.h"
   23 #include "multilangmgr.h"
   24 #include "rtimage.h"
   25 
   26 #include "../rtengine/procparams.h"
   27 
   28 using namespace rtengine;
   29 using namespace rtengine::procparams;
   30 
   31 
   32 History::History (bool bookmarkSupport) : historyVPaned(nullptr), blistener(nullptr), tpc (nullptr), bmnum (1)
   33 {
   34 
   35     blistenerLock = false; // sets default that the Before preview will not be locked
   36     // History List
   37     // ~~~~~~~~~~~~
   38     Gtk::ScrolledWindow* hscrollw = Gtk::manage (new Gtk::ScrolledWindow ());
   39     hscrollw->set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
   40 
   41     Gtk::Frame* histFrame = Gtk::manage (new Gtk::Frame (M("HISTORY_LABEL")));
   42     histFrame->set_name ("HistoryPanel");
   43     histFrame->add (*hscrollw);
   44 
   45     hTreeView = Gtk::manage (new Gtk::TreeView ());
   46     hscrollw->add (*hTreeView);
   47 
   48     historyModel = Gtk::ListStore::create (historyColumns);
   49     hTreeView->set_model (historyModel);
   50     hTreeView->set_headers_visible (false);
   51     hTreeView->set_hscroll_policy(Gtk::SCROLL_MINIMUM);
   52     hTreeView->set_vscroll_policy(Gtk::SCROLL_NATURAL);
   53     hTreeView->set_size_request(80, -1);
   54 
   55     Gtk::CellRendererText *changecrt = Gtk::manage (new Gtk::CellRendererText());
   56     changecrt->property_ellipsize() = Pango::ELLIPSIZE_END;
   57     Gtk::CellRendererText *valuecrt  = Gtk::manage (new Gtk::CellRendererText());
   58     valuecrt->property_ellipsize() = Pango::ELLIPSIZE_END;
   59     Gtk::TreeView::Column *hviewcol = Gtk::manage (new Gtk::TreeView::Column (""));
   60     hviewcol->pack_start (*changecrt, true);
   61     hviewcol->add_attribute (changecrt->property_markup (), historyColumns.text);
   62     hviewcol->set_expand(true);
   63     hviewcol->set_resizable (true);
   64     hviewcol->set_fixed_width(35);
   65     hviewcol->set_min_width(35);
   66     hviewcol->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
   67 
   68     Gtk::TreeView::Column *hviewcol2 = Gtk::manage (new Gtk::TreeView::Column (""));
   69     hviewcol2->pack_start (*valuecrt, true);
   70     hviewcol2->add_attribute (valuecrt->property_markup (), historyColumns.value);
   71     hviewcol2->set_expand(true);
   72     hviewcol2->set_resizable(true);
   73     hviewcol2->set_fixed_width(35);
   74     hviewcol2->set_min_width(35);
   75     hviewcol2->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
   76     valuecrt->set_alignment(1.f, 0.f);
   77 
   78     hTreeView->set_has_tooltip(true);
   79     hTreeView->signal_query_tooltip().connect( sigc::mem_fun(*this, &History::on_query_tooltip) );
   80     hTreeView->append_column (*hviewcol);
   81     hTreeView->append_column (*hviewcol2);
   82 
   83     selchangehist = hTreeView->get_selection()->signal_changed().connect(sigc::mem_fun(*this, &History::historySelectionChanged));
   84 
   85     // Bookmark List
   86     // ~~~~~~~~~~~~~
   87 
   88     Gtk::HBox* ahbox = Gtk::manage (new Gtk::HBox ());
   89     addBookmark = Gtk::manage (new Gtk::Button ());  // M("HISTORY_NEWSNAPSHOT")
   90     setExpandAlignProperties(addBookmark, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_START);
   91     //addBookmark->get_style_context()->set_junction_sides(Gtk::JUNCTION_RIGHT);
   92     addBookmark->get_style_context()->add_class("Left");
   93     addBookmark->set_tooltip_markup (M("HISTORY_NEWSNAPSHOT_TOOLTIP"));
   94     Gtk::Image* addimg = Gtk::manage (new RTImage ("add-small.png"));
   95     addBookmark->set_image (*addimg);
   96     ahbox->pack_start (*addBookmark);
   97 
   98     delBookmark = Gtk::manage (new Gtk::Button ());  // M("HISTORY_DELSNAPSHOT")
   99     setExpandAlignProperties(delBookmark, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_START);
  100     //delBookmark->get_style_context()->set_junction_sides(Gtk::JUNCTION_LEFT);
  101     delBookmark->get_style_context()->add_class("Right");
  102     Gtk::Image* delimg = Gtk::manage (new RTImage ("remove-small.png"));
  103     delBookmark->set_image (*delimg);
  104     ahbox->pack_start (*delBookmark);
  105 
  106     bscrollw = Gtk::manage (new Gtk::ScrolledWindow ());
  107 //    bscrollw->set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
  108     bscrollw->set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
  109     bscrollw->set_size_request (-1, 45);
  110 
  111     Gtk::Frame* bmFrame = Gtk::manage (new Gtk::Frame (M("HISTORY_SNAPSHOTS")));
  112     bmFrame->set_name("Snapshots");
  113     Gtk::VBox* bmBox = Gtk::manage (new Gtk::VBox ());
  114     bmFrame->add (*bmBox);
  115     bmBox->pack_start (*bscrollw, Gtk::PACK_EXPAND_WIDGET, 4);
  116     bmBox->pack_end (*ahbox, Gtk::PACK_SHRINK, 4);
  117     bmBox->set_size_request(-1,60);
  118 
  119     if (bookmarkSupport) {
  120         historyVPaned = Gtk::manage ( new Gtk::VPaned () );
  121         historyVPaned->pack1 (*histFrame, true, true);
  122         historyVPaned->pack2 (*bmFrame, false, false);
  123         pack_start(*historyVPaned);
  124     } else {
  125         pack_start (*histFrame);
  126     }
  127 
  128 
  129     bTreeView = Gtk::manage (new Gtk::TreeView ());
  130     bscrollw->add (*bTreeView);
  131 
  132     bookmarkModel = Gtk::ListStore::create (bookmarkColumns);
  133     bTreeView->set_model (bookmarkModel);
  134     bTreeView->set_headers_visible (false);
  135     bTreeView->append_column_editable (M("HISTORY_SNAPSHOTS"), bookmarkColumns.text);
  136 
  137     selchangebm = bTreeView->get_selection()->signal_changed().connect(sigc::mem_fun(*this, &History::bookmarkSelectionChanged));
  138 
  139     addBookmark->signal_clicked().connect( sigc::mem_fun(*this, &History::addBookmarkPressed) );
  140     delBookmark->signal_clicked().connect( sigc::mem_fun(*this, &History::delBookmarkPressed) );
  141 
  142     //hTreeView->set_grid_lines (Gtk::TREE_VIEW_GRID_LINES_HORIZONTAL);
  143     hTreeView->set_grid_lines (Gtk::TREE_VIEW_GRID_LINES_BOTH);
  144     //hTreeView->signal_size_allocate().connect( sigc::mem_fun(*this, &History::resized) );
  145 
  146     hTreeView->set_enable_search(false);
  147     bTreeView->set_enable_search(false);
  148 
  149     show_all_children ();
  150 }
  151 
  152 void History::initHistory ()
  153 {
  154 
  155     ConnectionBlocker selBlocker(selchangehist);
  156     historyModel->clear ();
  157     bookmarkModel->clear ();
  158 }
  159 
  160 void History::historySelectionChanged ()
  161 {
  162 
  163     Glib::RefPtr<Gtk::TreeSelection> selection = hTreeView->get_selection();
  164     Gtk::TreeModel::iterator iter = selection->get_selected();
  165 
  166     if (iter) {
  167         Gtk::TreeModel::Row row = *iter;
  168 
  169         if (row) {
  170             bTreeView->get_selection()->unselect_all ();
  171         }
  172 
  173         if (row && tpc) {
  174             ProcParams pparams = row[historyColumns.params];
  175             ParamsEdited pe(true);
  176             PartialProfile pp(&pparams, &pe);
  177             ParamsEdited paramsEdited = row[historyColumns.paramsEdited];
  178             tpc->profileChange (&pp, EvHistoryBrowsed, row[historyColumns.text], &paramsEdited);
  179         }
  180 
  181         if (blistener && !blistenerLock) {
  182             Gtk::TreeModel::Path path = historyModel->get_path (iter);
  183             path.prev ();
  184             iter = historyModel->get_iter (path);
  185 
  186             if (blistener && iter) {
  187                 blistener->historyBeforeLineChanged (iter->get_value (historyColumns.params));
  188             }
  189         }
  190     }
  191 }
  192 
  193 void History::bookmarkSelectionChanged ()
  194 {
  195 
  196     Glib::RefPtr<Gtk::TreeSelection> selection = bTreeView->get_selection();
  197     Gtk::TreeModel::iterator iter = selection->get_selected();
  198 
  199     if (iter) {
  200         Gtk::TreeModel::Row row = *iter;
  201 
  202         if (row) {
  203             hTreeView->get_selection()->unselect_all ();
  204         }
  205 
  206         if (row && tpc) {
  207             ProcParams pparams = row[bookmarkColumns.params];
  208             ParamsEdited pe(true);
  209             PartialProfile pp(&pparams, &pe);
  210             ParamsEdited paramsEdited = row[bookmarkColumns.paramsEdited];
  211             tpc->profileChange (&pp, EvBookmarkSelected, row[bookmarkColumns.text], &paramsEdited);
  212         }
  213     }
  214 }
  215 
  216 void History::procParamsChanged(
  217     const ProcParams* params,
  218     const ProcEvent& ev,
  219     const Glib::ustring& descr,
  220     const ParamsEdited* paramsEdited
  221 )
  222 {
  223     // to prevent recursion, we filter out the events triggered by the history and events that should not be registered
  224     if (ev == EvHistoryBrowsed || ev == EvMonitorTransform) {
  225         return;
  226     }
  227 
  228     selchangehist.block(true);
  229     selchangebm.block(true);
  230 
  231     if (ev == EvPhotoLoaded) {
  232         initHistory();
  233     }
  234 
  235     // construct formatted list content
  236 
  237     Glib::RefPtr<Gtk::TreeSelection> selection = hTreeView->get_selection();
  238     Gtk::TreeModel::iterator iter = selection->get_selected();
  239 
  240     // remove all rows after the selection
  241     if (iter) {
  242         ++iter;
  243 
  244         while (iter) {
  245             iter = historyModel->erase(iter);
  246         }
  247     }
  248 
  249     // lookup the last remaining item in the list
  250     const int size = historyModel->children().size();
  251     Gtk::TreeModel::Row row;
  252 
  253     if (size > 0) {
  254         row = historyModel->children()[size - 1];
  255     }
  256 
  257     // if there is no last item or its chev!=ev, create a new one
  258     if (size == 0 || !row || row[historyColumns.chev] != ev || ev == EvProfileChanged) {
  259         Gtk::TreeModel::Row newrow = *(historyModel->append());
  260         newrow[historyColumns.text] = ProcEventMapper::getInstance()->getHistoryMsg(ev);
  261         newrow[historyColumns.value] = g_markup_escape_text(descr.c_str(), -1);
  262         newrow[historyColumns.chev] = ev;
  263         newrow[historyColumns.params] = *params;
  264         newrow[historyColumns.paramsEdited] = paramsEdited ? *paramsEdited : defParamsEdited;
  265 
  266         if (ev != EvBookmarkSelected) {
  267             selection->select(newrow);
  268         }
  269 
  270         if (blistener && row && !blistenerLock) {
  271             blistener->historyBeforeLineChanged(row[historyColumns.params]);
  272         } else if (blistener && size == 0 && !blistenerLock) {
  273             blistener->historyBeforeLineChanged(newrow[historyColumns.params]);
  274         }
  275     } else { // else just update it
  276         row[historyColumns.value] = g_markup_escape_text(descr.c_str(), -1);
  277         row[historyColumns.params] = *params;
  278         row[historyColumns.paramsEdited] = paramsEdited ? *paramsEdited : defParamsEdited;
  279 
  280         if (ev != EvBookmarkSelected) {
  281             selection->select(row);
  282         }
  283     }
  284 
  285     if (ev != EvBookmarkSelected) {
  286         bTreeView->get_selection()->unselect_all();
  287     }
  288 
  289 
  290     if (!selection->get_selected_rows().empty()) {
  291         std::vector<Gtk::TreeModel::Path> selp = selection->get_selected_rows();
  292         hTreeView->scroll_to_row(*selp.begin());
  293     }
  294 
  295     selchangehist.block(false);
  296     selchangebm.block(false);
  297 }
  298 
  299 void History::clearParamChanges ()
  300 {
  301     initHistory ();
  302 }
  303 
  304 void History::addBookmarkWithText (Glib::ustring text)
  305 {
  306 
  307     // lookup the selected item in the history
  308     Glib::RefPtr<Gtk::TreeSelection> selection = hTreeView->get_selection();
  309     Gtk::TreeModel::iterator iter = selection->get_selected();
  310     Gtk::TreeModel::Row row = *iter;
  311 
  312     if (!row) {
  313         return;
  314     }
  315 
  316     // append new row to bookmarks
  317     Gtk::TreeModel::Row newrow = *(bookmarkModel->append());
  318     newrow[bookmarkColumns.text] = text;
  319     ProcParams params = row[historyColumns.params];
  320     newrow[bookmarkColumns.params] = params;
  321     ParamsEdited paramsEdited = row[historyColumns.paramsEdited];
  322     newrow[bookmarkColumns.paramsEdited] = paramsEdited;
  323 }
  324 
  325 void History::addBookmarkPressed ()
  326 {
  327 
  328     if (hTreeView->get_selection()->get_selected()) {
  329         addBookmarkWithText (Glib::ustring::compose ("%1 %2", M("HISTORY_SNAPSHOT"), bmnum++));
  330     }
  331 }
  332 
  333 void History::delBookmarkPressed ()
  334 {
  335 
  336     // lookup the selected item in the bookmark
  337     Glib::RefPtr<Gtk::TreeSelection> selection = bTreeView->get_selection();
  338     Gtk::TreeModel::iterator iter = selection->get_selected();
  339 
  340     if (!iter) {
  341         return;
  342     }
  343 
  344     // remove selected bookmark
  345     bookmarkModel->erase (iter);
  346     // select last item in history
  347     int size = historyModel->children().size ();
  348     Gtk::TreeModel::Row row = historyModel->children()[size - 1];
  349     hTreeView->get_selection()->select (row);
  350 }
  351 
  352 void History::undo ()
  353 {
  354 
  355     Glib::RefPtr<Gtk::TreeSelection> selection = hTreeView->get_selection();
  356     Gtk::TreeModel::iterator iter = selection->get_selected();
  357 
  358     if (iter && iter != historyModel->children().begin()) {
  359         selection->select (--iter);
  360     } else if (!iter) {
  361         int size = historyModel->children().size ();
  362 
  363         if (size > 1) {
  364             selection->select (historyModel->children().operator [](size - 2));
  365         }
  366     }
  367 }
  368 
  369 void History::redo ()
  370 {
  371 
  372     Glib::RefPtr<Gtk::TreeSelection> selection = hTreeView->get_selection();
  373     Gtk::TreeModel::iterator iter = selection->get_selected();
  374 
  375     if (iter) {
  376         ++iter;
  377 
  378         if (iter != historyModel->children().end()) {
  379             selection->select (iter);
  380         }
  381     } else {
  382         int size = historyModel->children().size ();
  383 
  384         if (size > 1) {
  385             selection->select (historyModel->children().operator [](size - 2));
  386         }
  387     }
  388 }
  389 
  390 /*
  391 void History::resized (Gtk::Allocation& req)
  392 {
  393 }
  394 */
  395 
  396 bool History::getBeforeLineParams (rtengine::procparams::ProcParams& params)
  397 {
  398 
  399     int size = historyModel->children().size ();
  400 
  401     if (size == 0 || !blistener) {
  402         return false;
  403     }
  404 
  405     Gtk::TreeModel::Row row;
  406     row = historyModel->children()[size == 1 ? 0 : size - 2];
  407     params = row[historyColumns.params];
  408     return true;
  409 }
  410 
  411 bool History::on_query_tooltip(int x, int y, bool keyboard_tooltip, const Glib::RefPtr<Gtk::Tooltip>& tooltip) {
  412     bool displayTooltip = false;
  413 
  414     Gtk::TreeModel::Path path;
  415     int x2 = -1;
  416     int y2 = -1;
  417     hTreeView->convert_widget_to_bin_window_coords(x, y, x2, y2);
  418     bool hasPath = hTreeView->get_path_at_pos(x2, y2, path);
  419 
  420     if (hasPath) {
  421         if (path && !path.empty()) {
  422             Gtk::TreeModel::iterator iter = historyModel->get_iter(path);
  423             if (iter) {
  424                 Glib::ustring text, val;
  425                 iter->get_value<Glib::ustring>(0, text);
  426                 iter->get_value<Glib::ustring>(1, val);
  427 
  428                 /*
  429                  *
  430                  *
  431                  * Why this doesn't work ???
  432                  *
  433                  *
  434                  *
  435                 Gtk::Label *left = Gtk::manage (new Gtk::Label(param+" :"));
  436                 Gtk::Label *right = Gtk::manage (new Gtk::Label(val));
  437                 right->set_justify(Gtk::JUSTIFY_LEFT);
  438                 Gtk::HBox *hbox = Gtk::manage (new Gtk::HBox());
  439                 hbox->set_spacing(5);
  440                 hbox->pack_start(*left, Gtk::PACK_SHRINK, 0);
  441                 hbox->pack_start(*right, Gtk::PACK_SHRINK, 0);
  442                 tooltip->set_custom(*hbox);
  443                 */
  444 
  445                 tooltip->set_text(text + " : " + val);
  446                 displayTooltip = true;
  447             }
  448         }
  449     }
  450     return displayTooltip;
  451 }