File indexing completed on 2024-05-12 09:56:57
0001 /* 0002 SPDX-FileCopyrightText: 2007-2008 Robert Knight <robertknight@gmail.com> 0003 SPDX-FileCopyrightText: 2020 Tomaz Canabrava <tcanabrava@gmail.com> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "HotSpot.h" 0009 0010 #include <QDebug> 0011 #include <QMouseEvent> 0012 0013 #include "FileFilterHotspot.h" 0014 #include "terminalDisplay/TerminalDisplay.h" 0015 #include "terminalDisplay/TerminalFonts.h" 0016 0017 using namespace Konsole; 0018 0019 HotSpot::~HotSpot() = default; 0020 0021 HotSpot::HotSpot(int startLine, int startColumn, int endLine, int endColumn) 0022 : _startLine(startLine) 0023 , _startColumn(startColumn) 0024 , _endLine(endLine) 0025 , _endColumn(endColumn) 0026 , _type(NotSpecified) 0027 { 0028 } 0029 0030 QList<QAction *> HotSpot::actions() 0031 { 0032 return {}; 0033 } 0034 0035 QList<QAction *> HotSpot::setupMenu(QMenu *) 0036 { 0037 return {}; 0038 } 0039 0040 int HotSpot::startLine() const 0041 { 0042 return _startLine; 0043 } 0044 0045 int HotSpot::endLine() const 0046 { 0047 return _endLine; 0048 } 0049 0050 int HotSpot::startColumn() const 0051 { 0052 return _startColumn; 0053 } 0054 0055 int HotSpot::endColumn() const 0056 { 0057 return _endColumn; 0058 } 0059 0060 HotSpot::Type HotSpot::type() const 0061 { 0062 return _type; 0063 } 0064 0065 void HotSpot::setType(Type type) 0066 { 0067 _type = type; 0068 } 0069 0070 QPair<QRegion, QRect> HotSpot::region(int fontWidth, int fontHeight, int columns, QRect terminalDisplayRect) const 0071 { 0072 QRegion region; 0073 QRect r; 0074 const int top = terminalDisplayRect.top(); 0075 const int left = terminalDisplayRect.left(); 0076 0077 if (startLine() == endLine()) { 0078 r.setCoords(startColumn() * fontWidth + left, 0079 startLine() * fontHeight + top, 0080 (endColumn()) * fontWidth + left - 1, 0081 (endLine() + 1) * fontHeight + top - 1); 0082 region |= r; 0083 } else { 0084 r.setCoords(startColumn() * fontWidth + left, startLine() * fontHeight + top, (columns)*fontWidth + left - 1, (startLine() + 1) * fontHeight + top - 1); 0085 region |= r; 0086 for (int line = startLine() + 1; line < endLine(); line++) { 0087 r.setCoords(0 * fontWidth + left, line * fontHeight + top, (columns)*fontWidth + left - 1, (line + 1) * fontHeight + top - 1); 0088 region |= r; 0089 } 0090 r.setCoords(0 * fontWidth + left, endLine() * fontHeight + top, (endColumn()) * fontWidth + left - 1, (endLine() + 1) * fontHeight + top - 1); 0091 region |= r; 0092 } 0093 return {region, r}; 0094 } 0095 0096 void HotSpot::mouseMoveEvent(TerminalDisplay *td, QMouseEvent *ev) 0097 { 0098 Q_UNUSED(td) 0099 Q_UNUSED(ev) 0100 } 0101 0102 bool HotSpot::isUrl() 0103 { 0104 return (_type == HotSpot::Link || _type == HotSpot::EMailAddress || _type == HotSpot::EscapedUrl || _type == HotSpot::File); 0105 } 0106 0107 void HotSpot::mouseEnterEvent(TerminalDisplay *td, QMouseEvent *ev) 0108 { 0109 if (!isUrl()) { 0110 return; 0111 } 0112 0113 if (td->cursor().shape() != Qt::PointingHandCursor && ((td->openLinksByDirectClick() || ((ev->modifiers() & Qt::ControlModifier) != 0u)))) { 0114 td->setCursor(Qt::PointingHandCursor); 0115 } 0116 0117 auto r = region(td->terminalFont()->fontWidth(), td->terminalFont()->fontHeight(), td->columns(), td->contentRect()).first; 0118 td->update(r); 0119 } 0120 0121 void HotSpot::mouseLeaveEvent(TerminalDisplay *td, QMouseEvent *ev) 0122 { 0123 Q_UNUSED(ev) 0124 0125 if (!isUrl()) { 0126 return; 0127 } 0128 0129 auto r = region(td->terminalFont()->fontWidth(), td->terminalFont()->fontHeight(), td->columns(), td->contentRect()).first; 0130 td->update(r); 0131 0132 td->resetCursor(); 0133 } 0134 0135 void HotSpot::mouseReleaseEvent(TerminalDisplay *td, QMouseEvent *ev) 0136 { 0137 if (!isUrl()) { 0138 return; 0139 } 0140 0141 if ((td->openLinksByDirectClick() || ((ev->modifiers() & Qt::ControlModifier) != 0u))) { 0142 activate(nullptr); 0143 } 0144 } 0145 0146 void HotSpot::keyPressEvent(TerminalDisplay *td, QKeyEvent *ev) 0147 { 0148 if (!isUrl()) { 0149 return; 0150 } 0151 0152 // If td->openLinksByDirectClick() is true, the shape has already been changed by the 0153 // mouseEnterEvent 0154 if (td->cursor().shape() != Qt::PointingHandCursor && (ev->modifiers() & Qt::ControlModifier) != 0u) { 0155 td->setCursor(Qt::PointingHandCursor); 0156 } 0157 } 0158 0159 void HotSpot::keyReleaseEvent(TerminalDisplay *td, QKeyEvent *ev) 0160 { 0161 Q_UNUSED(ev) 0162 0163 if (!isUrl()) { 0164 return; 0165 } 0166 0167 if (td->openLinksByDirectClick()) { 0168 return; 0169 } 0170 td->resetCursor(); 0171 } 0172 0173 void HotSpot::debug() 0174 { 0175 qDebug() << this; 0176 qDebug() << type(); 0177 qDebug() << _startLine << _endLine << _startColumn << _endColumn; 0178 } 0179 0180 bool Konsole::HotSpot::hasDragOperation() const 0181 { 0182 return false; 0183 } 0184 0185 void Konsole::HotSpot::startDrag() 0186 { 0187 }