From bc45093bf260de972b52f04b2cd82afc9dce3dd5 Mon Sep 17 00:00:00 2001 From: Yichao Yu Date: Tue, 8 Oct 2013 14:09:54 -0400 Subject: [PATCH] [qt4] more size tweak, more friendly for narrow scrollbars, #7. Cherry picked from QtCurve/qtcurve --- qt4/style/qtcurve.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/qt4/style/qtcurve.cpp b/qt4/style/qtcurve.cpp index cd40d77d..b57cde07 100644 --- a/qt4/style/qtcurve.cpp +++ b/qt4/style/qtcurve.cpp @@ -755,6 +755,9 @@ inline int numButtons(EScrollbar type) } // TODO make this better. +// Port to Qt5 and gtk2 +// Check if this breaks anything +// document static inline int sizeNumButtons(EScrollbar type) { @@ -3366,7 +3369,11 @@ int Style::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWi case PM_ToolBarHandleExtent: return LINE_1DOT==opts.handles ? 7 : 8; case PM_ScrollBarSliderMin: - return opts.sliderWidth+1; + // TODO make this better. + // Check if this breaks anything + // Port to Qt5 and gtk2 + // document + return qMax(opts.sliderWidth, 20) + 1; case PM_SliderThickness: return (SLIDER_CIRCULAR==opts.sliderStyle ? CIRCULAR_SLIDER_SIZE+6 @@ -9701,11 +9708,19 @@ QSize Style::sizeFromContents(ContentsType type, const QStyleOption *option, con { int scrollBarExtent(pixelMetric(PM_ScrollBarExtent, option, widget)), scrollBarSliderMinimum(pixelMetric(PM_ScrollBarSliderMin, option, widget)); - - if (scrollBar->orientation == Qt::Horizontal) - newSize = QSize(scrollBarExtent * sizeNumButtons(opts.scrollbarType) + scrollBarSliderMinimum, scrollBarExtent); - else - newSize = QSize(scrollBarExtent, scrollBarExtent * sizeNumButtons(opts.scrollbarType) + scrollBarSliderMinimum); + // TODO: document this + // Check if this breaks anything + // Port to qt5 and gtk2 + int scrollBarLen = + (qMax(scrollBarExtent, 13) * + sizeNumButtons(opts.scrollbarType) + + scrollBarSliderMinimum); + + if (scrollBar->orientation == Qt::Horizontal) { + newSize = QSize(scrollBarLen, scrollBarExtent); + } else { + newSize = QSize(scrollBarExtent, scrollBarLen); + } } break; case CT_LineEdit: