Skip to content

Commit

Permalink
Add an option to disable vertical margin between lines; fix #2464 (#2633
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ctrlaltca committed Apr 30, 2024
1 parent c2ae7a4 commit 6b25eda
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 32 deletions.
3 changes: 2 additions & 1 deletion src/kvirc/kernel/KviOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
3 changes: 2 additions & 1 deletion src/kvirc/kernel/KviOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
47 changes: 27 additions & 20 deletions src/kvirc/ui/KviIrcView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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++)
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/kvirc/ui/KviIrcView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 23 additions & 9 deletions src/modules/options/OptionsWidget_ircView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/modules/options/OptionsWidget_ircView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6b25eda

Please sign in to comment.