Skip to content

Commit d8aeae1

Browse files
committed
Avoid displaying an unnecessary horizontal scrollbar in SQL editor widgets
The following scroll width functionalities are added to QScintilla: setScrollWidth, getScrollWidth, setScrollWidthTracking and getScrollWidthTracking. This allows setting a lower value for the initial scroll width (default is 2000 pixels). Consequently, the horizontal scroll is only visible if the SQL lines become bigger than window width. The scroll width, though, is never reduced by Scintilla for performance reasons. See this for explanation: jacobslusser/ScintillaNET#216 And see this for a possible implementation of a fully adjusted scroll width with fixed-width fonts: https://groups.google.com/forum/#!topic/scintilla-interest/ly8u7mVDgyQ
1 parent e8e5671 commit d8aeae1

File tree

4 files changed

+127
-0
lines changed

4 files changed

+127
-0
lines changed

libs/DB4S_PATCH_03

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
diff --git a/libs/qscintilla/Qt4Qt5/Qsci/qsciscintilla.h b/libs/qscintilla/Qt4Qt5/Qsci/qsciscintilla.h
2+
index 3b5f185..49ca5cc 100644
3+
--- a/libs/qscintilla/Qt4Qt5/Qsci/qsciscintilla.h
4+
+++ b/libs/qscintilla/Qt4Qt5/Qsci/qsciscintilla.h
5+
@@ -2009,6 +2009,34 @@ public slots:
6+
//! \sa zoomIn(), zoomOut()
7+
virtual void zoomTo(int size);
8+
9+
+ //! For performance, Scintilla does not measure the display width
10+
+ //! of the document to determine the properties of the horizontal
11+
+ //! scroll bar. Instead, an assumed width is used. This sets the
12+
+ //! document width in pixels assumed by Scintilla to \a
13+
+ //! pixelWidth. The default value is 2000.
14+
+ //!
15+
+ //! \sa getScrollWidth(), setScrollWidthTracking()
16+
+ virtual void setScrollWidth(int pixelWidth);
17+
+
18+
+ //! Gets the document width in pixels assumed by Scintilla.
19+
+ //!
20+
+ //! \sa setScrollWidth(), setScrollWidthTracking()
21+
+ virtual int getScrollWidth() const;
22+
+
23+
+ //! If scroll width tracking is enabled then the scroll width is
24+
+ //! adjusted to ensure that all of the lines currently displayed
25+
+ //! can be completely scrolled. This mode never adjusts the scroll
26+
+ //! width to be narrower.
27+
+ //! Sets the scroll width tracking to \a enabled.
28+
+ //!
29+
+ //! \sa setScrollWidth(), getScrollWidthTracking()
30+
+ virtual void setScrollWidthTracking(bool enabled);
31+
+
32+
+ //! Gets the current scroll width tracking mode.
33+
+ //!
34+
+ //! \sa getScrollWidth(), setScrollWidthTracking()
35+
+ virtual bool getScrollWidthTracking() const;
36+
+
37+
signals:
38+
//! This signal is emitted whenever the cursor position changes. \a line
39+
//! contains the line number and \a index contains the character index
40+
diff --git a/libs/qscintilla/Qt4Qt5/qsciscintilla.cpp b/libs/qscintilla/Qt4Qt5/qsciscintilla.cpp
41+
index 4c9fe75..31dc579 100644
42+
--- a/libs/qscintilla/Qt4Qt5/qsciscintilla.cpp
43+
+++ b/libs/qscintilla/Qt4Qt5/qsciscintilla.cpp
44+
@@ -4481,3 +4481,26 @@ static QColor asQColor(long sci_colour)
45+
((int)(sci_colour >> 8)) & 0x00ff,
46+
((int)(sci_colour >> 16)) & 0x00ff);
47+
}
48+
+
49+
+void QsciScintilla::setScrollWidth(int pixelWidth)
50+
+{
51+
+ SendScintilla(SCI_SETSCROLLWIDTH, pixelWidth);
52+
+}
53+
+
54+
+int QsciScintilla::getScrollWidth() const
55+
+{
56+
+ return SendScintilla(SCI_GETSCROLLWIDTH);
57+
+}
58+
+
59+
+void QsciScintilla::setScrollWidthTracking(bool enabled)
60+
+{
61+
+ SendScintilla(SCI_SETSCROLLWIDTHTRACKING, enabled);
62+
+}
63+
+
64+
+bool QsciScintilla::getScrollWidthTracking() const
65+
+{
66+
+ return SendScintilla(SCI_GETSCROLLWIDTHTRACKING);
67+
+}
68+
+
69+
+
70+
+

