Commit 7fec9ea9 authored by Tomaz  Canabrava's avatar Tomaz Canabrava
Browse files

Move hotSpotRegion to FilterChain

FilterChain contains all the hotspots, it's the best place
to calculate the collective region. This removes code from
the TerminalDisplay, and that's much needed.
parent fa3968bf
......@@ -20,8 +20,18 @@
#include "FilterChain.h"
#include "Filter.h"
#include "HotSpot.h"
#include "widgets/TerminalDisplay.h"
#include <QRect>
using namespace Konsole;
FilterChain::FilterChain(TerminalDisplay *terminalDisplay)
: _terminalDisplay(terminalDisplay)
{
}
FilterChain::~FilterChain()
{
qDeleteAll(_filters);
......@@ -82,3 +92,35 @@ QList<QSharedPointer<HotSpot>> FilterChain::hotSpots() const
}
return list;
}
QRegion FilterChain::hotSpotRegion() const
{
QRegion region;
for (const auto &hotSpot : hotSpots()) {
QRect r;
r.setLeft(hotSpot->startColumn());
r.setTop(hotSpot->startLine());
if (hotSpot->startLine() == hotSpot->endLine()) {
r.setRight(hotSpot->endColumn());
r.setBottom(hotSpot->endLine());
region |= _terminalDisplay->imageToWidget(r);
} else {
r.setRight(_terminalDisplay->columns());
r.setBottom(hotSpot->startLine());
region |= _terminalDisplay->imageToWidget(r);
r.setLeft(0);
for (int line = hotSpot->startLine() + 1 ; line < hotSpot->endLine(); line++) {
r.moveTop(line);
region |= _terminalDisplay->imageToWidget(r);
}
r.moveTop(hotSpot->endLine());
r.setRight(hotSpot->endColumn());
region |= _terminalDisplay->imageToWidget(r);
}
}
return region;
}
......@@ -24,11 +24,13 @@
#include <QString>
#include <QList>
#include <QSharedPointer>
#include <QRegion>
namespace Konsole
{
class Filter;
class HotSpot;
class TerminalDisplay;
/**
* A chain which allows a group of filters to be processed as one.
......@@ -50,6 +52,7 @@ class HotSpot;
class FilterChain
{
public:
explicit FilterChain(TerminalDisplay *terminalDisplay);
virtual ~FilterChain();
/** Adds a new filter to the chain. The chain will delete this filter when it is destroyed */
......@@ -73,8 +76,13 @@ public:
QSharedPointer<HotSpot> hotSpotAt(int line, int column) const;
/** Returns a list of all the hotspots in all the chain's filters */
QList<QSharedPointer<HotSpot>> hotSpots() const;
/* Returns the region of the hotspot inside of the TerminalDisplay */
QRegion hotSpotRegion() const;
protected:
QList<Filter *> _filters;
TerminalDisplay *_terminalDisplay;
};
}
......
......@@ -24,10 +24,13 @@
#include "PlainTextDecoder.h"
#include "widgets/TerminalDisplay.h"
using namespace Konsole;
TerminalImageFilterChain::TerminalImageFilterChain() :
TerminalImageFilterChain::TerminalImageFilterChain(TerminalDisplay *terminalDisplay) :
FilterChain(terminalDisplay),
_buffer(nullptr),
_linePositions(nullptr)
{
......
......@@ -28,12 +28,13 @@
#include "Character.h"
namespace Konsole {
class TerminalDisplay;
/** A filter chain which processes character images from terminal displays */
class TerminalImageFilterChain : public FilterChain
{
public:
TerminalImageFilterChain();
TerminalImageFilterChain(TerminalDisplay *terminalDisplay);
~TerminalImageFilterChain() override;
/**
......
......@@ -497,7 +497,7 @@ TerminalDisplay::TerminalDisplay(QWidget* parent)
, _size(QSize())
, _blendColor(qRgba(0, 0, 0, 0xff))
, _wallpaper(nullptr)
, _filterChain(new TerminalImageFilterChain())
, _filterChain(new TerminalImageFilterChain(this))
, _mouseOverHotspotArea(QRegion())
, _filterUpdateRequired(true)
, _cursorShape(Enum::BlockCursor)
......@@ -1047,37 +1047,6 @@ void TerminalDisplay::scrollImage(int lines , const QRect& screenWindowRegion)
scroll(0 , _fontHeight * (-lines) , scrollRect);
}
QRegion TerminalDisplay::hotSpotRegion() const
{
QRegion region;
for (const auto &hotSpot : _filterChain->hotSpots()) {
QRect r;
r.setLeft(hotSpot->startColumn());
r.setTop(hotSpot->startLine());
if (hotSpot->startLine() == hotSpot->endLine()) {
r.setRight(hotSpot->endColumn());
r.setBottom(hotSpot->endLine());
region |= imageToWidget(r);
} else {
r.setRight(_columns);
r.setBottom(hotSpot->startLine());
region |= imageToWidget(r);
r.setLeft(0);
for (int line = hotSpot->startLine() + 1 ; line < hotSpot->endLine(); line++) {
r.moveTop(line);
region |= imageToWidget(r);
}
r.moveTop(hotSpot->endLine());
r.setRight(hotSpot->endColumn());
region |= imageToWidget(r);
}
}
return region;
}
void TerminalDisplay::processFilters()
{
......@@ -1089,7 +1058,7 @@ void TerminalDisplay::processFilters()
return;
}
QRegion preUpdateHotSpots = hotSpotRegion();
const QRegion preUpdateHotSpots = _filterChain->hotSpotRegion();
// use _screenWindow->getImage() here rather than _image because
// other classes may call processFilters() when this display's
......@@ -1102,7 +1071,7 @@ void TerminalDisplay::processFilters()
_screenWindow->getLineProperties());
_filterChain->process();
QRegion postUpdateHotSpots = hotSpotRegion();
const QRegion postUpdateHotSpots = _filterChain->hotSpotRegion();
update(preUpdateHotSpots | postUpdateHotSpots);
_filterUpdateRequired = false;
......
......@@ -379,6 +379,10 @@ public:
return _hasCompositeFocus;
}
// maps an area in the character image to an area on the widget
QRect imageToWidget(const QRect &imageArea) const;
QRect widgetToImage(const QRect &widgetArea) const;
public Q_SLOTS:
/**
* Scrolls current ScreenWindow
......@@ -675,9 +679,6 @@ private:
// --
// maps an area in the character image to an area on the widget
QRect imageToWidget(const QRect &imageArea) const;
QRect widgetToImage(const QRect &widgetArea) const;
// maps a point on the widget to the position ( ie. line and column )
// of the character at that point. When the edge is true, it maps to
......@@ -712,10 +713,6 @@ private:
void setupHeaderVisibility();
// returns a region covering all of the areas of the widget which contain
// a hotspot
QRegion hotSpotRegion() const;
// returns the position of the cursor in columns and lines
QPoint cursorPosition() const;
......
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