summaryrefslogtreecommitdiff
path: root/plugingui/checkbox.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2015-09-03 18:20:34 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2015-09-03 18:20:34 +0200
commit3ec43973d1e269c5e6124e02276107c2c3020180 (patch)
treede1bae3885ca8bd56ea6aa953d8df55179717138 /plugingui/checkbox.cc
parent2295655ffec08ba2f99973ef7a8464fe726ae899 (diff)
Use Notifier in CheckBox class.
Diffstat (limited to 'plugingui/checkbox.cc')
-rw-r--r--plugingui/checkbox.cc73
1 files changed, 29 insertions, 44 deletions
diff --git a/plugingui/checkbox.cc b/plugingui/checkbox.cc
index faf3741..ec0456f 100644
--- a/plugingui/checkbox.cc
+++ b/plugingui/checkbox.cc
@@ -30,22 +30,23 @@
#include <stdio.h>
-GUI::CheckBox::CheckBox(Widget *parent)
- : GUI::Widget(parent),
- bg_on(":switch_back_on.png"), bg_off(":switch_back_off.png"),
- knob(":switch_front.png")
+namespace GUI {
+
+CheckBox::CheckBox(Widget *parent)
+ : Widget(parent)
+ , bg_on(":switch_back_on.png")
+ , bg_off(":switch_back_off.png")
+ , knob(":switch_front.png")
+ , state(false)
+ , middle(false)
{
- middle = false;
- state = false;
- handler = NULL;
}
-void GUI::CheckBox::buttonEvent(ButtonEvent *e)
+void CheckBox::buttonEvent(ButtonEvent *e)
{
if(e->direction == -1 || e->doubleclick) {
- state = !state;
middle = false;
- if(handler) handler(ptr);
+ internalSetChecked(!state);
} else {
middle = true;
}
@@ -53,24 +54,18 @@ void GUI::CheckBox::buttonEvent(ButtonEvent *e)
repaintEvent(NULL);
}
-void GUI::CheckBox::setText(std::string text)
+void CheckBox::setText(std::string text)
{
_text = text;
repaintEvent(NULL);
}
-void GUI::CheckBox::registerClickHandler(void (*handler)(void *), void *ptr)
+void CheckBox::keyEvent(KeyEvent *e)
{
- this->handler = handler;
- this->ptr = ptr;
-}
-
-void GUI::CheckBox::keyEvent(KeyEvent *e)
-{
- if(e->keycode == GUI::KeyEvent::KEY_CHARACTER && e->text == " ") {
+ if(e->keycode == KeyEvent::KEY_CHARACTER && e->text == " ") {
if(e->direction == -1) {
- state = !state;
middle = false;
+ internalSetChecked(!state);
} else {
middle = true;
}
@@ -79,7 +74,7 @@ void GUI::CheckBox::keyEvent(KeyEvent *e)
}
}
-void GUI::CheckBox::repaintEvent(GUI::RepaintEvent *e)
+void CheckBox::repaintEvent(RepaintEvent *e)
{
Painter p(this);
@@ -94,37 +89,27 @@ void GUI::CheckBox::repaintEvent(GUI::RepaintEvent *e)
if(middle) p.drawImage((bg_on.width() - knob.width()) / 2 + 1, 0, &knob);
else p.drawImage(0, 0, &knob);
}
- /*
- p.setColour(Colour(1));
- Font font;
- p.drawText(box + 8, height() / 2 + 5, font, _text);
- */
}
-bool GUI::CheckBox::checked()
+bool CheckBox::checked()
{
return state;
}
-void GUI::CheckBox::setChecked(bool c)
+void CheckBox::setChecked(bool c)
{
- state = c;
- repaintEvent(NULL);
+ internalSetChecked(c);
}
-#ifdef TEST_CHECKBOX
-//Additional dependency files
-//deps:
-//Required cflags (autoconf vars may be used)
-//cflags:
-//Required link options (autoconf vars may be used)
-//libs:
-#include "test.h"
-
-TEST_BEGIN;
-
-// TODO: Put some testcode here (see test.h for usable macros).
+void CheckBox::internalSetChecked(bool checked)
+{
+ if(checked == state) {
+ return;
+ }
-TEST_END;
+ state = checked;
+ stateChangedNotifier.notify(state);
+ repaintEvent(NULL);
+}
-#endif/*TEST_CHECKBOX*/
+} // GUI::