libs/qscintilla/Qt4Qt5/Qsci/qsciscintilla.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,6 +2009,34 @@ public slots:
20092009
//! \sa zoomIn(), zoomOut()
20102010
virtual void zoomTo(int size);
20112011

2012+
//! For performance, Scintilla does not measure the display width
2013+
//! of the document to determine the properties of the horizontal
2014+
//! scroll bar. Instead, an assumed width is used. This sets the
2015+
//! document width in pixels assumed by Scintilla to \a
2016+
//! pixelWidth. The default value is 2000.
2017+
//!
2018+
//! \sa getScrollWidth(), setScrollWidthTracking()
2019+
virtual void setScrollWidth(int pixelWidth);
2020+
2021+
//! Gets the document width in pixels assumed by Scintilla.
2022+
//!
2023+
//! \sa setScrollWidth(), setScrollWidthTracking()
2024+
virtual int getScrollWidth() const;
2025+
2026+
//! If scroll width tracking is enabled then the scroll width is
2027+
//! adjusted to ensure that all of the lines currently displayed
2028+
//! can be completely scrolled. This mode never adjusts the scroll
2029+
//! width to be narrower.
2030+
//! Sets the scroll width tracking to \a enabled.
2031+
//!
2032+
//! \sa setScrollWidth(), getScrollWidthTracking()
2033+
virtual void setScrollWidthTracking(bool enabled);
2034+
2035+
//! Gets the current scroll width tracking mode.
2036+
//!
2037+
//! \sa getScrollWidth(), setScrollWidthTracking()
2038+
virtual bool getScrollWidthTracking() const;
2039+
20122040
signals:
20132041
//! This signal is emitted whenever the cursor position changes. \a line
20142042
//! contains the line number and \a index contains the character index

libs/qscintilla/Qt4Qt5/qsciscintilla.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4481,3 +4481,23 @@ static QColor asQColor(long sci_colour)
44814481
((int)(sci_colour >> 8)) & 0x00ff,
44824482
((int)(sci_colour >> 16)) & 0x00ff);
44834483
}
4484+
4485+
void QsciScintilla::setScrollWidth(int pixelWidth)
4486+
{
4487+
SendScintilla(SCI_SETSCROLLWIDTH, pixelWidth);
4488+
}
4489+
4490+
int QsciScintilla::getScrollWidth() const
4491+
{
4492+
return SendScintilla(SCI_GETSCROLLWIDTH);
4493+
}
4494+
4495+
void QsciScintilla::setScrollWidthTracking(bool enabled)
4496+
{
4497+
SendScintilla(SCI_SETSCROLLWIDTHTRACKING, enabled);
4498+
}
4499+
4500+
bool QsciScintilla::getScrollWidthTracking() const
4501+
{
4502+
return SendScintilla(SCI_GETSCROLLWIDTHTRACKING);
4503+
}

src/sqltextedit.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ SqlTextEdit::SqlTextEdit(QWidget* parent) :
4242
errorIndicatorNumber = indicatorDefine(QsciScintilla::SquiggleIndicator);
4343
setIndicatorForegroundColor(Qt::red, errorIndicatorNumber);
4444

45+
// Set a sensible scroll width, so the scroll bar is avoided in
46+
// most cases.
47+
setScrollWidth(80);
48+
49+
// Scroll width is adjusted to ensure that all of the lines
50+
// currently displayed can be completely scrolled. This mode never
51+
// adjusts the scroll width to be narrower.
52+
setScrollWidthTracking(true);
53+
4554
// Do rest of initialisation
4655
reloadSettings();
4756

0 commit comments

Comments
 (0)