Commit b6cb1540 authored by Tomaz  Canabrava's avatar Tomaz Canabrava

Move more code to HotSpots: mouseReleaseEvent

parent 41dc787d
......@@ -57,6 +57,11 @@ void EscapeSequenceUrlHotSpot::mouseEnterEvent(TerminalDisplay* td, QMouseEvent*
td->setCursor(Qt::PointingHandCursor);
td->update(r);
qDebug() << td->cursor();
}
void EscapeSequenceUrlHotSpot::mouseReleaseEvent(TerminalDisplay *td, QMouseEvent *ev)
{
if ((td->openLinksByDirectClick() || ((ev->modifiers() & Qt::ControlModifier) != 0u))) {
activate(nullptr);
}
}
......@@ -33,6 +33,7 @@ public:
void activate(QObject *obj) override;
void mouseEnterEvent(TerminalDisplay *td, QMouseEvent *ev) override;
void mouseReleaseEvent(TerminalDisplay *td, QMouseEvent *ev) override;
private:
QString _text;
QString _url;
......
......@@ -187,6 +187,15 @@ void FilterChain::mouseMoveEvent(TerminalDisplay *td, QMouseEvent *ev, int char
}
}
void FilterChain::mouseReleaseEvent(TerminalDisplay *td, QMouseEvent *ev, int charLine, int charColumn)
{
auto spot = hotSpotAt(charLine, charColumn);
if (!spot) {
return;
}
spot->mouseReleaseEvent(td, ev);
}
void FilterChain::paint(TerminalDisplay* td, QPainter& painter)
{
// get color of character under mouse and use it to draw
......
......@@ -90,6 +90,7 @@ public:
QList<QSharedPointer<HotSpot>> filterBy(HotSpot::Type type) const;
void mouseMoveEvent(TerminalDisplay *td, QMouseEvent *ev, int charLine, int charColumn);
void mouseReleaseEvent(TerminalDisplay *td, QMouseEvent *ev, int charLine, int charColumn);
void keyPressEvent(TerminalDisplay *td, QKeyEvent *ev, int charLine, int charColumn);
void keyReleaseEvent(TerminalDisplay *td, QKeyEvent *ev, int charLine, int charColumn);
void leaveEvent(TerminalDisplay *td, QEvent *ev);
......
......@@ -113,6 +113,7 @@ public:
virtual void mouseMoveEvent(TerminalDisplay *, QMouseEvent *);
virtual void mouseLeaveEvent(TerminalDisplay *, QMouseEvent *);
virtual void mouseEnterEvent(TerminalDisplay *, QMouseEvent *) {};
virtual void mouseReleaseEvent(TerminalDisplay *, QMouseEvent *){};
virtual void keyPressEvent(TerminalDisplay *, QKeyEvent *) {};
virtual void keyReleaseEvent(TerminalDisplay *, QKeyEvent *) {};
......
......@@ -149,6 +149,13 @@ void UrlFilterHotSpot::mouseEnterEvent(TerminalDisplay* td, QMouseEvent* ev)
setTerminalCursor(r, td, ev);
}
void UrlFilterHotSpot::mouseReleaseEvent(TerminalDisplay *td, QMouseEvent *ev)
{
if ((td->openLinksByDirectClick() || ((ev->modifiers() & Qt::ControlModifier) != 0u))) {
activate(nullptr);
}
}
void UrlFilterHotSpot::keyPressEvent(TerminalDisplay* td, QKeyEvent* ev)
{
QRegion r = region(td->fontWidth(), td->fontHeight(), td->columns(), td->contentRect()).first;
......
......@@ -46,6 +46,7 @@ public:
*/
void activate(QObject *object = nullptr) override;
void mouseEnterEvent(TerminalDisplay *td, QMouseEvent *ev) override;
void mouseReleaseEvent(TerminalDisplay *td, QMouseEvent *ev) override;
void keyPressEvent(TerminalDisplay *td, QKeyEvent *ev) override;
void keyReleaseEvent(TerminalDisplay *td, QKeyEvent *ev) override;
......
......@@ -2507,12 +2507,8 @@ void TerminalDisplay::mouseReleaseEvent(QMouseEvent* ev)
2);
}
// TODO: Move this code to hot spots too.
if (!_screenWindow->screen()->hasSelection() && (_openLinksByDirectClick || ((ev->modifiers() & Qt::ControlModifier) != 0u))) {
auto spot = _filterChain->hotSpotAt(charLine, charColumn);
if ((spot != nullptr) && (spot->type() == HotSpot::Link || spot->type() == HotSpot::EMailAddress || spot->type() == HotSpot::EscapedUrl)) {
spot->activate();
}
if (!_screenWindow->screen()->hasSelection()) {
_filterChain->mouseReleaseEvent(this, ev, charLine, charColumn);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment