mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-08-05 11:24:21 +00:00
Old sprites removed completely. Only #rrggbb and #rrggbbaa in styles.
Also moved Checkbox and Radiobutton to Ui namespace. Also child widgets in many boxes were wrapped in ChildWidget<>.
This commit is contained in:
@@ -163,109 +163,6 @@ void LinkButton::onStateChange(int oldState, ButtonStateChangeSource source) {
|
||||
LinkButton::~LinkButton() {
|
||||
}
|
||||
|
||||
IconedButton::IconedButton(QWidget *parent, const style::iconedButton &st, const QString &text) : Button(parent)
|
||||
, _text(text)
|
||||
, _st(st)
|
||||
, _width(_st.width)
|
||||
, a_opacity(_st.opacity)
|
||||
, a_bg(_st.bgColor->c)
|
||||
, _a_appearance(animation(this, &IconedButton::step_appearance))
|
||||
, _opacity(1) {
|
||||
|
||||
if (_width < 0) {
|
||||
_width = _st.font->width(text) - _width;
|
||||
} else if (!_width) {
|
||||
_width = _st.font->width(text) + _st.height - _st.font->height;
|
||||
}
|
||||
connect(this, SIGNAL(stateChanged(int, ButtonStateChangeSource)), this, SLOT(onStateChange(int, ButtonStateChangeSource)));
|
||||
resize(_width, _st.height);
|
||||
setCursor(_st.cursor);
|
||||
}
|
||||
|
||||
void IconedButton::setOpacity(float64 opacity) {
|
||||
_opacity = opacity;
|
||||
update();
|
||||
}
|
||||
|
||||
void IconedButton::setText(const QString &text) {
|
||||
if (_text != text) {
|
||||
_text = text;
|
||||
if (_st.width < 0) {
|
||||
_width = _st.font->width(text) - _st.width;
|
||||
} else if (!_st.width) {
|
||||
_width = _st.font->width(text) + _st.height - _st.font->height;
|
||||
}
|
||||
resize(_width, _st.height);
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
QString IconedButton::getText() const {
|
||||
return _text;
|
||||
}
|
||||
|
||||
void IconedButton::step_appearance(float64 ms, bool timer) {
|
||||
if (_st.duration <= 1) {
|
||||
_a_appearance.stop();
|
||||
a_opacity.finish();
|
||||
a_bg.finish();
|
||||
} else {
|
||||
float64 dt = ms / _st.duration;
|
||||
if (dt >= 1) {
|
||||
_a_appearance.stop();
|
||||
a_opacity.finish();
|
||||
a_bg.finish();
|
||||
} else {
|
||||
a_opacity.update(dt, anim::linear);
|
||||
a_bg.update(dt, anim::linear);
|
||||
}
|
||||
}
|
||||
if (timer) update();
|
||||
}
|
||||
|
||||
void IconedButton::onStateChange(int oldState, ButtonStateChangeSource source) {
|
||||
a_opacity.start((_state & (StateOver | StateDown)) ? _st.overOpacity : _st.opacity);
|
||||
a_bg.start(((_state & (StateOver | StateDown)) ? _st.overBgColor : _st.bgColor)->c);
|
||||
|
||||
if (source == ButtonByUser || source == ButtonByPress) {
|
||||
_a_appearance.stop();
|
||||
a_opacity.finish();
|
||||
a_bg.finish();
|
||||
update();
|
||||
} else {
|
||||
_a_appearance.start();
|
||||
}
|
||||
}
|
||||
|
||||
void IconedButton::paintEvent(QPaintEvent *e) {
|
||||
Painter p(this);
|
||||
|
||||
p.setOpacity(_opacity);
|
||||
|
||||
p.fillRect(e->rect(), a_bg.current());
|
||||
|
||||
p.setOpacity(a_opacity.current() * _opacity);
|
||||
|
||||
if (!_text.isEmpty()) {
|
||||
p.setFont(_st.font->f);
|
||||
p.setRenderHint(QPainter::TextAntialiasing);
|
||||
p.setPen(_st.color->p);
|
||||
const QPoint &t((_state & StateDown) ? _st.downTextPos : _st.textPos);
|
||||
p.drawText(t.x(), t.y() + _st.font->ascent, _text);
|
||||
}
|
||||
const style::sprite &i((_state & StateDown) ? _st.downIcon : _st.icon);
|
||||
if (i.pxWidth()) {
|
||||
QPoint t((_state & StateDown) ? _st.downIconPos : _st.iconPos);
|
||||
if (t.x() < 0) {
|
||||
t.setX((width() - i.pxWidth()) / 2);
|
||||
}
|
||||
if (t.y() < 0) {
|
||||
t.setY((height() - i.pxHeight()) / 2);
|
||||
}
|
||||
p.drawSprite(t, i);
|
||||
}
|
||||
}
|
||||
|
||||
BoxButton::BoxButton(QWidget *parent, const QString &text, const style::RoundButton &st) : Button(parent)
|
||||
, _text(text.toUpper())
|
||||
, _fullText(text.toUpper())
|
||||
|
||||
Reference in New Issue
Block a user