2016-10-20 14:34:48 +03:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 13:23:14 +03:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-10-20 14:34:48 +03:00
|
|
|
|
2018-01-03 13:23:14 +03:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-10-20 14:34:48 +03:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2019-04-02 13:13:30 +04:00
|
|
|
#include "ui/effects/animations.h"
|
2023-09-05 11:01:47 +03:00
|
|
|
|
|
|
|
namespace style {
|
|
|
|
struct RoundCheckbox;
|
|
|
|
struct RoundImageCheckbox;
|
|
|
|
} // namespace style
|
2016-10-20 14:34:48 +03:00
|
|
|
|
2022-09-17 00:23:27 +04:00
|
|
|
class Painter;
|
2022-11-01 15:17:13 +04:00
|
|
|
enum class ImageRoundRadius;
|
2022-09-17 00:23:27 +04:00
|
|
|
|
2016-10-20 14:34:48 +03:00
|
|
|
namespace Ui {
|
|
|
|
|
2023-07-17 19:59:27 +04:00
|
|
|
struct OutlineSegment;
|
|
|
|
|
2016-11-21 19:24:23 +03:00
|
|
|
class RoundCheckbox {
|
2016-10-20 14:34:48 +03:00
|
|
|
public:
|
2018-06-04 18:35:11 +03:00
|
|
|
RoundCheckbox(const style::RoundCheckbox &st, Fn<void()> updateCallback);
|
2016-10-20 14:34:48 +03:00
|
|
|
|
2022-09-17 00:23:27 +04:00
|
|
|
void paint(QPainter &p, int x, int y, int outerWidth, float64 masterScale = 1.) const;
|
2016-10-20 14:34:48 +03:00
|
|
|
|
2016-11-21 19:24:23 +03:00
|
|
|
void setDisplayInactive(bool displayInactive);
|
2016-10-20 16:41:46 +03:00
|
|
|
bool checked() const {
|
|
|
|
return _checked;
|
2016-10-20 14:34:48 +03:00
|
|
|
}
|
2020-03-13 17:05:21 +04:00
|
|
|
void setChecked(
|
|
|
|
bool newChecked,
|
|
|
|
anim::type animated = anim::type::normal);
|
2025-08-21 16:14:03 +04:00
|
|
|
void finishAnimating();
|
2016-10-20 14:34:48 +03:00
|
|
|
|
2016-12-20 16:03:51 +03:00
|
|
|
void invalidateCache();
|
|
|
|
|
2016-10-20 14:34:48 +03:00
|
|
|
private:
|
2016-11-21 19:24:23 +03:00
|
|
|
void prepareInactiveCache();
|
2016-10-20 14:34:48 +03:00
|
|
|
|
2016-11-21 19:24:23 +03:00
|
|
|
const style::RoundCheckbox &_st;
|
2018-06-04 18:35:11 +03:00
|
|
|
Fn<void()> _updateCallback;
|
2016-10-20 14:34:48 +03:00
|
|
|
|
2016-10-20 16:41:46 +03:00
|
|
|
bool _checked = false;
|
2019-04-02 13:13:30 +04:00
|
|
|
Ui::Animations::Simple _checkedProgress;
|
2016-10-20 14:34:48 +03:00
|
|
|
|
2016-11-21 19:24:23 +03:00
|
|
|
bool _displayInactive = false;
|
|
|
|
QPixmap _inactiveCacheBg, _inactiveCacheFg;
|
|
|
|
|
2016-10-20 14:34:48 +03:00
|
|
|
};
|
|
|
|
|
2016-11-21 19:24:23 +03:00
|
|
|
class RoundImageCheckbox {
|
|
|
|
public:
|
2018-06-04 18:35:11 +03:00
|
|
|
using PaintRoundImage = Fn<void(Painter &p, int x, int y, int outerWidth, int size)>;
|
2022-11-01 15:17:13 +04:00
|
|
|
RoundImageCheckbox(
|
|
|
|
const style::RoundImageCheckbox &st,
|
|
|
|
Fn<void()> updateCallback,
|
|
|
|
PaintRoundImage &&paintRoundImage,
|
2022-12-05 16:18:10 +04:00
|
|
|
Fn<std::optional<int>(int size)> roundingRadius = nullptr);
|
2023-07-17 19:59:27 +04:00
|
|
|
RoundImageCheckbox(RoundImageCheckbox&&);
|
|
|
|
~RoundImageCheckbox();
|
2016-11-21 19:24:23 +03:00
|
|
|
|
2022-06-02 01:21:26 +03:00
|
|
|
void paint(Painter &p, int x, int y, int outerWidth) const;
|
2016-11-21 19:24:23 +03:00
|
|
|
float64 checkedAnimationRatio() const;
|
|
|
|
|
2022-06-02 01:21:26 +03:00
|
|
|
void setColorOverride(std::optional<QBrush> fg);
|
2023-07-17 19:59:27 +04:00
|
|
|
void setCustomizedSegments(std::vector<OutlineSegment> segments);
|
2022-06-02 01:21:26 +03:00
|
|
|
|
2016-11-21 19:24:23 +03:00
|
|
|
bool checked() const {
|
|
|
|
return _check.checked();
|
|
|
|
}
|
2020-03-13 17:05:21 +04:00
|
|
|
void setChecked(
|
|
|
|
bool newChecked,
|
|
|
|
anim::type animated = anim::type::normal);
|
2016-11-21 19:24:23 +03:00
|
|
|
|
2016-12-20 16:03:51 +03:00
|
|
|
void invalidateCache() {
|
|
|
|
_check.invalidateCache();
|
|
|
|
}
|
|
|
|
|
2016-11-21 19:24:23 +03:00
|
|
|
private:
|
|
|
|
void prepareWideCache();
|
|
|
|
|
|
|
|
const style::RoundImageCheckbox &_st;
|
2018-06-04 18:35:11 +03:00
|
|
|
Fn<void()> _updateCallback;
|
2016-11-21 19:24:23 +03:00
|
|
|
PaintRoundImage _paintRoundImage;
|
2022-12-05 16:18:10 +04:00
|
|
|
Fn<std::optional<int>(int size)> _roundingRadius;
|
2016-11-21 19:24:23 +03:00
|
|
|
|
|
|
|
QPixmap _wideCache;
|
2019-04-02 13:13:30 +04:00
|
|
|
Ui::Animations::Simple _selection;
|
2016-11-21 19:24:23 +03:00
|
|
|
|
|
|
|
RoundCheckbox _check;
|
|
|
|
|
2023-07-04 00:05:11 +04:00
|
|
|
//std::optional<QBrush> _fgOverride;
|
2023-07-17 19:59:27 +04:00
|
|
|
std::vector<OutlineSegment> _segments;
|
2022-06-02 01:21:26 +03:00
|
|
|
|
2016-11-21 19:24:23 +03:00
|
|
|
};
|
|
|
|
|
2016-10-20 14:34:48 +03:00
|
|
|
} // namespace Ui
|