[gnote] Take colors from link widget



commit 052bcb052b97cb29bd8f3226d2b41d06b41a60a5
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sun May 9 20:55:54 2021 +0300

    Take colors from link widget

 src/notetag.cpp | 33 ++++++++++++---------------------
 src/notetag.hpp | 15 ---------------
 2 files changed, 12 insertions(+), 36 deletions(-)
---
diff --git a/src/notetag.cpp b/src/notetag.cpp
index ee6e3588..259a461c 100644
--- a/src/notetag.cpp
+++ b/src/notetag.cpp
@@ -22,6 +22,7 @@
 
 #include <gtk/gtk.h>
 #include <gtkmm/image.h>
+#include <gtkmm/linkbutton.h>
 
 #include "sharp/xmlreader.hpp"
 #include "sharp/xmlwriter.hpp"
@@ -292,22 +293,6 @@ namespace gnote {
     }
   }
 
-  Gdk::RGBA NoteTag::get_background() const
-  {
-    /* We can't know the exact background because we're not
-       in TextView's rendering, but we can make a guess */
-    if (property_background_set().get_value())
-      return property_background_rgba().get_value();
-
-    return Gtk::TextView().get_style_context()->get_background_color();
-  }
-
-  Gdk::RGBA NoteTag::render_foreground(ContrastPaletteColor symbol)
-  {
-    return contrast_render_foreground_color(get_background(), symbol);
-  }
-
-
   void DynamicNoteTag::write(sharp::XmlWriter & xml, bool start) const
   {
     if (can_serialize()) {
@@ -379,6 +364,12 @@ namespace gnote {
   void NoteTagTable::_init_common_tags()
   {
     NoteTag::Ptr tag;
+    Gdk::RGBA active_link_color, visited_link_color;
+    {
+      Gtk::LinkButton link;
+      active_link_color = link.get_style_context()->get_color(Gtk::STATE_FLAG_LINK);
+      visited_link_color = link.get_style_context()->get_color(Gtk::STATE_FLAG_VISITED);
+    }
 
     // Font stylings
 
@@ -409,7 +400,7 @@ namespace gnote {
     add (tag);
 
     tag = NoteTag::create("note-title", 0);
-    tag->set_palette_foreground(CONTRAST_COLOR_BLUE);
+    tag->property_foreground_rgba().set_value(active_link_color);
     tag->property_scale() = Pango::SCALE_XX_LARGE;
     // FiXME: Hack around extra rewrite on open
     tag->set_can_serialize(false);
@@ -427,7 +418,7 @@ namespace gnote {
     tag = NoteTag::create("datetime", 0);
     tag->property_scale() = Pango::SCALE_SMALL;
     tag->property_style() = Pango::STYLE_ITALIC;
-    tag->set_palette_foreground(CONTRAST_COLOR_GREY);
+    tag->property_foreground_rgba().set_value(visited_link_color);
     tag->set_save_type(META);
     add (tag);
 
@@ -453,21 +444,21 @@ namespace gnote {
 
     tag = NoteTag::create("link:broken", NoteTag::CAN_ACTIVATE);
     tag->property_underline() = Pango::UNDERLINE_SINGLE;
-    tag->set_palette_foreground(CONTRAST_COLOR_GREY);
+    tag->property_foreground_rgba().set_value(visited_link_color);
     tag->set_save_type(META);
     add (tag);
     m_broken_link_tag = tag;
 
     tag = NoteTag::create("link:internal", NoteTag::CAN_ACTIVATE);
     tag->property_underline() = Pango::UNDERLINE_SINGLE;
-    tag->set_palette_foreground(CONTRAST_COLOR_BLUE);
+    tag->property_foreground_rgba().set_value(active_link_color);
     tag->set_save_type(META);
     add (tag);
     m_link_tag = tag;
 
     tag = NoteTag::create("link:url", NoteTag::CAN_ACTIVATE);
     tag->property_underline() = Pango::UNDERLINE_SINGLE;
-    tag->set_palette_foreground(CONTRAST_COLOR_BLUE);
+    tag->property_foreground_rgba().set_value(active_link_color);
     tag->set_save_type(META);
     add (tag);
     m_url_tag = tag;
diff --git a/src/notetag.hpp b/src/notetag.hpp
index 57b758f5..e9ce6510 100644
--- a/src/notetag.hpp
+++ b/src/notetag.hpp
@@ -31,7 +31,6 @@
 #include <gtkmm/texttag.h>
 #include <gtkmm/texttagtable.h>
 
-#include "contrast.hpp"
 #include "tag.hpp"
 #include "sharp/exception.hpp"
 
@@ -146,16 +145,6 @@ public:
     { 
       return m_signal_changed;
     }
-  ContrastPaletteColor get_palette_foreground() const
-    {
-      return m_palette_foreground;
-    }
-  void set_palette_foreground(ContrastPaletteColor value)
-    {
-      m_palette_foreground = value;
-      // XXX We should also watch theme changes.
-      property_foreground_rgba().set_value(render_foreground(value));
-    }
 protected:
   NoteTag(const Glib::ustring & tag_name, int flags = 0);
   NoteTag();
@@ -166,16 +155,12 @@ protected:
   virtual bool on_event(const Glib::RefPtr<Glib::Object> &, GdkEvent *, const Gtk::TextIter & ) override;
   virtual bool on_activate(const NoteEditor & , const Gtk::TextIter &, const Gtk::TextIter &);
 private:
-  Gdk::RGBA get_background() const;
-  Gdk::RGBA render_foreground(ContrastPaletteColor symbol);
-
   Glib::ustring       m_element_name;
   Glib::RefPtr<Gtk::TextMark> m_widget_location;
   Gtk::Widget       * m_widget;
   bool                m_allow_middle_activate;
   int                 m_flags;
   TagActivatedHandler m_signal_activate;
-  ContrastPaletteColor m_palette_foreground;
   sigc::signal<void,const Gtk::TextTag&,bool> m_signal_changed;
   TagSaveType         m_save_type;
 };


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]