Added IconButtonWithText control.
This commit is contained in:
parent
9f28a0b106
commit
c035b78f87
6 changed files with 98 additions and 6 deletions
|
|
@ -170,6 +170,8 @@ PRIVATE
|
||||||
ui/widgets/checkbox.h
|
ui/widgets/checkbox.h
|
||||||
ui/widgets/dropdown_menu.cpp
|
ui/widgets/dropdown_menu.cpp
|
||||||
ui/widgets/dropdown_menu.h
|
ui/widgets/dropdown_menu.h
|
||||||
|
ui/widgets/icon_button_with_text.cpp
|
||||||
|
ui/widgets/icon_button_with_text.h
|
||||||
ui/widgets/inner_dropdown.cpp
|
ui/widgets/inner_dropdown.cpp
|
||||||
ui/widgets/inner_dropdown.h
|
ui/widgets/inner_dropdown.h
|
||||||
ui/widgets/input_fields.cpp
|
ui/widgets/input_fields.cpp
|
||||||
|
|
|
||||||
|
|
@ -476,14 +476,19 @@ void IconButton::setRippleColorOverride(const style::color *colorOverride) {
|
||||||
_rippleColorOverride = colorOverride;
|
_rippleColorOverride = colorOverride;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float64 IconButton::iconOverOpacity() const {
|
||||||
|
return (isDown() || forceRippled())
|
||||||
|
? 1.
|
||||||
|
: _a_over.value(isOver() ? 1. : 0.);
|
||||||
|
}
|
||||||
|
|
||||||
void IconButton::paintEvent(QPaintEvent *e) {
|
void IconButton::paintEvent(QPaintEvent *e) {
|
||||||
Painter p(this);
|
Painter p(this);
|
||||||
|
|
||||||
paintRipple(p, _st.rippleAreaPosition, _rippleColorOverride ? &(*_rippleColorOverride)->c : nullptr);
|
paintRipple(p, _st.rippleAreaPosition, _rippleColorOverride ? &(*_rippleColorOverride)->c : nullptr);
|
||||||
|
|
||||||
auto down = isDown();
|
const auto overIconOpacity = iconOverOpacity();
|
||||||
auto overIconOpacity = (down || forceRippled()) ? 1. : _a_over.value(isOver() ? 1. : 0.);
|
const auto overIcon = [&] {
|
||||||
auto overIcon = [this] {
|
|
||||||
if (_iconOverrideOver) {
|
if (_iconOverrideOver) {
|
||||||
return _iconOverrideOver;
|
return _iconOverrideOver;
|
||||||
} else if (!_st.iconOver.empty()) {
|
} else if (!_st.iconOver.empty()) {
|
||||||
|
|
@ -493,13 +498,13 @@ void IconButton::paintEvent(QPaintEvent *e) {
|
||||||
}
|
}
|
||||||
return &_st.icon;
|
return &_st.icon;
|
||||||
};
|
};
|
||||||
auto justIcon = [this] {
|
const auto justIcon = [&] {
|
||||||
if (_iconOverride) {
|
if (_iconOverride) {
|
||||||
return _iconOverride;
|
return _iconOverride;
|
||||||
}
|
}
|
||||||
return &_st.icon;
|
return &_st.icon;
|
||||||
};
|
};
|
||||||
auto icon = (overIconOpacity == 1.) ? overIcon() : justIcon();
|
const auto icon = (overIconOpacity == 1.) ? overIcon() : justIcon();
|
||||||
auto position = _st.iconPosition;
|
auto position = _st.iconPosition;
|
||||||
if (position.x() < 0) {
|
if (position.x() < 0) {
|
||||||
position.setX((width() - icon->width()) / 2);
|
position.setX((width() - icon->width()) / 2);
|
||||||
|
|
@ -509,7 +514,7 @@ void IconButton::paintEvent(QPaintEvent *e) {
|
||||||
}
|
}
|
||||||
icon->paint(p, position, width());
|
icon->paint(p, position, width());
|
||||||
if (overIconOpacity > 0. && overIconOpacity < 1.) {
|
if (overIconOpacity > 0. && overIconOpacity < 1.) {
|
||||||
auto iconOver = overIcon();
|
const auto iconOver = overIcon();
|
||||||
if (iconOver != icon) {
|
if (iconOver != icon) {
|
||||||
p.setOpacity(overIconOpacity);
|
p.setOpacity(overIconOpacity);
|
||||||
iconOver->paint(p, position, width());
|
iconOver->paint(p, position, width());
|
||||||
|
|
|
||||||
|
|
@ -196,6 +196,8 @@ protected:
|
||||||
QImage prepareRippleMask() const override;
|
QImage prepareRippleMask() const override;
|
||||||
QPoint prepareRippleStartPosition() const override;
|
QPoint prepareRippleStartPosition() const override;
|
||||||
|
|
||||||
|
[[nodiscard]] float64 iconOverOpacity() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const style::IconButton &_st;
|
const style::IconButton &_st;
|
||||||
const style::icon *_iconOverride = nullptr;
|
const style::icon *_iconOverride = nullptr;
|
||||||
|
|
|
||||||
41
ui/widgets/icon_button_with_text.cpp
Normal file
41
ui/widgets/icon_button_with_text.cpp
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
#include "ui/widgets/icon_button_with_text.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
|
||||||
|
IconButtonWithText::IconButtonWithText(
|
||||||
|
not_null<RpWidget*> parent,
|
||||||
|
const style::IconButtonWithText &st)
|
||||||
|
: IconButton(parent, st.iconButton)
|
||||||
|
, _st(st) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void IconButtonWithText::paintEvent(QPaintEvent *e) {
|
||||||
|
IconButton::paintEvent(e);
|
||||||
|
|
||||||
|
const auto r = rect() - _st.textPadding;
|
||||||
|
|
||||||
|
Painter p(this);
|
||||||
|
p.setFont(_st.font);
|
||||||
|
p.setPen(_st.textFg);
|
||||||
|
p.drawText(r, _text, style::al_center);
|
||||||
|
|
||||||
|
const auto overIconOpacity = IconButton::iconOverOpacity();
|
||||||
|
if (overIconOpacity > 0. && overIconOpacity < 1.) {
|
||||||
|
p.setPen(_st.textFgOver);
|
||||||
|
p.setOpacity(overIconOpacity);
|
||||||
|
p.drawText(r, _text, style::al_center);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void IconButtonWithText::setText(const QString &text) {
|
||||||
|
_text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Ui
|
||||||
31
ui/widgets/icon_button_with_text.h
Normal file
31
ui/widgets/icon_button_with_text.h
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
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/widgets/buttons.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
|
||||||
|
class IconButtonWithText final : public Ui::IconButton {
|
||||||
|
public:
|
||||||
|
IconButtonWithText(
|
||||||
|
not_null<RpWidget*> parent,
|
||||||
|
const style::IconButtonWithText &st);
|
||||||
|
|
||||||
|
void setText(const QString &text);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent *e) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const style::IconButtonWithText &_st;
|
||||||
|
QString _text;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Ui
|
||||||
|
|
@ -338,6 +338,17 @@ IconButton {
|
||||||
ripple: RippleAnimation;
|
ripple: RippleAnimation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IconButtonWithText {
|
||||||
|
iconButton: IconButton;
|
||||||
|
height: pixels;
|
||||||
|
|
||||||
|
textFg: color;
|
||||||
|
textFgOver: color;
|
||||||
|
textPadding: margins;
|
||||||
|
|
||||||
|
font: font;
|
||||||
|
}
|
||||||
|
|
||||||
MediaSlider {
|
MediaSlider {
|
||||||
width: pixels;
|
width: pixels;
|
||||||
activeFg: color;
|
activeFg: color;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue