tdesktop/Telegram/SourceFiles/passport/passport_panel_details_row.h

85 lines
1.8 KiB
C
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "ui/rp_widget.h"
2019-04-02 09:13:30 +00:00
#include "ui/effects/animations.h"
#include "ui/wrap/padding_wrap.h"
#include "ui/widgets/labels.h"
#include "boxes/abstract_box.h"
namespace Ui {
class InputField;
2018-04-10 11:26:21 +00:00
class FlatLabel;
template <typename Widget>
class SlideWrap;
} // namespace Ui
namespace Passport {
2018-04-10 11:26:21 +00:00
class PanelController;
enum class PanelDetailsType {
Text,
2018-05-15 13:35:59 +00:00
Postcode,
2018-04-10 11:26:21 +00:00
Country,
Date,
Gender,
};
class PanelDetailsRow : public Ui::RpWidget {
public:
2018-04-10 11:26:21 +00:00
using Type = PanelDetailsType;
PanelDetailsRow(
QWidget *parent,
2018-06-08 19:26:08 +00:00
const QString &label,
int maxLabelWidth);
2018-04-10 11:26:21 +00:00
static object_ptr<PanelDetailsRow> Create(
QWidget *parent,
Type type,
not_null<PanelController*> controller,
const QString &label,
2018-06-08 19:26:08 +00:00
int maxLabelWidth,
2018-04-10 11:26:21 +00:00
const QString &value,
2018-04-13 11:15:07 +00:00
const QString &error,
int limit = 0);
2018-06-08 19:26:08 +00:00
static int LabelWidth(const QString &label);
2018-04-10 11:26:21 +00:00
virtual bool setFocusFast();
virtual rpl::producer<QString> value() const = 0;
virtual QString valueCurrent() const = 0;
2018-09-21 16:28:46 +00:00
void showError(std::optional<QString> error = std::nullopt);
2018-04-17 17:54:52 +00:00
bool errorShown() const;
2018-04-10 11:26:21 +00:00
void hideError();
void finishAnimating();
protected:
int resizeGetHeight(int newWidth) override;
void paintEvent(QPaintEvent *e) override;
private:
2018-04-10 11:26:21 +00:00
virtual int resizeInner(int left, int top, int width) = 0;
virtual void showInnerError() = 0;
virtual void finishInnerAnimating() = 0;
void startErrorAnimation(bool shown);
QString _label;
2018-06-08 19:26:08 +00:00
int _maxLabelWidth = 0;
2018-04-10 11:26:21 +00:00
object_ptr<Ui::SlideWrap<Ui::FlatLabel>> _error = { nullptr };
bool _errorShown = false;
bool _errorHideSubscription = false;
2019-04-02 09:13:30 +00:00
Ui::Animations::Simple _errorAnimation;
};
} // namespace Passport