summaryrefslogtreecommitdiff
path: root/plugingui/checkbox.cc
diff options
context:
space:
mode:
authorAndré Nusser <andre.nusser@googlemail.com>2017-03-23 12:22:00 +0100
committerAndré Nusser <andre.nusser@googlemail.com>2017-04-01 16:33:49 +0200
commit0e969842ccb1badc7689959c82208bd325cd01c7 (patch)
treed44cc6244e72babe78b318fd5880158266c61091 /plugingui/checkbox.cc
parent6c0bcd6719d929272057a71e62d72ae7aadeb507 (diff)
New Toggle class which includes the basic functionality of CheckBox
Diffstat (limited to 'plugingui/checkbox.cc')
-rw-r--r--plugingui/checkbox.cc96
1 files changed, 2 insertions, 94 deletions
diff --git a/plugingui/checkbox.cc b/plugingui/checkbox.cc
index 2a17635..499b2c1 100644
--- a/plugingui/checkbox.cc
+++ b/plugingui/checkbox.cc
@@ -32,63 +32,13 @@ namespace GUI
{
CheckBox::CheckBox(Widget* parent)
- : Widget(parent)
+ : Toggle(parent)
, bg_on(getImageCache(), ":switch_back_on.png")
, bg_off(getImageCache(), ":switch_back_off.png")
, knob(getImageCache(), ":switch_front.png")
{
}
-void CheckBox::buttonEvent(ButtonEvent* buttonEvent)
-{
- // Ignore everything except left clicks.
- if(buttonEvent->button != MouseButton::left)
- {
- return;
- }
-
- if((buttonEvent->direction == Direction::up) || buttonEvent->doubleClick)
- {
- buttonDown = false;
- middle = false;
- if(inCheckbox)
- {
- internalSetChecked(!state);
- }
- }
- else
- {
- buttonDown = true;
- middle = true;
- }
-
- redraw();
-}
-
-void CheckBox::setText(std::string text)
-{
- _text = text;
- redraw();
-}
-
-void CheckBox::keyEvent(KeyEvent* keyEvent)
-{
- if(keyEvent->keycode == Key::character && keyEvent->text == " ")
- {
- if(keyEvent->direction == Direction::up)
- {
- middle = false;
- internalSetChecked(!state);
- }
- else
- {
- middle = true;
- }
-
- redraw();
- }
-}
-
void CheckBox::repaintEvent(RepaintEvent* repaintEvent)
{
Painter p(*this);
@@ -97,7 +47,7 @@ void CheckBox::repaintEvent(RepaintEvent* repaintEvent)
p.drawImage(0, (knob.height() - bg_on.height()) / 2, state ? bg_on : bg_off);
- if(middle)
+ if(clicked)
{
p.drawImage((bg_on.width() - knob.width()) / 2 + 1, 0, knob);
return;
@@ -113,46 +63,4 @@ void CheckBox::repaintEvent(RepaintEvent* repaintEvent)
}
}
-bool CheckBox::checked()
-{
- return state;
-}
-
-void CheckBox::setChecked(bool c)
-{
- internalSetChecked(c);
-}
-
-void CheckBox::mouseLeaveEvent()
-{
- inCheckbox = false;
- if(buttonDown)
- {
- middle = false;
- redraw();
- }
-}
-
-void CheckBox::mouseEnterEvent()
-{
- inCheckbox = true;
- if(buttonDown)
- {
- middle = true;
- redraw();
- }
-}
-
-void CheckBox::internalSetChecked(bool checked)
-{
- if(checked == state)
- {
- return;
- }
-
- state = checked;
- stateChangedNotifier(state);
- redraw();
-}
-
} // GUI::