2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 10:47:38 +00:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2015-10-03 13:16:42 +00:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2016-02-08 10:56:18 +00:00
|
|
|
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/checkbox.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-04-21 17:57:29 +00:00
|
|
|
#include "lang.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
namespace Ui {
|
|
|
|
namespace {
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
class RadiobuttonGroup : public QMap<Radiobutton*, bool> {
|
|
|
|
using Parent = QMap<Radiobutton*, bool>;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
public:
|
2016-10-28 09:20:24 +00:00
|
|
|
RadiobuttonGroup(const QString &name) : _name(name) {
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
void remove(Radiobutton * const &radio);
|
2014-05-30 08:53:19 +00:00
|
|
|
int32 val() const {
|
|
|
|
return _val;
|
|
|
|
}
|
|
|
|
void setVal(int32 val) {
|
|
|
|
_val = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString _name;
|
2016-10-28 09:20:24 +00:00
|
|
|
int _val = 0;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
class Radiobuttons : public QMap<QString, RadiobuttonGroup*> {
|
|
|
|
using Parent = QMap<QString, RadiobuttonGroup*>;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
public:
|
2016-10-28 09:20:24 +00:00
|
|
|
RadiobuttonGroup *reg(const QString &group) {
|
2015-10-12 21:31:05 +00:00
|
|
|
typename Parent::const_iterator i = Parent::constFind(group);
|
|
|
|
if (i == Parent::cend()) {
|
2016-10-28 09:20:24 +00:00
|
|
|
i = Parent::insert(group, new RadiobuttonGroup(group));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
return i.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
int remove(const QString &group) {
|
2015-10-12 21:31:05 +00:00
|
|
|
typename Parent::iterator i = Parent::find(group);
|
|
|
|
if (i != Parent::cend()) {
|
2014-05-30 08:53:19 +00:00
|
|
|
delete i.value();
|
2015-10-12 21:31:05 +00:00
|
|
|
Parent::erase(i);
|
2014-05-30 08:53:19 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
~Radiobuttons() {
|
2015-10-12 21:31:05 +00:00
|
|
|
for (typename Parent::const_iterator i = Parent::cbegin(), e = Parent::cend(); i != e; ++i) {
|
2014-05-30 08:53:19 +00:00
|
|
|
delete *i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
Radiobuttons radiobuttons;
|
2015-10-06 19:49:23 +00:00
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
} // namespace
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
void RadiobuttonGroup::remove(Radiobutton * const &radio) {
|
2014-05-30 08:53:19 +00:00
|
|
|
Parent::remove(radio);
|
|
|
|
if (isEmpty()) {
|
2015-10-06 19:49:23 +00:00
|
|
|
radiobuttons.remove(_name);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-11 13:46:04 +00:00
|
|
|
Checkbox::Checkbox(QWidget *parent, const QString &text, bool checked, const style::Checkbox &st) : AbstractButton(parent)
|
2015-12-08 12:33:37 +00:00
|
|
|
, _st(st)
|
|
|
|
, a_over(0)
|
|
|
|
, a_checked(checked ? 1 : 0)
|
|
|
|
, _a_over(animation(this, &Checkbox::step_over))
|
|
|
|
, _a_checked(animation(this, &Checkbox::step_checked))
|
|
|
|
, _text(text)
|
|
|
|
, _fullText(text)
|
|
|
|
, _textWidth(st.font->width(text))
|
|
|
|
, _checked(checked) {
|
2015-10-06 19:49:23 +00:00
|
|
|
if (_st.width <= 0) {
|
|
|
|
resize(_textWidth - _st.width, _st.height);
|
|
|
|
} else {
|
|
|
|
if (_st.width < _st.textPosition.x() + _textWidth + (_st.textPosition.x() - _st.diameter)) {
|
2016-04-18 20:33:43 +00:00
|
|
|
_text = _st.font->elided(_fullText, qMax(_st.width - (_st.textPosition.x() + (_st.textPosition.x() - _st.diameter)), 1));
|
2015-10-06 19:49:23 +00:00
|
|
|
_textWidth = _st.font->width(_text);
|
|
|
|
}
|
|
|
|
resize(_st.width, _st.height);
|
|
|
|
}
|
|
|
|
_checkRect = myrtlrect(0, 0, _st.diameter, _st.diameter);
|
|
|
|
|
|
|
|
connect(this, SIGNAL(clicked()), this, SLOT(onClicked()));
|
|
|
|
|
|
|
|
setCursor(style::cur_pointer);
|
|
|
|
|
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Checkbox::checked() const {
|
|
|
|
return _checked;
|
|
|
|
}
|
|
|
|
|
2016-06-01 13:07:03 +00:00
|
|
|
void Checkbox::setChecked(bool checked, NotifyAboutChange notify) {
|
2015-10-06 19:49:23 +00:00
|
|
|
if (_checked != checked) {
|
|
|
|
_checked = checked;
|
|
|
|
if (_checked) {
|
|
|
|
a_checked.start(1);
|
|
|
|
} else {
|
|
|
|
a_checked.start(0);
|
|
|
|
}
|
|
|
|
_a_checked.start();
|
2016-06-01 13:07:03 +00:00
|
|
|
if (notify == NotifyAboutChange::Notify) {
|
|
|
|
emit changed();
|
|
|
|
}
|
2015-10-06 19:49:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-01 13:07:03 +00:00
|
|
|
void Checkbox::finishAnimations() {
|
|
|
|
a_checked.finish();
|
|
|
|
_a_checked.stop();
|
|
|
|
}
|
|
|
|
|
2015-12-08 12:33:37 +00:00
|
|
|
void Checkbox::step_over(float64 ms, bool timer) {
|
2015-10-06 19:49:23 +00:00
|
|
|
float64 dt = ms / _st.duration;
|
|
|
|
if (dt >= 1) {
|
2015-12-08 12:33:37 +00:00
|
|
|
_a_over.stop();
|
2015-10-06 19:49:23 +00:00
|
|
|
a_over.finish();
|
|
|
|
} else {
|
|
|
|
a_over.update(dt, anim::linear);
|
|
|
|
}
|
2015-12-08 12:33:37 +00:00
|
|
|
if (timer) update(_checkRect);
|
2015-10-06 19:49:23 +00:00
|
|
|
}
|
|
|
|
|
2015-12-08 12:33:37 +00:00
|
|
|
void Checkbox::step_checked(float64 ms, bool timer) {
|
2015-10-06 19:49:23 +00:00
|
|
|
float64 dt = ms / _st.duration;
|
|
|
|
if (dt >= 1) {
|
|
|
|
a_checked.finish();
|
2015-12-08 12:33:37 +00:00
|
|
|
_a_checked.stop();
|
2015-10-06 19:49:23 +00:00
|
|
|
} else {
|
|
|
|
a_checked.update(dt, anim::linear);
|
|
|
|
}
|
2015-12-08 12:33:37 +00:00
|
|
|
if (timer) update(_checkRect);
|
2015-10-06 19:49:23 +00:00
|
|
|
}
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
int Checkbox::naturalWidth() const {
|
|
|
|
return _st.textPosition.x() + _st.font->width(_fullText);
|
|
|
|
}
|
|
|
|
|
2015-10-06 19:49:23 +00:00
|
|
|
void Checkbox::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
float64 over = a_over.current(), checked = a_checked.current();
|
|
|
|
bool cnone = (over == 0. && checked == 0.), cover = (over == 1. && checked == 0.), cchecked = (checked == 1.);
|
|
|
|
bool cbad = !cnone && !cover && !cchecked;
|
|
|
|
QColor color;
|
|
|
|
if (cbad) {
|
|
|
|
float64 onone = (1. - over) * (1. - checked), oover = over * (1. - checked), ochecked = checked;
|
|
|
|
color.setRedF(_st.checkFg->c.redF() * onone + _st.checkFgOver->c.redF() * oover + _st.checkFgActive->c.redF() * ochecked);
|
|
|
|
color.setGreenF(_st.checkFg->c.greenF() * onone + _st.checkFgOver->c.greenF() * oover + _st.checkFgActive->c.greenF() * ochecked);
|
|
|
|
color.setBlueF(_st.checkFg->c.blueF() * onone + _st.checkFgOver->c.blueF() * oover + _st.checkFgActive->c.blueF() * ochecked);
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect r(e->rect());
|
|
|
|
p.setClipRect(r);
|
2016-10-31 12:29:26 +00:00
|
|
|
p.fillRect(r, _st.textBg);
|
2015-10-06 19:49:23 +00:00
|
|
|
if (_checkRect.intersects(r)) {
|
|
|
|
p.setRenderHint(QPainter::HighQualityAntialiasing);
|
|
|
|
|
|
|
|
QPen pen;
|
|
|
|
if (cbad) {
|
|
|
|
pen = QPen(color);
|
|
|
|
} else {
|
|
|
|
pen = (cnone ? _st.checkFg : (cover ? _st.checkFgOver : _st.checkFgActive))->p;
|
|
|
|
color = (cnone ? _st.checkFg : (cover ? _st.checkFgOver : _st.checkFgActive))->c;
|
|
|
|
}
|
|
|
|
pen.setWidth(_st.thickness);
|
|
|
|
p.setPen(pen);
|
|
|
|
if (checked > 0) {
|
2016-10-31 12:29:26 +00:00
|
|
|
color.setRedF(color.redF() * checked + _st.checkBg->c.redF() * (1. - checked));
|
|
|
|
color.setGreenF(color.greenF() * checked + _st.checkBg->c.greenF() * (1. - checked));
|
|
|
|
color.setBlueF(color.blueF() * checked + _st.checkBg->c.blueF() * (1. - checked));
|
2015-10-06 19:49:23 +00:00
|
|
|
p.setBrush(color);
|
|
|
|
} else {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setBrush(_st.checkBg);
|
2015-10-06 19:49:23 +00:00
|
|
|
}
|
2016-07-07 12:35:14 +00:00
|
|
|
p.drawRoundedRect(QRectF(_checkRect).marginsRemoved(QMarginsF(_st.thickness / 2., _st.thickness / 2., _st.thickness / 2., _st.thickness / 2.)), st::buttonRadius - (_st.thickness / 2.), st::buttonRadius - (_st.thickness / 2.));
|
2015-10-06 19:49:23 +00:00
|
|
|
p.setRenderHint(QPainter::HighQualityAntialiasing, false);
|
|
|
|
|
|
|
|
if (checked > 0) {
|
2016-06-07 19:59:39 +00:00
|
|
|
_st.checkIcon.paint(p, QPoint(0, 0), width());
|
2015-10-06 19:49:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_checkRect.contains(r)) return;
|
|
|
|
|
|
|
|
p.setPen(_st.textFg);
|
|
|
|
p.setFont(_st.font);
|
|
|
|
p.drawTextLeft(_st.textPosition.x(), _st.textPosition.y(), width(), _text, _textWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Checkbox::onClicked() {
|
|
|
|
if (_state & StateDisabled) return;
|
|
|
|
setChecked(!checked());
|
|
|
|
}
|
|
|
|
|
2016-11-11 13:46:04 +00:00
|
|
|
void Checkbox::onStateChanged(int oldState, StateChangeSource source) {
|
2015-10-06 19:49:23 +00:00
|
|
|
if ((_state & StateOver) && !(oldState & StateOver)) {
|
|
|
|
a_over.start(1);
|
|
|
|
_a_over.start();
|
|
|
|
} else if (!(_state & StateOver) && (oldState & StateOver)) {
|
|
|
|
a_over.start(0);
|
|
|
|
_a_over.start();
|
|
|
|
}
|
|
|
|
if ((_state & StateDisabled) && !(oldState & StateDisabled)) {
|
|
|
|
setCursor(style::cur_default);
|
|
|
|
} else if (!(_state & StateDisabled) && (oldState & StateDisabled)) {
|
|
|
|
setCursor(style::cur_pointer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-11 13:46:04 +00:00
|
|
|
Radiobutton::Radiobutton(QWidget *parent, const QString &group, int32 value, const QString &text, bool checked, const style::Radiobutton &st) : AbstractButton(parent)
|
2015-12-08 12:33:37 +00:00
|
|
|
, _st(st)
|
|
|
|
, a_over(0)
|
|
|
|
, a_checked(checked ? 1 : 0)
|
|
|
|
, _a_over(animation(this, &Radiobutton::step_over))
|
|
|
|
, _a_checked(animation(this, &Radiobutton::step_checked))
|
|
|
|
, _text(text)
|
|
|
|
, _fullText(text)
|
|
|
|
, _textWidth(st.font->width(text))
|
|
|
|
, _checked(checked)
|
|
|
|
, _group(radiobuttons.reg(group))
|
|
|
|
, _value(value) {
|
2015-10-06 19:49:23 +00:00
|
|
|
if (_st.width <= 0) {
|
|
|
|
resize(_textWidth - _st.width, _st.height);
|
|
|
|
} else {
|
|
|
|
if (_st.width < _st.textPosition.x() + _textWidth + (_st.textPosition.x() - _st.diameter)) {
|
2016-04-18 20:33:43 +00:00
|
|
|
_text = _st.font->elided(_fullText, qMax(_st.width - (_st.textPosition.x() + (_st.textPosition.x() - _st.diameter)), 1));
|
2015-10-06 19:49:23 +00:00
|
|
|
_textWidth = _st.font->width(_text);
|
|
|
|
}
|
|
|
|
resize(_st.width, _st.height);
|
|
|
|
}
|
|
|
|
_checkRect = myrtlrect(0, 0, _st.diameter, _st.diameter);
|
|
|
|
|
|
|
|
connect(this, SIGNAL(clicked()), this, SLOT(onClicked()));
|
|
|
|
|
|
|
|
setCursor(style::cur_pointer);
|
|
|
|
|
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
|
|
|
|
|
|
|
reinterpret_cast<RadiobuttonGroup*>(_group)->insert(this, true);
|
|
|
|
if (_checked) onChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Radiobutton::checked() const {
|
|
|
|
return _checked;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Radiobutton::setChecked(bool checked) {
|
|
|
|
if (_checked != checked) {
|
|
|
|
_checked = checked;
|
|
|
|
if (_checked) {
|
|
|
|
a_checked.start(1);
|
|
|
|
} else {
|
|
|
|
a_checked.start(0);
|
|
|
|
}
|
|
|
|
_a_checked.start();
|
|
|
|
|
|
|
|
onChanged();
|
|
|
|
emit changed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-08 12:33:37 +00:00
|
|
|
void Radiobutton::step_over(float64 ms, bool timer) {
|
2015-10-06 19:49:23 +00:00
|
|
|
float64 dt = ms / _st.duration;
|
|
|
|
if (dt >= 1) {
|
2015-12-08 12:33:37 +00:00
|
|
|
_a_over.stop();
|
2015-10-06 19:49:23 +00:00
|
|
|
a_over.finish();
|
|
|
|
} else {
|
|
|
|
a_over.update(dt, anim::linear);
|
|
|
|
}
|
2015-12-08 12:33:37 +00:00
|
|
|
if (timer) update(_checkRect);
|
2015-10-06 19:49:23 +00:00
|
|
|
}
|
|
|
|
|
2015-12-08 12:33:37 +00:00
|
|
|
void Radiobutton::step_checked(float64 ms, bool timer) {
|
2015-10-06 19:49:23 +00:00
|
|
|
float64 dt = ms / _st.duration;
|
|
|
|
if (dt >= 1) {
|
|
|
|
a_checked.finish();
|
2015-12-08 12:33:37 +00:00
|
|
|
_a_checked.stop();
|
2015-10-06 19:49:23 +00:00
|
|
|
} else {
|
|
|
|
a_checked.update(dt, anim::linear);
|
|
|
|
}
|
2015-12-08 12:33:37 +00:00
|
|
|
if (timer) update(_checkRect);
|
2015-10-06 19:49:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Radiobutton::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
float64 over = a_over.current(), checked = a_checked.current();
|
|
|
|
bool cnone = (over == 0. && checked == 0.), cover = (over == 1. && checked == 0.), cchecked = (checked == 1.);
|
|
|
|
bool cbad = !cnone && !cover && !cchecked;
|
|
|
|
QColor color;
|
|
|
|
if (cbad) {
|
|
|
|
float64 onone = (1. - over) * (1. - checked), oover = over * (1. - checked), ochecked = checked;
|
|
|
|
color.setRedF(_st.checkFg->c.redF() * onone + _st.checkFgOver->c.redF() * oover + _st.checkFgActive->c.redF() * ochecked);
|
|
|
|
color.setGreenF(_st.checkFg->c.greenF() * onone + _st.checkFgOver->c.greenF() * oover + _st.checkFgActive->c.greenF() * ochecked);
|
|
|
|
color.setBlueF(_st.checkFg->c.blueF() * onone + _st.checkFgOver->c.blueF() * oover + _st.checkFgActive->c.blueF() * ochecked);
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect r(e->rect());
|
|
|
|
p.setClipRect(r);
|
|
|
|
p.fillRect(r, _st.textBg->b);
|
|
|
|
if (_checkRect.intersects(r)) {
|
|
|
|
p.setRenderHint(QPainter::HighQualityAntialiasing);
|
|
|
|
|
|
|
|
QPen pen;
|
|
|
|
if (cbad) {
|
|
|
|
pen = QPen(color);
|
|
|
|
} else {
|
|
|
|
pen = (cnone ? _st.checkFg : (cover ? _st.checkFgOver : _st.checkFgActive))->p;
|
|
|
|
}
|
|
|
|
pen.setWidth(_st.thickness);
|
|
|
|
p.setPen(pen);
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setBrush(_st.checkBg);
|
2016-06-24 16:58:41 +00:00
|
|
|
//int32 skip = qCeil(_st.thickness / 2.);
|
2015-10-06 19:49:23 +00:00
|
|
|
//p.drawEllipse(_checkRect.marginsRemoved(QMargins(skip, skip, skip, skip)));
|
2016-06-24 16:58:41 +00:00
|
|
|
p.drawEllipse(QRectF(_checkRect).marginsRemoved(QMarginsF(_st.thickness / 2., _st.thickness / 2., _st.thickness / 2., _st.thickness / 2.)));
|
2015-10-06 19:49:23 +00:00
|
|
|
|
|
|
|
if (checked > 0) {
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
if (cbad) {
|
|
|
|
p.setBrush(color);
|
|
|
|
} else {
|
|
|
|
p.setBrush(cnone ? _st.checkFg : (cover ? _st.checkFgOver : _st.checkFgActive));
|
|
|
|
}
|
|
|
|
float64 skip0 = _checkRect.width() / 2., skip1 = _st.checkSkip / 10., checkSkip = skip0 * (1. - checked) + skip1 * checked;
|
|
|
|
p.drawEllipse(QRectF(_checkRect).marginsRemoved(QMarginsF(checkSkip, checkSkip, checkSkip, checkSkip)));
|
|
|
|
//int32 fskip = qFloor(checkSkip), cskip = qCeil(checkSkip);
|
|
|
|
//if (2 * fskip < _checkRect.width()) {
|
|
|
|
// if (fskip != cskip) {
|
|
|
|
// p.setOpacity(float64(cskip) - checkSkip);
|
|
|
|
// p.drawEllipse(_checkRect.marginsRemoved(QMargins(fskip, fskip, fskip, fskip)));
|
|
|
|
// p.setOpacity(1.);
|
|
|
|
// }
|
|
|
|
// if (2 * cskip < _checkRect.width()) {
|
|
|
|
// p.drawEllipse(_checkRect.marginsRemoved(QMargins(cskip, cskip, cskip, cskip)));
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
|
|
|
|
p.setRenderHint(QPainter::HighQualityAntialiasing, false);
|
|
|
|
}
|
|
|
|
if (_checkRect.contains(r)) return;
|
|
|
|
|
|
|
|
p.setPen(_st.textFg);
|
|
|
|
p.setFont(_st.font);
|
|
|
|
p.drawTextLeft(_st.textPosition.x(), _st.textPosition.y(), width(), _text, _textWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Radiobutton::onClicked() {
|
|
|
|
if (_state & StateDisabled) return;
|
|
|
|
setChecked(!checked());
|
|
|
|
}
|
|
|
|
|
2016-11-11 13:46:04 +00:00
|
|
|
void Radiobutton::onStateChanged(int oldState, StateChangeSource source) {
|
2015-10-06 19:49:23 +00:00
|
|
|
if ((_state & StateOver) && !(oldState & StateOver)) {
|
|
|
|
a_over.start(1);
|
|
|
|
_a_over.start();
|
|
|
|
} else if (!(_state & StateOver) && (oldState & StateOver)) {
|
|
|
|
a_over.start(0);
|
|
|
|
_a_over.start();
|
|
|
|
}
|
|
|
|
if ((_state & StateDisabled) && !(oldState & StateDisabled)) {
|
|
|
|
setCursor(style::cur_default);
|
|
|
|
} else if (!(_state & StateDisabled) && (oldState & StateDisabled)) {
|
|
|
|
setCursor(style::cur_pointer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Radiobutton::onChanged() {
|
|
|
|
RadiobuttonGroup *group = reinterpret_cast<RadiobuttonGroup*>(_group);
|
|
|
|
if (checked()) {
|
|
|
|
int32 uncheck = group->val();
|
|
|
|
if (uncheck != _value) {
|
|
|
|
group->setVal(_value);
|
|
|
|
for (RadiobuttonGroup::const_iterator i = group->cbegin(), e = group->cend(); i != e; ++i) {
|
|
|
|
if (i.key()->val() == uncheck) {
|
|
|
|
i.key()->setChecked(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (group->val() == _value) {
|
|
|
|
setChecked(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Radiobutton::~Radiobutton() {
|
|
|
|
reinterpret_cast<RadiobuttonGroup*>(_group)->remove(this);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-10-28 09:20:24 +00:00
|
|
|
|
|
|
|
} // namespace Ui
|