File indexing completed on 2024-04-28 05:50:52

0001 /*
0002     SPDX-FileCopyrightText: 2020-2020 Gustavo Carneiro <gcarneiroa@hotmail.com>
0003     SPDX-FileCopyrightText: 2007-2008 Robert Knight <robertknight@gmail.com>
0004     SPDX-FileCopyrightText: 1997, 1998 Lars Doelle <lars.doelle@on-line.de>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef TERMINALPAINTER_HPP
0010 #define TERMINALPAINTER_HPP
0011 
0012 // Qt
0013 #include <QVector>
0014 
0015 // Konsole
0016 #include "../characters/Character.h"
0017 #include "Enumeration.h"
0018 #include "ScreenWindow.h"
0019 #include "colorscheme/ColorSchemeWallpaper.h"
0020 #include "profile/Profile.h"
0021 #include "terminalDisplay/TerminalDisplay.h"
0022 
0023 class QRect;
0024 class QColor;
0025 class QRegion;
0026 class QPainter;
0027 class QString;
0028 class QTimer;
0029 
0030 namespace Konsole
0031 {
0032 class Character;
0033 class TerminalDisplay;
0034 
0035 class TerminalPainter : public QObject
0036 {
0037 public:
0038     explicit TerminalPainter(TerminalDisplay *parentDisplay);
0039     ~TerminalPainter() override = default;
0040 
0041 public Q_SLOTS:
0042     // -- Drawing helpers --
0043 
0044     // divides the part of the display specified by 'rect' into
0045     // fragments according to their colors and styles and calls
0046     // drawTextFragment() or drawPrinterFriendlyTextFragment()
0047     // to draw the fragments
0048     void drawContents(Character *image,
0049                       QPainter &paint,
0050                       const QRect &rect,
0051                       bool PrinterFriendly,
0052                       int imageSize,
0053                       bool bidiEnabled,
0054                       QVector<LineProperty> lineProperties,
0055                       CharacterColor const *ulColorTable = nullptr);
0056 
0057     // draw a transparent rectangle over the line of the current match
0058     void drawCurrentResultRect(QPainter &painter, const QRect &searchResultRect);
0059 
0060     // draw a thin highlight on the left of the screen for lines that have been scrolled into view
0061     void highlightScrolledLines(QPainter &painter, bool isTimerActive, QRect rect);
0062 
0063     // compute which region need to be repainted for scrolled lines highlight
0064     QRegion highlightScrolledLinesRegion(TerminalScrollBar *scrollBar);
0065 
0066     // draws the background for a text fragment
0067     // if useOpacitySetting is true then the color's alpha value will be set to
0068     // the display's transparency (set with setOpacity()), otherwise the background
0069     // will be drawn fully opaque
0070     void drawBackground(QPainter &painter, const QRect &rect, const QColor &backgroundColor, bool useOpacitySetting);
0071 
0072     // draws the characters or line graphics in a text fragment
0073     void drawCharacters(QPainter &painter,
0074                         const QRect &rect,
0075                         const QString &text,
0076                         const Character style,
0077                         const QColor &characterColor,
0078                         const LineProperty lineProperty);
0079 
0080     // draws the preedit string for input methods
0081     void drawInputMethodPreeditString(QPainter &painter, const QRect &rect, TerminalDisplay::InputMethodData &inputMethodData, Character *image);
0082 
0083 private:
0084     // draws a string of line graphics
0085     void drawLineCharString(TerminalDisplay *display, QPainter &painter, int x, int y, const QString &str, const Character attributes);
0086 
0087     void updateCursorTextColor(const QColor &backgroundColor, QColor &characterColor);
0088     // draws the cursor character
0089     void drawCursor(QPainter &painter, const QRect &rect, const QColor &foregroundColor, const QColor &backgroundColor, QColor &characterColor);
0090 
0091     TerminalDisplay *m_parentDisplay = nullptr;
0092     void drawBelowText(QPainter &painter,
0093                        const QRect &rect,
0094                        Character *style,
0095                        int startX,
0096                        int width,
0097                        int fontWidth,
0098                        const QColor *colorTable,
0099                        const bool invertedRendition,
0100                        int *vis2line,
0101                        int *line2log,
0102                        bool bidiEnabled,
0103                        int lastNonSpace,
0104                        QColor background);
0105     void drawAboveText(QPainter &painter,
0106                        const QRect &rect,
0107                        Character *style,
0108                        int startX,
0109                        int width,
0110                        int fontWidth,
0111                        const QColor *colorTable,
0112                        const bool invertedRendition,
0113                        int *vis2line,
0114                        int *line2log,
0115                        bool bidiEnabled,
0116                        int lastNonSpace,
0117                        CharacterColor const *ulColorTable);
0118     void drawImagesBelowText(QPainter &painter, const QRect &rect, int fontWidth, int fontHeight, int &placementIdx);
0119     void drawImagesAboveText(QPainter &painter, const QRect &rect, int fontWidth, int fontHeight, int &placementIdx);
0120 
0121     void drawTextCharacters(QPainter &painter,
0122                             const QRect &rect,
0123                             const QString &text,
0124                             Character style,
0125                             const QColor *colorTable,
0126                             const bool invertedRendition,
0127                             const LineProperty lineProperty,
0128                             bool printerFriendly,
0129                             RenditionFlags &oldRendition,
0130                             QColor oldColor,
0131                             QFont::Weight normalWeight,
0132                             QFont::Weight boldWeight);
0133 };
0134 
0135 }
0136 
0137 #endif