Simplify labels with custom click handlers.
This commit is contained in:
parent
2e63c6103e
commit
4ec399f169
2 changed files with 26 additions and 0 deletions
|
|
@ -378,6 +378,30 @@ void FlatLabel::setClickHandlerFilter(ClickHandlerFilter &&filter) {
|
|||
_clickHandlerFilter = std::move(filter);
|
||||
}
|
||||
|
||||
void FlatLabel::overrideLinkClickHandler(Fn<void()> handler) {
|
||||
setClickHandlerFilter([=](
|
||||
const ClickHandlerPtr &link,
|
||||
Qt::MouseButton button) {
|
||||
if (button != Qt::LeftButton) {
|
||||
return true;
|
||||
}
|
||||
handler();
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
void FlatLabel::overrideLinkClickHandler(Fn<void(QString url)> handler) {
|
||||
setClickHandlerFilter([=](
|
||||
const ClickHandlerPtr &link,
|
||||
Qt::MouseButton button) {
|
||||
if (button != Qt::LeftButton) {
|
||||
return true;
|
||||
}
|
||||
handler(link->dragText());
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
void FlatLabel::mouseMoveEvent(QMouseEvent *e) {
|
||||
_lastMousePos = e->globalPos();
|
||||
dragActionUpdate();
|
||||
|
|
|
|||
|
|
@ -139,6 +139,8 @@ public:
|
|||
|
||||
using ClickHandlerFilter = Fn<bool(const ClickHandlerPtr&, Qt::MouseButton)>;
|
||||
void setClickHandlerFilter(ClickHandlerFilter &&filter);
|
||||
void overrideLinkClickHandler(Fn<void()> handler);
|
||||
void overrideLinkClickHandler(Fn<void(QString url)> handler);
|
||||
|
||||
// ClickHandlerHost interface
|
||||
void clickHandlerActiveChanged(const ClickHandlerPtr &action, bool active) override;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue