]> jfr.im git - irc/kvirc/KVIrc.git/commitdiff
Use floating point widths in KviIrcView: fixes overlapping texts
authorSzymon Tomasz Stefanek <redacted>
Sat, 15 Jul 2023 15:03:58 +0000 (17:03 +0200)
committerSzymon Tomasz Stefanek <redacted>
Sat, 15 Jul 2023 15:03:58 +0000 (17:03 +0200)
src/kvirc/ui/KviIrcView.cpp
src/kvirc/ui/KviIrcView.h
src/kvirc/ui/KviIrcView_private.h

index 7402f3f8186d20220cf38c87969bc56b442db3c2..57b111463a211410e8d3a5cec46bbe6ea7f3551d 100644 (file)
@@ -1133,7 +1133,7 @@ void KviIrcView::paintEvent(QPaintEvent * p)
        // Have lines visible
        int curBottomCoord = widgetHeight - KVI_IRCVIEW_VERTICAL_BORDER;
        int maxLineWidth = widgetWidth - KVI_IRCVIEW_DOUBLEBORDER_WIDTH;
-       int defLeftCoord = KVI_IRCVIEW_HORIZONTAL_BORDER;
+       float defLeftCoord = KVI_IRCVIEW_HORIZONTAL_BORDER;
        int lineWrapsHeight;
 
        // if we draw an icon as a line preamble, we have to change borders geometry accordingly
@@ -1200,7 +1200,7 @@ void KviIrcView::paintEvent(QPaintEvent * p)
                bool bacWasTransp = false;
                char curFore = defaultFore;
                char curBack = defaultBack;
-               int curLeftCoord = defLeftCoord;
+               float curLeftCoord = defLeftCoord;
                curBottomCoord -= m_iFontDescent; //rise up the text...
 
                //
