index ef27ff390f2b8e88e1de201cdefb596cfb2bd659..df543c8d399c731134d2bc2143a363605f3d872f 100644 (file)
#include "xml/node-event-vector.h"
#include "widgets/widget-sizes.h"
#include "helper/units.h"
+#include "helper/action.h"
#include "inkscape.h"
enum {
namespace UI {
namespace Widget {
-StyleSwatch::StyleSwatch(SPCSSAttr *css)
+StyleSwatch::StyleSwatch(SPCSSAttr *css, gchar const *main_tip)
:
_tool_path(NULL),
_css (NULL),
_tooltips ()
{
- _label[SS_FILL].set_markup(_("F:"));
- _label[SS_STROKE].set_markup(_("S:"));
+ _label[SS_FILL].set_markup(_("Fill:"));
+ _label[SS_STROKE].set_markup(_("Stroke:"));
for (int i = SS_FILL; i <= SS_STROKE; i++) {
_label[i].set_alignment(0.0, 0.5);
_stroke_width_place.add(_stroke_width);
_stroke.pack_start(_stroke_width_place, Gtk::PACK_SHRINK);
- _table.attach(_label[SS_FILL], 0,1, 0,1, Gtk::SHRINK, Gtk::SHRINK);
- _table.attach(_label[SS_STROKE], 0,1, 1,2, Gtk::SHRINK, Gtk::SHRINK);
+ _table.attach(_label[SS_FILL], 0,1, 0,1, Gtk::FILL, Gtk::SHRINK);
+ _table.attach(_label[SS_STROKE], 0,1, 1,2, Gtk::FILL, Gtk::SHRINK);
_table.attach(_place[SS_FILL], 1,2, 0,1);
_table.attach(_stroke, 1,2, 1,2);
_opacity_place.add(_opacity_value);
_table.attach(_opacity_place, 2,3, 0,2, Gtk::SHRINK, Gtk::SHRINK);
- pack_start(_table, true, true, 0);
+ _swatch.add(_table);
+ pack_start(_swatch, true, true, 0);
set_size_request (STYLE_SWATCH_WIDTH, -1);
}
setStyle (css);
+
+ _swatch.signal_button_press_event().connect(sigc::mem_fun(*this, &StyleSwatch::on_click));
+
+ _tooltips.set_tip(_swatch, main_tip);
+}
+
+void StyleSwatch::setClickVerb(sp_verb_t verb_t) {
+ _verb_t = verb_t;
+}
+
+void StyleSwatch::setDesktop(SPDesktop *desktop) {
+ _desktop = desktop;
+}
+
+bool
+StyleSwatch::on_click(GdkEventButton *event)
+{
+ if (this->_desktop && this->_verb_t != SP_VERB_NONE) {
+ Inkscape::Verb *verb = Inkscape::Verb::get(this->_verb_t);
+ SPAction *action = verb->get_action((Inkscape::UI::View::View *) this->_desktop);
+ sp_action_perform (action, NULL);
+ return true;
+ }
+ return false;
}
StyleSwatch::~StyleSwatch()
sp_repr_css_merge(_css, css);
gchar const *css_string = sp_repr_css_write_string (_css);
- SPStyle *temp_spstyle = sp_style_new();
+ SPStyle *temp_spstyle = sp_style_new(SP_ACTIVE_DOCUMENT);
if (css_string)
sp_style_merge_from_style_string (temp_spstyle, css_string);
paint = &(query->stroke);
}
- if (paint->set && paint->type == SP_PAINT_TYPE_COLOR) {
- guint32 color = sp_color_get_rgba32_falpha (&(paint->value.color),
- SP_SCALE24_TO_FLOAT ((i == SS_FILL)? query->fill_opacity.value : query->stroke_opacity.value));
- ((Inkscape::UI::Widget::ColorPreview*)_color_preview[i])->setRgba32 (color);
- _color_preview[i]->show_all();
- place->add(*_color_preview[i]);
- gchar *tip;
- if (i == SS_FILL) {
- tip = g_strdup_printf (_("Fill: %06x/%.3g"), color >> 8, SP_RGBA32_A_F(color));
- } else {
- tip = g_strdup_printf (_("Stroke: %06x/%.3g"), color >> 8, SP_RGBA32_A_F(color));
- }
- _tooltips.set_tip(*place, tip);
- g_free (tip);
- } else if (paint->set && paint->type == SP_PAINT_TYPE_PAINTSERVER) {
+ if (paint->set && paint->isPaintserver()) {
SPPaintServer *server = (i == SS_FILL)? SP_STYLE_FILL_SERVER (query) : SP_STYLE_STROKE_SERVER (query);
if (SP_IS_LINEARGRADIENT (server)) {
_tooltips.set_tip(*place, (i == SS_FILL)? (_("Pattern fill")) : (_("Pattern stroke")));
}
- } else if (paint->set && paint->type == SP_PAINT_TYPE_NONE) {
+ } else if (paint->set && paint->isColor()) {
+ guint32 color = paint->value.color.toRGBA32( SP_SCALE24_TO_FLOAT ((i == SS_FILL)? query->fill_opacity.value : query->stroke_opacity.value) );
+ ((Inkscape::UI::Widget::ColorPreview*)_color_preview[i])->setRgba32 (color);
+ _color_preview[i]->show_all();
+ place->add(*_color_preview[i]);
+ gchar *tip;
+ if (i == SS_FILL) {
+ tip = g_strdup_printf (_("Fill: %06x/%.3g"), color >> 8, SP_RGBA32_A_F(color));
+ } else {
+ tip = g_strdup_printf (_("Stroke: %06x/%.3g"), color >> 8, SP_RGBA32_A_F(color));
+ }
+ _tooltips.set_tip(*place, tip);
+ g_free (tip);
+ } else if (paint->set && paint->isNone()) {
_value[i].set_markup(_("<i>None</i>"));
place->add(_value[i]);
_tooltips.set_tip(*place, (i == SS_FILL)? (_("No fill")) : (_("No stroke")));