Commit 4ee99c6c authored by Gustavo Carneiro's avatar Gustavo Carneiro
Browse files

Initial refactoring TerminalPainter class.

parent 2a6e520a
......@@ -471,8 +471,6 @@ TerminalDisplay::TerminalDisplay(QWidget* parent)
, _filterChain(new TerminalImageFilterChain(this))
, _filterUpdateRequired(true)
, _cursorShape(Enum::BlockCursor)
, _cursorColor(QColor())
, _cursorTextColor(QColor())
, _antialiasText(true)
, _useFontLineCharacters(false)
, _sessionController(nullptr)
......@@ -565,13 +563,21 @@ TerminalDisplay::TerminalDisplay(QWidget* parent)
connect(KonsoleSettings::self(), &KonsoleSettings::configChanged, this, &TerminalDisplay::setupHeaderVisibility);
_terminalPainter = new TerminalPainter(this);
connect(this, &TerminalDisplay::drawContents, _terminalPainter, &TerminalPainter::drawContents);
connect(this, &TerminalDisplay::drawCurrentResultRect, _terminalPainter, &TerminalPainter::drawCurrentResultRect);
connect(this, &TerminalDisplay::highlightScrolledLines, _terminalPainter, &TerminalPainter::highlightScrolledLines);
connect(this, &TerminalDisplay::highlightScrolledLinesRegion, _terminalPainter, &TerminalPainter::highlightScrolledLinesRegion);
connect(this, &TerminalDisplay::drawBackground, _terminalPainter, &TerminalPainter::drawBackground);
connect(this, &TerminalDisplay::drawCursor, _terminalPainter, &TerminalPainter::drawCursor);
connect(this, &TerminalDisplay::drawCharacters, _terminalPainter, &TerminalPainter::drawCharacters);
connect(this, &TerminalDisplay::drawInputMethodPreeditString, _terminalPainter, &TerminalPainter::drawInputMethodPreeditString);
auto ldrawBackground = [this](QPainter &painter,
const QRect &rect, const QColor &backgroundColor, bool useOpacitySetting) {
_terminalPainter->drawBackground(painter, rect, backgroundColor, useOpacitySetting);
emit drawBackground(painter, rect, backgroundColor, useOpacitySetting);
};
auto ldrawContents = [this](QPainter &paint, const QRect &rect, bool friendly) {
_terminalPainter->drawContents(paint, rect, friendly);
emit drawContents(_image, paint, rect, friendly, _imageSize, _bidiEnabled, _fixedFont, _lineProperties);
};
auto lgetBackgroundColor = [this]() {
return getBackgroundColor();
......@@ -671,16 +677,6 @@ void TerminalDisplay::resetCursorStyle()
}
}
void TerminalDisplay::setKeyboardCursorColor(const QColor& color)
{
_cursorColor = color;
}
void TerminalDisplay::setKeyboardCursorTextColor(const QColor& color)
{
_cursorTextColor = color;
}
void TerminalDisplay::setOpacity(qreal opacity)
{
QColor color(_blendColor);
......@@ -924,7 +920,12 @@ void TerminalDisplay::updateImage()
}
if (_highlightScrolledLinesControl.enabled) {
dirtyRegion |= _terminalPainter->highlightScrolledLinesRegion(dirtyRegion.isEmpty());
dirtyRegion |= emit highlightScrolledLinesRegion(dirtyRegion.isEmpty(),
_highlightScrolledLinesControl.timer,
_highlightScrolledLinesControl.previousScrollCount,
_highlightScrolledLinesControl.rect,
_highlightScrolledLinesControl.needToClear,
HIGHLIGHT_SCROLLED_LINES_WIDTH);
}
_screenWindow->resetScrollCount();
......@@ -983,7 +984,7 @@ void TerminalDisplay::paintEvent(QPaintEvent* pe)
for (const QRect &rect : region) {
dirtyImageRegion += widgetToImage(rect);
_terminalPainter->drawBackground(paint, rect, getBackgroundColor(), true /* use opacity setting */);
emit drawBackground(paint, rect, getBackgroundColor(), true /* use opacity setting */);
}
if (_displayVerticalLine) {
......@@ -999,11 +1000,13 @@ void TerminalDisplay::paintEvent(QPaintEvent* pe)
paint.setRenderHint(QPainter::TextAntialiasing, _antialiasText);
for (const QRect &rect : qAsConst(dirtyImageRegion)) {
_terminalPainter->drawContents(paint, rect, false);
emit drawContents(_image, paint, rect, false, _imageSize, _bidiEnabled, _fixedFont, _lineProperties);
}
emit drawCurrentResultRect(paint, _searchResultRect);
if (_highlightScrolledLinesControl.enabled) {
emit highlightScrolledLines(paint, _highlightScrolledLinesControl.timer, _highlightScrolledLinesControl.rect);
}
_terminalPainter->drawCurrentResultRect(paint);
_terminalPainter->highlightScrolledLines(paint);
_terminalPainter->drawInputMethodPreeditString(paint, preeditRect());
emit drawInputMethodPreeditString(paint, preeditRect(), _inputMethodData, _image);
paintFilters(paint);
const bool drawDimmed = _dimWhenInactive && !hasFocus();
......@@ -3131,12 +3134,6 @@ void TerminalDisplay::applyProfile(const Profile::Ptr &profile)
// cursor shape
setKeyboardCursorShape(Enum::CursorShapeEnum(profile->property<int>(Profile::CursorShape)));
// cursor color
// an invalid QColor is used to inform the view widget to
// draw the cursor using the default color( matching the text)
setKeyboardCursorColor(profile->useCustomCursorColor() ? profile->customCursorColor() : QColor());
setKeyboardCursorTextColor(profile->useCustomCursorColor() ? profile->customCursorTextColor() : QColor());
// word characters
setWordCharacters(profile->wordCharacters());
......@@ -3155,6 +3152,8 @@ void TerminalDisplay::applyProfile(const Profile::Ptr &profile)
_filterChain->setReverseUrlHints(profile->property<bool>(Profile::ReverseUrlHints));
_peekPrimaryShortcut = profile->peekPrimaryKeySequence();
_terminalPainter->applyProfile(profile);
}
void TerminalDisplay::printScreen()
......
......@@ -166,36 +166,6 @@ public:
*/
void resetCursorStyle();
/**
* Sets the color used to draw the keyboard cursor.
*
* The keyboard cursor defaults to using the foreground color of the character
* underneath it.
*
* @param color By default, the widget uses the color of the
* character under the cursor to draw the cursor, and inverts the
* color of that character to make sure it is still readable. If @p
* color is a valid QColor, the widget uses that color to draw the
* cursor. If @p color is not an valid QColor, the widget falls back
* to the default behavior.
*/
void setKeyboardCursorColor(const QColor &color);
/**
* Sets the color used to draw the character underneath the keyboard cursor.
*
* The keyboard cursor defaults to using the background color of the
* terminal cell to draw the character at the cursor position.
*
* @param color By default, the widget uses the color of the
* character under the cursor to draw the cursor, and inverts the
* color of that character to make sure it is still readable. If @p
* color is a valid QColor, the widget uses that color to draw the
* character underneath the cursor. If @p color is not an valid QColor,
* the widget falls back to the default behavior.
*/
void setKeyboardCursorTextColor(const QColor &color);
/**
* Returns the number of lines of text which can be displayed in the widget.
*
......@@ -219,6 +189,11 @@ public:
return _columns;
}
int usedColumns() const
{
return _usedColumns;
}
/**
* Returns the height of the characters in the font used to draw the text in the display.
*/
......@@ -369,14 +344,79 @@ public:
// toggle the header bar Minimize/Maximize button.
void setExpandedMode(bool expand);
friend class TerminalPainter;
friend class TerminalScrollBar;
TerminalScrollBar *scrollBar()
TerminalScrollBar *scrollBar() const
{
return _scrollBar;
}
qreal opacity() const
{
return _opacity;
}
QRgb blendColor() const
{
return _blendColor;
}
bool cursorBlinking() const
{
return _cursorBlinking;
}
bool textBlinking() const
{
return _textBlinking;
}
Enum::CursorShapeEnum cursorShape() const
{
return _cursorShape;
}
bool boldIntense() const
{
return _boldIntense;
}
bool useFontLineCharacters() const
{
return _useFontLineCharacters;
}
bool bidiEnabled() const
{
return _bidiEnabled;
}
int fontAscent() const
{
return _fontAscent;
}
bool antialiasText() const
{
return _antialiasText;
}
ColorSchemeWallpaper::Ptr wallpaper() const
{
return _wallpaper;
}
struct InputMethodData {
QString preeditString;
QRect previousPreeditRect;
};
// returns true if the cursor's position is on display.
bool isCursorOnDisplay() const;
// returns the position of the cursor in columns and lines
QPoint cursorPosition() const;
public Q_SLOTS:
/**
* Scrolls current ScreenWindow
......@@ -504,6 +544,8 @@ public Q_SLOTS:
void printScreen();
Character getCursorCharacter(int column, int line);
int loc(int x, int y) const;
Q_SIGNALS:
void requestToggleExpansion();
/**
......@@ -547,6 +589,20 @@ Q_SIGNALS:
void peekPrimaryRequested(bool doPeek);
void drawContents(Character *image, QPainter &paint, const QRect &rect, bool printerFriendly, int imageSize, bool bidiEnabled, bool &fixedFont,
QVector<LineProperty> lineProperties);
void drawCurrentResultRect(QPainter &painter, QRect searchResultRect);
void highlightScrolledLines(QPainter& painter, QTimer *timer, QRect rect);
QRegion highlightScrolledLinesRegion(bool nothingChanged, QTimer *timer, int &previousScrollCount, QRect &rect, bool &needToClear, int HighlightScrolledLinesWidth);
void drawBackground(QPainter &painter, const QRect &rect, const QColor &backgroundColor, bool useOpacitySetting);
void drawCursor(QPainter &painter, const QRect &rect, const QColor &foregroundColor,
const QColor &backgroundColor, QColor &characterColor);
void drawCharacters(QPainter &painter, const QRect &rect, const QString &text,
const Character *style, const QColor &characterColor);
void drawInputMethodPreeditString(QPainter &painter, const QRect &rect, TerminalDisplay::InputMethodData &inputMethodData, Character *image);
protected:
// events
bool event(QEvent *event) override;
......@@ -634,12 +690,6 @@ private:
void setupHeaderVisibility();
// returns the position of the cursor in columns and lines
QPoint cursorPosition() const;
// returns true if the cursor's position is on display.
bool isCursorOnDisplay() const;
// redraws the cursor
void updateCursor();
......@@ -660,8 +710,6 @@ private:
// Boilerplate setup for MessageWidget
KMessageWidget* createMessageWidget(const QString &text);
int loc(int x, int y) const;
// the window onto the terminal screen which this display
// is currently showing.
QPointer<ScreenWindow> _screenWindow;
......@@ -762,18 +810,6 @@ private:
Enum::CursorShapeEnum _cursorShape;
// cursor color. If it is invalid (by default) then the foreground
// color of the character under the cursor is used
QColor _cursorColor;
// cursor text color. If it is invalid (by default) then the background
// color of the character under the cursor is used
QColor _cursorTextColor;
struct InputMethodData {
QString preeditString;
QRect previousPreeditRect;
};
InputMethodData _inputMethodData;
bool _antialiasText; // do we anti-alias or not
......
This diff is collapsed.
......@@ -20,6 +20,8 @@
#include "ScreenWindow.h"
#include "Enumeration.h"
#include "colorscheme/ColorSchemeWallpaper.h"
#include "profile/Profile.h"
#include "terminalDisplay/TerminalDisplay.h"
class QRect;
class QColor;
......@@ -34,55 +36,68 @@ namespace Konsole
class Character;
class TerminalDisplay;
class TerminalPainter
class TerminalPainter : public QObject
{
public:
explicit TerminalPainter(TerminalDisplay *display);
explicit TerminalPainter(QObject *parent = nullptr);
~TerminalPainter() = default;
void applyProfile(const Profile::Ptr &profile);
// -- Drawing helpers --
// divides the part of the display specified by 'rect' into
// fragments according to their colors and styles and calls
// drawTextFragment() or drawPrinterFriendlyTextFragment()
// to draw the fragments
void drawContents(QPainter &paint, const QRect &rect, bool PrinterFriendly);
void drawContents(Character *image, QPainter &paint, const QRect &rect, bool PrinterFriendly, int imageSize, bool bidiEnabled, bool &fixedFont,
QVector<LineProperty> lineProperties);
// draw a transparent rectangle over the line of the current match
void drawCurrentResultRect(QPainter &painter);
void drawCurrentResultRect(QPainter &painter, QRect searchResultRect);
// draw a thin highlight on the left of the screen for lines that have been scrolled into view
void highlightScrolledLines(QPainter& painter);
// compute which region need to be repainted for scrolled lines highlight
QRegion highlightScrolledLinesRegion(bool nothingChanged);
void highlightScrolledLines(QPainter& painter, QTimer *timer, QRect rect);
// draws a section of text, all the text in this section
// has a common color and style
void drawTextFragment(QPainter &painter, const QRect &rect, const QString &text,
const Character *style);
// compute which region need to be repainted for scrolled lines highlight
QRegion highlightScrolledLinesRegion(bool nothingChanged, QTimer *timer, int &previousScrollCount, QRect &rect, bool &needToClear, int HighlightScrolledLinesWidth);
void drawPrinterFriendlyTextFragment(QPainter &painter, const QRect &rect, const QString &text,
const Character *style);
// draws the background for a text fragment
// if useOpacitySetting is true then the color's alpha value will be set to
// the display's transparency (set with setOpacity()), otherwise the background
// will be drawn fully opaque
void drawBackground(QPainter &painter, const QRect &rect, const QColor &backgroundColor,
bool useOpacitySetting);
// draws the cursor character
void drawCursor(QPainter &painter, const QRect &rect, const QColor &foregroundColor,
const QColor &backgroundColor, QColor &characterColor);
// draws the characters or line graphics in a text fragment
void drawCharacters(QPainter &painter, const QRect &rect, const QString &text,
const Character *style, const QColor &characterColor);
// draws a string of line graphics
void drawLineCharString(QPainter &painter, int x, int y, const QString &str,
const Character *attributes);
// draws the preedit string for input methods
void drawInputMethodPreeditString(QPainter &painter, const QRect &rect);
void drawInputMethodPreeditString(QPainter &painter, const QRect &rect, TerminalDisplay::InputMethodData &inputMethodData, Character *image);
private:
// draws a string of line graphics
void drawLineCharString(TerminalDisplay *display, QPainter &painter, int x, int y, const QString &str, const Character *attributes);
// draws a section of text, all the text in this section
// has a common color and style
void drawTextFragment(QPainter &painter, const QRect &rect, const QString &text,
const Character *style, const ColorEntry *colorTable);
void drawPrinterFriendlyTextFragment(QPainter &painter, const QRect &rect, const QString &text,
const Character *style);
// cursor color. If it is invalid (by default) then the foreground
// color of the character under the cursor is used
QColor m_cursorColor;
TerminalDisplay *_display;
// cursor text color. If it is invalid (by default) then the background
// color of the character under the cursor is used
QColor m_cursorTextColor;
};
}
......
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