From 1725692ad6413172aab01170ee40f300032383e3 Mon Sep 17 00:00:00 2001 From: pjx206 Date: Thu, 22 Jul 2021 14:08:43 +0800 Subject: [PATCH] less #define and replaced some deprecated methods --- qmltermwidget/lib/Character.h | 31 ++++++++++++++------------- qmltermwidget/lib/TerminalDisplay.cpp | 8 +++---- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/qmltermwidget/lib/Character.h b/qmltermwidget/lib/Character.h index 9c9fae2..0a56a55 100644 --- a/qmltermwidget/lib/Character.h +++ b/qmltermwidget/lib/Character.h @@ -33,25 +33,26 @@ namespace Konsole { typedef unsigned char LineProperty; +typedef quint16 RenditionFlags; static const int LINE_DEFAULT = 0; static const int LINE_WRAPPED = (1 << 0); static const int LINE_DOUBLEWIDTH = (1 << 1); static const int LINE_DOUBLEHEIGHT = (1 << 2); -#define DEFAULT_RENDITION 0 -#define RE_BOLD (1 << 0) -#define RE_BLINK (1 << 1) -#define RE_UNDERLINE (1 << 2) -#define RE_REVERSE (1 << 3) // Screen only -#define RE_INTENSIVE (1 << 3) // Widget only -#define RE_ITALIC (1 << 4) -#define RE_CURSOR (1 << 5) -#define RE_EXTENDED_CHAR (1 << 6) -#define RE_FAINT (1 << 7) -#define RE_STRIKEOUT (1 << 8) -#define RE_CONCEAL (1 << 9) -#define RE_OVERLINE (1 << 10) +const RenditionFlags DEFAULT_RENDITION = 0; +const RenditionFlags RE_BOLD = (1 << 0); +const RenditionFlags RE_BLINK = (1 << 1); +const RenditionFlags RE_UNDERLINE = (1 << 2); +const RenditionFlags RE_REVERSE = (1 << 3); // Screen only +const RenditionFlags RE_INTENSIVE = (1 << 3); // Widget only +const RenditionFlags RE_ITALIC = (1 << 4); +const RenditionFlags RE_CURSOR = (1 << 5); +const RenditionFlags RE_EXTENDED_CHAR = (1 << 6); +const RenditionFlags RE_FAINT = (1 << 7); +const RenditionFlags RE_STRIKEOUT = (1 << 8); +const RenditionFlags RE_CONCEAL = (1 << 9); +const RenditionFlags RE_OVERLINE = (1 << 10); /** * A single character in the terminal which consists of a unicode character @@ -72,7 +73,7 @@ public: inline Character(quint16 _c = ' ', CharacterColor _f = CharacterColor(COLOR_SPACE_DEFAULT,DEFAULT_FORE_COLOR), CharacterColor _b = CharacterColor(COLOR_SPACE_DEFAULT,DEFAULT_BACK_COLOR), - quint8 _r = DEFAULT_RENDITION) + RenditionFlags _r = DEFAULT_RENDITION) : character(_c), rendition(_r), foregroundColor(_f), backgroundColor(_b) {} union @@ -90,7 +91,7 @@ public: }; /** A combination of RENDITION flags which specify options for drawing the character. */ - quint8 rendition; + RenditionFlags rendition; /** The foreground color used to draw this character. */ CharacterColor foregroundColor; diff --git a/qmltermwidget/lib/TerminalDisplay.cpp b/qmltermwidget/lib/TerminalDisplay.cpp index e038f39..b753164 100644 --- a/qmltermwidget/lib/TerminalDisplay.cpp +++ b/qmltermwidget/lib/TerminalDisplay.cpp @@ -221,14 +221,14 @@ void TerminalDisplay::fontChange(const QFont&) // "Base character width on widest ASCII character. This prevents too wide // characters in the presence of double wide (e.g. Japanese) characters." // Get the width from representative normal width characters - _fontWidth = qRound((double)fm.width(QLatin1String(REPCHAR))/(double)qstrlen(REPCHAR)); + _fontWidth = qRound((double)fm.horizontalAdvance(QLatin1String(REPCHAR))/(double)qstrlen(REPCHAR)); _fixedFont = true; - int fw = fm.width(QLatin1Char(REPCHAR[0])); + int fw = fm.horizontalAdvance(QLatin1Char(REPCHAR[0])); for(unsigned int i=1; i< qstrlen(REPCHAR); i++) { - if (fw != fm.width(QLatin1Char(REPCHAR[i]))) + if (fw != fm.horizontalAdvance(QLatin1Char(REPCHAR[i]))) { _fixedFont = false; break; @@ -1611,7 +1611,7 @@ void TerminalDisplay::drawContents(QPainter &paint, const QRect &rect) bool doubleWidth = (_image[ qMin(loc(x,y)+1,_imageSize) ].character == 0); CharacterColor currentForeground = _image[loc(x,y)].foregroundColor; CharacterColor currentBackground = _image[loc(x,y)].backgroundColor; - quint8 currentRendition = _image[loc(x,y)].rendition; + RenditionFlags currentRendition = _image[loc(x,y)].rendition; while (x+len <= rlx && _image[loc(x+len,y)].foregroundColor == currentForeground &&