Merge branch 'dev' into review-idle_register-calls

This commit is contained in:
Flössie
2018-12-31 14:58:26 +01:00
420 changed files with 15921 additions and 16795 deletions

View File

@@ -50,12 +50,29 @@ bool notifyListenerUI(Crop* self)
return false;
}
inline void get_custom_ratio(int w, int h, double &rw, double &rh)
{
if (w < h) {
double r = double(h) / double(w);
int rr = r * 100 + 0.5;
rw = 1.0;
rh = rr / 100.0;
} else {
double r = double(w) / double(h);
int rr = r * 100 + 0.5;
rw = rr / 100.0;
rh = 1.0;
}
}
} // namespace
Crop::Crop():
FoldableToolPanel(this, "crop", M("TP_CROP_LABEL"), false, true),
crop_ratios{
{M("GENERAL_ASIMAGE"), 0.0},
{M("GENERAL_CURRENT"), -1.0},
{"3:2", 3.0 / 2.0}, // L1.5, P0.666...
{"4:3", 4.0 / 3.0}, // L1.333..., P0.75
{"16:9", 16.0 / 9.0}, // L1.777..., P0.5625
@@ -97,89 +114,141 @@ Crop::Crop():
maxw = 3000;
maxh = 2000;
Gtk::HBox* hb1 = Gtk::manage (new Gtk::HBox ());
methodgrid = Gtk::manage(new Gtk::Grid());
methodgrid->get_style_context()->add_class("grid-spacing");
setExpandAlignProperties(methodgrid, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_CENTER);
hb1->pack_start (*Gtk::manage (new Gtk::Label (Glib::ustring(" ") + M("TP_CROP_X") + ": ")));
Gtk::Label* xlab = Gtk::manage (new Gtk::Label (M("TP_CROP_X") + ":"));
setExpandAlignProperties(xlab, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
x = Gtk::manage (new MySpinButton ());
x->set_size_request (60, -1);
hb1->pack_start (*x);
setExpandAlignProperties(x, true, false, Gtk::ALIGN_END, Gtk::ALIGN_CENTER);
x->set_width_chars(6);
hb1->pack_start (*Gtk::manage (new Gtk::Label (Glib::ustring(" ") + M("TP_CROP_Y") + ": ")));
Gtk::Label* ylab = Gtk::manage (new Gtk::Label (M("TP_CROP_Y") + ":"));
setExpandAlignProperties(ylab, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
y = Gtk::manage (new MySpinButton ());
y->set_size_request (60, -1);
hb1->pack_start (*y);
pack_start (*hb1, Gtk::PACK_SHRINK, 2);
Gtk::HBox* hb2 = Gtk::manage (new Gtk::HBox ());
hb2->pack_start (*Gtk::manage (new Gtk::Label (M("TP_CROP_W") + ": ")));
setExpandAlignProperties(y, true, false, Gtk::ALIGN_END, Gtk::ALIGN_CENTER);
y->set_width_chars(6);
Gtk::Label* wlab = Gtk::manage (new Gtk::Label (M("TP_CROP_W") + ":"));
setExpandAlignProperties(wlab, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
w = Gtk::manage (new MySpinButton ());
w->set_size_request (60, -1);
hb2->pack_start (*w);
setExpandAlignProperties(w, true, false, Gtk::ALIGN_END, Gtk::ALIGN_CENTER);
w->set_width_chars(6);
hb2->pack_start (*Gtk::manage (new Gtk::Label (M("TP_CROP_H") + ": ")));
Gtk::Label* hlab = Gtk::manage (new Gtk::Label (M("TP_CROP_H") + ":"));
setExpandAlignProperties(hlab, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
h = Gtk::manage (new MySpinButton ());
h->set_size_request (60, -1);
hb2->pack_start (*h);
pack_start (*hb2, Gtk::PACK_SHRINK, 4);
setExpandAlignProperties(h, true, false, Gtk::ALIGN_END, Gtk::ALIGN_CENTER);
h->set_width_chars(6);
selectCrop = Gtk::manage (new Gtk::Button (M("TP_CROP_SELECTCROP")));
setExpandAlignProperties(selectCrop, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_CENTER);
selectCrop->get_style_context()->add_class("independent");
selectCrop->set_image (*Gtk::manage (new RTImage ("crop-small.png")));
pack_start (*selectCrop, Gtk::PACK_SHRINK, 2);
resetCrop = Gtk::manage (new Gtk::Button (M("TP_CROP_RESETCROP")));
setExpandAlignProperties(resetCrop, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_CENTER);
resetCrop->get_style_context()->add_class("independent");
resetCrop->set_image (*Gtk::manage (new RTImage ("undo-small.png")));
methodgrid->attach (*xlab, 0, 0, 1, 1);
methodgrid->attach (*x, 1, 0, 1, 1);
methodgrid->attach (*ylab, 2, 0, 1, 1);
methodgrid->attach (*y, 3, 0, 1, 1);
methodgrid->attach (*wlab, 0, 1, 1, 1);
methodgrid->attach (*w, 1, 1, 1, 1);
methodgrid->attach (*hlab, 2, 1, 1, 1);
methodgrid->attach (*h, 3, 1, 1, 1);
methodgrid->attach (*selectCrop, 0, 2, 2, 1);
methodgrid->attach (*resetCrop, 2, 2, 2, 1);
pack_start (*methodgrid, Gtk::PACK_EXPAND_WIDGET, 0 );
Gtk::HSeparator* methodseparator = Gtk::manage (new Gtk::HSeparator());
methodseparator->get_style_context()->add_class("grid-row-separator");
pack_start (*methodseparator, Gtk::PACK_SHRINK, 0);
Gtk::HBox* hb3 = Gtk::manage (new Gtk::HBox ());
Gtk::Grid* settingsgrid = Gtk::manage(new Gtk::Grid());
settingsgrid->get_style_context()->add_class("grid-spacing");
setExpandAlignProperties(settingsgrid, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_CENTER);
fixr = Gtk::manage (new Gtk::CheckButton (M("TP_CROP_FIXRATIO")));
setExpandAlignProperties(fixr, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
fixr->set_active (1);
hb3->pack_start (*fixr, Gtk::PACK_SHRINK, 4);
Gtk::Grid* ratiogrid = Gtk::manage(new Gtk::Grid());
ratiogrid->get_style_context()->add_class("grid-spacing");
setExpandAlignProperties(ratiogrid, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_CENTER);
ratio = Gtk::manage (new MyComboBoxText ());
hb3->pack_start (*ratio, Gtk::PACK_EXPAND_WIDGET, 4);
setExpandAlignProperties(ratio, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_CENTER);
orientation = Gtk::manage (new MyComboBoxText ());
hb3->pack_start (*orientation);
setExpandAlignProperties(orientation, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_CENTER);
pack_start (*hb3, Gtk::PACK_SHRINK, 4);
Gtk::HBox* hb31 = Gtk::manage (new Gtk::HBox ());
hb31->pack_start (*Gtk::manage (new Gtk::Label (M("TP_CROP_GUIDETYPE"))), Gtk::PACK_SHRINK, 4);
customRatioLabel = Gtk::manage(new Gtk::Label(""));
customRatioLabel->hide();
setExpandAlignProperties(customRatioLabel, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER);
ratiogrid->set_column_homogeneous (true);
ratiogrid->attach (*ratio, 0, 0, 1, 1);
ratiogrid->attach (*customRatioLabel, 1, 0, 1, 1);
ratiogrid->attach (*orientation, 1, 0, 1, 1);
Gtk::Label* guidelab = Gtk::manage (new Gtk::Label (M("TP_CROP_GUIDETYPE")));
setExpandAlignProperties(guidelab, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
guide = Gtk::manage (new MyComboBoxText ());
hb31->pack_start (*guide);
setExpandAlignProperties(guide, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_CENTER);
pack_start (*hb31, Gtk::PACK_SHRINK, 4);
settingsgrid->attach (*fixr, 0, 0, 1, 1);
settingsgrid->attach (*ratiogrid, 1, 0, 1, 1);
settingsgrid->attach (*guidelab, 0, 1, 1, 1);
settingsgrid->attach (*guide, 1, 1, 1, 1);
pack_start (*settingsgrid, Gtk::PACK_SHRINK, 0 );
// ppibox START
ppibox = Gtk::manage (new Gtk::VBox());
ppibox->pack_start (*Gtk::manage (new Gtk::HSeparator()), Gtk::PACK_SHRINK, 2);
Gtk::HBox* hb4 = Gtk::manage (new Gtk::HBox ());
hb4->pack_start (*Gtk::manage (new Gtk::Label (M("TP_CROP_PPI"))));
// ppigrid START
ppigrid = Gtk::manage(new Gtk::Grid());
ppigrid->get_style_context()->add_class("grid-spacing");
ppigrid->set_column_homogeneous (true);
setExpandAlignProperties(ppigrid, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_CENTER);
Gtk::HSeparator* ppiseparator = Gtk::manage (new Gtk::HSeparator());
ppiseparator->get_style_context()->add_class("grid-row-separator");
Gtk::Grid* ppisubgrid = Gtk::manage(new Gtk::Grid());
ppisubgrid->get_style_context()->add_class("grid-spacing");
setExpandAlignProperties(ppisubgrid, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_CENTER);
Gtk::Label* ppilab = Gtk::manage (new Gtk::Label (M("TP_CROP_PPI")));
setExpandAlignProperties(ppilab, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
ppi = Gtk::manage (new MySpinButton ());
ppi->set_size_request (60, -1);
hb4->pack_start (*ppi);
sizebox = Gtk::manage (new Gtk::VBox());
setExpandAlignProperties(ppi, true, false, Gtk::ALIGN_END, Gtk::ALIGN_CENTER);
ppi->set_width_chars(6);
ppisubgrid->attach (*ppilab, 0, 0, 1, 1);
ppisubgrid->attach (*ppi, 1, 0, 1, 1);
sizecm = Gtk::manage (new Gtk::Label (M("GENERAL_NA") + " cm x " + M("GENERAL_NA") + " cm"));
setExpandAlignProperties(sizecm, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER);
sizein = Gtk::manage (new Gtk::Label (M("GENERAL_NA") + " in x " + M("GENERAL_NA") + " in"));
sizebox->pack_start (*sizecm, Gtk::PACK_SHRINK, 4);
sizebox->pack_start (*Gtk::manage (new Gtk::HSeparator()), Gtk::PACK_SHRINK, 6);
sizebox->pack_start (*sizein, Gtk::PACK_SHRINK, 4);
sizebox->pack_start (*Gtk::manage (new Gtk::HSeparator()), Gtk::PACK_SHRINK, 6);
sizebox->pack_start (*hb4, Gtk::PACK_SHRINK, 2);
ppibox->pack_start (*sizebox, Gtk::PACK_SHRINK, 1);
pack_start (*ppibox, Gtk::PACK_SHRINK, 0);
setExpandAlignProperties(sizein, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER);
ppigrid->attach (*ppiseparator, 0, 0, 2, 1);
ppigrid->attach (*sizecm, 1, 1, 1, 1);
ppigrid->attach (*sizein, 1, 2, 1, 1);
ppigrid->attach (*ppisubgrid, 0, 1, 1, 2);
pack_start (*ppigrid, Gtk::PACK_SHRINK, 0 );
ppi->set_value (300);
// ppibox END
// ppigrid END
// Populate the combobox
for (const auto& crop_ratio : crop_ratios) {
@@ -239,10 +308,25 @@ Crop::Crop():
oconn = orientation->signal_changed().connect( sigc::mem_fun(*this, &Crop::ratioChanged) );
gconn = guide->signal_changed().connect( sigc::mem_fun(*this, &Crop::notifyListener) );
selectCrop->signal_pressed().connect( sigc::mem_fun(*this, &Crop::selectPressed) );
resetCrop->signal_pressed().connect( sigc::mem_fun(*this, &Crop::doresetCrop) );
ppi->signal_value_changed().connect( sigc::mem_fun(*this, &Crop::refreshSize) );
nx = ny = nw = nh = 0;
lastRotationDeg = 0;
//GTK318
#if GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION < 20
methodgrid->set_row_spacing(4);
methodgrid->set_column_spacing(4);
settingsgrid->set_row_spacing(4);
settingsgrid->set_column_spacing(4);
ppigrid->set_row_spacing(4);
ppigrid->set_column_spacing(4);
ppisubgrid->set_row_spacing(4);
ppisubgrid->set_column_spacing(4);
#endif
//GTK318
show_all ();
}
@@ -292,13 +376,6 @@ void Crop::read (const ProcParams* pp, const ParamsEdited* pedited)
setDimensions (pp->crop.x + pp->crop.w, pp->crop.y + pp->crop.h);
}
if (pp->crop.ratio == "As Image") {
ratio->set_active(0);
} else {
ratio->set_active_text (pp->crop.ratio);
}
fixr->set_active (pp->crop.fixratio);
const bool flip_orientation = pp->crop.fixratio && crop_ratios[ratio->get_active_row_number()].value > 0 && crop_ratios[ratio->get_active_row_number()].value < 1.0;
if (pp->crop.orientation == "Landscape") {
@@ -339,6 +416,20 @@ void Crop::read (const ProcParams* pp, const ParamsEdited* pedited)
nw = pp->crop.w;
nh = pp->crop.h;
customRatioLabel->hide();
orientation->show();
if (pp->crop.ratio == "As Image") {
ratio->set_active(0);
} else if (pp->crop.ratio == "Current") {
ratio->set_active(1);
updateCurrentRatio();
customRatioLabel->show();
orientation->hide();
} else {
ratio->set_active_text (pp->crop.ratio);
}
fixr->set_active (pp->crop.fixratio);
lastRotationDeg = pp->coarse.rotate;
wDirty = false;
@@ -391,7 +482,13 @@ void Crop::write (ProcParams* pp, ParamsEdited* pedited)
pp->crop.w = nw;
pp->crop.h = nh;
pp->crop.fixratio = fixr->get_active ();
pp->crop.ratio = ratio->get_active_text ();
if (ratio->get_active_row_number() == 0) {
pp->crop.ratio = "As Image";
} else if (ratio->get_active_row_number() == 1) {
pp->crop.ratio = "Current";
} else {
pp->crop.ratio = ratio->get_active_text ();
}
// for historical reasons we store orientation different if ratio is written as 2:3 instead of 3:2, but in GUI 'landscape' is always long side horizontal regardless of the ratio is written short or long side first.
const bool flip_orientation = fixr->get_active() && crop_ratios[ratio->get_active_row_number()].value > 0 && crop_ratios[ratio->get_active_row_number()].value < 1.0;
@@ -480,6 +577,23 @@ void Crop::selectPressed ()
}
}
void Crop::doresetCrop ()
{
xDirty = true;
yDirty = true;
wDirty = true;
hDirty = true;
int X = 0;
int Y = 0;
int W = maxw;
int H = maxh;
cropResized (X, Y, W, H);
idle_register.add<Crop>(notifyListenerUI, this, false);
refreshSpins();
}
void Crop::notifyListener ()
{
@@ -625,6 +739,15 @@ void Crop::ratioFixedChanged ()
// change to orientation or ration
void Crop::ratioChanged ()
{
if (ratio->get_active_row_number() == 1) {
orientation->hide();
updateCurrentRatio();
customRatioLabel->show();
} else {
orientation->show();
customRatioLabel->hide();
}
if (!fixr->get_active ()) {
fixr->set_active(true); // will adjust ratio anyway
} else {
@@ -636,18 +759,51 @@ void Crop::ratioChanged ()
void Crop::adjustCropToRatio()
{
if (fixr->get_active() && !fixr->get_inconsistent()) {
int W1 = nw, W2 = nw;
int H1 = nh, H2 = nh;
int X1 = nx, X2 = nx;
int Y1 = ny, Y2 = ny;
// int W = w->get_value ();
// int H = h->get_value ();
int W = nw;
int H = nh;
int X = nx;
int Y = ny;
float r = getRatio();
if (W >= H) {
cropWidth2Resized (X, Y, W, H);
H1 = round(W1 / r);
Y1 = ny + (nh - H1)/2.0;
if (Y1 < 0) {
Y1 = 0;
}
if (H1 > maxh) {
H1 = maxh;
W1 = round(H1 * r);
X1 = nx + (nw - W1)/2.0;
}
if (Y1+H1 > maxh) {
Y1 = maxh - H1;
}
W2 = round(H2 * r);
X2 = nx + (nw - W2)/2.0;
if (X2 < 0) {
X2 = 0;
}
if (W2 > maxw) {
W2 = maxw;
H2 = round(W2 / r);
Y2 = ny + (nh - H2)/2.0;
}
if (X2+W2 > maxw) {
X2 = maxw - W2;
}
if (W1 * H1 >= W2 * H2) {
nx = X1;
ny = Y1;
nw = W1;
nh = H1;
} else {
cropHeight2Resized (X, Y, W, H);
nx = X2;
ny = Y2;
nw = W2;
nh = H2;
}
}
@@ -771,6 +927,10 @@ bool Crop::refreshSpins (bool notify)
wconn.block (false);
hconn.block (false);
if (ratio->get_active_row_number() == 1 && !fixr->get_active()) {
updateCurrentRatio();
}
refreshSize ();
if (notify) {
@@ -1292,5 +1452,16 @@ void Crop::setBatchMode (bool batchMode)
ratio->append (M("GENERAL_UNCHANGED"));
orientation->append (M("GENERAL_UNCHANGED"));
guide->append (M("GENERAL_UNCHANGED"));
removeIfThere (this, ppibox);
removeIfThere (this, ppigrid);
removeIfThere (methodgrid, selectCrop);
removeIfThere (methodgrid, resetCrop);
}
void Crop::updateCurrentRatio()
{
double rw, rh;
get_custom_ratio(w->get_value(), h->get_value(), rw, rh);
customRatioLabel->set_text(Glib::ustring::compose("%1:%2", rw, rh));
crop_ratios[1].value = double(w->get_value())/double(h->get_value());
}