Allow clickable links in Ui::Checkbox texts.
This commit is contained in:
parent
676d8697c6
commit
e1ec6a38be
2 changed files with 67 additions and 2 deletions
|
|
@ -486,6 +486,9 @@ Checkbox::Checkbox(
|
||||||
std::move(value),
|
std::move(value),
|
||||||
_checkboxRichOptions);
|
_checkboxRichOptions);
|
||||||
resizeToText();
|
resizeToText();
|
||||||
|
if (_text.hasLinks()) {
|
||||||
|
setMouseTracking(true);
|
||||||
|
}
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
@ -689,6 +692,59 @@ void Checkbox::paintEvent(QPaintEvent *e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Checkbox::mousePressEvent(QMouseEvent *e) {
|
||||||
|
RippleButton::mousePressEvent(e);
|
||||||
|
ClickHandler::pressed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Checkbox::mouseMoveEvent(QMouseEvent *e) {
|
||||||
|
RippleButton::mouseMoveEvent(e);
|
||||||
|
const auto state = getTextState(e->pos());
|
||||||
|
if (state.link != ClickHandler::getActive()) {
|
||||||
|
ClickHandler::setActive(state.link, this);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Checkbox::mouseReleaseEvent(QMouseEvent *e) {
|
||||||
|
if (auto activated = _activatingHandler = ClickHandler::unpressed()) {
|
||||||
|
const auto button = e->button();
|
||||||
|
crl::on_main(this, [=] {
|
||||||
|
const auto guard = window();
|
||||||
|
ActivateClickHandler(guard, activated, button);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
RippleButton::mouseReleaseEvent(e);
|
||||||
|
_activatingHandler = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Checkbox::leaveEventHook(QEvent *e) {
|
||||||
|
RippleButton::leaveEventHook(e);
|
||||||
|
ClickHandler::clearActive(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
Text::StateResult Checkbox::getTextState(const QPoint &m) const {
|
||||||
|
if (!(_checkAlignment & Qt::AlignLeft)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
const auto check = checkRect();
|
||||||
|
const auto textSkip = _st.checkPosition.x()
|
||||||
|
+ check.width()
|
||||||
|
+ _st.textPosition.x();
|
||||||
|
const auto availableTextWidth = std::max(width() - textSkip, 1);
|
||||||
|
const auto textTop = _st.margin.top() + _st.textPosition.y();
|
||||||
|
return !_allowTextLines
|
||||||
|
? _text.getStateElided(
|
||||||
|
m - QPoint(textSkip, textTop),
|
||||||
|
availableTextWidth,
|
||||||
|
{})
|
||||||
|
: _text.getStateElidedLeft(
|
||||||
|
m - QPoint(textSkip, textTop),
|
||||||
|
availableTextWidth,
|
||||||
|
width(),
|
||||||
|
{});
|
||||||
|
}
|
||||||
|
|
||||||
QPixmap Checkbox::grabCheckCache() const {
|
QPixmap Checkbox::grabCheckCache() const {
|
||||||
auto checkSize = _check->getSize();
|
auto checkSize = _check->getSize();
|
||||||
auto image = QImage(
|
auto image = QImage(
|
||||||
|
|
@ -724,8 +780,10 @@ void Checkbox::onStateChanged(State was, StateChangeSource source) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Checkbox::handlePress() {
|
void Checkbox::handlePress() {
|
||||||
|
if (!_activatingHandler) {
|
||||||
setChecked(!checked());
|
setChecked(!checked());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int Checkbox::resizeGetHeight(int newWidth) {
|
int Checkbox::resizeGetHeight(int newWidth) {
|
||||||
const auto result = _check->getSize().height();
|
const auto result = _check->getSize().height();
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Checkbox : public RippleButton {
|
class Checkbox : public RippleButton, public ClickHandlerHost {
|
||||||
public:
|
public:
|
||||||
Checkbox(
|
Checkbox(
|
||||||
QWidget *parent,
|
QWidget *parent,
|
||||||
|
|
@ -210,6 +210,11 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
|
|
||||||
|
void mousePressEvent(QMouseEvent *e) override;
|
||||||
|
void mouseMoveEvent(QMouseEvent *e) override;
|
||||||
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
||||||
|
void leaveEventHook(QEvent *e) override;
|
||||||
|
|
||||||
void onStateChanged(State was, StateChangeSource source) override;
|
void onStateChanged(State was, StateChangeSource source) override;
|
||||||
int resizeGetHeight(int newWidth) override;
|
int resizeGetHeight(int newWidth) override;
|
||||||
|
|
||||||
|
|
@ -222,10 +227,12 @@ private:
|
||||||
void resizeToText();
|
void resizeToText();
|
||||||
QPixmap grabCheckCache() const;
|
QPixmap grabCheckCache() const;
|
||||||
int countTextMinWidth() const;
|
int countTextMinWidth() const;
|
||||||
|
Text::StateResult getTextState(const QPoint &m) const;
|
||||||
|
|
||||||
const style::Checkbox &_st;
|
const style::Checkbox &_st;
|
||||||
std::unique_ptr<AbstractCheckView> _check;
|
std::unique_ptr<AbstractCheckView> _check;
|
||||||
rpl::event_stream<bool> _checkedChanges;
|
rpl::event_stream<bool> _checkedChanges;
|
||||||
|
ClickHandlerPtr _activatingHandler;
|
||||||
QPixmap _checkCache;
|
QPixmap _checkCache;
|
||||||
|
|
||||||
style::align _checkAlignment = style::al_left;
|
style::align _checkAlignment = style::al_left;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue