Commit 65cbe19c authored by Tomaz  Canabrava's avatar Tomaz Canabrava

Move hotSpot region code to HotSpot

parent f9889eb5
......@@ -72,3 +72,38 @@ void HotSpot::setType(Type type)
{
_type = type;
}
QPair<QRegion, QRect> HotSpot::region(int fontWidth, int fontHeight, int columns, QRect terminalDisplayRect) const
{
QRegion region;
QRect r;
const int top = terminalDisplayRect.top();
const int left = terminalDisplayRect.left();
if (startLine() == endLine()) {
r.setCoords(startColumn() * fontWidth + left,
startLine() * fontHeight + top,
(endColumn()) * fontWidth + left - 1,
(endLine() + 1) * fontHeight + top - 1);
region |= r;
} else {
r.setCoords(startColumn() * fontWidth + left,
startLine() * fontHeight + top,
(columns) * fontWidth + left - 1,
(startLine() + 1) *fontHeight + top - 1);
region |= r;
for (int line = startLine() + 1 ; line < endLine() ; line++) {
r.setCoords(0 * fontWidth + left,
line * fontHeight + top,
(columns)* fontWidth + left - 1,
(line + 1)* fontHeight + top - 1);
region |= r;
}
r.setCoords(0 * fontWidth + left,
endLine()* fontHeight + top,
(endColumn()) * fontWidth + left - 1,
(endLine() + 1) * fontHeight + top - 1);
region |= r;
}
return {region, r};
}
......@@ -24,6 +24,8 @@
#include <QObject>
#include <QList>
#include <QRegion>
#include <QRect>
class QAction;
class QMenu;
......@@ -100,6 +102,8 @@ public:
* Setups a menu with actions for the hotspot.
*/
virtual void setupMenu(QMenu *menu);
QPair<QRegion, QRect> region(int fontWidth, int fontHeight, int columns, QRect terminalDisplayRect) const;
protected:
/** Sets the type of a hotspot. This should only be set once */
void setType(Type type);
......
......@@ -1437,32 +1437,9 @@ void TerminalDisplay::paintFilters(QPainter& painter)
for (const auto &spot : spots) {
QRegion region;
if (spot->type() == HotSpot::Link || spot->type() == HotSpot::EMailAddress || spot->type() == HotSpot::EscapedUrl) {
QRect r;
if (spot->startLine() == spot->endLine()) {
r.setCoords(spot->startColumn()*_fontWidth + _contentRect.left(),
spot->startLine()*_fontHeight + _contentRect.top(),
(spot->endColumn())*_fontWidth + _contentRect.left() - 1,
(spot->endLine() + 1)*_fontHeight + _contentRect.top() - 1);
region |= r;
} else {
r.setCoords(spot->startColumn()*_fontWidth + _contentRect.left(),
spot->startLine()*_fontHeight + _contentRect.top(),
(_columns)*_fontWidth + _contentRect.left() - 1,
(spot->startLine() + 1)*_fontHeight + _contentRect.top() - 1);
region |= r;
for (int line = spot->startLine() + 1 ; line < spot->endLine() ; line++) {
r.setCoords(0 * _fontWidth + _contentRect.left(),
line * _fontHeight + _contentRect.top(),
(_columns)*_fontWidth + _contentRect.left() - 1,
(line + 1)*_fontHeight + _contentRect.top() - 1);
region |= r;
}
r.setCoords(0 * _fontWidth + _contentRect.left(),
spot->endLine()*_fontHeight + _contentRect.top(),
(spot->endColumn())*_fontWidth + _contentRect.left() - 1,
(spot->endLine() + 1)*_fontHeight + _contentRect.top() - 1);
region |= r;
}
QPair<QRegion, QRect> spotRegion = spot->region(_fontWidth, _fontHeight, _columns, _contentRect);
region = spotRegion.first;
QRect r = spotRegion.second;
if (_showUrlHint && spot->type() == HotSpot::Link) {
if (urlNumber >= 0 && urlNumber < 10) {
......
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