summaryrefslogtreecommitdiff
path: root/plugingui/checkbox.cc
diff options
context:
space:
mode:
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::