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
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2016-12-02 19:16:35 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-11-15 11:56:49 +00:00
|
|
|
#include "styles/style_widgets.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
namespace Ui {
|
2015-10-06 19:49:23 +00:00
|
|
|
|
2016-12-02 19:16:35 +00:00
|
|
|
class Checkbox : public RippleButton {
|
2015-10-06 19:49:23 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
Checkbox(QWidget *parent, const QString &text, bool checked = false, const style::Checkbox &st = st::defaultCheckbox);
|
|
|
|
|
|
|
|
bool checked() const;
|
2016-06-01 13:07:03 +00:00
|
|
|
enum class NotifyAboutChange {
|
|
|
|
Notify,
|
|
|
|
DontNotify,
|
|
|
|
};
|
|
|
|
void setChecked(bool checked, NotifyAboutChange notify = NotifyAboutChange::Notify);
|
2015-10-06 19:49:23 +00:00
|
|
|
|
2016-06-01 13:07:03 +00:00
|
|
|
void finishAnimations();
|
2015-10-06 19:49:23 +00:00
|
|
|
|
2016-12-02 19:16:35 +00:00
|
|
|
QMargins getMargins() const override {
|
|
|
|
return _st.margin;
|
|
|
|
}
|
2016-08-22 17:16:21 +00:00
|
|
|
int naturalWidth() const override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
2015-10-06 19:49:23 +00:00
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void onStateChanged(State was, StateChangeSource source) override;
|
2016-12-02 19:16:35 +00:00
|
|
|
int resizeGetHeight(int newWidth) override;
|
|
|
|
|
|
|
|
QImage prepareRippleMask() const override;
|
|
|
|
QPoint prepareRippleStartPosition() const override;
|
2016-11-11 13:46:04 +00:00
|
|
|
|
|
|
|
public slots:
|
2015-10-06 19:49:23 +00:00
|
|
|
void onClicked();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void changed();
|
|
|
|
|
|
|
|
private:
|
|
|
|
const style::Checkbox &_st;
|
|
|
|
|
2016-12-31 15:19:22 +00:00
|
|
|
Text _text;
|
2015-10-06 19:49:23 +00:00
|
|
|
QRect _checkRect;
|
|
|
|
|
|
|
|
bool _checked;
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation _a_checked;
|
2015-10-06 19:49:23 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-03-18 11:55:04 +00:00
|
|
|
class Radiobutton;
|
2015-10-06 19:49:23 +00:00
|
|
|
|
2017-03-18 11:55:04 +00:00
|
|
|
class RadiobuttonGroup {
|
2015-10-06 19:49:23 +00:00
|
|
|
public:
|
2017-03-18 11:55:04 +00:00
|
|
|
RadiobuttonGroup() = default;
|
|
|
|
RadiobuttonGroup(int value) : _value(value), _hasValue(true) {
|
|
|
|
}
|
2015-10-06 19:49:23 +00:00
|
|
|
|
2017-03-18 11:55:04 +00:00
|
|
|
void setChangedCallback(base::lambda<void(int value)> callback) {
|
|
|
|
_changedCallback = std::move(callback);
|
|
|
|
}
|
2015-10-06 19:49:23 +00:00
|
|
|
|
2017-03-18 11:55:04 +00:00
|
|
|
bool hasValue() const {
|
|
|
|
return _hasValue;
|
|
|
|
}
|
|
|
|
int value() const {
|
2015-10-06 19:49:23 +00:00
|
|
|
return _value;
|
|
|
|
}
|
2017-03-18 11:55:04 +00:00
|
|
|
void setValue(int value);
|
|
|
|
|
2017-03-18 21:06:10 +00:00
|
|
|
private:
|
|
|
|
friend class Radiobutton;
|
2017-03-18 11:55:04 +00:00
|
|
|
void registerButton(Radiobutton *button) {
|
|
|
|
if (!base::contains(_buttons, button)) {
|
|
|
|
_buttons.push_back(button);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void unregisterButton(Radiobutton *button) {
|
|
|
|
_buttons.erase(std::remove(_buttons.begin(), _buttons.end(), button), _buttons.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
int _value = 0;
|
|
|
|
bool _hasValue = false;
|
|
|
|
base::lambda<void(int value)> _changedCallback;
|
|
|
|
std::vector<Radiobutton*> _buttons;
|
|
|
|
|
|
|
|
};
|
2015-10-06 19:49:23 +00:00
|
|
|
|
2017-03-18 11:55:04 +00:00
|
|
|
class Radiobutton : public RippleButton {
|
|
|
|
public:
|
|
|
|
Radiobutton(QWidget *parent, const std::shared_ptr<RadiobuttonGroup> &group, int value, const QString &text, const style::Checkbox &st = st::defaultCheckbox);
|
|
|
|
|
2016-12-02 19:16:35 +00:00
|
|
|
QMargins getMargins() const override {
|
|
|
|
return _st.margin;
|
|
|
|
}
|
|
|
|
int naturalWidth() const override;
|
2015-10-06 19:49:23 +00:00
|
|
|
|
|
|
|
~Radiobutton();
|
|
|
|
|
2016-11-11 13:46:04 +00:00
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void onStateChanged(State was, StateChangeSource source) override;
|
2016-12-02 19:16:35 +00:00
|
|
|
int resizeGetHeight(int newWidth) override;
|
|
|
|
|
|
|
|
QImage prepareRippleMask() const override;
|
|
|
|
QPoint prepareRippleStartPosition() const override;
|
2016-11-11 13:46:04 +00:00
|
|
|
|
2015-10-06 19:49:23 +00:00
|
|
|
private:
|
2017-03-18 11:55:04 +00:00
|
|
|
friend class RadiobuttonGroup;
|
|
|
|
void handleNewGroupValue(int value);
|
|
|
|
|
|
|
|
std::shared_ptr<RadiobuttonGroup> _group;
|
|
|
|
int _value = 0;
|
2015-10-06 19:49:23 +00:00
|
|
|
|
2016-12-02 19:16:35 +00:00
|
|
|
const style::Checkbox &_st;
|
2015-10-06 19:49:23 +00:00
|
|
|
|
2016-12-31 15:19:22 +00:00
|
|
|
Text _text;
|
2015-10-06 19:49:23 +00:00
|
|
|
QRect _checkRect;
|
|
|
|
|
2017-03-18 11:55:04 +00:00
|
|
|
bool _checked = false;
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation _a_checked;
|
2015-10-06 19:49:23 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
};
|
2016-10-28 09:20:24 +00:00
|
|
|
|
2017-03-18 21:06:10 +00:00
|
|
|
template <typename Enum>
|
|
|
|
class Radioenum;
|
|
|
|
|
|
|
|
template <typename Enum>
|
|
|
|
class RadioenumGroup {
|
|
|
|
public:
|
|
|
|
RadioenumGroup() = default;
|
|
|
|
RadioenumGroup(Enum value) : _group(static_cast<int>(value)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Callback>
|
|
|
|
void setChangedCallback(Callback &&callback) {
|
|
|
|
_group.setChangedCallback([callback](int value) {
|
|
|
|
callback(static_cast<Enum>(value));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasValue() const {
|
|
|
|
return _group.hasValue();
|
|
|
|
}
|
|
|
|
Enum value() const {
|
|
|
|
return static_cast<Enum>(_group.value());
|
|
|
|
}
|
|
|
|
void setValue(Enum value) {
|
|
|
|
_group.setValue(static_cast<int>(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
template <typename OtherEnum>
|
|
|
|
friend class Radioenum;
|
|
|
|
|
|
|
|
RadiobuttonGroup _group;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Enum>
|
|
|
|
class Radioenum : public Radiobutton {
|
|
|
|
public:
|
|
|
|
Radioenum(QWidget *parent, const std::shared_ptr<RadioenumGroup<Enum>> &group, Enum value, const QString &text, const style::Checkbox &st = st::defaultCheckbox)
|
|
|
|
: Radiobutton(parent, std::shared_ptr<RadiobuttonGroup>(group, &group->_group), static_cast<int>(value), text, st) {
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
} // namespace Ui
|