mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 14:38:15 +00:00
Refactor Ui::Radiobutton. Add Ui::Radioenum<Enum>.
Now group of Ui::Radiobutton instances share Ui::RadiobuttonGroup. All value management is done through the group instance, not through separate radio buttons. Also a template for groups over enums added.
This commit is contained in:
@@ -90,12 +90,8 @@ void BlockWidget::createChildRow(object_ptr<Ui::Checkbox> &child, style::margins
|
||||
connect(child, SIGNAL(changed()), this, slot);
|
||||
}
|
||||
|
||||
void BlockWidget::createChildRow(object_ptr<Ui::Radiobutton> &child, style::margins &margin, const std::shared_ptr<Ui::RadiobuttonGroup> &group, int value, const QString &text) {
|
||||
child.create(this, group, value, text, st::defaultBoxCheckbox);
|
||||
}
|
||||
|
||||
void BlockWidget::createChildRow(object_ptr<Ui::LinkButton> &child, style::margins &margin, const QString &text, const char *slot, const style::LinkButton &st) {
|
||||
child .create(this, text, st);
|
||||
child.create(this, text, st);
|
||||
connect(child, SIGNAL(clicked()), this, slot);
|
||||
}
|
||||
|
||||
|
@@ -28,6 +28,10 @@ class Checkbox;
|
||||
class RadiobuttonGroup;
|
||||
class Radiobutton;
|
||||
class LinkButton;
|
||||
template <typename Enum>
|
||||
class RadioenumGroup;
|
||||
template <typename Enum>
|
||||
class Radioenum;
|
||||
template <typename Widget>
|
||||
class WidgetSlideWrap;
|
||||
} // namespace Ui
|
||||
@@ -88,27 +92,35 @@ private:
|
||||
margin.setBottom(margin.bottom() - padding.bottom());
|
||||
}
|
||||
void createChildRow(object_ptr<Ui::Checkbox> &child, style::margins &margin, const QString &text, const char *slot, bool checked);
|
||||
void createChildRow(object_ptr<Ui::Radiobutton> &child, style::margins &margin, const Ui::RadiobuttonGroup &group, int value, const QString &text);
|
||||
void createChildRow(object_ptr<Ui::LinkButton> &child, style::margins &margin, const QString &text, const char *slot, const style::LinkButton &st = st::boxLinkButton);
|
||||
|
||||
template <typename Enum>
|
||||
void createChildRow(object_ptr<Ui::Radioenum<Enum>> &child, style::margins &margin, const std::shared_ptr<Ui::RadioenumGroup<Enum>> &group, Enum value, const QString &text) {
|
||||
child.create(this, group, value, text, st::defaultBoxCheckbox);
|
||||
}
|
||||
|
||||
void addCreatedRow(TWidget *child, const style::margins &margin);
|
||||
void rowHeightUpdated();
|
||||
|
||||
template <typename Widget>
|
||||
struct IsWidgetSlideWrap {
|
||||
static constexpr bool value = false;
|
||||
struct IsWidgetSlideWrap : std::false_type {
|
||||
};
|
||||
template <typename Widget>
|
||||
struct IsWidgetSlideWrap<Ui::WidgetSlideWrap<Widget>> {
|
||||
static constexpr bool value = true;
|
||||
struct IsWidgetSlideWrap<Ui::WidgetSlideWrap<Widget>> : std::true_type {
|
||||
};
|
||||
template <typename Widget>
|
||||
struct IsRadioenum : std::false_type {
|
||||
};
|
||||
template <typename Enum>
|
||||
struct IsRadioenum<Ui::Radioenum<Enum>> : std::true_type {
|
||||
};
|
||||
|
||||
template <typename Widget>
|
||||
using NotImplementedYet = std::enable_if_t<
|
||||
!IsWidgetSlideWrap<Widget>::value &&
|
||||
!std::is_same<Widget, Ui::Checkbox>::value &&
|
||||
!std::is_same<Widget, Ui::Radiobutton>::value &&
|
||||
!std::is_same<Widget, Ui::LinkButton>::value>;
|
||||
!IsRadioenum<Widget>::value &&
|
||||
!std::is_same<Ui::Checkbox, Widget>::value &&
|
||||
!std::is_same<Ui::LinkButton, Widget>::value>;
|
||||
|
||||
template <typename Widget, typename... Args, typename = NotImplementedYet<Widget>>
|
||||
void createChildRow(object_ptr<Widget> &child, style::margins &margin, Args&&... args) {
|
||||
|
@@ -180,10 +180,10 @@ void ChatSettingsWidget::createControls() {
|
||||
}
|
||||
#endif // OS_WIN_STORE
|
||||
|
||||
auto group = std::make_shared<Ui::RadiobuttonGroup>(cCtrlEnter() ? 1 : 0);
|
||||
addChildRow(_sendByEnter, marginSmall, group, 0, lang(lng_settings_send_enter));
|
||||
addChildRow(_sendByCtrlEnter, marginSkip, group, 1, lang((cPlatform() == dbipMac || cPlatform() == dbipMacOld) ? lng_settings_send_cmdenter : lng_settings_send_ctrlenter), SLOT(onSendByCtrlEnter()), cCtrlEnter());
|
||||
group->setChangedCallback([this](int value) {
|
||||
auto group = std::make_shared<Ui::RadioenumGroup<SendByType>>(cCtrlEnter() ? SendByType::CtrlEnter : SendByType::Enter);
|
||||
addChildRow(_sendByEnter, marginSmall, group, SendByType::Enter, lang(lng_settings_send_enter));
|
||||
addChildRow(_sendByCtrlEnter, marginSkip, group, SendByType::CtrlEnter, lang((cPlatform() == dbipMac || cPlatform() == dbipMacOld) ? lng_settings_send_cmdenter : lng_settings_send_ctrlenter));
|
||||
group->setChangedCallback([this](SendByType value) {
|
||||
sendByChanged(value);
|
||||
});
|
||||
|
||||
@@ -210,8 +210,8 @@ void ChatSettingsWidget::onDontAskDownloadPath() {
|
||||
#endif // OS_WIN_STORE
|
||||
}
|
||||
|
||||
void ChatSettingsWidget::sendByChanged(int value) {
|
||||
cSetCtrlEnter(value == 1);
|
||||
void ChatSettingsWidget::sendByChanged(SendByType value) {
|
||||
cSetCtrlEnter(value == SendByType::CtrlEnter);
|
||||
if (App::main()) App::main()->ctrlEnterSubmitUpdated();
|
||||
Local::writeUserSettings();
|
||||
}
|
||||
|
@@ -102,7 +102,11 @@ private slots:
|
||||
void onManageStickerSets();
|
||||
|
||||
private:
|
||||
void sendByChanged(int value);
|
||||
enum class SendByType {
|
||||
Enter,
|
||||
CtrlEnter,
|
||||
};
|
||||
void sendByChanged(SendByType value);
|
||||
void createControls();
|
||||
|
||||
object_ptr<Ui::Checkbox> _replaceEmoji = { nullptr };
|
||||
@@ -113,8 +117,8 @@ private:
|
||||
object_ptr<Ui::WidgetSlideWrap<DownloadPathState>> _downloadPath = { nullptr };
|
||||
#endif // OS_WIN_STORE
|
||||
|
||||
object_ptr<Ui::Radiobutton> _sendByEnter = { nullptr };
|
||||
object_ptr<Ui::Radiobutton> _sendByCtrlEnter = { nullptr };
|
||||
object_ptr<Ui::Radioenum<SendByType>> _sendByEnter = { nullptr };
|
||||
object_ptr<Ui::Radioenum<SendByType>> _sendByCtrlEnter = { nullptr };
|
||||
object_ptr<Ui::LinkButton> _automaticMediaDownloadSettings = { nullptr };
|
||||
object_ptr<Ui::LinkButton> _manageStickerSets = { nullptr };
|
||||
|
||||
|
Reference in New Issue
Block a user