Implemented picker in guiutils as class

This commit is contained in:
Dániel Battyányi 2023-07-18 17:39:38 +02:00
parent 9e159bbee0
commit c06ba81a23
2 changed files with 109 additions and 1 deletions

View File

@ -1923,3 +1923,83 @@ void BackBuffer::copySurface(Cairo::RefPtr<Cairo::Context> crDest, Gdk::Rectangl
crDest->fill();
}
}
SpotPicker::SpotPicker(int const defaultValue, Glib::ustring const &buttonKey, Glib::ustring const &buttonTooltip, Glib::ustring const &labelKey) :
Gtk::Grid(),
_associatedVar(defaultValue),
_spotLabel(Gtk::manage(new Gtk::Label(M(labelKey)))),
_spotSizeSetter(Gtk::manage(selecterSetup())),
_spotButton(Gtk::manage(spotButtonTemplate(buttonKey, buttonTooltip)))
{
setExpandAlignProperties(_spotLabel, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
Gtk::Grid* spotSizeHelper(Gtk::manage(new Gtk::Grid()));
spotSizeHelper->set_name("Spot-Size-Helper");
setExpandAlignProperties(spotSizeHelper, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
this->get_style_context()->add_class("grid-spacing");
setExpandAlignProperties(this, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_CENTER);
spotSizeHelper->attach (*_spotSizeSetter, 0, 0, 1, 1);
this->attach (*_spotButton, 0, 0, 1, 1);
this->attach (*_spotLabel, 1, 0, 1, 1);
this->attach (*spotSizeHelper, 2, 0, 1, 1);
_spotSizeSetter->signal_changed().connect( sigc::mem_fun(*this, &SpotPicker::spotSizeChanged));
}
SpotPicker::~SpotPicker()
{
}
MyComboBoxText* SpotPicker::selecterSetup()
{
MyComboBoxText* spotSize(new MyComboBoxText ());
setExpandAlignProperties(spotSize, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_CENTER);
spotSize->append ("2");
if (_associatedVar == 2) {
spotSize->set_active(0);
}
spotSize->append ("4");
if (_associatedVar == 4) {
spotSize->set_active(1);
}
spotSize->append ("8");
if (_associatedVar == 8) {
spotSize->set_active(2);
}
spotSize->append ("16");
if (_associatedVar == 16) {
spotSize->set_active(3);
}
spotSize->append ("32");
if (_associatedVar == 32) {
spotSize->set_active(4);
}
return spotSize;
}
Gtk::ToggleButton* SpotPicker::spotButtonTemplate(Glib::ustring const &key, const Glib::ustring &tooltip)
{
Gtk::ToggleButton *spotButton(new Gtk::ToggleButton(key));
setExpandAlignProperties(spotButton, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_CENTER);
spotButton->get_style_context()->add_class("independent");
spotButton->set_tooltip_text(tooltip);
spotButton->set_image(*Gtk::manage(new RTImage("color-picker-small.png")));
return spotButton;
}
void SpotPicker::spotSizeChanged()
{
_associatedVar = atoi(_spotSizeSetter->get_active_text().c_str());
}

View File

@ -689,7 +689,35 @@ public:
}
};
inline void setActiveTextOrIndex (Gtk::ComboBoxText& comboBox, const Glib::ustring& text, int index)
/**
* @brief A gui element for picking spots on an image
*/
class SpotPicker : public Gtk::Grid
{
public:
int _associatedVar;
Gtk::Label* const _spotLabel;
MyComboBoxText* const _spotSizeSetter;
Gtk::ToggleButton* const _spotButton;
SpotPicker(int const defaultValue, Glib::ustring const &buttonKey, Glib::ustring const &buttonTooltip, Glib::ustring const &labelKey);
~SpotPicker();
inline Gtk::TreeModel::iterator get_active()
{
return _spotSizeSetter->get_active();
}
void set_active(bool b)
{
_spotButton->set_active(b);
}
protected:
MyComboBoxText* selecterSetup();
static Gtk::ToggleButton *spotButtonTemplate(Glib::ustring const &key, const Glib::ustring &tooltip);
void spotSizeChanged();
};
inline void setActiveTextOrIndex(Gtk::ComboBoxText &comboBox, const Glib::ustring &text, int index)
{
bool valueSet = false;
if (!text.empty()) {