Specify icon overrides for side bar button.
This commit is contained in:
parent
1f0a772b18
commit
ec6744022c
2 changed files with 30 additions and 2 deletions
|
|
@ -58,6 +58,14 @@ void SideBarButton::setBadge(const QString &badge, bool muted) {
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SideBarButton::setIconOverride(
|
||||||
|
const style::icon *iconOverride,
|
||||||
|
const style::icon *iconOverrideActive) {
|
||||||
|
_iconOverride = iconOverride;
|
||||||
|
_iconOverrideActive = iconOverrideActive;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
int SideBarButton::resizeGetHeight(int newWidth) {
|
int SideBarButton::resizeGetHeight(int newWidth) {
|
||||||
auto result = _st.minHeight;
|
auto result = _st.minHeight;
|
||||||
const auto text = _text.countHeight(newWidth - _st.textSkip * 2);
|
const auto text = _text.countHeight(newWidth - _st.textSkip * 2);
|
||||||
|
|
@ -73,7 +81,7 @@ void SideBarButton::paintEvent(QPaintEvent *e) {
|
||||||
|
|
||||||
RippleButton::paintRipple(p, 0, 0);
|
RippleButton::paintRipple(p, 0, 0);
|
||||||
|
|
||||||
const auto &icon = _active ? _st.iconActive : _st.icon;
|
const auto &icon = computeIcon();
|
||||||
const auto x = (_st.iconPosition.x() < 0)
|
const auto x = (_st.iconPosition.x() < 0)
|
||||||
? (width() - icon.width()) / 2
|
? (width() - icon.width()) / 2
|
||||||
: _st.iconPosition.x();
|
: _st.iconPosition.x();
|
||||||
|
|
@ -116,6 +124,20 @@ void SideBarButton::paintEvent(QPaintEvent *e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const style::icon &SideBarButton::computeIcon() const {
|
||||||
|
return _active
|
||||||
|
? (_iconOverrideActive
|
||||||
|
? *_iconOverrideActive
|
||||||
|
: !_st.iconActive.empty()
|
||||||
|
? _st.iconActive
|
||||||
|
: _iconOverride
|
||||||
|
? *_iconOverride
|
||||||
|
: _st.icon)
|
||||||
|
: _iconOverride
|
||||||
|
? *_iconOverride
|
||||||
|
: _st.icon;
|
||||||
|
}
|
||||||
|
|
||||||
void SideBarButton::validateIconCache() {
|
void SideBarButton::validateIconCache() {
|
||||||
Expects(_st.iconPosition.x() < 0);
|
Expects(_st.iconPosition.x() < 0);
|
||||||
Expects(_st.iconPosition.y() >= 0);
|
Expects(_st.iconPosition.y() >= 0);
|
||||||
|
|
@ -123,7 +145,7 @@ void SideBarButton::validateIconCache() {
|
||||||
if (!(_active ? _iconCacheActive : _iconCache).isNull()) {
|
if (!(_active ? _iconCacheActive : _iconCache).isNull()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto &icon = _active ? _st.iconActive : _st.icon;
|
const auto &icon = computeIcon();
|
||||||
auto image = QImage(
|
auto image = QImage(
|
||||||
icon.size() * style::DevicePixelRatio(),
|
icon.size() * style::DevicePixelRatio(),
|
||||||
QImage::Format_ARGB32_Premultiplied);
|
QImage::Format_ARGB32_Premultiplied);
|
||||||
|
|
|
||||||
|
|
@ -26,15 +26,21 @@ public:
|
||||||
|
|
||||||
void setActive(bool active);
|
void setActive(bool active);
|
||||||
void setBadge(const QString &badge, bool muted);
|
void setBadge(const QString &badge, bool muted);
|
||||||
|
void setIconOverride(
|
||||||
|
const style::icon *iconOverride,
|
||||||
|
const style::icon *iconOverrideActive = nullptr);
|
||||||
|
|
||||||
int resizeGetHeight(int newWidth) override;
|
int resizeGetHeight(int newWidth) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
|
|
||||||
|
[[nodiscard]] const style::icon &computeIcon() const;
|
||||||
void validateIconCache();
|
void validateIconCache();
|
||||||
|
|
||||||
const style::SideBarButton &_st;
|
const style::SideBarButton &_st;
|
||||||
|
const style::icon *_iconOverride = nullptr;
|
||||||
|
const style::icon *_iconOverrideActive = nullptr;
|
||||||
Ui::Text::String _text;
|
Ui::Text::String _text;
|
||||||
Ui::Text::String _badge;
|
Ui::Text::String _badge;
|
||||||
QImage _iconCache;
|
QImage _iconCache;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue