2016-08-19 17:26:31 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
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
|
2016-08-19 17:26:31 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "core/observer.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2016-08-19 17:26:31 +00:00
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
namespace Ui {
|
2016-08-22 17:16:21 +00:00
|
|
|
class Checkbox;
|
|
|
|
class Radiobutton;
|
2016-11-11 13:46:04 +00:00
|
|
|
class LinkButton;
|
2016-08-22 17:16:21 +00:00
|
|
|
template <typename Widget>
|
|
|
|
class WidgetSlideWrap;
|
|
|
|
} // namespace Ui
|
|
|
|
|
2016-08-19 17:26:31 +00:00
|
|
|
namespace Settings {
|
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
class BlockWidget : public TWidget, protected base::Subscriber {
|
2016-08-19 17:26:31 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
BlockWidget(QWidget *parent, UserData *self, const QString &title);
|
|
|
|
|
|
|
|
void setContentLeft(int contentLeft);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
virtual void paintContents(Painter &p) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// Where does the block content start (after the title).
|
|
|
|
int contentLeft() const {
|
|
|
|
return _contentLeft;
|
|
|
|
}
|
|
|
|
int contentTop() const;
|
|
|
|
|
|
|
|
// Resizes content and counts natural widget height for the desired width.
|
2016-08-22 17:16:21 +00:00
|
|
|
int resizeGetHeight(int newWidth) override;
|
2016-08-19 17:26:31 +00:00
|
|
|
|
|
|
|
void contentSizeUpdated() {
|
|
|
|
resizeToWidth(width());
|
|
|
|
emit heightUpdated();
|
|
|
|
}
|
|
|
|
|
|
|
|
UserData *self() const {
|
|
|
|
return _self;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool emptyTitle() const {
|
|
|
|
return _title.isEmpty();
|
|
|
|
}
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
template <typename Widget, typename ...Args>
|
2016-12-13 17:07:56 +00:00
|
|
|
Widget *addChildRow(object_ptr<Widget> &child, style::margins margin, Args&&... args) {
|
2017-02-21 13:45:56 +00:00
|
|
|
createChildRow(child, margin, std::forward<Args>(args)...);
|
2016-08-22 17:16:21 +00:00
|
|
|
addCreatedRow(child, margin);
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
2016-08-19 17:26:31 +00:00
|
|
|
private:
|
2016-08-22 17:16:21 +00:00
|
|
|
template <typename Widget, typename ...Args>
|
2016-12-13 17:07:56 +00:00
|
|
|
void createChildRow(object_ptr<Ui::WidgetSlideWrap<Widget>> &child, style::margins &margin, const style::margins &padding, Args&&... args) {
|
|
|
|
object_ptr<Widget> entity = { nullptr };
|
2017-02-21 13:45:56 +00:00
|
|
|
createChildRow(entity, margin, std::forward<Args>(args)...);
|
|
|
|
child.create(this, std::move(entity), padding, [this] { rowHeightUpdated(); });
|
2016-08-22 17:16:21 +00:00
|
|
|
margin.setLeft(margin.left() - padding.left());
|
|
|
|
margin.setTop(margin.top() - padding.top());
|
|
|
|
margin.setRight(margin.right() - padding.right());
|
|
|
|
margin.setBottom(margin.bottom() - padding.bottom());
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
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 QString &group, int value, const QString &text, const char *slot, bool checked);
|
|
|
|
void createChildRow(object_ptr<Ui::LinkButton> &child, style::margins &margin, const QString &text, const char *slot, const style::LinkButton &st = st::boxLinkButton);
|
2016-08-22 17:16:21 +00:00
|
|
|
|
|
|
|
void addCreatedRow(TWidget *child, const style::margins &margin);
|
|
|
|
void rowHeightUpdated();
|
|
|
|
|
|
|
|
template <typename Widget>
|
|
|
|
struct IsWidgetSlideWrap {
|
|
|
|
static constexpr bool value = false;
|
|
|
|
};
|
|
|
|
template <typename Widget>
|
|
|
|
struct IsWidgetSlideWrap<Ui::WidgetSlideWrap<Widget>> {
|
|
|
|
static constexpr bool value = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Widget>
|
2017-02-21 13:45:56 +00:00
|
|
|
using NotImplementedYet = std::enable_if_t<
|
2016-08-22 17:16:21 +00:00
|
|
|
!IsWidgetSlideWrap<Widget>::value &&
|
2017-02-21 13:45:56 +00:00
|
|
|
!std::is_same<Widget, Ui::Checkbox>::value &&
|
|
|
|
!std::is_same<Widget, Ui::Radiobutton>::value &&
|
|
|
|
!std::is_same<Widget, Ui::LinkButton>::value>;
|
2016-08-22 17:16:21 +00:00
|
|
|
|
|
|
|
template <typename Widget, typename... Args, typename = NotImplementedYet<Widget>>
|
2016-12-13 17:07:56 +00:00
|
|
|
void createChildRow(object_ptr<Widget> &child, style::margins &margin, Args&&... args) {
|
2017-02-21 13:45:56 +00:00
|
|
|
child.create(this, std::forward<Args>(args)...);
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-19 17:26:31 +00:00
|
|
|
void paintTitle(Painter &p);
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
struct ChildRow {
|
|
|
|
TWidget *child;
|
|
|
|
style::margins margin;
|
|
|
|
};
|
|
|
|
QVector<ChildRow> _rows;
|
|
|
|
|
2016-08-19 17:26:31 +00:00
|
|
|
int _contentLeft = 0;
|
|
|
|
UserData *_self;
|
|
|
|
QString _title;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Settings
|