diff --git a/gtk-imports.h b/gtk-imports.h
index 42b686e..20c3eaf 100644
--- a/gtk-imports.h
+++ b/gtk-imports.h
@@ -73,6 +73,7 @@ typedef void GtkComboBox;
typedef void GtkGrid;
typedef void GtkColorButton;
typedef void GtkColorChooser;
+typedef void GtkSpinButton;
typedef int gboolean;
typedef int gint;
@@ -669,6 +670,10 @@ DECL(GdkEvent*, gtk_get_current_event, (void ))
DECL(void, gtk_main_do_event, (GdkEvent* event))
DECL(void, gdk_event_free, (GdkEvent* event))
+DECL(GtkWidget*, gtk_spin_button_new_with_range, (gdouble min, gdouble max, gdouble step))
+DECL(void, gtk_spin_button_set_value, (GtkSpinButton* spin_button, gdouble value ))
+DECL(gint, gtk_spin_button_get_value_as_int, (GtkSpinButton* spin_button ))
+
DECL(unsigned long, g_signal_connect_data, (GObject *obj, const char *signal, GCallback c_handler, gpointer data, GClosureNotify destroy_data, GConnectFlags connect_flags))
// Messages
diff --git a/title_only.png b/title_only.png
new file mode 100644
index 0000000..c60b627
Binary files /dev/null and b/title_only.png differ
diff --git a/title_only.svg b/title_only.svg
new file mode 100644
index 0000000..400b1aa
--- /dev/null
+++ b/title_only.svg
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/tr.cpp b/tr.cpp
index e217f8b..9db430b 100644
--- a/tr.cpp
+++ b/tr.cpp
@@ -1,5 +1,6 @@
#include "tr.h"
#include
+#include
void tr::add(const char *sentence, ...)
{
@@ -39,9 +40,12 @@ const char *tr::translate(const char *str)
{
std::unordered_map::iterator it;
+ if (_lang == "en") { return str; }
+
it = _translations.find(_lang);
if (it == _translations.end()) {
+ std::cerr << "No translation for: " << str << std::endl;
return str;
} else {
Translations_t *m = it->second;
@@ -49,6 +53,7 @@ const char *tr::translate(const char *str)
std::string s(str);
n_it = m->find(s);
if (n_it == m->end()) {
+ std::cerr << "No translation for: " << str << std::endl;
return str;
} else {
return n_it->second.c_str();
@@ -61,14 +66,36 @@ void tr::setLang(const std::string &l)
_lang = l;
}
+#define nl(a, b) add(a, "nl:" b, nullptr)
+#define en(a, b) add(a, "en:" b, nullptr)
+
tr::tr()
{
- add("Quit", "nl:Beƫindigen", nullptr);
- add("New Note", "nl:Nieuwe Notitie", nullptr);
- add("Show Notes", "nl:Notities Presenteren", nullptr);
- add("Hide Notes", "nl:Notities Verbergen", nullptr);
- add("Reload Notes", "nl:Notities opnieuw laden", nullptr);
- add("Setup", "nl:Instellingen", nullptr);
+
+ nl("Quit", "Beƫindigen");
+ nl("New Note", "Nieuwe Notitie");
+ nl("Show Notes", "Notities Presenteren");
+ nl("Hide Notes", "Notities Verbergen");
+ nl("Reload Notes", "Notities opnieuw laden");
+ nl("Setup", "Instellingen");
+ nl("Notes on desktop", "Noties naar achteren");
+ nl("Language:", "Taalinstelling:");
+ nl("Language:", "Taalinstelling:");
+ nl("Ok", "Ok");
+ nl("Yellownotes Setup", "Yellownotes Instellingen");
+ nl("Foreground Color", "Voorgrond kleur");
+ nl("Background Color", "Achtergrond kleur");
+ nl("Dark", "Donker");
+ nl("Yellow", "Geel");
+ nl("Orange", "Oranje");
+ nl("Blue", "Blauw");
+ nl("Cyan", "Cyaan");
+ nl("Green", "Groen");
+ nl("Red", "Rood");
+ nl("Grey", "Grijs");
+ nl("Font size:", "Lettertype Grootte:");
+ nl("Actual Font Size in Note", "Werkelijke lettertype grootte in de notitie");
+
_lang = "en";
}
diff --git a/yellownotes.cpp b/yellownotes.cpp
index 786bc14..fa962e1 100644
--- a/yellownotes.cpp
+++ b/yellownotes.cpp
@@ -52,6 +52,7 @@ private:
GtkImage *_plus_image;
GtkImage *_hide_image;
GtkImage *_to_desktop_image;
+ GtkImage *_title_only_image;
GtkWidget *_title_label;
GtkWidget *_title_entry;
GtkWidget *_title_separator;
@@ -67,6 +68,9 @@ private:
bool _hidden;
bool _hidden_loaded;
+ bool _title_only;
+ bool _title_only_loaded;
+
int _x;
int _y;
bool _pos_loaded;
@@ -102,6 +106,7 @@ private:
void updatePosition();
void updateHidden();
void updateSize();
+ void updateTitleOnly();
void adjustTitle(bool mutate);
@@ -125,6 +130,7 @@ public:
void toDesktop();
void fromDesktop();
void updateColor();
+ void toggleTitleOnly();
public:
bool move_begin(GtkWidget *sender, GdkEventButton *evt);
@@ -142,6 +148,7 @@ public:
std::string title();
bool isHidden();
void doubleClicked();
+ YellowNotes *notes();
public:
void load();
@@ -152,11 +159,14 @@ public:
~YellowNote();
};
-class ColorSet
+class SettingContainer
{
public:
ColorType_t color;
+ GtkLabel *font_label;
+ GtkSpinButton *font_size_btn;
YellowNotes *notes;
+ YellowNote *note;
bool bg;
public:
@@ -171,14 +181,31 @@ public:
}
}
- ColorSet(ColorType_t t, bool _bg, YellowNotes *n) {
+ void fontSizeSet(GtkWidget *Sender) {
+ int size = gtk_spin_button_get_value_as_int(font_size_btn);
+ notes->updateWidgetCss(font_label, ColorType_t::YELLOW);
+ notes->setFontSize(size);
+ }
+
+ SettingContainer(ColorType_t t, bool _bg, YellowNotes *n) {
color = t;
bg = _bg;
notes = n;
+ font_label = nullptr;
+ font_size_btn = nullptr;
+ }
+
+ SettingContainer(GtkSpinButton *btn, GtkLabel *fl, YellowNotes *n) {
+ color = FIRST;
+ font_label = fl;
+ font_size_btn = btn;
+ notes = n;
+ bg = false;
}
};
-SIGNAL(ColorSet, on_color_set, colorSet);
+SIGNAL(SettingContainer, on_color_set, colorSet);
+SIGNAL(SettingContainer, on_font_size_set, fontSizeSet);
SIGNAL2(YellowNote, on_size_allocated, size_allocated, GtkAllocation)
BSIGNAL2(YellowNote, on_button_press, move_begin, GdkEventButton);
@@ -284,6 +311,20 @@ void YellowNotes::toRGBA(const std::string &col, GdkRGBA &rgba)
rgba.red = red;
}
+void YellowNotes::updateWidgetCss(GtkWidget *w, ColorType_t col)
+{
+ auto set_style = [this, col](GtkWidget *widget) {
+ GtkStyleContext *c = gtk_widget_get_style_context(widget);
+ const char *style = gtk_style_context_to_string(c, GTK_STYLE_CONTEXT_PRINT_RECURSE);
+ GtkCssProvider *css_p = gtk_css_provider_new();
+ gtk_style_context_add_provider(c, css_p, GTK_STYLE_PROVIDER_PRIORITY_USER);
+ std::string widget_css = css(col);
+ gtk_css_provider_load_from_data(css_p, widget_css.c_str(), widget_css.size(), nullptr);
+ };
+
+ set_style(w);
+}
+
std::string YellowNotes::getFgColor(ColorType_t type)
{
char buf[100];
@@ -395,9 +436,28 @@ std::string YellowNotes::css(ColorType_t type)
int YellowNotes::fontSize()
{
+ std::string key("font_size");
+ std::unordered_map::iterator it;
+ it = _cfg.find(key);
+ if (it != _cfg.end()) {
+ _font_size = atoi(it->second.c_str());
+ if (_font_size < 6 || _font_size > 30) { _font_size = 15; }
+ }
return _font_size;
}
+void YellowNotes::setFontSize(int size)
+{
+ _font_size = size;
+ char buf[100];
+ sprintf(buf, "%d", size);
+ std::string v = buf;
+ std::string key("font_size");
+ _cfg.erase(key);
+ _cfg.insert(std::pair(key, v));
+ saveConfig();
+}
+
int YellowNotes::iconSize()
{
return _font_size * 1.5;
@@ -520,7 +580,6 @@ void YellowNotes::loadConfig()
}
setLang(currentLang());
-
}
void YellowNotes::saveConfig()
@@ -639,12 +698,12 @@ void YellowNotes::setupClose(GtkWidget *sender)
setCurrentLang(lang);
gtk_widget_destroy(_dlg);
- std::list::iterator it;
- for(it = _color_sets.begin() ; it != _color_sets.end(); it++) {
- ColorSet *s = *it;
+ std::list::iterator it;
+ for(it = _settings_containers.begin() ; it != _settings_containers.end(); it++) {
+ SettingContainer *s = *it;
delete s;
}
- _color_sets.clear();
+ _settings_containers.clear();
_dlg = nullptr;
_langs = nullptr;
@@ -689,7 +748,7 @@ void YellowNotes::setup(void *sender)
gtk_grid_attach(grid, lbl_langs, 0, 0, 1, 1);
gtk_grid_attach(grid, langs, 1, 0, 2, 1);
- GtkLabel *lbl_fg = gtk_label_new(_("Forground Color"));
+ GtkLabel *lbl_fg = gtk_label_new(_("Foreground Color"));
GtkLabel *lbl_bg = gtk_label_new(_("Background Color"));
gtk_grid_attach(grid, lbl_fg, 1, 1, 1, 1);
gtk_grid_attach(grid, lbl_bg, 2, 1, 1, 1);
@@ -713,18 +772,35 @@ void YellowNotes::setup(void *sender)
GtkColorButton *fg_btn = gtk_color_button_new();
gtk_color_chooser_set_rgba(fg_btn, &fg_rgba);
- ColorSet *fg = new ColorSet(static_cast(i), false, this);
+ SettingContainer *fg = new SettingContainer(static_cast(i), false, this);
+ _settings_containers.push_back(fg);
g_signal_connect(fg_btn, "color_set", on_color_set, fg);
gtk_grid_attach(grid, fg_btn, 1, i + offset, 1, 1);
GtkColorButton *bg_btn = gtk_color_button_new();
gtk_color_chooser_set_rgba(bg_btn, &bg_rgba);
- ColorSet *bg = new ColorSet(static_cast(i), true, this);
+ SettingContainer *bg = new SettingContainer(static_cast(i), true, this);
+ _settings_containers.push_back(bg);
g_signal_connect(bg_btn, "color_set", on_color_set, bg);
gtk_grid_attach(grid, bg_btn, 2, i + offset, 1, 1);
-
}
+ offset = i + offset;
+
+ gtk_grid_attach(grid, gtk_label_new(_("Font size:")), 0, offset, 1, 1);
+ GtkSpinButton *fs = gtk_spin_button_new_with_range(6.0, 20.0, 1.0);
+ gtk_spin_button_set_value(fs, fontSize());
+ gtk_grid_attach(grid, fs, 1, offset, 1, 1);
+
+ GtkLabel *font_label = gtk_label_new(_("Actual Font Size in Note"));
+ gtk_widget_set_size_request(font_label, 400, -1);
+ gtk_grid_attach(grid, font_label, 2, offset, 1, 1);
+
+ SettingContainer *fl = new SettingContainer(fs, font_label, this);
+ _settings_containers.push_back(fl);
+ g_signal_connect(fs, "value_changed", on_font_size_set, fl);
+ fl->fontSizeSet(fs);
+
gtk_container_add(content, grid);
g_signal_connect(ok_btn, "clicked", on_setup_ok, this);
@@ -874,6 +950,7 @@ YellowNote::YellowNote(YellowNotes *notes, const std::string &filename)
_width = 300;
_height = 200;
_hidden = false;
+ _title_only = false;
_editing_title = false;
_save_counter = 0;
_save_id = -1;
@@ -965,12 +1042,21 @@ YellowNote::YellowNote(YellowNotes *notes, const std::string &filename)
gtk_widget_set_halign(_to_desktop_image, GtkAlign::GTK_ALIGN_END);
g_object_unref(to_desktop_pixbuf);
+ GdkPixbuf *title_only_pixbuf = gdk_pixbuf_new_from_file_at_size(notes->imageFile("title_only").c_str(),
+ width, height, nullptr
+ );
+ _title_only_image = gtk_image_new_from_pixbuf(title_only_pixbuf);
+ gtk_widget_set_halign(_title_only_image, GtkAlign::GTK_ALIGN_END);
+ g_object_unref(title_only_pixbuf);
+
+
gtk_container_add(_note_header, _color_image);
gtk_container_add(_note_header, _title_label);
gtk_container_add(_note_header, _plus_image);
gtk_container_add(_note_header, _delete_image);
gtk_container_add(_note_header, _hide_image);
gtk_container_add(_note_header, _to_desktop_image);
+ gtk_container_add(_note_header, _title_only_image);
gtk_container_add(_scroll_widget, _text_widget);
@@ -1013,6 +1099,7 @@ YellowNote::YellowNote(YellowNotes *notes, const std::string &filename)
g_object_ref(_plus_image);
g_object_ref(_hide_image);
g_object_ref(_to_desktop_image);
+ g_object_ref(_title_only_image);
load();
@@ -1027,6 +1114,7 @@ YellowNote::~YellowNote()
g_object_unref(_plus_image);
g_object_unref(_hide_image);
g_object_unref(_to_desktop_image);
+ g_object_unref(_title_only_image);
gtk_widget_destroy(_note_widget);
_note_widget = nullptr;
}
@@ -1043,6 +1131,7 @@ void YellowNote::updateWidgetColors(GtkWidget *w)
};
set_style(w);
+ _notes->updateWidgetCss(w, _color);
}
void YellowNote::updateColor()
@@ -1102,6 +1191,19 @@ void YellowNote::updateTitle()
gtk_label_set_label(_title_label, _title.c_str());
}
+void YellowNote::updateTitleOnly()
+{
+ if (_title_only) {
+ gtk_widget_hide(_scroll_widget);
+ GtkAllocation alloc;
+ gtk_widget_get_allocation(_note_header, &alloc);
+ gtk_window_resize(_note_widget, _width, alloc.height);
+ } else {
+ gtk_widget_show_all(_scroll_widget);
+ gtk_window_resize(_note_widget, _width, _height);
+ }
+}
+
void YellowNote::updateHidden()
{
if (_hidden) { hide(); }
@@ -1115,8 +1217,8 @@ void YellowNote::updatePosition()
void YellowNote::updateSize()
{
- std::cout << "Update size to: " << _width << ", " << _height << std::endl;
- gtk_window_resize(_note_widget, _width, _height);
+ updateTitleOnly();
+ //gtk_window_resize(_note_widget, _width, _height);
}
void YellowNote::showNote(GtkWidget *sender)
@@ -1138,6 +1240,12 @@ void YellowNote::hide()
save();
}
+void YellowNote::toggleTitleOnly()
+{
+ _title_only = !_title_only;
+ updateTitleOnly();
+ save();
+}
void YellowNote::resized(int width, int height)
{
@@ -1148,18 +1256,12 @@ void YellowNote::resized(int width, int height)
void YellowNote::size_allocated(GtkWidget *sender, GtkAllocation *alloc)
{
- std::cout << "loaded: " << _size_loaded << ", " << _pos_loaded << std::endl;
int width = alloc->width;
int height = alloc->height;
- //if (_size_loaded) {
- std::cout << "width, height = " << width << ", " << height << std::endl;
- // _width = width;
- // _height = height;
- // save();
- // }
if (!_moving) {
if (width != _width || height != _height) {
- gtk_window_resize(_note_widget, _width, _height);
+ updateSize();
+ //gtk_window_resize(_note_widget, _width, _height);
}
}
}
@@ -1179,7 +1281,6 @@ void YellowNote::toFront()
gtk_window_move(_note_widget, _x, _y);
gtk_widget_hide(_note_widget);
} else {
- std::cout << "to_front x = " << _x << std::endl;
int x = _x;
int y = _y;
gtk_window_present(_note_widget);
@@ -1191,7 +1292,6 @@ void YellowNote::toFront()
void YellowNote::toDesktop()
{
#ifdef __linux
- std::cout << "todesktop: width: " << _width << ", height: " << _height << std::endl;
gtk_window_set_type_hint(_note_widget, GdkWindowTypeHint::GDK_WINDOW_TYPE_HINT_DESKTOP);
#endif
}
@@ -1260,6 +1360,8 @@ void YellowNote::adjustTitle(bool mutate)
gtk_container_add(_note_header, _hide_image);
gtk_container_remove(_note_header, _to_desktop_image);
gtk_container_add(_note_header, _to_desktop_image);
+ gtk_container_remove(_note_header, _title_only_image);
+ gtk_container_add(_note_header, _title_only_image);
}
@@ -1342,6 +1444,11 @@ void YellowNote::doubleClicked()
}
}
+YellowNotes *YellowNote::notes()
+{
+ return _notes;
+}
+
bool YellowNote::move_begin(GtkWidget *sender, GdkEventButton *evt)
{
int x = evt->x_root;
@@ -1368,6 +1475,9 @@ bool YellowNote::move_begin(GtkWidget *sender, GdkEventButton *evt)
int to_desktop_left, to_desktop_right;
get_screen_left_right(_to_desktop_image, to_desktop_left, to_desktop_right);
+ int title_only_left, title_only_right;
+ get_screen_left_right(_title_only_image, title_only_left, title_only_right);
+
if (y >= header_top && y <= header_bottom) {
if (x >= color_left && x <= color_right) {
nextColor();
@@ -1385,6 +1495,10 @@ bool YellowNote::move_begin(GtkWidget *sender, GdkEventButton *evt)
_notes->notesToDesktop(this);
return true;
}
+ if (x >= title_only_left && x <= title_only_right) {
+ toggleTitleOnly();
+ return true;
+ }
if (x >= delete_left && x <= delete_right) {
deleteMe();
return true;
@@ -1402,6 +1516,8 @@ bool YellowNote::move_begin(GtkWidget *sender, GdkEventButton *evt)
gtk_container_add(_note_header, _hide_image);
gtk_container_remove(_note_header, _to_desktop_image);
gtk_container_add(_note_header, _to_desktop_image);
+ gtk_container_remove(_note_header, _title_only_image);
+ gtk_container_add(_note_header, _title_only_image);
gtk_widget_show(_title_entry);
gtk_entry_set_text(_title_entry, _title.c_str());
gtk_widget_grab_focus(_title_entry);
@@ -1456,7 +1572,6 @@ bool YellowNote::moving(GtkWidget *sender, GdkEventMotion *evt)
if (_moving) {
int the_x = x - _x_orig;
int the_y = y - _y_orig;
- std::cout << "moving" << std::endl;
gtk_window_move(_note_widget, the_x, the_y);
positioned(_note_widget, the_x, the_y);
return true;
@@ -1472,8 +1587,6 @@ bool YellowNote::moving(GtkWidget *sender, GdkEventMotion *evt)
if (height < 60) { height = 60; }
gtk_window_resize(_note_widget, width, height);
resized(width, height);
-
- //size_allocated(_note_box, width, height);
return true;
}
@@ -1486,7 +1599,6 @@ bool YellowNote::moving(GtkWidget *sender, GdkEventMotion *evt)
if (width < 100) { width = 100; }
gtk_window_resize(_note_widget, width, h);
resized(width, h);
- //size_allocated(_note_box, width, h);
return true;
}
@@ -1499,7 +1611,6 @@ bool YellowNote::moving(GtkWidget *sender, GdkEventMotion *evt)
if (height < 60) { height = 60; }
gtk_window_resize(_note_widget, w, height);
resized(w, height);
- //size_allocated(_note_box, w, height);
return true;
}
}
@@ -1533,7 +1644,7 @@ bool YellowNote::moving(GtkWidget *sender, GdkEventMotion *evt)
return false;
}
-#define YELLOWNOTE_VERSION 1
+#define YELLOWNOTE_VERSION 2
void YellowNote::load()
{
@@ -1554,6 +1665,7 @@ void YellowNote::load()
int hidden, x, y, width, height;
ColorType_t c;
std::string title;
+ bool title_only;
size_t s = 0;
if (std::filesystem::is_regular_file(p)) {
@@ -1574,6 +1686,11 @@ void YellowNote::load()
color = readInt(f, ColorType_t::YELLOW);
c = static_cast(color);
+ if (version >= 2) {
+ int t = readInt(f, 0);
+ title_only = (t) ? true : false;
+ }
+
char *buf = static_cast(malloc(s));
memset(buf, 0, s);
@@ -1600,13 +1717,17 @@ void YellowNote::load()
_pos_loaded = true;
updatePosition();
- _width = width; _height = height;
- _size_loaded = true;
- updateSize();
-
_hidden = hidden;
_hidden_loaded = true;
updateHidden();
+
+ _title_only = title_only;
+ _title_only_loaded = true;
+ updateTitleOnly();
+
+ _width = width; _height = height;
+ _size_loaded = true;
+ updateSize();
}
}
@@ -1619,8 +1740,6 @@ void YellowNote::save()
return;
}
- std::cout << "Saving " << _title << "..." << _size_loaded << ", " << _width << ", h = " << _height << std::endl;
-
std::filesystem::path p(_filename);
FILE *f = fopen(_filename.c_str(), "wt");
if (f) {
@@ -1631,6 +1750,7 @@ void YellowNote::save()
fprintf(f, "%d\n", _width);
fprintf(f, "%d\n", _height);
fprintf(f, "%d\n", _color);
+ fprintf(f, "%d\n", _title_only);
fprintf(f, "%s\n", _title.c_str());
GtkTextIter start, end;
diff --git a/yellownotes.h b/yellownotes.h
index be20dce..2ec54e1 100644
--- a/yellownotes.h
+++ b/yellownotes.h
@@ -10,7 +10,7 @@ extern "C" {
}
class YellowNote;
-class ColorSet;
+class SettingContainer;
typedef enum {
DARK = 0,
@@ -33,7 +33,7 @@ private:
void *_dlg;
void *_langs;
- std::list _color_sets;
+ std::list _settings_containers;
std::list _notes;
int _font_size;
@@ -56,6 +56,8 @@ public:
int fontSize();
int iconSize();
GtkWindow *topLevel();
+ void colorSet(void *sender);
+ void setFontSize(int size);
public:
void popupTrayMenu(void *sender);
@@ -83,11 +85,11 @@ public:
void setBgColor(ColorType_t type, const std::string &col);
std::string fromRGBA(const GdkRGBA &rgba);
void toRGBA(const std::string &col, GdkRGBA &rgba);
+ void updateWidgetCss(GtkWidget *w, ColorType_t col);
public:
YellowNotes(void *app);
~YellowNotes();
- void colorSet(void *sender);
};
#define YELLOWNOTES(obj) reinterpret_cast(obj)