mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-30 22:25:12 +00:00
Removing almost all animated over states in IconButton.
This commit is contained in:
@@ -64,8 +64,8 @@ void DropdownMenu::init() {
|
||||
hide();
|
||||
}
|
||||
|
||||
QAction *DropdownMenu::addAction(const QString &text, const QObject *receiver, const char* member, const style::icon *icon) {
|
||||
return _menu->addAction(text, receiver, member, icon);
|
||||
QAction *DropdownMenu::addAction(const QString &text, const QObject *receiver, const char* member, const style::icon *icon, const style::icon *iconOver) {
|
||||
return _menu->addAction(text, receiver, member, icon, iconOver);
|
||||
}
|
||||
|
||||
QAction *DropdownMenu::addSeparator() {
|
||||
|
@@ -30,7 +30,7 @@ class DropdownMenu : public InnerDropdown {
|
||||
public:
|
||||
DropdownMenu(QWidget *parent, const style::DropdownMenu &st = st::defaultDropdownMenu);
|
||||
|
||||
QAction *addAction(const QString &text, const QObject *receiver, const char* member, const style::icon *icon = nullptr);
|
||||
QAction *addAction(const QString &text, const QObject *receiver, const char* member, const style::icon *icon = nullptr, const style::icon *iconOver = nullptr);
|
||||
QAction *addSeparator();
|
||||
void clearActions();
|
||||
|
||||
|
@@ -43,10 +43,10 @@ void MediaSlider::paintEvent(QPaintEvent *e) {
|
||||
Painter p(this);
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setRenderHint(QPainter::HighQualityAntialiasing);
|
||||
p.setOpacity(fadeOpacity());
|
||||
|
||||
auto horizontal = isHorizontal();
|
||||
auto ms = getms();
|
||||
auto masterOpacity = fadeOpacity();
|
||||
auto radius = _st.width / 2;
|
||||
auto disabled = isDisabled();
|
||||
auto over = getCurrentOverFactor(ms);
|
||||
@@ -62,16 +62,21 @@ void MediaSlider::paintEvent(QPaintEvent *e) {
|
||||
auto length = _alwaysDisplayMarker ? (horizontal ? width() : height()) : markerLength;
|
||||
auto mid = qRound(from + value * length);
|
||||
auto end = from + length;
|
||||
auto &activeFg = disabled ? _st.disabledActiveFg : _st.activeFg;
|
||||
auto &inactiveFg = disabled ? _st.disabledInactiveFg : _st.inactiveFg;
|
||||
auto activeFg = disabled ? &_st.activeFgDisabled : (over == 1. ? &_st.activeFgOver : (over == 0. ? &_st.activeFg : nullptr));
|
||||
auto inactiveFg = disabled ? &_st.inactiveFgDisabled : (over == 1. ? &_st.inactiveFgOver : (over == 0. ? &_st.inactiveFg : nullptr));
|
||||
auto activeFgOver = activeFg ? QColor() : style::interpolate(_st.activeFg, _st.activeFgOver, over);
|
||||
auto inactiveFgOver = inactiveFg ? QColor() : style::interpolate(_st.inactiveFg, _st.inactiveFgOver, over);
|
||||
if (mid > from) {
|
||||
auto fromClipRect = horizontal ? QRect(0, 0, mid, height()) : QRect(0, 0, width(), mid);
|
||||
auto fromRect = horizontal
|
||||
? QRect(from, (height() - _st.width) / 2, mid + radius - from, _st.width)
|
||||
: QRect((width() - _st.width) / 2, from, _st.width, mid + radius - from);
|
||||
p.setClipRect(fromClipRect);
|
||||
p.setOpacity(masterOpacity * (over * _st.activeOpacity + (1. - over) * _st.inactiveOpacity));
|
||||
p.setBrush(horizontal ? activeFg : inactiveFg);
|
||||
if (auto brush = (horizontal ? activeFg : inactiveFg)) {
|
||||
p.setBrush(*brush);
|
||||
} else {
|
||||
p.setBrush(horizontal ? activeFgOver : inactiveFgOver);
|
||||
}
|
||||
p.drawRoundedRect(fromRect, radius, radius);
|
||||
}
|
||||
if (end > mid) {
|
||||
@@ -80,8 +85,11 @@ void MediaSlider::paintEvent(QPaintEvent *e) {
|
||||
? QRect(mid - radius, (height() - _st.width) / 2, end - (mid - radius), _st.width)
|
||||
: QRect((width() - _st.width) / 2, mid - radius, _st.width, end - (mid - radius));
|
||||
p.setClipRect(endClipRect);
|
||||
p.setOpacity(masterOpacity);
|
||||
p.setBrush(horizontal ? inactiveFg : activeFg);
|
||||
if (auto brush = (horizontal ? inactiveFg : activeFg)) {
|
||||
p.setBrush(*brush);
|
||||
} else {
|
||||
p.setBrush(horizontal ? inactiveFgOver : activeFgOver);
|
||||
}
|
||||
p.drawRoundedRect(endRect, radius, radius);
|
||||
}
|
||||
auto markerSizeRatio = disabled ? 0. : (_alwaysDisplayMarker ? 1. : over);
|
||||
@@ -94,8 +102,11 @@ void MediaSlider::paintEvent(QPaintEvent *e) {
|
||||
auto remove = static_cast<int>(((1. - markerSizeRatio) * size) / 2.);
|
||||
if (remove * 2 < size) {
|
||||
p.setClipRect(rect());
|
||||
p.setOpacity(masterOpacity * _st.activeOpacity);
|
||||
p.setBrush(activeFg);
|
||||
if (activeFg) {
|
||||
p.setBrush(*activeFg);
|
||||
} else {
|
||||
p.setBrush(activeFgOver);
|
||||
}
|
||||
p.drawEllipse(seekButton.marginsRemoved(QMargins(remove, remove, remove, remove)));
|
||||
}
|
||||
}
|
||||
|
@@ -49,18 +49,19 @@ void Menu::init() {
|
||||
setAttribute(Qt::WA_OpaquePaintEvent);
|
||||
}
|
||||
|
||||
QAction *Menu::addAction(const QString &text, const QObject *receiver, const char* member, const style::icon *icon) {
|
||||
QAction *Menu::addAction(const QString &text, const QObject *receiver, const char* member, const style::icon *icon, const style::icon *iconOver) {
|
||||
auto action = new QAction(text, this);
|
||||
connect(action, SIGNAL(triggered(bool)), receiver, member, Qt::QueuedConnection);
|
||||
return addAction(action, icon);
|
||||
return addAction(action, icon, iconOver);
|
||||
}
|
||||
|
||||
QAction *Menu::addAction(QAction *action, const style::icon *icon) {
|
||||
QAction *Menu::addAction(QAction *action, const style::icon *icon, const style::icon *iconOver) {
|
||||
connect(action, SIGNAL(changed()), this, SLOT(actionChanged()));
|
||||
_actions.push_back(action);
|
||||
|
||||
ActionData data;
|
||||
data.icon = icon;
|
||||
data.iconOver = iconOver ? iconOver : icon;
|
||||
data.hasSubmenu = (action->menu() != nullptr);
|
||||
_actionsData.push_back(data);
|
||||
|
||||
@@ -167,10 +168,8 @@ void Menu::paintEvent(QPaintEvent *e) {
|
||||
} else {
|
||||
auto enabled = action->isEnabled(), selected = (i == _selected && enabled);
|
||||
p.fillRect(0, 0, width(), actionHeight, selected ? _st.itemBgOver : _st.itemBg);
|
||||
if (data.icon) {
|
||||
p.setOpacity(selected ? _st.itemIconOverOpacity : _st.itemIconOpacity);
|
||||
data.icon->paint(p, _st.itemIconPosition, width());
|
||||
p.setOpacity(1.);
|
||||
if (auto icon = (selected ? data.iconOver : data.icon)) {
|
||||
icon->paint(p, _st.itemIconPosition, width());
|
||||
}
|
||||
p.setPen(selected ? _st.itemFgOver : (enabled ? _st.itemFg : _st.itemFgDisabled));
|
||||
p.drawTextLeft(_st.itemPadding.left(), _st.itemPadding.top(), width(), data.text);
|
||||
|
@@ -31,7 +31,7 @@ public:
|
||||
Menu(QWidget *parent, const style::Menu &st = st::defaultMenu);
|
||||
Menu(QWidget *parent, QMenu *menu, const style::Menu &st = st::defaultMenu);
|
||||
|
||||
QAction *addAction(const QString &text, const QObject *receiver, const char* member, const style::icon *icon = nullptr);
|
||||
QAction *addAction(const QString &text, const QObject *receiver, const char* member, const style::icon *icon = nullptr, const style::icon *iconOver = nullptr);
|
||||
QAction *addSeparator();
|
||||
void clearActions();
|
||||
|
||||
@@ -92,7 +92,7 @@ private:
|
||||
|
||||
// Returns the new width.
|
||||
int processAction(QAction *action, int index, int width);
|
||||
QAction *addAction(QAction *a, const style::icon *icon = nullptr);
|
||||
QAction *addAction(QAction *a, const style::icon *icon = nullptr, const style::icon *iconOver = nullptr);
|
||||
|
||||
void setSelected(int selected);
|
||||
void clearMouseSelection();
|
||||
@@ -115,6 +115,7 @@ private:
|
||||
QString text;
|
||||
QString shortcut;
|
||||
const style::icon *icon = nullptr;
|
||||
const style::icon *iconOver = nullptr;
|
||||
};
|
||||
using ActionsData = QList<ActionData>;
|
||||
|
||||
|
@@ -80,8 +80,8 @@ void PopupMenu::handleMenuResize() {
|
||||
_inner = QRect(_padding.left(), _padding.top(), width() - _padding.left() - _padding.right(), height() - _padding.top() - _padding.bottom());
|
||||
}
|
||||
|
||||
QAction *PopupMenu::addAction(const QString &text, const QObject *receiver, const char* member, const style::icon *icon) {
|
||||
return _menu->addAction(text, receiver, member, icon);
|
||||
QAction *PopupMenu::addAction(const QString &text, const QObject *receiver, const char* member, const style::icon *icon, const style::icon *iconOver) {
|
||||
return _menu->addAction(text, receiver, member, icon, iconOver);
|
||||
}
|
||||
|
||||
QAction *PopupMenu::addSeparator() {
|
||||
|
@@ -28,7 +28,7 @@ public:
|
||||
PopupMenu(const style::PopupMenu &st = st::defaultPopupMenu);
|
||||
PopupMenu(QMenu *menu, const style::PopupMenu &st = st::defaultPopupMenu);
|
||||
|
||||
QAction *addAction(const QString &text, const QObject *receiver, const char* member, const style::icon *icon = nullptr);
|
||||
QAction *addAction(const QString &text, const QObject *receiver, const char* member, const style::icon *icon = nullptr, const style::icon *iconOver = nullptr);
|
||||
QAction *addSeparator();
|
||||
void clearActions();
|
||||
|
||||
|
@@ -31,12 +31,11 @@ IconButton {
|
||||
width: pixels;
|
||||
height: pixels;
|
||||
|
||||
opacity: double;
|
||||
overOpacity: double;
|
||||
|
||||
icon: icon;
|
||||
iconOver: icon;
|
||||
|
||||
iconPosition: point;
|
||||
downIconPosition: point;
|
||||
iconPositionDown: point;
|
||||
|
||||
duration: int;
|
||||
}
|
||||
@@ -52,7 +51,7 @@ MaskButton {
|
||||
iconBgOver: color;
|
||||
|
||||
iconPosition: point;
|
||||
downIconPosition: point;
|
||||
iconPositionDown: point;
|
||||
|
||||
duration: int;
|
||||
}
|
||||
@@ -61,10 +60,10 @@ MediaSlider {
|
||||
width: pixels;
|
||||
activeFg: color;
|
||||
inactiveFg: color;
|
||||
disabledActiveFg: color;
|
||||
disabledInactiveFg: color;
|
||||
activeOpacity: double;
|
||||
inactiveOpacity: double;
|
||||
activeFgOver: color;
|
||||
inactiveFgOver: color;
|
||||
activeFgDisabled: color;
|
||||
inactiveFgDisabled: color;
|
||||
seekSize: size;
|
||||
duration: int;
|
||||
}
|
||||
@@ -137,8 +136,6 @@ Menu {
|
||||
itemFgShortcutDisabled: color;
|
||||
itemPadding: margins;
|
||||
itemIconPosition: point;
|
||||
itemIconOpacity: double;
|
||||
itemIconOverOpacity: double;
|
||||
itemFont: font;
|
||||
|
||||
separatorPadding: margins;
|
||||
@@ -184,15 +181,9 @@ defaultLabelSimple: LabelSimple {
|
||||
textFg: windowTextFg;
|
||||
}
|
||||
|
||||
defaultIconButton: IconButton {
|
||||
opacity: 0.78;
|
||||
overOpacity: 1.;
|
||||
duration: 150;
|
||||
}
|
||||
|
||||
defaultMaskButton: MaskButton {
|
||||
iconPosition: point(-1px, -1px);
|
||||
downIconPosition: point(-1px, -1px);
|
||||
iconPositionDown: point(-1px, -1px);
|
||||
duration: 150;
|
||||
}
|
||||
|
||||
@@ -223,8 +214,6 @@ defaultMenu: Menu {
|
||||
itemFgShortcutOver: #7c99b2;
|
||||
itemFgShortcutDisabled: #cccccc;
|
||||
itemIconPosition: point(0px, 0px);
|
||||
itemIconOpacity: 1.;
|
||||
itemIconOverOpacity: 1.;
|
||||
itemPadding: margins(17px, 8px, 17px, 7px);
|
||||
itemFont: normalFont;
|
||||
|
||||
|
Reference in New Issue
Block a user