Allow repainting SeparatePanel title.
This commit is contained in:
parent
b2293c86e1
commit
1ba24ed511
4 changed files with 219 additions and 71 deletions
|
|
@ -469,6 +469,10 @@ IconButton::IconButton(QWidget *parent, const style::IconButton &st) : RippleBut
|
||||||
resize(_st.width, _st.height);
|
resize(_st.width, _st.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const style::IconButton &IconButton::st() const {
|
||||||
|
return _st;
|
||||||
|
}
|
||||||
|
|
||||||
void IconButton::setIconOverride(const style::icon *iconOverride, const style::icon *iconOverOverride) {
|
void IconButton::setIconOverride(const style::icon *iconOverride, const style::icon *iconOverOverride) {
|
||||||
_iconOverride = iconOverride;
|
_iconOverride = iconOverride;
|
||||||
_iconOverrideOver = iconOverOverride;
|
_iconOverrideOver = iconOverOverride;
|
||||||
|
|
|
||||||
|
|
@ -184,6 +184,8 @@ class IconButton : public RippleButton {
|
||||||
public:
|
public:
|
||||||
IconButton(QWidget *parent, const style::IconButton &st);
|
IconButton(QWidget *parent, const style::IconButton &st);
|
||||||
|
|
||||||
|
[[nodiscard]] const style::IconButton &st() const;
|
||||||
|
|
||||||
// Pass nullptr to restore the default icon.
|
// Pass nullptr to restore the default icon.
|
||||||
void setIconOverride(const style::icon *iconOverride, const style::icon *iconOverOverride = nullptr);
|
void setIconOverride(const style::icon *iconOverride, const style::icon *iconOverOverride = nullptr);
|
||||||
void setRippleColorOverride(const style::color *colorOverride);
|
void setRippleColorOverride(const style::color *colorOverride);
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/layers/box_content.h"
|
#include "ui/layers/box_content.h"
|
||||||
#include "ui/layers/layer_widget.h"
|
#include "ui/layers/layer_widget.h"
|
||||||
#include "ui/layers/show.h"
|
#include "ui/layers/show.h"
|
||||||
|
#include "ui/style/style_core_palette.h"
|
||||||
#include "ui/painter.h"
|
#include "ui/painter.h"
|
||||||
#include "base/debug_log.h"
|
#include "base/debug_log.h"
|
||||||
#include "styles/style_widgets.h"
|
#include "styles/style_widgets.h"
|
||||||
|
|
@ -54,6 +55,44 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[[nodiscard]] std::unique_ptr<style::palette> MakeAdjustedPalette(
|
||||||
|
QColor color) {
|
||||||
|
auto result = std::make_unique<style::palette>();
|
||||||
|
*result = *style::main_palette::get();
|
||||||
|
|
||||||
|
const auto set = [](const style::color &color, QColor value) {
|
||||||
|
color.set(
|
||||||
|
uchar(value.red()),
|
||||||
|
uchar(value.green()),
|
||||||
|
uchar(value.blue()),
|
||||||
|
uchar(value.alpha()));
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto contrast = 2.5;
|
||||||
|
const auto luminance = 0.2126 * color.redF()
|
||||||
|
+ 0.7152 * color.greenF()
|
||||||
|
+ 0.0722 * color.blueF();
|
||||||
|
const auto textColor = (luminance > 0.5)
|
||||||
|
? QColor(0, 0, 0)
|
||||||
|
: QColor(255, 255, 255);
|
||||||
|
const auto textLuminance = (luminance > 0.5) ? 0 : 1;
|
||||||
|
const auto adaptiveOpacity = (luminance - textLuminance + contrast)
|
||||||
|
/ contrast;
|
||||||
|
const auto opacity = std::clamp(adaptiveOpacity, 0.5, 0.64);
|
||||||
|
auto buttonColor = textColor;
|
||||||
|
buttonColor.setAlphaF(opacity);
|
||||||
|
auto rippleColor = textColor;
|
||||||
|
rippleColor.setAlphaF(opacity * 0.1);
|
||||||
|
|
||||||
|
set(result->windowFg(), textColor);
|
||||||
|
set(result->boxTitleCloseFg(), buttonColor);
|
||||||
|
set(result->boxTitleCloseFgOver(), buttonColor);
|
||||||
|
set(result->windowBgOver(), rippleColor);
|
||||||
|
|
||||||
|
result->finalize();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
PanelShow::PanelShow(not_null<SeparatePanel*> panel)
|
PanelShow::PanelShow(not_null<SeparatePanel*> panel)
|
||||||
: _panel(panel.get()) {
|
: _panel(panel.get()) {
|
||||||
}
|
}
|
||||||
|
|
@ -102,7 +141,7 @@ PanelShow::operator bool() const {
|
||||||
SeparatePanel::SeparatePanel(SeparatePanelArgs &&args)
|
SeparatePanel::SeparatePanel(SeparatePanelArgs &&args)
|
||||||
: RpWidget(args.parent)
|
: RpWidget(args.parent)
|
||||||
, _close(this, st::separatePanelClose)
|
, _close(this, st::separatePanelClose)
|
||||||
, _back(this, object_ptr<Ui::IconButton>(this, st::separatePanelBack))
|
, _back(this, object_ptr<IconButton>(this, st::separatePanelBack))
|
||||||
, _body(this)
|
, _body(this)
|
||||||
, _titleHeight(st::separatePanelTitleHeight) {
|
, _titleHeight(st::separatePanelTitleHeight) {
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
|
|
@ -111,8 +150,11 @@ SeparatePanel::SeparatePanel(SeparatePanelArgs &&args)
|
||||||
initLayout(args);
|
initLayout(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SeparatePanel::~SeparatePanel() = default;
|
||||||
|
|
||||||
void SeparatePanel::setTitle(rpl::producer<QString> title) {
|
void SeparatePanel::setTitle(rpl::producer<QString> title) {
|
||||||
_title.create(this, std::move(title), st::separatePanelTitle);
|
_title.create(this, std::move(title), st::separatePanelTitle);
|
||||||
|
updateTitleColors();
|
||||||
_title->setAttribute(Qt::WA_TransparentForMouseEvents);
|
_title->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
_title->show();
|
_title->show();
|
||||||
updateTitleGeometry(width());
|
updateTitleGeometry(width());
|
||||||
|
|
@ -148,6 +190,54 @@ void SeparatePanel::initControls() {
|
||||||
_close->raise();
|
_close->raise();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SeparatePanel::updateTitleButtonColors(not_null<IconButton*> button) {
|
||||||
|
if (!_titleOverridePalette) {
|
||||||
|
_titleOverrideStyles.remove(button);
|
||||||
|
button->setIconOverride(nullptr, nullptr);
|
||||||
|
button->setRippleColorOverride(nullptr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto &st = button->st();
|
||||||
|
auto &updated = _titleOverrideStyles[button];
|
||||||
|
updated = std::make_unique<style::IconButton>(st);
|
||||||
|
updated->icon = st.icon.withPalette(*_titleOverridePalette);
|
||||||
|
updated->iconOver = st.iconOver.withPalette(*_titleOverridePalette);
|
||||||
|
updated->ripple.color = _titleOverridePalette->windowBgOver();
|
||||||
|
button->setIconOverride(&updated->icon, &updated->iconOver);
|
||||||
|
button->setRippleColorOverride(&updated->ripple.color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SeparatePanel::updateTitleColors() {
|
||||||
|
_title->setTextColorOverride(_titleOverridePalette
|
||||||
|
? _titleOverridePalette->windowFg()->c
|
||||||
|
: std::optional<QColor>());
|
||||||
|
}
|
||||||
|
|
||||||
|
void SeparatePanel::overrideTitleColor(std::optional<QColor> color) {
|
||||||
|
if (_titleOverrideColor == color) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_titleOverrideColor = color;
|
||||||
|
_titleOverrideBorderParts = _titleOverrideColor
|
||||||
|
? createBorderImage(*_titleOverrideColor)
|
||||||
|
: QPixmap();
|
||||||
|
_titleOverridePalette = color
|
||||||
|
? MakeAdjustedPalette(*color)
|
||||||
|
: nullptr;
|
||||||
|
updateTitleButtonColors(_back->entity());
|
||||||
|
updateTitleButtonColors(_close.data());
|
||||||
|
if (_menuToggle) {
|
||||||
|
updateTitleButtonColors(_menuToggle.data());
|
||||||
|
}
|
||||||
|
if (_title) {
|
||||||
|
updateTitleColors();
|
||||||
|
}
|
||||||
|
if (!_titleOverridePalette) {
|
||||||
|
_titleOverrideStyles.clear();
|
||||||
|
}
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
void SeparatePanel::updateTitleGeometry(int newWidth) {
|
void SeparatePanel::updateTitleGeometry(int newWidth) {
|
||||||
_title->resizeToWidth(newWidth
|
_title->resizeToWidth(newWidth
|
||||||
- _padding.left() - _back->width()
|
- _padding.left() - _back->width()
|
||||||
|
|
@ -195,6 +285,7 @@ void SeparatePanel::setBackAllowed(bool allowed) {
|
||||||
void SeparatePanel::setMenuAllowed(
|
void SeparatePanel::setMenuAllowed(
|
||||||
Fn<void(const Menu::MenuCallback&)> fill) {
|
Fn<void(const Menu::MenuCallback&)> fill) {
|
||||||
_menuToggle.create(this, st::separatePanelMenu);
|
_menuToggle.create(this, st::separatePanelMenu);
|
||||||
|
updateTitleButtonColors(_menuToggle.data());
|
||||||
_menuToggle->show();
|
_menuToggle->show();
|
||||||
_menuToggle->setClickedCallback([=] { showMenu(fill); });
|
_menuToggle->setClickedCallback([=] { showMenu(fill); });
|
||||||
|
|
||||||
|
|
@ -231,8 +322,8 @@ bool SeparatePanel::createMenu(not_null<IconButton*> button) {
|
||||||
}
|
}
|
||||||
_menu = base::make_unique_q<PopupMenu>(this, st::popupMenuWithIcons);
|
_menu = base::make_unique_q<PopupMenu>(this, st::popupMenuWithIcons);
|
||||||
_menu->setDestroyedCallback([
|
_menu->setDestroyedCallback([
|
||||||
weak = Ui::MakeWeak(this),
|
weak = MakeWeak(this),
|
||||||
weakButton = Ui::MakeWeak(button),
|
weakButton = MakeWeak(button),
|
||||||
menu = _menu.get()]{
|
menu = _menu.get()]{
|
||||||
if (weak && weak->_menu == menu) {
|
if (weak && weak->_menu == menu) {
|
||||||
if (weakButton) {
|
if (weakButton) {
|
||||||
|
|
@ -299,19 +390,23 @@ void SeparatePanel::initLayout(const SeparatePanelArgs &args) {
|
||||||
setAttribute(Qt::WA_NoSystemBackground, true);
|
setAttribute(Qt::WA_NoSystemBackground, true);
|
||||||
setAttribute(Qt::WA_TranslucentBackground, true);
|
setAttribute(Qt::WA_TranslucentBackground, true);
|
||||||
|
|
||||||
createBorderImage();
|
validateBorderImage();
|
||||||
style::PaletteChanged(
|
style::PaletteChanged(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
createBorderImage();
|
validateBorderImage();
|
||||||
Ui::ForceFullRepaint(this);
|
ForceFullRepaint(this);
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
if (args.onAllSpaces) {
|
if (args.onAllSpaces) {
|
||||||
Ui::Platform::InitOnTopPanel(this);
|
Platform::InitOnTopPanel(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SeparatePanel::createBorderImage() {
|
void SeparatePanel::validateBorderImage() {
|
||||||
|
_borderParts = createBorderImage(st::windowBg->c);
|
||||||
|
}
|
||||||
|
|
||||||
|
QPixmap SeparatePanel::createBorderImage(QColor color) const {
|
||||||
const auto shadowPadding = st::callShadow.extend;
|
const auto shadowPadding = st::callShadow.extend;
|
||||||
const auto cacheSize = st::separatePanelBorderCacheSize;
|
const auto cacheSize = st::separatePanelBorderCacheSize;
|
||||||
auto cache = QImage(
|
auto cache = QImage(
|
||||||
|
|
@ -324,9 +419,9 @@ void SeparatePanel::createBorderImage() {
|
||||||
auto p = QPainter(&cache);
|
auto p = QPainter(&cache);
|
||||||
auto inner = QRect(0, 0, cacheSize, cacheSize).marginsRemoved(
|
auto inner = QRect(0, 0, cacheSize, cacheSize).marginsRemoved(
|
||||||
shadowPadding);
|
shadowPadding);
|
||||||
Ui::Shadow::paint(p, inner, cacheSize, st::callShadow);
|
Shadow::paint(p, inner, cacheSize, st::callShadow);
|
||||||
p.setCompositionMode(QPainter::CompositionMode_Source);
|
p.setCompositionMode(QPainter::CompositionMode_Source);
|
||||||
p.setBrush(st::windowBg);
|
p.setBrush(color);
|
||||||
p.setPen(Qt::NoPen);
|
p.setPen(Qt::NoPen);
|
||||||
PainterHighQualityEnabler hq(p);
|
PainterHighQualityEnabler hq(p);
|
||||||
p.drawRoundedRect(
|
p.drawRoundedRect(
|
||||||
|
|
@ -334,7 +429,7 @@ void SeparatePanel::createBorderImage() {
|
||||||
st::callRadius,
|
st::callRadius,
|
||||||
st::callRadius);
|
st::callRadius);
|
||||||
}
|
}
|
||||||
_borderParts = Ui::PixmapFromImage(std::move(cache));
|
return PixmapFromImage(std::move(cache));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SeparatePanel::toggleOpacityAnimation(bool visible) {
|
void SeparatePanel::toggleOpacityAnimation(bool visible) {
|
||||||
|
|
@ -346,7 +441,7 @@ void SeparatePanel::toggleOpacityAnimation(bool visible) {
|
||||||
if (_useTransparency) {
|
if (_useTransparency) {
|
||||||
if (_animationCache.isNull()) {
|
if (_animationCache.isNull()) {
|
||||||
showControls();
|
showControls();
|
||||||
_animationCache = Ui::GrabWidget(this);
|
_animationCache = GrabWidget(this);
|
||||||
hideChildren();
|
hideChildren();
|
||||||
}
|
}
|
||||||
_opacityAnimation.start(
|
_opacityAnimation.start(
|
||||||
|
|
@ -458,7 +553,7 @@ void SeparatePanel::ensureLayerCreated() {
|
||||||
if (_layer) {
|
if (_layer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_layer = base::make_unique_q<Ui::LayerStackWidget>(
|
_layer = base::make_unique_q<LayerStackWidget>(
|
||||||
_body,
|
_body,
|
||||||
crl::guard(this, [=] { return std::make_shared<PanelShow>(this); }));
|
crl::guard(this, [=] { return std::make_shared<PanelShow>(this); }));
|
||||||
_layer->setHideByBackgroundClick(false);
|
_layer->setHideByBackgroundClick(false);
|
||||||
|
|
@ -481,14 +576,14 @@ void SeparatePanel::destroyLayer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto layer = base::take(_layer);
|
auto layer = base::take(_layer);
|
||||||
const auto resetFocus = Ui::InFocusChain(layer);
|
const auto resetFocus = InFocusChain(layer);
|
||||||
if (resetFocus) {
|
if (resetFocus) {
|
||||||
setFocus();
|
setFocus();
|
||||||
}
|
}
|
||||||
layer = nullptr;
|
layer = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SeparatePanel::showInner(base::unique_qptr<Ui::RpWidget> inner) {
|
void SeparatePanel::showInner(base::unique_qptr<RpWidget> inner) {
|
||||||
Expects(!size().isEmpty());
|
Expects(!size().isEmpty());
|
||||||
|
|
||||||
_inner = std::move(inner);
|
_inner = std::move(inner);
|
||||||
|
|
@ -562,7 +657,7 @@ void SeparatePanel::initGeometry(QSize size) {
|
||||||
if (center.y() - size.height() / 2 < available.y()) {
|
if (center.y() - size.height() / 2 < available.y()) {
|
||||||
center.setY(available.y() + size.height() / 2);
|
center.setY(available.y() + size.height() / 2);
|
||||||
}
|
}
|
||||||
_useTransparency = Ui::Platform::TranslucentWindowsSupported();
|
_useTransparency = Platform::TranslucentWindowsSupported();
|
||||||
_padding = _useTransparency
|
_padding = _useTransparency
|
||||||
? st::callShadow.extend
|
? st::callShadow.extend
|
||||||
: style::margins(
|
: style::margins(
|
||||||
|
|
@ -647,15 +742,24 @@ void SeparatePanel::paintShadowBorder(QPainter &p) const {
|
||||||
const auto part1 = size / 3;
|
const auto part1 = size / 3;
|
||||||
const auto part2 = size - part1;
|
const auto part2 = size - part1;
|
||||||
const auto corner = QSize(part1, part1) * factor;
|
const auto corner = QSize(part1, part1) * factor;
|
||||||
|
const auto radius = st::callRadius;
|
||||||
|
|
||||||
|
const auto &header = _titleOverrideColor
|
||||||
|
? _titleOverrideBorderParts
|
||||||
|
: _borderParts;
|
||||||
const auto topleft = QRect(QPoint(0, 0), corner);
|
const auto topleft = QRect(QPoint(0, 0), corner);
|
||||||
p.drawPixmap(QRect(0, 0, part1, part1), _borderParts, topleft);
|
p.drawPixmap(QRect(0, 0, part1, part1), header, topleft);
|
||||||
|
|
||||||
const auto topright = QRect(QPoint(part2, 0) * factor, corner);
|
const auto topright = QRect(QPoint(part2, 0) * factor, corner);
|
||||||
|
p.drawPixmap(QRect(width() - part1, 0, part1, part1), header, topright);
|
||||||
|
|
||||||
|
const auto top = QRect(
|
||||||
|
QPoint(part1, 0) * factor,
|
||||||
|
QSize(part2 - part1, _padding.top() + radius) * factor);
|
||||||
p.drawPixmap(
|
p.drawPixmap(
|
||||||
QRect(width() - part1, 0, part1, part1),
|
QRect(part1, 0, width() - 2 * part1, _padding.top() + radius),
|
||||||
_borderParts,
|
header,
|
||||||
topright);
|
top);
|
||||||
|
|
||||||
const auto bottomleft = QRect(QPoint(0, part2) * factor, corner);
|
const auto bottomleft = QRect(QPoint(0, part2) * factor, corner);
|
||||||
p.drawPixmap(
|
p.drawPixmap(
|
||||||
|
|
@ -669,56 +773,65 @@ void SeparatePanel::paintShadowBorder(QPainter &p) const {
|
||||||
_borderParts,
|
_borderParts,
|
||||||
bottomright);
|
bottomright);
|
||||||
|
|
||||||
const auto left = QRect(
|
|
||||||
QPoint(0, part1) * factor,
|
|
||||||
QSize(_padding.left(), part2 - part1) * factor);
|
|
||||||
p.drawPixmap(
|
|
||||||
QRect(0, part1, _padding.left(), height() - 2 * part1),
|
|
||||||
_borderParts,
|
|
||||||
left);
|
|
||||||
|
|
||||||
const auto top = QRect(
|
|
||||||
QPoint(part1, 0) * factor,
|
|
||||||
QSize(part2 - part1, _padding.top() + st::callRadius) * factor);
|
|
||||||
p.drawPixmap(
|
|
||||||
QRect(
|
|
||||||
part1,
|
|
||||||
0,
|
|
||||||
width() - 2 * part1,
|
|
||||||
_padding.top() + st::callRadius),
|
|
||||||
_borderParts,
|
|
||||||
top);
|
|
||||||
|
|
||||||
const auto right = QRect(
|
|
||||||
QPoint(size - _padding.right(), part1) * factor,
|
|
||||||
QSize(_padding.right(), part2 - part1) * factor);
|
|
||||||
p.drawPixmap(
|
|
||||||
QRect(
|
|
||||||
width() - _padding.right(),
|
|
||||||
part1,
|
|
||||||
_padding.right(),
|
|
||||||
height() - 2 * part1),
|
|
||||||
_borderParts,
|
|
||||||
right);
|
|
||||||
|
|
||||||
const auto bottom = QRect(
|
const auto bottom = QRect(
|
||||||
QPoint(part1, size - _padding.bottom() - st::callRadius) * factor,
|
QPoint(part1, size - _padding.bottom() - radius) * factor,
|
||||||
QSize(part2 - part1, _padding.bottom() + st::callRadius) * factor);
|
QSize(part2 - part1, _padding.bottom() + radius) * factor);
|
||||||
p.drawPixmap(
|
p.drawPixmap(
|
||||||
QRect(
|
QRect(
|
||||||
part1,
|
part1,
|
||||||
height() - _padding.bottom() - st::callRadius,
|
height() - _padding.bottom() - radius,
|
||||||
width() - 2 * part1,
|
width() - 2 * part1,
|
||||||
_padding.bottom() + st::callRadius),
|
_padding.bottom() + radius),
|
||||||
_borderParts,
|
_borderParts,
|
||||||
bottom);
|
bottom);
|
||||||
|
|
||||||
p.fillRect(
|
const auto fillLeft = [&](int from, int till, const auto &parts) {
|
||||||
_padding.left(),
|
const auto left = QRect(
|
||||||
_padding.top() + st::callRadius,
|
QPoint(0, part1) * factor,
|
||||||
width() - _padding.left() - _padding.right(),
|
QSize(_padding.left(), part2 - part1) * factor);
|
||||||
height() - _padding.top() - _padding.bottom() - 2 * st::callRadius,
|
p.drawPixmap(
|
||||||
st::windowBg);
|
QRect(0, from, _padding.left(), till - from),
|
||||||
|
parts,
|
||||||
|
left);
|
||||||
|
};
|
||||||
|
const auto fillRight = [&](int from, int till, const auto &parts) {
|
||||||
|
const auto right = QRect(
|
||||||
|
QPoint(size - _padding.right(), part1) * factor,
|
||||||
|
QSize(_padding.right(), part2 - part1) * factor);
|
||||||
|
p.drawPixmap(
|
||||||
|
QRect(
|
||||||
|
width() - _padding.right(),
|
||||||
|
from,
|
||||||
|
_padding.right(),
|
||||||
|
till - from),
|
||||||
|
parts,
|
||||||
|
right);
|
||||||
|
};
|
||||||
|
const auto fillBody = [&](int from, int till, QColor color) {
|
||||||
|
p.fillRect(
|
||||||
|
_padding.left(),
|
||||||
|
from,
|
||||||
|
width() - _padding.left() - _padding.right(),
|
||||||
|
till - from,
|
||||||
|
color);
|
||||||
|
};
|
||||||
|
const auto bg = st::windowBg->c;
|
||||||
|
if (_titleOverrideColor) {
|
||||||
|
const auto half = height() / 2;
|
||||||
|
fillLeft(part1, half, _titleOverrideBorderParts);
|
||||||
|
fillLeft(half, height() - part1, _borderParts);
|
||||||
|
fillRight(part1, half, _titleOverrideBorderParts);
|
||||||
|
fillRight(half, height() - part1, _borderParts);
|
||||||
|
fillBody(_padding.top() + radius, half, *_titleOverrideColor);
|
||||||
|
fillBody(half, height() - _padding.bottom() - radius, bg);
|
||||||
|
} else {
|
||||||
|
fillLeft(part1, height() - part1, _borderParts);
|
||||||
|
fillRight(part1, height() - part1, _borderParts);
|
||||||
|
fillBody(
|
||||||
|
_padding.top() + radius,
|
||||||
|
height() - _padding.bottom() - radius,
|
||||||
|
bg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SeparatePanel::paintOpaqueBorder(QPainter &p) const {
|
void SeparatePanel::paintOpaqueBorder(QPainter &p) const {
|
||||||
|
|
@ -745,12 +858,22 @@ void SeparatePanel::paintOpaqueBorder(QPainter &p) const {
|
||||||
_padding.bottom(),
|
_padding.bottom(),
|
||||||
border);
|
border);
|
||||||
|
|
||||||
p.fillRect(
|
const auto fillBody = [&](int from, int till, QColor color) {
|
||||||
_padding.left(),
|
p.fillRect(
|
||||||
_padding.top(),
|
_padding.left(),
|
||||||
width() - _padding.left() - _padding.right(),
|
from,
|
||||||
height() - _padding.top() - _padding.bottom(),
|
width() - _padding.left() - _padding.right(),
|
||||||
st::windowBg);
|
till - from,
|
||||||
|
color);
|
||||||
|
};
|
||||||
|
const auto bg = st::windowBg->c;
|
||||||
|
if (_titleOverrideColor) {
|
||||||
|
const auto half = height() / 2;
|
||||||
|
fillBody(_padding.top(), half, *_titleOverrideColor);
|
||||||
|
fillBody(half, height() - _padding.bottom(), bg);
|
||||||
|
} else {
|
||||||
|
fillBody(_padding.top(), height() - _padding.bottom(), bg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SeparatePanel::closeEvent(QCloseEvent *e) {
|
void SeparatePanel::closeEvent(QCloseEvent *e) {
|
||||||
|
|
@ -806,11 +929,11 @@ void SeparatePanel::mouseReleaseEvent(QMouseEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SeparatePanel::leaveEventHook(QEvent *e) {
|
void SeparatePanel::leaveEventHook(QEvent *e) {
|
||||||
Ui::Tooltip::Hide();
|
Tooltip::Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SeparatePanel::leaveToChildEvent(QEvent *e, QWidget *child) {
|
void SeparatePanel::leaveToChildEvent(QEvent *e, QWidget *child) {
|
||||||
Ui::Tooltip::Hide();
|
Tooltip::Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "base/flat_map.h"
|
||||||
#include "base/weak_ptr.h"
|
#include "base/weak_ptr.h"
|
||||||
#include "ui/rp_widget.h"
|
#include "ui/rp_widget.h"
|
||||||
#include "ui/effects/animations.h"
|
#include "ui/effects/animations.h"
|
||||||
|
|
@ -15,6 +16,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
class Painter;
|
class Painter;
|
||||||
|
|
||||||
|
namespace style {
|
||||||
|
struct IconButton;
|
||||||
|
} // namespace style
|
||||||
|
|
||||||
namespace Ui::Menu {
|
namespace Ui::Menu {
|
||||||
struct MenuCallback;
|
struct MenuCallback;
|
||||||
} // namespace Ui::Menu
|
} // namespace Ui::Menu
|
||||||
|
|
@ -45,6 +50,7 @@ struct SeparatePanelArgs {
|
||||||
class SeparatePanel final : public RpWidget {
|
class SeparatePanel final : public RpWidget {
|
||||||
public:
|
public:
|
||||||
explicit SeparatePanel(SeparatePanelArgs &&args = {});
|
explicit SeparatePanel(SeparatePanelArgs &&args = {});
|
||||||
|
~SeparatePanel();
|
||||||
|
|
||||||
void setTitle(rpl::producer<QString> title);
|
void setTitle(rpl::producer<QString> title);
|
||||||
void setTitleHeight(int height);
|
void setTitleHeight(int height);
|
||||||
|
|
@ -73,6 +79,8 @@ public:
|
||||||
|
|
||||||
void setMenuAllowed(Fn<void(const Menu::MenuCallback&)> fill);
|
void setMenuAllowed(Fn<void(const Menu::MenuCallback&)> fill);
|
||||||
|
|
||||||
|
void overrideTitleColor(std::optional<QColor> color);
|
||||||
|
|
||||||
base::weak_ptr<Toast::Instance> showToast(Toast::Config &&config);
|
base::weak_ptr<Toast::Instance> showToast(Toast::Config &&config);
|
||||||
base::weak_ptr<Toast::Instance> showToast(
|
base::weak_ptr<Toast::Instance> showToast(
|
||||||
TextWithEntities &&text,
|
TextWithEntities &&text,
|
||||||
|
|
@ -103,7 +111,8 @@ private:
|
||||||
void updateGeometry(QSize size);
|
void updateGeometry(QSize size);
|
||||||
void showControls();
|
void showControls();
|
||||||
void updateControlsGeometry();
|
void updateControlsGeometry();
|
||||||
void createBorderImage();
|
void validateBorderImage();
|
||||||
|
[[nodiscard]] QPixmap createBorderImage(QColor color) const;
|
||||||
void opacityCallback();
|
void opacityCallback();
|
||||||
void ensureLayerCreated();
|
void ensureLayerCreated();
|
||||||
void destroyLayer();
|
void destroyLayer();
|
||||||
|
|
@ -120,6 +129,9 @@ private:
|
||||||
void showMenu(Fn<void(const Menu::MenuCallback&)> fill);
|
void showMenu(Fn<void(const Menu::MenuCallback&)> fill);
|
||||||
[[nodiscard]] bool createMenu(not_null<IconButton*> button);
|
[[nodiscard]] bool createMenu(not_null<IconButton*> button);
|
||||||
|
|
||||||
|
void updateTitleButtonColors(not_null<IconButton*> button);
|
||||||
|
void updateTitleColors();
|
||||||
|
|
||||||
object_ptr<IconButton> _close;
|
object_ptr<IconButton> _close;
|
||||||
object_ptr<IconButton> _menuToggle = { nullptr };
|
object_ptr<IconButton> _menuToggle = { nullptr };
|
||||||
object_ptr<FlatLabel> _title = { nullptr };
|
object_ptr<FlatLabel> _title = { nullptr };
|
||||||
|
|
@ -148,6 +160,13 @@ private:
|
||||||
QPixmap _animationCache;
|
QPixmap _animationCache;
|
||||||
QPixmap _borderParts;
|
QPixmap _borderParts;
|
||||||
|
|
||||||
|
std::optional<QColor> _titleOverrideColor;
|
||||||
|
QPixmap _titleOverrideBorderParts;
|
||||||
|
std::unique_ptr<style::palette> _titleOverridePalette;
|
||||||
|
base::flat_map<
|
||||||
|
not_null<IconButton*>,
|
||||||
|
std::unique_ptr<style::IconButton>> _titleOverrideStyles;
|
||||||
|
|
||||||
Fn<bool(int zorder)> _animationsPaused;
|
Fn<bool(int zorder)> _animationsPaused;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue