From 6b25eda9cba32221b5a48861accaf70904951185 Mon Sep 17 00:00:00 2001 From: ctrlaltca Date: Tue, 30 Apr 2024 09:26:24 +0200 Subject: [PATCH] Add an option to disable vertical margin between lines; fix #2464 (#2633) --- src/kvirc/kernel/KviOptions.cpp | 3 +- src/kvirc/kernel/KviOptions.h | 3 +- src/kvirc/ui/KviIrcView.cpp | 47 +++++++++++-------- src/kvirc/ui/KviIrcView.h | 2 +- src/modules/options/OptionsWidget_ircView.cpp | 32 +++++++++---- src/modules/options/OptionsWidget_ircView.h | 2 + 6 files changed, 57 insertions(+), 32 deletions(-) diff --git a/src/kvirc/kernel/KviOptions.cpp b/src/kvirc/kernel/KviOptions.cpp index d0c6be308d..0391ae1eea 100644 --- a/src/kvirc/kernel/KviOptions.cpp +++ b/src/kvirc/kernel/KviOptions.cpp @@ -637,7 +637,8 @@ KviUIntOption g_uintOptionsTable[KVI_NUM_UINT_OPTIONS] = { UINT_OPTION("ToolBarButtonStyle", 0, KviOption_groupTheme), // 0 = Qt::ToolButtonIconOnly UINT_OPTION("MaximumBlowFishKeySize", 56, KviOption_sectFlagNone), UINT_OPTION("CustomCursorWidth", 1, KviOption_resetUpdateGui), - UINT_OPTION("UserListMinimumWidth", 100, KviOption_sectFlagUserListView | KviOption_resetUpdateGui | KviOption_groupTheme) + UINT_OPTION("UserListMinimumWidth", 100, KviOption_sectFlagUserListView | KviOption_resetUpdateGui | KviOption_groupTheme), + UINT_OPTION("IrcViewLineVMarginType", 1, KviOption_sectFlagIrcView | KviOption_groupTheme) }; #define FONT_OPTION(_name, _face, _size, _flags) \ diff --git a/src/kvirc/kernel/KviOptions.h b/src/kvirc/kernel/KviOptions.h index 3b4bac15b4..ffe0775e0b 100644 --- a/src/kvirc/kernel/KviOptions.h +++ b/src/kvirc/kernel/KviOptions.h @@ -597,8 +597,9 @@ DECLARE_OPTION_STRUCT(KviStringListOption, QStringList) #define KviOption_uintMaximumBlowFishKeySize 80 #define KviOption_uintCustomCursorWidth 81 /* Interface */ #define KviOption_uintUserListMinimumWidth 82 +#define KviOption_uintIrcViewLineVMarginType 83 /* interface::features::components::ircview */ -#define KVI_NUM_UINT_OPTIONS 83 +#define KVI_NUM_UINT_OPTIONS 84 namespace KviIdentdOutputMode { diff --git a/src/kvirc/ui/KviIrcView.cpp b/src/kvirc/ui/KviIrcView.cpp index 571596555f..4fa30321d4 100644 --- a/src/kvirc/ui/KviIrcView.cpp +++ b/src/kvirc/ui/KviIrcView.cpp @@ -260,7 +260,7 @@ KviIrcView::KviIrcView(QWidget * parent, KviWindow * pWnd) m_pFm = nullptr; // will be updated in the first paint event m_iFontDescent = 0; m_iFontLineSpacing = 0; - m_iFontLineWidth = 0; + m_iFontLineVMargin = 0; m_pToolTip = new KviIrcViewToolTip(this); @@ -1006,7 +1006,7 @@ void KviIrcView::fastScroll(int lines) if(maxLineWidth != l->iMaxLineWidth) calculateLineWraps(l, maxLineWidth); heightToPaint += l->uLineWraps * m_iFontLineSpacing; - heightToPaint += (m_iFontLineSpacing + m_iFontDescent); + heightToPaint += (m_iFontLineSpacing + m_iFontLineVMargin); lines--; l = l->pPrev; } @@ -1172,7 +1172,7 @@ void KviIrcView::paintEvent(QPaintEvent * p) if((curBottomCoord - m_iFontLineSpacing) > rectBottom) { // not in update rect... skip - curBottomCoord -= (m_iFontLineSpacing + m_iFontDescent); + curBottomCoord -= (m_iFontLineSpacing + m_iFontLineVMargin); pCurTextLine = pCurTextLine->pPrev; continue; } @@ -1202,7 +1202,7 @@ void KviIrcView::paintEvent(QPaintEvent * p) char curFore = defaultFore; char curBack = defaultBack; float curLeftCoord = defLeftCoord; - curBottomCoord -= m_iFontDescent; //rise up the text... + curBottomCoord -= m_iFontLineVMargin; //rise up the text... // // Single text line loop (paint all text blocks) @@ -1591,7 +1591,7 @@ void KviIrcView::paintEvent(QPaintEvent * p) } pa.setPen(pen); - pa.drawLine(0, curBottomCoord, widgetWidth, curBottomCoord); + pa.drawLine(0, curBottomCoord + m_iFontDescent, widgetWidth, curBottomCoord + m_iFontDescent); //pa.setRasterOp(CopyROP); } // else was partially visible only } @@ -1622,7 +1622,7 @@ void KviIrcView::paintEvent(QPaintEvent * p) // the line wraps for the visible lines MUST have been already calculated // for this view width lineWrapsHeight = (pCurTextLine->uLineWraps) * m_iFontLineSpacing; - curBottomCoord -= lineWrapsHeight + m_iFontLineSpacing + m_iFontDescent; + curBottomCoord -= lineWrapsHeight + m_iFontLineSpacing + m_iFontLineVMargin; pCurTextLine = pCurTextLine->pPrev; } @@ -2197,7 +2197,17 @@ void KviIrcView::recalcFontVariables(const QFont & font, const QFontInfo & fi) m_iFontLineSpacing = KVI_IRCVIEW_PIXMAP_SIZE; m_iFontDescent = m_pFm->descent(); - m_iFontLineWidth = m_pFm->lineWidth(); + + switch(KVI_OPTION_UINT(KviOption_uintIrcViewLineVMarginType)) + { + case 0: + m_iFontLineVMargin = 0; + break; + case 1: + default: + m_iFontLineVMargin = m_iFontDescent; + break; + } // cache the first 256 characters for(unsigned short i = 0; i < 256; i++) @@ -2224,9 +2234,6 @@ void KviIrcView::recalcFontVariables(const QFont & font, const QFontInfo & fi) // fix for #489 (horizontal tabulations) m_iFontCharacterWidth[9] = m_pFm->horizontalAdvance("\t"); - if(m_iFontLineWidth < 1) - m_iFontLineWidth = 1; - if(KVI_OPTION_BOOL(KviOption_boolIrcViewTimestamp)) { QString szTimestamp; @@ -2486,13 +2493,13 @@ void KviIrcView::ensureLineVisible(KviIrcViewLine * pLineToShow) { if(pCurLine->iMaxLineWidth != maxLineWidth) calculateLineWraps(pCurLine, maxLineWidth); - curBottomCoord += ((pCurLine->uLineWraps + 1) * m_iFontLineSpacing) + m_iFontDescent; + curBottomCoord += ((pCurLine->uLineWraps + 1) * m_iFontLineSpacing) + m_iFontLineVMargin; pCurLine = pCurLine->pPrev; sc--; } if(pLine == pLineToShow) break; - curBottomCoord -= m_iFontDescent; + curBottomCoord -= m_iFontLineVMargin; pLine = pLine->pPrev; } @@ -2639,13 +2646,13 @@ KviIrcViewLine * KviIrcView::getVisibleLineAt(int yPos) { KviIrcViewLine * l = m_pCurLine; int toolWidgetHeight = (m_pToolWidget && m_pToolWidget->isVisible()) ? m_pToolWidget->sizeHint().height() : 0; - int iTop = height() + m_iFontDescent - KVI_IRCVIEW_VERTICAL_BORDER - toolWidgetHeight; + int iTop = height() + m_iFontLineVMargin - KVI_IRCVIEW_VERTICAL_BORDER - toolWidgetHeight; while(iTop > yPos) { if(l) { - iTop -= ((l->uLineWraps + 1) * m_iFontLineSpacing) + m_iFontDescent; + iTop -= ((l->uLineWraps + 1) * m_iFontLineSpacing) + m_iFontLineVMargin; if(iTop <= yPos) return l; l = l->pPrev; @@ -2668,7 +2675,7 @@ int KviIrcView::getVisibleCharIndexAt(KviIrcViewLine *, int xPos, int yPos) KviIrcViewLine * l = m_pCurLine; int toolWidgetHeight = (m_pToolWidget && m_pToolWidget->isVisible()) ? m_pToolWidget->sizeHint().height() : 0; - int iTop = height() + m_iFontDescent - KVI_IRCVIEW_VERTICAL_BORDER - toolWidgetHeight; + int iTop = height() + m_iFontLineVMargin - KVI_IRCVIEW_VERTICAL_BORDER - toolWidgetHeight; // our current line begins after the mouse position... go on while(iTop > yPos) @@ -2678,7 +2685,7 @@ int KviIrcView::getVisibleCharIndexAt(KviIrcViewLine *, int xPos, int yPos) return -1; // subtract from iTop the height of the current line (aka go to the end of the previous / start of the current point) - iTop -= ((l->uLineWraps + 1) * m_iFontLineSpacing) + m_iFontDescent; + iTop -= ((l->uLineWraps + 1) * m_iFontLineSpacing) + m_iFontLineVMargin; // we're still below the mouse position.. go on if(iTop > yPos) @@ -2802,7 +2809,7 @@ KviIrcViewWrappedBlock * KviIrcView::getLinkUnderMouse(int xPos, int yPos, QRect KviIrcViewLine * l = m_pCurLine; int toolWidgetHeight = (m_pToolWidget && m_pToolWidget->isVisible()) ? m_pToolWidget->sizeHint().height() : 0; - int iTop = height() + m_iFontDescent - KVI_IRCVIEW_VERTICAL_BORDER - toolWidgetHeight; + int iTop = height() + m_iFontLineVMargin - KVI_IRCVIEW_VERTICAL_BORDER - toolWidgetHeight; // our current line begins after the mouse position... go on while(iTop > yPos) @@ -2812,7 +2819,7 @@ KviIrcViewWrappedBlock * KviIrcView::getLinkUnderMouse(int xPos, int yPos, QRect return nullptr; // subtract from iTop the height of the current line (aka go to the end of the previous / start of the current point) - iTop -= ((l->uLineWraps + 1) * m_iFontLineSpacing) + m_iFontDescent; + iTop -= ((l->uLineWraps + 1) * m_iFontLineSpacing) + m_iFontLineVMargin; // we're still below the mouse position.. go on if(iTop > yPos) @@ -2973,7 +2980,7 @@ KviIrcViewWrappedBlock * KviIrcView::getLinkUnderMouse(int xPos, int yPos, QRect *pRect = QRect(iLeftBorder, bHadWordWraps ? iLastEscapeBlockTop : iTop, iRightBorder, - ((uLineWraps + 1) * m_iFontLineSpacing) + m_iFontDescent); + ((uLineWraps + 1) * m_iFontLineSpacing) + m_iFontLineVMargin); } if(linkCmd) { @@ -3045,7 +3052,7 @@ KviIrcViewWrappedBlock * KviIrcView::getLinkUnderMouse(int xPos, int yPos, QRect *pRect = QRect(iLastLeft, bHadWordWraps ? firstRowTop : iTop, iBlockWidth, - ((l->uLineWraps + 1) * m_iFontLineSpacing) + m_iFontDescent); + ((l->uLineWraps + 1) * m_iFontLineSpacing) + m_iFontLineVMargin); } if(linkCmd) { diff --git a/src/kvirc/ui/KviIrcView.h b/src/kvirc/ui/KviIrcView.h index 3e6a8d135c..0a35eccb62 100644 --- a/src/kvirc/ui/KviIrcView.h +++ b/src/kvirc/ui/KviIrcView.h @@ -105,7 +105,7 @@ class KVIRC_API KviIrcView : public QWidget // Font related stuff (needs precalculation!) int m_iFontLineSpacing; - int m_iFontLineWidth; + int m_iFontLineVMargin; int m_iFontDescent; float m_iFontCharacterWidth[256]; bool m_bUseRealBold; diff --git a/src/modules/options/OptionsWidget_ircView.cpp b/src/modules/options/OptionsWidget_ircView.cpp index 85319908e9..faaf76f179 100644 --- a/src/modules/options/OptionsWidget_ircView.cpp +++ b/src/modules/options/OptionsWidget_ircView.cpp @@ -141,17 +141,28 @@ OptionsWidget_ircViewFeatures::OptionsWidget_ircViewFeatures(QWidget * parent) setObjectName("ircviewfeatures_options_widget"); createLayout(); - addBoolSelector(0, 7, 0, 7, __tr2qs_ctx("Enable URL highlighting", "options"), KviOption_boolIrcViewUrlHighlighting); - addBoolSelector(0, 8, 0, 8, __tr2qs_ctx("Use line wrap margin", "options"), KviOption_boolIrcViewWrapMargin); - KviUIntSelector * s = addUIntSelector(0, 9, 0, 9, __tr2qs_ctx("Maximum buffer size:", "options"), KviOption_uintIrcViewMaxBufferSize, 32, 32767, 2048); + addBoolSelector(0, 7, 1, 7, __tr2qs_ctx("Enable URL highlighting", "options"), KviOption_boolIrcViewUrlHighlighting); + addBoolSelector(0, 8, 1, 8, __tr2qs_ctx("Use line wrap margin", "options"), KviOption_boolIrcViewWrapMargin); + + addLabel(0, 9, 0, 9, __tr2qs_ctx("Vertical line margin:", "options")); + m_pVMarginStyle = new QComboBox(this); + addWidgetToLayout(m_pVMarginStyle, 1, 9, 1, 9); + + m_pVMarginStyle->addItem(__tr2qs_ctx("No margin", "options")); + m_pVMarginStyle->addItem(__tr2qs_ctx("Normal margin", "options")); + + unsigned int uStyle = KVI_OPTION_UINT(KviOption_uintIrcViewLineVMarginType); + m_pVMarginStyle->setCurrentIndex(uStyle < 2 ? uStyle : 0); + + KviUIntSelector * s = addUIntSelector(0, 10, 1, 10, __tr2qs_ctx("Maximum buffer size:", "options"), KviOption_uintIrcViewMaxBufferSize, 32, 32767, 2048); s->setSuffix(__tr2qs_ctx(" lines", "options")); - s = addUIntSelector(0, 10, 0, 10, __tr2qs_ctx("Link tooltip show delay:", "options"), KviOption_uintIrcViewToolTipTimeoutInMsec, 256, 10000, 1800); + s = addUIntSelector(0, 11, 1, 11, __tr2qs_ctx("Link tooltip show delay:", "options"), KviOption_uintIrcViewToolTipTimeoutInMsec, 256, 10000, 1800); s->setSuffix(__tr2qs_ctx(" msec", "options")); - s = addUIntSelector(0, 11, 0, 11, __tr2qs_ctx("Link tooltip hide delay:", "options"), KviOption_uintIrcViewToolTipHideTimeoutInMsec, 256, 10000, 12000); + s = addUIntSelector(0, 12, 1, 12, __tr2qs_ctx("Link tooltip hide delay:", "options"), KviOption_uintIrcViewToolTipHideTimeoutInMsec, 256, 10000, 12000); s->setSuffix(__tr2qs_ctx(" msec", "options")); - addBoolSelector(0, 12, 0, 12, __tr2qs_ctx("Enable animated smiles", "options"), KviOption_boolEnableAnimatedSmiles); + addBoolSelector(0, 13, 1, 13, __tr2qs_ctx("Enable animated smiles", "options"), KviOption_boolEnableAnimatedSmiles); - KviTalGroupBox * pGroup = addGroupBox(0, 13, 0, 13, Qt::Horizontal, __tr2qs_ctx("Enable Tooltips for", "options")); + KviTalGroupBox * pGroup = addGroupBox(0, 14, 1, 14, Qt::Horizontal, __tr2qs_ctx("Enable Tooltips for", "options")); addBoolSelector(pGroup, __tr2qs_ctx("URL links", "options"), KviOption_boolEnableUrlLinkToolTip); addBoolSelector(pGroup, __tr2qs_ctx("Host links", "options"), KviOption_boolEnableHostLinkToolTip); addBoolSelector(pGroup, __tr2qs_ctx("Server links", "options"), KviOption_boolEnableServerLinkToolTip); @@ -160,11 +171,14 @@ OptionsWidget_ircViewFeatures::OptionsWidget_ircViewFeatures(QWidget * parent) addBoolSelector(pGroup, __tr2qs_ctx("Channel links", "options"), KviOption_boolEnableChannelLinkToolTip); addBoolSelector(pGroup, __tr2qs_ctx("Escape sequences", "options"), KviOption_boolEnableEscapeLinkToolTip); - addRowSpacer(0, 14, 0, 14); + addRowSpacer(0, 15, 1, 15); } OptionsWidget_ircViewFeatures::~OptionsWidget_ircViewFeatures() - = default; +{ + KVI_OPTION_UINT(KviOption_uintIrcViewLineVMarginType) = m_pVMarginStyle->currentIndex(); + KviOptionsWidget::commit(); +} OptionsWidget_ircViewMarker::OptionsWidget_ircViewMarker(QWidget * parent) : KviOptionsWidget(parent) diff --git a/src/modules/options/OptionsWidget_ircView.h b/src/modules/options/OptionsWidget_ircView.h index 1d184b6b10..832948e52b 100644 --- a/src/modules/options/OptionsWidget_ircView.h +++ b/src/modules/options/OptionsWidget_ircView.h @@ -77,6 +77,8 @@ class OptionsWidget_ircViewFeatures : public KviOptionsWidget public: OptionsWidget_ircViewFeatures(QWidget * parent); ~OptionsWidget_ircViewFeatures(); +private: + QComboBox * m_pVMarginStyle; }; #define KVI_OPTIONS_WIDGET_ICON_OptionsWidget_ircViewMarker KviIconManager::HideDoubleView