summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJon A. Cruz <jon@joncruz.org>2009-03-04 09:11:28 +0000
committerjoncruz <joncruz@users.sourceforge.net>2009-03-04 09:11:28 +0000
commit112ae1a9b695d21a4e6a7ad32bad36bb6584e494 (patch)
tree7cff1037371a8f354105606b6e9a093cbfc0d718 /src
parentCleanup and prep for more work (diff)
downloadinkscape-112ae1a9b695d21a4e6a7ad32bad36bb6584e494.tar.gz
inkscape-112ae1a9b695d21a4e6a7ad32bad36bb6584e494.zip
Removed boolean "remove" from swatch, used new type enum in ColorDef.
(bzr r7411)
Diffstat (limited to 'src')
-rw-r--r--src/ui/dialog/swatches.cpp74
-rw-r--r--src/ui/dialog/swatches.h2
-rw-r--r--src/widgets/eek-color-def.cpp6
-rw-r--r--src/widgets/eek-color-def.h6
4 files changed, 56 insertions, 32 deletions
diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp
index b294a1400..1a5ef8521 100644
--- a/src/ui/dialog/swatches.cpp
+++ b/src/ui/dialog/swatches.cpp
@@ -41,10 +41,19 @@ namespace Inkscape {
namespace UI {
namespace Dialogs {
-ColorItem::ColorItem() : _isRemove(true){};
+// create a None color swatch
+ColorItem::ColorItem() :
+ def(),
+ _isLive(false),
+ _linkIsTone(false),
+ _linkPercent(0),
+ _linkGray(0),
+ _linkSrc(0)
+{
+}
+
ColorItem::ColorItem( unsigned int r, unsigned int g, unsigned int b, Glib::ustring& name ) :
def( r, g, b, name ),
- _isRemove(false),
_isLive(false),
_linkIsTone(false),
_linkPercent(0),
@@ -251,7 +260,7 @@ static void dragBegin( GtkWidget */*widget*/, GdkDragContext* dc, gpointer data
ColorItem* item = reinterpret_cast<ColorItem*>(data);
if ( item )
{
- if (item->isRemove()){
+ if (item->def.getType() != eek::ColorDef::RGB){
GError *error = NULL;
gchar *filepath = (gchar *) g_strdup_printf("%s/remove-color.png", INKSCAPE_PIXMAPDIR);
gsize bytesRead = 0;
@@ -588,7 +597,7 @@ void ColorItem::_colorDefChanged(void* data)
str = 0;
if ( bruteForce( document, rroot, paletteName, item->def.getR(), item->def.getG(), item->def.getB() ) ) {
- sp_document_done( document , SP_VERB_DIALOG_SWATCHES,
+ sp_document_done( document , SP_VERB_DIALOG_SWATCHES,
_("Change color definition"));
}
}
@@ -617,7 +626,7 @@ Gtk::Widget* ColorItem::getPreview(PreviewStyle style, ViewType view, ::PreviewS
Gtk::Widget* newBlot = Glib::wrap(eekWidget);
eek_preview_set_color( preview, (def.getR() << 8) | def.getR(), (def.getG() << 8) | def.getG(), (def.getB() << 8) | def.getB());
- if ( _isRemove ) {
+ if ( def.getType() != eek::ColorDef::RGB ) {
GError *error = NULL;
gchar *filepath = (gchar *) g_strdup_printf("%s/remove-color.png", INKSCAPE_PIXMAPDIR);
gsize bytesRead = 0;
@@ -686,8 +695,10 @@ Gtk::Widget* ColorItem::getPreview(PreviewStyle style, ViewType view, ::PreviewS
gtk_drag_source_set( GTK_WIDGET(newBlot->gobj()),
GDK_BUTTON1_MASK,
- isRemove() ? sourceNoColorEntries : sourceColorEntries,
- isRemove() ? G_N_ELEMENTS(sourceNoColorEntries) : G_N_ELEMENTS(sourceColorEntries),
+ (def.getType() != eek::ColorDef::RGB) ? sourceNoColorEntries :
+ sourceColorEntries,
+ (def.getType() != eek::ColorDef::RGB) ? G_N_ELEMENTS(sourceNoColorEntries) :
+ G_N_ELEMENTS(sourceColorEntries),
GdkDragAction(GDK_ACTION_MOVE | GDK_ACTION_COPY) );
g_signal_connect( G_OBJECT(newBlot->gobj()),
@@ -747,26 +758,37 @@ Gtk::Widget* ColorItem::getPreview(PreviewStyle style, ViewType view, ::PreviewS
void ColorItem::buttonClicked(bool secondary)
{
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
- if (!desktop) return;
- char const * attrName = secondary ? "stroke" : "fill";
-
- gchar c[64];
- if (!_isRemove){
- guint32 rgba = (def.getR() << 24) | (def.getG() << 16) | (def.getB() << 8) | 0xff;
- sp_svg_write_color(c, sizeof(c), rgba);
- }
-
- SPCSSAttr *css = sp_repr_css_attr_new();
- sp_repr_css_set_property( css, attrName, _isRemove ? "none" : c );
- sp_desktop_set_style(desktop, css);
- sp_repr_css_attr_unref(css);
+ if (desktop) {
+ char const * attrName = secondary ? "stroke" : "fill";
+
+ SPCSSAttr *css = sp_repr_css_attr_new();
+ Glib::ustring descr;
+ switch (def.getType()) {
+ case eek::ColorDef::CLEAR: {
+ // TODO actually make this clear
+ sp_repr_css_set_property( css, attrName, "none" );
+ descr = secondary? _("Remove stroke color") : _("Remove fill color");
+ break;
+ }
+ case eek::ColorDef::NONE: {
+ sp_repr_css_set_property( css, attrName, "none" );
+ descr = secondary? _("Set stroke color to none") : _("Set fill color to none");
+ break;
+ }
+ case eek::ColorDef::RGB: {
+ gchar c[64];
+ guint32 rgba = (def.getR() << 24) | (def.getG() << 16) | (def.getB() << 8) | 0xff;
+ sp_svg_write_color(c, sizeof(c), rgba);
+
+ sp_repr_css_set_property( css, attrName, c );
+ descr = secondary? _("Set stroke color from swatch") : _("Set fill color from swatch");
+ break;
+ }
+ }
+ sp_desktop_set_style(desktop, css);
+ sp_repr_css_attr_unref(css);
- if (_isRemove){
- sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_SWATCHES,
- secondary? _("Remove stroke color") : _("Remove fill color"));
- } else {
- sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_SWATCHES,
- secondary? _("Set stroke color from swatch") : _("Set fill color from swatch"));
+ sp_document_done( sp_desktop_document(desktop), SP_VERB_DIALOG_SWATCHES, descr.c_str() );
}
}
diff --git a/src/ui/dialog/swatches.h b/src/ui/dialog/swatches.h
index 8428919e0..17081733d 100644
--- a/src/ui/dialog/swatches.h
+++ b/src/ui/dialog/swatches.h
@@ -42,7 +42,6 @@ public:
::PreviewSize size,
guint ratio);
void buttonClicked(bool secondary = false);
- bool isRemove(){ return _isRemove; }
eek::ColorDef def;
private:
@@ -70,7 +69,6 @@ private:
Gtk::Tooltips tips;
std::vector<Gtk::Widget*> _previews;
- bool _isRemove;
bool _isLive;
bool _linkIsTone;
int _linkPercent;
diff --git a/src/widgets/eek-color-def.cpp b/src/widgets/eek-color-def.cpp
index 85b00b251..d7cb41b38 100644
--- a/src/widgets/eek-color-def.cpp
+++ b/src/widgets/eek-color-def.cpp
@@ -54,20 +54,20 @@ namespace eek
ColorDef::ColorDef() :
descr(_("none")),
+ type(NONE),
r(0),
g(0),
b(0),
- none(true),
editable(false)
{
}
ColorDef::ColorDef( unsigned int r, unsigned int g, unsigned int b, const std::string& description ) :
descr(description),
+ type(RGB),
r(r),
g(g),
b(b),
- none(false),
editable(false)
{
}
@@ -87,11 +87,11 @@ ColorDef& ColorDef::operator=( ColorDef const &other )
{
if ( this != & other )
{
+ type = other.type;
r = other.r;
g = other.g;
b = other.b;
descr = other.descr;
- none = other.none;
editable = other.editable;
}
return *this;
diff --git a/src/widgets/eek-color-def.h b/src/widgets/eek-color-def.h
index 63cd096be..764a28b12 100644
--- a/src/widgets/eek-color-def.h
+++ b/src/widgets/eek-color-def.h
@@ -52,6 +52,8 @@ typedef void (*ColorCallback)( void* data );
class ColorDef
{
public:
+ enum ColorType{CLEAR, NONE, RGB};
+
ColorDef();
ColorDef( unsigned int r, unsigned int g, unsigned int b, const std::string& description );
virtual ~ColorDef();
@@ -59,6 +61,8 @@ public:
ColorDef( ColorDef const &other );
virtual ColorDef& operator=( ColorDef const &other );
+ ColorType getType() const { return type; }
+
void setRGB( unsigned int r, unsigned int g, unsigned int b );
unsigned int getR() const { return r; }
unsigned int getG() const { return g; }
@@ -73,10 +77,10 @@ public:
std::string descr;
protected:
+ ColorType type;
unsigned int r;
unsigned int g;
unsigned int b;
- bool none;
bool editable;
private: