Add an optional function to the pop-up button, so that it will select the next entry when clicked and also do some miscellaneous code clean-ups including forward declarations.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
#include "colortoning.h"
|
||||
#include "mycurve.h"
|
||||
#include "rtimage.h"
|
||||
|
||||
using namespace rtengine;
|
||||
using namespace rtengine::procparams;
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "mydiagonalcurve.h"
|
||||
#include "curveeditor.h"
|
||||
#include "diagonalcurveeditorsubgroup.h"
|
||||
#include "rtimage.h"
|
||||
|
||||
DiagonalCurveEditorSubGroup::DiagonalCurveEditorSubGroup (CurveEditorGroup* prt, Glib::ustring& curveDir) : CurveEditorSubGroup(curveDir)
|
||||
{
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "soundman.h"
|
||||
#include "rtimage.h"
|
||||
#include <iostream>
|
||||
#include "popupbutton.h"
|
||||
|
||||
using namespace rtengine::procparams;
|
||||
|
||||
@@ -76,7 +77,7 @@ private:
|
||||
|
||||
void prepareIntentBox ()
|
||||
{
|
||||
PopUpButton *bt = new PopUpButton();
|
||||
PopUpButton *bt = new PopUpButton(Glib::ustring(), true);
|
||||
intentBox = Gtk::manage(bt);
|
||||
intentBox->addEntry("intent-relative.png", M("PREFERENCES_INTENT_RELATIVE"));
|
||||
intentBox->addEntry("intent-perceptual.png", M("PREFERENCES_INTENT_PERCEPTUAL"));
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "myflatcurve.h"
|
||||
#include "curveeditor.h"
|
||||
#include "flatcurveeditorsubgroup.h"
|
||||
#include "rtimage.h"
|
||||
|
||||
FlatCurveEditorSubGroup::FlatCurveEditorSubGroup (CurveEditorGroup* prt, Glib::ustring& curveDir) : CurveEditorSubGroup(curveDir)
|
||||
{
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
|
||||
#include "popupbutton.h"
|
||||
|
||||
#include <gtkmm/box.h>
|
||||
|
||||
/*
|
||||
* PopUpButton::PopUpButton (const Glib::ustring& label, bool imgRight)
|
||||
*
|
||||
@@ -28,8 +30,14 @@
|
||||
*
|
||||
* Parameters:
|
||||
* label = label displayed in the button
|
||||
* nextOnClicked = selects the next entry if the button is clicked
|
||||
*/
|
||||
PopUpButton::PopUpButton (const Glib::ustring& label) : Gtk::Button(), PopUpCommon(this, label) { }
|
||||
PopUpButton::PopUpButton (const Glib::ustring& label, bool nextOnClicked)
|
||||
: Gtk::Button ()
|
||||
, PopUpCommon (this, label)
|
||||
, nextOnClicked(nextOnClicked)
|
||||
{
|
||||
}
|
||||
|
||||
void PopUpButton::show()
|
||||
{
|
||||
@@ -44,3 +52,22 @@ void PopUpButton::set_sensitive (bool isSensitive)
|
||||
{
|
||||
buttonGroup->set_sensitive(isSensitive);
|
||||
}
|
||||
|
||||
bool PopUpButton::on_button_release_event (GdkEventButton* event)
|
||||
{
|
||||
if (nextOnClicked && getEntryCount () > 1)
|
||||
{
|
||||
const int last = getEntryCount () - 1;
|
||||
int next = getSelected ();
|
||||
|
||||
if (event->state & GDK_SHIFT_MASK) {
|
||||
next = next > 0 ? next - 1 : last;
|
||||
} else {
|
||||
next = next < last ? next + 1 : 0;
|
||||
}
|
||||
|
||||
entrySelected (next);
|
||||
}
|
||||
|
||||
return Gtk::Button::on_button_release_event(event);
|
||||
}
|
||||
|
||||
@@ -21,17 +21,24 @@
|
||||
#ifndef _POPUPBUTTON_
|
||||
#define _POPUPBUTTON_
|
||||
|
||||
#include <gtkmm.h>
|
||||
#include <gtkmm/button.h>
|
||||
#include "popupcommon.h"
|
||||
|
||||
class PopUpButton : public Gtk::Button, public PopUpCommon
|
||||
{
|
||||
|
||||
public:
|
||||
PopUpButton (const Glib::ustring& label = "");
|
||||
PopUpButton (const Glib::ustring& label = Glib::ustring (), bool nextOnClicked = false);
|
||||
void show ();
|
||||
void set_tooltip_text (const Glib::ustring &text);
|
||||
void set_sensitive (bool isSensitive=true);
|
||||
|
||||
protected:
|
||||
bool on_button_release_event (GdkEventButton* event);
|
||||
|
||||
private:
|
||||
bool nextOnClicked;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -26,6 +26,9 @@
|
||||
#include "rtimage.h"
|
||||
|
||||
PopUpCommon::PopUpCommon (Gtk::Button* thisButton, const Glib::ustring& label)
|
||||
: selected (-1) // -1 means that the button is invalid
|
||||
, menu (0)
|
||||
, buttonImage (0)
|
||||
{
|
||||
button = thisButton;
|
||||
hasMenu = false;
|
||||
@@ -42,15 +45,6 @@ PopUpCommon::PopUpCommon (Gtk::Button* thisButton, const Glib::ustring& label)
|
||||
// Create the global container and put the button in it
|
||||
buttonGroup = Gtk::manage( new Gtk::HBox(false, 0));
|
||||
buttonGroup->pack_start(*button, Gtk::PACK_EXPAND_WIDGET, 0);
|
||||
// Create the list entry
|
||||
imageFilenames.clear();
|
||||
images.clear();
|
||||
sItems.clear();
|
||||
items.clear();
|
||||
selected = -1; // -1 : means that the button is invalid
|
||||
menu = 0;
|
||||
buttonImage = 0;
|
||||
buttonHint = "";
|
||||
}
|
||||
|
||||
PopUpCommon::~PopUpCommon ()
|
||||
@@ -59,40 +53,23 @@ PopUpCommon::~PopUpCommon ()
|
||||
delete *i;
|
||||
}
|
||||
|
||||
for (std::vector<Gtk::ImageMenuItem*>::iterator i = items.begin(); i != items.end(); ++i) {
|
||||
delete *i;
|
||||
}
|
||||
|
||||
if (menu) {
|
||||
delete menu;
|
||||
}
|
||||
|
||||
if (buttonImage) {
|
||||
delete buttonImage;
|
||||
}
|
||||
|
||||
delete buttonGroup;
|
||||
}
|
||||
|
||||
PopUpCommon::type_signal_changed PopUpCommon::signal_changed()
|
||||
bool PopUpCommon::addEntry (const Glib::ustring& fileName, const Glib::ustring& label)
|
||||
{
|
||||
return message;
|
||||
}
|
||||
if (label.empty ())
|
||||
return false;
|
||||
|
||||
bool PopUpCommon::addEntry (Glib::ustring fileName, Glib::ustring label)
|
||||
{
|
||||
bool added = false;
|
||||
|
||||
if ( label.size() ) {
|
||||
imageFilenames.push_back(fileName);
|
||||
sItems.push_back(label);
|
||||
// Create the image
|
||||
RTImage* newImage = new RTImage(fileName);
|
||||
images.push_back(newImage);
|
||||
imageFilenames.push_back(fileName);
|
||||
int currPos = (int)images.size();
|
||||
// Create the menu item
|
||||
Gtk::ImageMenuItem* newItem = new Gtk::ImageMenuItem (*newImage, label);
|
||||
items.push_back(newItem);
|
||||
Gtk::ImageMenuItem* newItem = Gtk::manage(new Gtk::ImageMenuItem (*newImage, label));
|
||||
|
||||
if (selected == -1) {
|
||||
// Create the menu on the first item
|
||||
@@ -118,22 +95,17 @@ bool PopUpCommon::addEntry (Glib::ustring fileName, Glib::ustring label)
|
||||
|
||||
newItem->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &PopUpCommon::entrySelected), currPos - 1));
|
||||
menu->attach (*newItem, 0, 1, currPos - 1, currPos);
|
||||
// The item has been created
|
||||
added = true;
|
||||
}
|
||||
|
||||
return added;
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: 'PopUpCommon::removeEntry' method to be created...
|
||||
|
||||
void PopUpCommon::entrySelected (int i)
|
||||
{
|
||||
if (setSelected((unsigned int)i))
|
||||
// Emit a a signal if the selected item has changed
|
||||
{
|
||||
message.emit(selected);
|
||||
}
|
||||
if (setSelected (i))
|
||||
message (selected);
|
||||
}
|
||||
|
||||
void PopUpCommon::setItemSensitivity (int i, bool isSensitive) {
|
||||
@@ -181,7 +153,12 @@ void PopUpCommon::setButtonHint()
|
||||
}
|
||||
|
||||
if (selected > -1) {
|
||||
hint += sItems.at(selected);
|
||||
// HACK: Gtk::MenuItem::get_label does not seem to work reliably.
|
||||
Gtk::MenuItem& item = menu->items ()[selected];
|
||||
Gtk::Label* label = dynamic_cast<Gtk::Label*>(item.get_child ());
|
||||
|
||||
if (label)
|
||||
hint += label->get_text ();
|
||||
}
|
||||
|
||||
button->set_tooltip_markup(hint);
|
||||
|
||||
@@ -21,11 +21,21 @@
|
||||
#ifndef _POPUPCOMMON_
|
||||
#define _POPUPCOMMON_
|
||||
|
||||
#include <vector>
|
||||
#include <glibmm/ustring.h>
|
||||
#include <sigc++/signal.h>
|
||||
|
||||
#include <gtkmm.h>
|
||||
#include <sigc++/sigc++.h>
|
||||
#include "rtimage.h"
|
||||
namespace Gtk
|
||||
{
|
||||
class HBox;
|
||||
class Menu;
|
||||
class Button;
|
||||
class ImageMenuItem;
|
||||
}
|
||||
|
||||
typedef struct _GdkEventButton GdkEventButton;
|
||||
|
||||
class RTImage;
|
||||
|
||||
class PopUpCommon
|
||||
{
|
||||
@@ -37,12 +47,10 @@ public:
|
||||
|
||||
PopUpCommon (Gtk::Button* button, const Glib::ustring& label = "");
|
||||
virtual ~PopUpCommon ();
|
||||
bool addEntry (Glib::ustring fileName, Glib::ustring label);
|
||||
bool addEntry (const Glib::ustring& fileName, const Glib::ustring& label);
|
||||
int getEntryCount () const;
|
||||
bool setSelected (int entryNum);
|
||||
int getSelected ()
|
||||
{
|
||||
return selected;
|
||||
}
|
||||
int getSelected () const;
|
||||
void setButtonHint();
|
||||
void show ();
|
||||
void set_tooltip_text (const Glib::ustring &text);
|
||||
@@ -50,14 +58,8 @@ public:
|
||||
private:
|
||||
type_signal_changed message;
|
||||
|
||||
/*
|
||||
TODO: MenuItem::get_label() doesn't return any string, or an empty string !?
|
||||
That's why we store entries strings in sItems, but it would be nice to get ride of it...
|
||||
*/
|
||||
std::vector<Glib::ustring> sItems;
|
||||
std::vector<Glib::ustring> imageFilenames;
|
||||
std::vector<RTImage*> images;
|
||||
std::vector<Gtk::ImageMenuItem*> items;
|
||||
Glib::ustring buttonHint;
|
||||
RTImage* buttonImage;
|
||||
Gtk::HBox* imageContainer;
|
||||
@@ -67,9 +69,26 @@ private:
|
||||
bool hasMenu;
|
||||
|
||||
void showMenu(GdkEventButton* event);
|
||||
void entrySelected (int i);
|
||||
void setItemSensitivity (int i, bool isSensitive);
|
||||
|
||||
protected:
|
||||
void entrySelected (int i);
|
||||
|
||||
};
|
||||
|
||||
inline PopUpCommon::type_signal_changed PopUpCommon::signal_changed ()
|
||||
{
|
||||
return message;
|
||||
}
|
||||
|
||||
inline int PopUpCommon::getEntryCount () const
|
||||
{
|
||||
return images.size();
|
||||
}
|
||||
|
||||
inline int PopUpCommon::getSelected () const
|
||||
{
|
||||
return selected;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#ifndef _POPUPTOGGLEBUTTON_
|
||||
#define _POPUPTOGGLEBUTTON_
|
||||
|
||||
#include "popupbutton.h"
|
||||
#include <gtkmm/togglebutton.h>
|
||||
#include "popupcommon.h"
|
||||
|
||||
class PopUpToggleButton : public Gtk::ToggleButton, public PopUpCommon
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
#include "retinex.h"
|
||||
#include "mycurve.h"
|
||||
#include "rtimage.h"
|
||||
|
||||
using namespace rtengine;
|
||||
using namespace rtengine::procparams;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <cmath>
|
||||
#include "edit.h"
|
||||
#include "guiutils.h"
|
||||
#include "rtimage.h"
|
||||
|
||||
using namespace rtengine;
|
||||
using namespace rtengine::procparams;
|
||||
|
||||
Reference in New Issue
Block a user