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 "zoompanel.h"
20 #include "multilangmgr.h"
21 #include "imagearea.h"
22 #include "rtimage.h"
23 
ZoomPanel(ImageArea * iarea)24 ZoomPanel::ZoomPanel (ImageArea* iarea) : iarea(iarea)
25 {
26     set_name ("EditorZoomPanel");
27 
28     Gtk::Image* imageOut = Gtk::manage (new RTImage ("magnifier-minus.png"));
29     imageOut->set_padding(0, 0);
30     Gtk::Image* imageIn = Gtk::manage (new RTImage ("magnifier-plus.png"));
31     imageIn->set_padding(0, 0);
32     Gtk::Image* image11 = Gtk::manage ( new RTImage ("magnifier-1to1.png"));
33     image11->set_padding(0, 0);
34     Gtk::Image* imageFit = Gtk::manage (new RTImage ("magnifier-fit.png"));
35     imageFit->set_padding(0, 0);
36     Gtk::Image* imageFitCrop = Gtk::manage (new RTImage ("magnifier-crop.png"));
37     imageFit->set_padding(0, 0);
38 
39     zoomOut = Gtk::manage (new Gtk::Button());
40     zoomOut->add (*imageOut);
41     zoomOut->set_relief(Gtk::RELIEF_NONE);
42     setExpandAlignProperties(zoomOut, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_FILL);
43     zoomIn = Gtk::manage (new Gtk::Button());
44     zoomIn->add (*imageIn);
45     zoomIn->set_relief(Gtk::RELIEF_NONE);
46     setExpandAlignProperties(zoomIn, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_FILL);
47     zoomFit = Gtk::manage (new Gtk::Button());
48     zoomFit->add (*imageFit);
49     zoomFit->set_relief(Gtk::RELIEF_NONE);
50     setExpandAlignProperties(zoomFit, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_FILL);
51     zoomFitCrop = Gtk::manage (new Gtk::Button());
52     zoomFitCrop->add (*imageFitCrop);
53     zoomFitCrop->set_relief(Gtk::RELIEF_NONE);
54     setExpandAlignProperties(zoomFitCrop, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_FILL);
55     zoom11 = Gtk::manage (new Gtk::Button());
56     zoom11->add (*image11);
57     zoom11->set_relief(Gtk::RELIEF_NONE);
58     setExpandAlignProperties(zoom11, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_FILL);
59 
60     attach_next_to (*zoomOut, Gtk::POS_RIGHT, 1, 1);
61     attach_next_to (*zoomIn, Gtk::POS_RIGHT, 1, 1);
62     attach_next_to (*zoomFit, Gtk::POS_RIGHT, 1, 1);
63     attach_next_to (*zoomFitCrop, Gtk::POS_RIGHT, 1, 1);
64     attach_next_to (*zoom11, Gtk::POS_RIGHT, 1, 1);
65 
66     zoomLabel = Gtk::manage (new Gtk::Label ());
67     setExpandAlignProperties(zoomLabel, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_FILL);
68     attach_next_to (*zoomLabel, Gtk::POS_RIGHT, 1, 1);
69 
70     Gtk::Image* imageCrop = Gtk::manage (new RTImage ("window-add.png"));
71     imageCrop->set_padding(0, 0);
72     newCrop = Gtk::manage (new Gtk::Button());
73     newCrop->add (*imageCrop);
74     newCrop->set_relief(Gtk::RELIEF_NONE);
75     setExpandAlignProperties(newCrop, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_FILL);
76     attach_next_to (*newCrop, Gtk::POS_RIGHT, 1, 1);
77 
78     show_all_children ();
79 
80     zoomIn->signal_clicked().connect ( sigc::mem_fun(*this, &ZoomPanel::zoomInClicked) );
81     zoomOut->signal_clicked().connect( sigc::mem_fun(*this, &ZoomPanel::zoomOutClicked) );
82     zoomFit->signal_clicked().connect( sigc::mem_fun(*this, &ZoomPanel::zoomFitClicked) );
83     zoomFitCrop->signal_clicked().connect( sigc::mem_fun(*this, &ZoomPanel::zoomFitCropClicked) );
84     zoom11->signal_clicked().connect ( sigc::mem_fun(*this, &ZoomPanel::zoom11Clicked) );
85     newCrop->signal_clicked().connect ( sigc::mem_fun(*this, &ZoomPanel::newCropClicked) );
86 
87     zoomIn->set_tooltip_markup (M("ZOOMPANEL_ZOOMIN"));
88     zoomOut->set_tooltip_markup (M("ZOOMPANEL_ZOOMOUT"));
89     zoom11->set_tooltip_markup (M("ZOOMPANEL_ZOOM100"));
90     zoomFit->set_tooltip_markup (M("ZOOMPANEL_ZOOMFITSCREEN"));
91     zoomFitCrop->set_tooltip_markup (M("ZOOMPANEL_ZOOMFITCROPSCREEN"));
92     newCrop->set_tooltip_markup (M("ZOOMPANEL_NEWCROPWINDOW"));
93 
94     zoomLabel->set_text (M("ZOOMPANEL_100"));
95 }
96 
zoomInClicked()97 void ZoomPanel::zoomInClicked ()
98 {
99 
100     if (iarea->mainCropWindow) {
101         iarea->mainCropWindow->zoomIn ();
102     }
103 }
104 
zoomOutClicked()105 void ZoomPanel::zoomOutClicked ()
106 {
107 
108     if (iarea->mainCropWindow) {
109         iarea->mainCropWindow->zoomOut ();
110     }
111 }
112 
zoomFitClicked()113 void ZoomPanel::zoomFitClicked ()
114 {
115 
116     if (iarea->mainCropWindow) {
117         iarea->mainCropWindow->zoomFit ();
118     }
119 }
120 
zoomFitCropClicked()121 void ZoomPanel::zoomFitCropClicked ()
122 {
123 
124     if (iarea->mainCropWindow) {
125         iarea->mainCropWindow->zoomFitCrop ();
126     }
127 }
128 
zoom11Clicked()129 void ZoomPanel::zoom11Clicked ()
130 {
131 
132     if (iarea->mainCropWindow) {
133         iarea->mainCropWindow->zoom11 ();
134     }
135 }
136 
refreshZoomLabel()137 void ZoomPanel::refreshZoomLabel ()
138 {
139 
140     if (iarea->mainCropWindow) {
141         int z = (int)(iarea->mainCropWindow->getZoom () * 100);
142 
143         if (z < 100) {
144             zoomLabel->set_text (Glib::ustring::compose(" %1%%", z));
145         } else {
146             zoomLabel->set_text (Glib::ustring::compose("%1%%", z));
147         }
148     }
149 }
150 
newCropClicked()151 void ZoomPanel::newCropClicked ()
152 {
153 
154     iarea->addCropWindow ();
155 }
156