mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-30 22:16:14 +00:00
ITextLink moved to ClickHandler, TextLinkPtr > ClickHandlerPtr.
Global methods textlnkOver/Down/DrawOver were replaced by static members of ClickHandler, now global state consists of the handler pointer + host pointer, who declares callbacks for the active and pressed handler changed events. This will allow to use ClickHandler from different hosts simultaneously (like HistoryItem / BotDescription / BotKeyboard). Not yet tested.
This commit is contained in:
@@ -83,33 +83,30 @@ void ConfirmBox::mouseMoveEvent(QMouseEvent *e) {
|
||||
void ConfirmBox::mousePressEvent(QMouseEvent *e) {
|
||||
_lastMousePos = e->globalPos();
|
||||
updateHover();
|
||||
if (textlnkOver()) {
|
||||
textlnkDown(textlnkOver());
|
||||
update();
|
||||
}
|
||||
ClickHandler::pressed();
|
||||
return LayeredWidget::mousePressEvent(e);
|
||||
}
|
||||
|
||||
void ConfirmBox::mouseReleaseEvent(QMouseEvent *e) {
|
||||
_lastMousePos = e->globalPos();
|
||||
updateHover();
|
||||
if (textlnkOver() && textlnkOver() == textlnkDown()) {
|
||||
if (ClickHandlerPtr activated = ClickHandler::unpressed()) {
|
||||
Ui::hideLayer();
|
||||
textlnkOver()->onClick(e->button());
|
||||
App::activateClickHandler(activated, e->button());
|
||||
}
|
||||
textlnkDown(TextLinkPtr());
|
||||
}
|
||||
|
||||
void ConfirmBox::leaveEvent(QEvent *e) {
|
||||
if (_myLink) {
|
||||
if (textlnkOver() == _myLink) {
|
||||
textlnkOver(TextLinkPtr());
|
||||
update();
|
||||
}
|
||||
_myLink = TextLinkPtr();
|
||||
setCursor(style::cur_default);
|
||||
update();
|
||||
}
|
||||
ClickHandler::clearActive(this);
|
||||
}
|
||||
|
||||
void ConfirmBox::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) {
|
||||
setCursor(active ? style::cur_pointer : style::cur_default);
|
||||
update();
|
||||
}
|
||||
|
||||
void ConfirmBox::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) {
|
||||
update();
|
||||
}
|
||||
|
||||
void ConfirmBox::updateLink() {
|
||||
@@ -119,17 +116,12 @@ void ConfirmBox::updateLink() {
|
||||
|
||||
void ConfirmBox::updateHover() {
|
||||
QPoint m(mapFromGlobal(_lastMousePos));
|
||||
bool wasMy = (_myLink == textlnkOver());
|
||||
|
||||
textstyleSet(&st::boxTextStyle);
|
||||
_myLink = _text.linkLeft(m.x() - st::boxPadding.left(), m.y() - st::boxPadding.top(), _textWidth, width(), (_text.maxWidth() < width()) ? style::al_center : style::al_left);
|
||||
ClickHandlerPtr handler = _text.linkLeft(m.x() - st::boxPadding.left(), m.y() - st::boxPadding.top(), _textWidth, width(), (_text.maxWidth() < width()) ? style::al_center : style::al_left);
|
||||
textstyleRestore();
|
||||
if (_myLink != textlnkOver()) {
|
||||
if (wasMy || _myLink || rect().contains(m)) {
|
||||
textlnkOver(_myLink);
|
||||
}
|
||||
setCursor(_myLink ? style::cur_pointer : style::cur_default);
|
||||
update();
|
||||
}
|
||||
|
||||
ClickHandler::setActive(handler, this);
|
||||
}
|
||||
|
||||
void ConfirmBox::closePressed() {
|
||||
@@ -182,9 +174,9 @@ ConfirmLinkBox::ConfirmLinkBox(const QString &url) : ConfirmBox(lang(lng_open_th
|
||||
void ConfirmLinkBox::onOpenLink() {
|
||||
Ui::hideLayer();
|
||||
if (reMailStart().match(_url).hasMatch()) {
|
||||
EmailLink(_url).onClick(Qt::LeftButton);
|
||||
EmailClickHandler::doOpen(_url);
|
||||
} else {
|
||||
TextLink(_url).onClick(Qt::LeftButton);
|
||||
UrlClickHandler::doOpen(_url);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user