@@ -1354,7 +1354,7 @@ void KviIrcView::paintEvent(QPaintEvent * p)
 #define DRAW_SELECTED_TEXT(_text_str, _text_idx, _text_len, _text_width)                                                                                                               \
        SET_PEN(KVI_OPTION_MSGTYPE(KVI_OUT_SELECT).fore(), block->pChunk ? block->pChunk->customFore : QColor());                                                                          \
        {                                                                                                                                                                                  \
-               int theWdth = _text_width;                                                                                                                                                     \
+               float theWdth = _text_width;                                                                                                                                                     \
                if(theWdth < 0)                                                                                                                                                                \
                        theWdth = width() - (curLeftCoord + KVI_IRCVIEW_HORIZONTAL_BORDER + scrollbarWidth);                                                                                       \
                pa.fillRect(curLeftCoord, curBottomCoord - m_iFontLineSpacing + m_iFontDescent, theWdth, m_iFontLineSpacing, getMircColor(KVI_OPTION_MSGTYPE(KVI_OUT_SELECT).back())); \
@@ -1443,7 +1443,7 @@ void KviIrcView::paintEvent(QPaintEvent * p)
                                                        break;
                                                case KVI_IRCVIEW_BLOCK_SELECTION_ICON:
                                                {
-                                                       int theWdth = block->block_width;
+                                                       float theWdth = block->block_width;
                                                        if(theWdth < 0)
                                                                theWdth = width() - (curLeftCoord + KVI_IRCVIEW_HORIZONTAL_BORDER + scrollbarWidth);
                                                        pa.fillRect(curLeftCoord, curBottomCoord - m_iFontLineSpacing + m_iFontDescent, theWdth, m_iFontLineSpacing,
@@ -1457,7 +1457,7 @@ void KviIrcView::paintEvent(QPaintEvent * p)
                                {
                                        if(block->pChunk && block->pChunk->type == KviControlCodes::Icon)
                                                goto no_selection_paint;
-                                       int wdth = block->block_width;
+                                       float wdth = block->block_width;
                                        if(wdth == 0)
                                        {
                                                // Last block before a word wrap, or a zero characters attribute block ?
@@ -1479,7 +1479,7 @@ void KviIrcView::paintEvent(QPaintEvent * p)
                        no_selection_paint:
                                if(block->pChunk && block->pChunk->type == KviControlCodes::Icon)
                                {
-                                       int wdth = block->block_width;
+                                       float wdth = block->block_width;
                                        if(wdth < 0)
                                                wdth = widgetWidth - (curLeftCoord + KVI_IRCVIEW_HORIZONTAL_BORDER);
                                        int imageYPos = curBottomCoord - m_iRelativePixmapY;
@@ -1513,7 +1513,7 @@ void KviIrcView::paintEvent(QPaintEvent * p)
                                }
                                else
                                {
-                                       int wdth = block->block_width;
+                                       float wdth = block->block_width;
                                        if(wdth < 0)
                                                wdth = widgetWidth - (curLeftCoord + KVI_IRCVIEW_HORIZONTAL_BORDER);
 
@@ -1701,7 +1701,7 @@ void KviIrcView::calculateLineWraps(KviIrcViewLine * ptr, int maxWidth)
        ptr->uLineWraps = 0;                                                                          // no line wraps yet
 
        unsigned int curAttrBlock = 0; // Current attribute block
-       int curLineWidth = 0;
+       float curLineWidth = 0;
 
        // init the first block
        ptr->pBlocks->block_start = 0;
@@ -1719,7 +1719,7 @@ void KviIrcView::calculateLineWraps(KviIrcViewLine * ptr, int maxWidth)
                const QChar * p = unicode + ptr->pBlocks[ptr->iBlockCount].block_start;
 
                int curBlockLen = 0;
-               int curBlockWidth = 0;
+               float curBlockWidth = 0;
 
                if(ptr->pChunks[curAttrBlock].type == KviControlCodes::Icon)
                {
@@ -2087,7 +2087,7 @@ void KviIrcView::recalcFontVariables(const QFont & font, const QFontInfo & fi)
        if(m_pFm)
                delete m_pFm;
 
-       m_pFm = new QFontMetrics(font);
+       m_pFm = new QFontMetricsF(font);
 
        m_iFontLineSpacing = m_pFm->lineSpacing();
 
index 5c85453efb6f2611de2251468bf9f5087312b195..3e6a8d135c3476cbb8f5f415e12ea8a35052aaf5 100644 (file)
@@ -107,7 +107,7 @@ private:
        int m_iFontLineSpacing;
        int m_iFontLineWidth;
        int m_iFontDescent;
-       int m_iFontCharacterWidth[256]; //1024 bytes fixed
+       float m_iFontCharacterWidth[256];
        bool m_bUseRealBold;
 
        int m_iWrapMargin;
@@ -138,7 +138,7 @@ private:
        bool m_bPostedPaintEventPending;
        std::vector<KviIrcViewLine *> m_pMessagesStoppedWhileSelecting;
        KviIrcView * m_pMasterView;
-       QFontMetrics * m_pFm; // assume this valid only inside a paint event (may be 0 in other circumstances)
+       QFontMetricsF * m_pFm; // assume this valid only inside a paint event (may be 0 in other circumstances)
 
        QMouseEvent * m_pLastEvent;
        qint64 m_iLastMouseClickTime;
index 8be1842d40e88745c1bcd9947e714488a7a57930..22928700b4fbbea061b0a9623c32fd25e12ebd46 100644 (file)
@@ -102,7 +102,7 @@ struct KviIrcViewWrappedBlock
        KviIrcViewLineChunk * pChunk; // pointer to real line chunk or 0 for word wraps
        int block_start;              // this is generally different than pAttribute->block_idx!
        int block_len;                // length if the block in characters
-       int block_width;              // width of the block in pixels
+       float block_width;              // width of the block in pixels
 } _KVI_PACKED;
 
 struct KviIrcViewLine
@@ -135,11 +135,11 @@ struct KviIrcViewWrappedBlockSelectionInfo
 {
        int selection_type;
        int part_1_length;
-       int part_1_width;
+       float part_1_width;
        int part_2_length;
-       int part_2_width;
+       float part_2_width;
        int part_3_length;
-       int part_3_width;
+       float part_3_width;
 };
 
 #ifdef COMPILE_ON_WINDOWS