summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2015-11-20 20:04:39 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2015-11-20 20:04:39 +0100
commit299f6ef8499bb3ee4ada5d63dc71091fddcb39c6 (patch)
treeb7fdf5b33af017d5e38d8df1aed2d8017e930cfd
parent01b32ebab05428d3cd57ca72d2db1f0c431e007f (diff)
Improve behaviour when holding the mouse down and moving it in and out of the checkbox.
-rw-r--r--plugingui/checkbox.cc55
-rw-r--r--plugingui/checkbox.h7
2 files changed, 41 insertions, 21 deletions
diff --git a/plugingui/checkbox.cc b/plugingui/checkbox.cc
index 0d37127..60ed7a6 100644
--- a/plugingui/checkbox.cc
+++ b/plugingui/checkbox.cc
@@ -46,11 +46,16 @@ void CheckBox::buttonEvent(ButtonEvent* buttonEvent)
{
if((buttonEvent->direction == Direction::up) || buttonEvent->doubleClick)
{
+ buttonDown = false;
middle = false;
- internalSetChecked(!state);
+ if(inCheckbox)
+ {
+ internalSetChecked(!state);
+ }
}
else
{
+ buttonDown = true;
middle = true;
}
@@ -87,29 +92,21 @@ void CheckBox::repaintEvent(RepaintEvent* repaintEvent)
p.clear();
+ p.drawImage(0, (knob.height() - bg_on.height()) / 2, state ? bg_on : bg_off);
+
+ if(middle)
+ {
+ p.drawImage((bg_on.width() - knob.width()) / 2 + 1, 0, knob);
+ return;
+ }
+
if(state)
{
- p.drawImage(0, (knob.height() - bg_on.height()) / 2, bg_on);
- if(middle)
- {
- p.drawImage((bg_on.width() - knob.width()) / 2 + 1, 0, knob);
- }
- else
- {
- p.drawImage(bg_on.width() - 40 + 2, 0, knob);
- }
+ p.drawImage(bg_on.width() - 40 + 2, 0, knob);
}
else
{
- p.drawImage(0, (knob.height() - bg_off.height()) / 2, bg_off);
- if(middle)
- {
- p.drawImage((bg_on.width() - knob.width()) / 2 + 1, 0, knob);
- }
- else
- {
- p.drawImage(0, 0, knob);
- }
+ p.drawImage(0, 0, knob);
}
}
@@ -123,6 +120,26 @@ void CheckBox::setChecked(bool c)
internalSetChecked(c);
}
+void CheckBox::mouseLeaveEvent()
+{
+ inCheckbox = false;
+ if(buttonDown)
+ {
+ middle = false;
+ repaintEvent(nullptr);
+ }
+}
+
+void CheckBox::mouseEnterEvent()
+{
+ inCheckbox = true;
+ if(buttonDown)
+ {
+ middle = true;
+ repaintEvent(nullptr);
+ }
+}
+
void CheckBox::internalSetChecked(bool checked)
{
if(checked == state)
diff --git a/plugingui/checkbox.h b/plugingui/checkbox.h
index 093c5c3..927bf6d 100644
--- a/plugingui/checkbox.h
+++ b/plugingui/checkbox.h
@@ -40,6 +40,7 @@ public:
// From Widget:
bool isFocusable() override { return true; }
+ bool catchMouse() override { return true; }
bool checked();
void setChecked(bool checked);
@@ -47,12 +48,12 @@ public:
Notifier<bool> stateChangedNotifier;
protected:
- virtual void clicked() {}
-
// From Widget:
virtual void repaintEvent(RepaintEvent* repaintEvent) override;
virtual void buttonEvent(ButtonEvent* buttonEvent) override;
virtual void keyEvent(KeyEvent* keyEvent) override;
+ virtual void mouseLeaveEvent() override;
+ virtual void mouseEnterEvent() override;
private:
void internalSetChecked(bool checked);
@@ -63,6 +64,8 @@ private:
bool state;
bool middle;
+ bool buttonDown = false;
+ bool inCheckbox = false;
std::string _text;
};