2016-10-20 11:34:48 +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
|
|
|
|
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "styles/style_widgets.h"
|
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
|
2016-11-21 16:24:23 +00:00
|
|
|
class RoundCheckbox {
|
2016-10-20 11:34:48 +00:00
|
|
|
public:
|
2016-11-21 16:24:23 +00:00
|
|
|
RoundCheckbox(const style::RoundCheckbox &st, const base::lambda_copy<void()> &updateCallback);
|
2016-10-20 11:34:48 +00:00
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
void paint(Painter &p, TimeMs ms, int x, int y, int outerWidth, float64 masterScale = 1.);
|
2016-10-20 11:34:48 +00:00
|
|
|
|
2016-11-21 16:24:23 +00:00
|
|
|
void setDisplayInactive(bool displayInactive);
|
2016-10-20 13:41:46 +00:00
|
|
|
bool checked() const {
|
|
|
|
return _checked;
|
2016-10-20 11:34:48 +00:00
|
|
|
}
|
2016-10-20 13:41:46 +00:00
|
|
|
enum class SetStyle {
|
|
|
|
Animated,
|
|
|
|
Fast,
|
|
|
|
};
|
2016-11-21 16:24:23 +00:00
|
|
|
void setChecked(bool newChecked, SetStyle speed = SetStyle::Animated);
|
2016-10-20 11:34:48 +00:00
|
|
|
|
2016-12-20 13:03:51 +00:00
|
|
|
void invalidateCache();
|
|
|
|
|
2016-10-20 11:34:48 +00:00
|
|
|
private:
|
|
|
|
struct Icon {
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation fadeIn;
|
|
|
|
Animation fadeOut;
|
2016-10-20 11:34:48 +00:00
|
|
|
QPixmap wideCheckCache;
|
|
|
|
};
|
|
|
|
void removeFadeOutedIcons();
|
|
|
|
void prepareWideCheckIconCache(Icon *icon);
|
2016-11-21 16:24:23 +00:00
|
|
|
void prepareInactiveCache();
|
|
|
|
QRect cacheDestRect(int x, int y, float64 scale) const;
|
2016-10-20 11:34:48 +00:00
|
|
|
|
2016-11-21 16:24:23 +00:00
|
|
|
const style::RoundCheckbox &_st;
|
2016-11-20 12:54:07 +00:00
|
|
|
base::lambda_copy<void()> _updateCallback;
|
2016-10-20 11:34:48 +00:00
|
|
|
|
2016-10-20 13:41:46 +00:00
|
|
|
bool _checked = false;
|
2016-10-20 11:34:48 +00:00
|
|
|
std_::vector_of_moveable<Icon> _icons;
|
|
|
|
|
2016-11-21 16:24:23 +00:00
|
|
|
bool _displayInactive = false;
|
|
|
|
QPixmap _inactiveCacheBg, _inactiveCacheFg;
|
|
|
|
|
2016-10-20 11:34:48 +00:00
|
|
|
// Those pixmaps are shared among all checkboxes that have the same style.
|
|
|
|
QPixmap _wideCheckBgCache, _wideCheckFullCache;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-11-21 16:24:23 +00:00
|
|
|
class RoundImageCheckbox {
|
|
|
|
public:
|
|
|
|
using PaintRoundImage = base::lambda<void(Painter &p, int x, int y, int outerWidth, int size)>;
|
|
|
|
RoundImageCheckbox(const style::RoundImageCheckbox &st, const base::lambda_copy<void()> &updateCallback, PaintRoundImage &&paintRoundImage);
|
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
void paint(Painter &p, TimeMs ms, int x, int y, int outerWidth);
|
2016-11-21 16:24:23 +00:00
|
|
|
float64 checkedAnimationRatio() const;
|
|
|
|
|
|
|
|
bool checked() const {
|
|
|
|
return _check.checked();
|
|
|
|
}
|
|
|
|
using SetStyle = RoundCheckbox::SetStyle;
|
|
|
|
void setChecked(bool newChecked, SetStyle speed = SetStyle::Animated);
|
|
|
|
|
2016-12-20 13:03:51 +00:00
|
|
|
void invalidateCache() {
|
|
|
|
_check.invalidateCache();
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:24:23 +00:00
|
|
|
private:
|
|
|
|
void prepareWideCache();
|
|
|
|
|
|
|
|
const style::RoundImageCheckbox &_st;
|
|
|
|
base::lambda_copy<void()> _updateCallback;
|
|
|
|
PaintRoundImage _paintRoundImage;
|
|
|
|
|
|
|
|
QPixmap _wideCache;
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation _selection;
|
2016-11-21 16:24:23 +00:00
|
|
|
|
|
|
|
RoundCheckbox _check;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-10-20 11:34:48 +00:00
|
|
|
} // namespace Ui
|