Fix email links in labels.

This commit is contained in:
John Preston 2019-09-26 11:05:11 +03:00
parent 3ef71f63b8
commit ba1c7d8d31
2 changed files with 15 additions and 9 deletions

View file

@ -57,6 +57,9 @@ void UrlClickHandler::Open(QString url, QVariant context) {
Ui::Tooltip::Hide(); Ui::Tooltip::Hide();
if (!Ui::Integration::Instance().handleUrlClick(url, context) if (!Ui::Integration::Instance().handleUrlClick(url, context)
&& !url.isEmpty()) { && !url.isEmpty()) {
if (IsEmail(url)) {
url = "mailto: " + url;
}
QDesktopServices::openUrl(url); QDesktopServices::openUrl(url);
} }
} }

View file

@ -357,7 +357,6 @@ void FlatLabel::setLinksTrusted() {
return true; return true;
}; };
setClickHandlerFilter(TrustedLinksFilter); setClickHandlerFilter(TrustedLinksFilter);
} }
void FlatLabel::setClickHandlerFilter(ClickHandlerFilter &&filter) { void FlatLabel::setClickHandlerFilter(ClickHandlerFilter &&filter) {
@ -537,7 +536,9 @@ void FlatLabel::keyPressEvent(QKeyEvent *e) {
} }
void FlatLabel::contextMenuEvent(QContextMenuEvent *e) { void FlatLabel::contextMenuEvent(QContextMenuEvent *e) {
if (!_selectable) return; if (!_selectable && !_text.hasLinks()) {
return;
}
showContextMenu(e, ContextMenuReason::FromEvent); showContextMenu(e, ContextMenuReason::FromEvent);
} }
@ -625,12 +626,14 @@ void FlatLabel::showContextMenu(QContextMenuEvent *e, ContextMenuReason reason)
} }
auto state = dragActionUpdate(); auto state = dragActionUpdate();
bool hasSelection = !_selection.empty(); const auto hasSelection = _selectable && !_selection.empty();
bool uponSelection = state.uponSymbol && (state.symbol >= _selection.from) && (state.symbol < _selection.to); const auto uponSelection = _selectable
bool fullSelection = _text.isFullSelection(_selection); && ((reason == ContextMenuReason::FromTouch && hasSelection)
if (reason == ContextMenuReason::FromTouch && hasSelection && !uponSelection) { || (state.uponSymbol
uponSelection = hasSelection; && (state.symbol >= _selection.from)
} && (state.symbol < _selection.to)));
const auto fullSelection = _selectable
&& _text.isFullSelection(_selection);
_contextMenu = new PopupMenu(this); _contextMenu = new PopupMenu(this);
@ -639,7 +642,7 @@ void FlatLabel::showContextMenu(QContextMenuEvent *e, ContextMenuReason reason)
} else if (uponSelection && !fullSelection) { } else if (uponSelection && !fullSelection) {
const auto text = Integration::Instance().phraseContextCopySelected(); const auto text = Integration::Instance().phraseContextCopySelected();
_contextMenu->addAction(text, this, SLOT(onCopySelectedText())); _contextMenu->addAction(text, this, SLOT(onCopySelectedText()));
} else if (!hasSelection && !_contextCopyText.isEmpty()) { } else if (_selectable && !hasSelection && !_contextCopyText.isEmpty()) {
_contextMenu->addAction(_contextCopyText, this, SLOT(onCopyContextText())); _contextMenu->addAction(_contextCopyText, this, SLOT(onCopyContextText()));
} }