rawTherapee/rtgui/adjuster.cc
natureh aff832f721 Batch editor's sliders behaves better and easier to code for the developper :
- if only one file is selected, all sliders are in SET mode
- if more than one file is selected, the ADD/SET mode depend on the preference

The range of the slider in ADD mode is now twice the range of the same slider in SET mode, so you'll be able to reach the total range for each image at each session. Overflows are correctly handled.

I've added more sliders in the preference window (the one that are not listed behave in SET mode, like before). It's also easier to code for the developper, as the Adjuster class now handle the "add" booleans, instead of each tools. But it's still spreaded all over the code :-/

Furthermore, when clicking on the reset button of a slider, it now reset to the system default value ; resetting to the value of the loaded profil can still be done with CTRL+click on the reset button. This behavior is available in the Editors and in the Batch Editor if only one file is selected.
2011-06-15 22:57:05 +02:00

341 lines
9.3 KiB
C++

/*
* This file is part of RawTherapee.
*
* Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
*
* RawTherapee is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RawTherapee is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <adjuster.h>
#include <sigc++/class_slot.h>
#include <math.h>
#include <multilangmgr.h>
#include <rtengine.h>
#include <options.h>
extern Glib::ustring argv0;
Adjuster::Adjuster (Glib::ustring vlabel, double vmin, double vmax, double vstep, double vdefault, bool editedcb) {
adjusterListener = NULL;
afterReset = false;
blocked = false;
vMin = vmin;
vMax = vmax;
vStep = vstep;
initialDefaultVal = vdefault;
addMode = false;
// TODO: let the user chose the default value of Adjuster::delay, for slow machines
delay = options.adjusterDelay; // delay is no more static, so we can set the delay individually (usefull for the RAW editor tab)
set_border_width (2);
hbox = Gtk::manage (new Gtk::HBox ());
label = Gtk::manage (new Gtk::Label (vlabel, Gtk::ALIGN_LEFT));
if (editedcb) {
editedCheckBox = Gtk::manage (new Gtk::CheckButton ());
editedChange = editedCheckBox->signal_toggled().connect( sigc::mem_fun(*this, &Adjuster::editedToggled) );
hbox->pack_start (*editedCheckBox);
}
else
editedCheckBox = NULL;
hbox->pack_start (*label);
reset = Gtk::manage (new Gtk::Button ());
reset->add (*Gtk::manage (new Gtk::Image (argv0+"/images/undo.png")));
reset->set_relief (Gtk::RELIEF_NONE);
reset->set_border_width (0);
reset->set_tooltip_text (M("ADJUSTER_RESET_TO_DEFAULT"));
hbox->pack_end (*reset, Gtk::PACK_SHRINK, 0);
spin = Gtk::manage (new Gtk::SpinButton ());
spin->set_size_request (70, -1);
hbox->pack_end (*spin, Gtk::PACK_SHRINK, 0);
reset->set_size_request (-1, spin->get_height());
slider = Gtk::manage (new Gtk::HScale ());
slider->set_draw_value (false);
pack_start (*hbox, false, false);
pack_start (*slider, false, false);
setLimits (vmin, vmax, vstep, vdefault);
defaultVal = shapeValue (vdefault);
initialDefaultVal = shapeValue (vdefault);
editedState = defEditedState = Irrelevant;
sliderChange = slider->signal_value_changed().connect( sigc::mem_fun(*this, &Adjuster::sliderChanged) );
spinChange = spin->signal_value_changed().connect ( sigc::mem_fun(*this, &Adjuster::spinChanged), true);
reset->signal_button_release_event().connect_notify( sigc::mem_fun(*this, &Adjuster::resetPressed) );
slider->set_update_policy (Gtk::UPDATE_CONTINUOUS);
show_all ();
}
Adjuster::~Adjuster () {
sliderChange.block (true);
spinChange.block (true);
delayConnection.block (true);
adjusterListener = NULL;
}
void Adjuster::setDefault (double def) {
defaultVal = shapeValue (def);
}
void Adjuster::setDefaultEditedState (EditedState eState) {
defEditedState = eState;
}
void Adjuster::resetPressed (GdkEventButton* event) {
if (editedState!=Irrelevant) {
editedState = defEditedState;
if (editedCheckBox) {
editedChange.block (true);
editedCheckBox->set_active (defEditedState==Edited);
editedChange.block (false);
}
refreshLabelStyle ();
}
afterReset = true;
if ((event != NULL) && (event->state & GDK_CONTROL_MASK) && (event->button == 1))
// CTRL pressed : resetting to current default value
slider->set_value (defaultVal);
else
// no modifier key or addMode=true : resetting to initial default value
slider->set_value (initialDefaultVal);
}
double Adjuster::shapeValue (double a) {
return round(a*pow(double(10), digits)) / pow(double(10), digits);
}
void Adjuster::setLimits (double vmin, double vmax, double vstep, double vdefault) {
sliderChange.block (true);
spinChange.block (true);
for (digits=0; fabs(vstep*pow(double(10),digits)-floor(vstep*pow(double(10),digits)))>0.000000000001; digits++);
spin->set_digits (digits);
spin->set_increments (vstep, 2.0*vstep);
spin->set_range (vmin, vmax);
spin->set_value (shapeValue(vdefault));
slider->set_digits (digits);
slider->set_increments (vstep, 2.0*vstep);
slider->set_range (vmin, vmax);
slider->set_value (shapeValue(vdefault));
//defaultVal = shapeValue (vdefault);
sliderChange.block (false);
spinChange.block (false);
}
void Adjuster::setAddMode(bool addM) {
if (addM != addMode) {
// Switching the Adjuster to the new mode
if (addM) {
// Switching to the relative mode
double range = -vMin + vMax;
if (range < 0.) range = -range;
setLimits(-range, range, vStep, 0);
}
else {
// Switching to the absolute mode
setLimits(vMin, vMax, vStep, defaultVal);
}
addMode = addM;
}
}
void Adjuster::setAdjusterListener (AdjusterListener* alistener) {
adjusterListener = alistener;
}
void Adjuster::spinChanged () {
sliderChange.block (true);
slider->set_value (spin->get_value ());
sliderChange.block (false);
if (delay==0) {
if (adjusterListener!=NULL && !blocked)
adjusterListener->adjusterChanged (this, spin->get_value ());
}
else
Glib::signal_idle().connect (sigc::mem_fun(*this, &Adjuster::notifyListener));
if (editedState==UnEdited) {
editedState = Edited;
if (editedCheckBox) {
editedChange.block (true);
editedCheckBox->set_active (true);
editedChange.block (false);
}
refreshLabelStyle ();
}
afterReset = false;
}
void Adjuster::sliderChanged () {
if (delayConnection.connected())
delayConnection.disconnect ();
spinChange.block (true);
spin->set_value (slider->get_value ());
spinChange.block (false);
if (delay==0) {
if (adjusterListener && !blocked)
adjusterListener->adjusterChanged (this, spin->get_value ());
}
else
delayConnection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &Adjuster::notifyListener), delay);
if (!afterReset && editedState==UnEdited) {
editedState = Edited;
if (editedCheckBox) {
editedChange.block (true);
editedCheckBox->set_active (true);
editedChange.block (false);
}
refreshLabelStyle ();
}
afterReset = false;
}
void Adjuster::setValue (double a) {
spinChange.block (true);
sliderChange.block (true);
spin->set_value (shapeValue (a));
slider->set_value (shapeValue (a));
sliderChange.block (false);
spinChange.block (false);
afterReset = false;
}
// return the value trimmed to the limits at construction time
double Adjuster::getValue () {
return spin->get_value ();
}
// return the value trimmed to the limits at construction time
int Adjuster::getIntValue () {
return spin->get_value_as_int ();
}
// method only used by the history manager
Glib::ustring Adjuster::getTextValue () {
return spin->get_text ();
}
bool Adjuster::notifyListener () {
if (adjusterListener!=NULL && !blocked) {
gdk_threads_enter();
adjusterListener->adjusterChanged (this, spin->get_value ());
gdk_threads_leave();
}
return false;
}
void Adjuster::setEnabled (bool enabled) {
spin->set_sensitive (enabled);
slider->set_sensitive (enabled);
}
void Adjuster::setEditedState (EditedState eState) {
if (editedState!=eState) {
if (editedCheckBox) {
editedChange.block (true);
editedCheckBox->set_active (eState==Edited);
editedChange.block (false);
}
editedState = eState;
refreshLabelStyle ();
}
}
EditedState Adjuster::getEditedState () {
if (editedState!=Irrelevant && editedCheckBox)
editedState = editedCheckBox->get_active () ? Edited : UnEdited;
return editedState;
}
void Adjuster::showEditedCB () {
if (!editedCheckBox) {
editedCheckBox = Gtk::manage(new Gtk::CheckButton ());
hbox->pack_start (*editedCheckBox, Gtk::PACK_SHRINK, 2);
hbox->reorder_child (*editedCheckBox, 0);
editedChange = editedCheckBox->signal_toggled().connect( sigc::mem_fun(*this, &Adjuster::editedToggled) );
}
}
void Adjuster::refreshLabelStyle () {
/* Glib::RefPtr<Gtk::Style> style = label->get_style ();
Pango::FontDescription fd = style->get_font ();
fd.set_weight (editedState==Edited ? Pango::WEIGHT_BOLD : Pango::WEIGHT_NORMAL);
style->set_font (fd);
label->set_style (style);
label->queue_draw ();*/
}
void Adjuster::editedToggled () {
if (adjusterListener && !blocked)
adjusterListener->adjusterChanged (this, spin->get_value ());
}
double Adjuster::trimValue (double& val) {
if (val > vMax) val = vMax; // shapeValue(vMax) ?
else if (val < vMin) val = vMin; // shapeValue(vMin) ?
return val;
}
int Adjuster::trimValue (int& val) {
if (val > (int)vMax) val = (int)vMax; // shapeValue(vMax) ?
else if (val < (int)vMin) val = (int)vMin; // shapeValue(vMin) ?
return val;
}
float Adjuster::trimValue (float& val) {
if (val > (float)vMax) val = (float)vMax; // shapeValue(vMax) ?
else if (val < (float)vMin) val = (float)vMin; // shapeValue(vMin) ?
return val;
}