Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Avoid displaying an unnecessary horizontal scrollbar in SQL editor wi…
…dgets

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
  • Loading branch information
mgrojo committed Nov 12, 2017
1 parent e8e5671 commit d8aeae1
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
70 changes: 70 additions & 0 deletions libs/DB4S_PATCH_03
@@ -0,0 +1,70 @@
diff --git a/libs/qscintilla/Qt4Qt5/Qsci/qsciscintilla.h b/libs/qscintilla/Qt4Qt5/Qsci/qsciscintilla.h
index 3b5f185..49ca5cc 100644
--- a/libs/qscintilla/Qt4Qt5/Qsci/qsciscintilla.h
+++ b/libs/qscintilla/Qt4Qt5/Qsci/qsciscintilla.h
@@ -2009,6 +2009,34 @@ public slots:
//! \sa zoomIn(), zoomOut()
virtual void zoomTo(int size);

+ //! For performance, Scintilla does not measure the display width
+ //! of the document to determine the properties of the horizontal
+ //! scroll bar. Instead, an assumed width is used. This sets the
+ //! document width in pixels assumed by Scintilla to \a
+ //! pixelWidth. The default value is 2000.
+ //!
+ //! \sa getScrollWidth(), setScrollWidthTracking()
+ virtual void setScrollWidth(int pixelWidth);
+
+ //! Gets the document width in pixels assumed by Scintilla.
+ //!
+ //! \sa setScrollWidth(), setScrollWidthTracking()
+ virtual int getScrollWidth() const;
+
+ //! If scroll width tracking is enabled then the scroll width is
+ //! adjusted to ensure that all of the lines currently displayed
+ //! can be completely scrolled. This mode never adjusts the scroll
+ //! width to be narrower.
+ //! Sets the scroll width tracking to \a enabled.
+ //!
+ //! \sa setScrollWidth(), getScrollWidthTracking()
+ virtual void setScrollWidthTracking(bool enabled);
+
+ //! Gets the current scroll width tracking mode.
+ //!
+ //! \sa getScrollWidth(), setScrollWidthTracking()
+ virtual bool getScrollWidthTracking() const;
+
signals:
//! This signal is emitted whenever the cursor position changes. \a line
//! contains the line number and \a index contains the character index
diff --git a/libs/qscintilla/Qt4Qt5/qsciscintilla.cpp b/libs/qscintilla/Qt4Qt5/qsciscintilla.cpp
index 4c9fe75..31dc579 100644
--- a/libs/qscintilla/Qt4Qt5/qsciscintilla.cpp
+++ b/libs/qscintilla/Qt4Qt5/qsciscintilla.cpp
@@ -4481,3 +4481,26 @@ static QColor asQColor(long sci_colour)
((int)(sci_colour >> 8)) & 0x00ff,
((int)(sci_colour >> 16)) & 0x00ff);
}
+
+void QsciScintilla::setScrollWidth(int pixelWidth)
+{
+ SendScintilla(SCI_SETSCROLLWIDTH, pixelWidth);
+}
+
+int QsciScintilla::getScrollWidth() const
+{
+ return SendScintilla(SCI_GETSCROLLWIDTH);
+}
+
+void QsciScintilla::setScrollWidthTracking(bool enabled)
+{
+ SendScintilla(SCI_SETSCROLLWIDTHTRACKING, enabled);
+}
+
+bool QsciScintilla::getScrollWidthTracking() const
+{
+ return SendScintilla(SCI_GETSCROLLWIDTHTRACKING);
+}
+
+
+
28 changes: 28 additions & 0 deletions libs/qscintilla/Qt4Qt5/Qsci/qsciscintilla.h
Expand Up @@ -2009,6 +2009,34 @@ public slots:
//! \sa zoomIn(), zoomOut()
virtual void zoomTo(int size);

//! For performance, Scintilla does not measure the display width
//! of the document to determine the properties of the horizontal
//! scroll bar. Instead, an assumed width is used. This sets the
//! document width in pixels assumed by Scintilla to \a
//! pixelWidth. The default value is 2000.
//!
//! \sa getScrollWidth(), setScrollWidthTracking()
virtual void setScrollWidth(int pixelWidth);

//! Gets the document width in pixels assumed by Scintilla.
//!
//! \sa setScrollWidth(), setScrollWidthTracking()
virtual int getScrollWidth() const;

//! If scroll width tracking is enabled then the scroll width is
//! adjusted to ensure that all of the lines currently displayed
//! can be completely scrolled. This mode never adjusts the scroll
//! width to be narrower.
//! Sets the scroll width tracking to \a enabled.
//!
//! \sa setScrollWidth(), getScrollWidthTracking()
virtual void setScrollWidthTracking(bool enabled);

//! Gets the current scroll width tracking mode.
//!
//! \sa getScrollWidth(), setScrollWidthTracking()
virtual bool getScrollWidthTracking() const;

signals:
//! This signal is emitted whenever the cursor position changes. \a line
//! contains the line number and \a index contains the character index
Expand Down
20 changes: 20 additions & 0 deletions libs/qscintilla/Qt4Qt5/qsciscintilla.cpp
Expand Up @@ -4481,3 +4481,23 @@ static QColor asQColor(long sci_colour)
((int)(sci_colour >> 8)) & 0x00ff,
((int)(sci_colour >> 16)) & 0x00ff);
}

void QsciScintilla::setScrollWidth(int pixelWidth)
{
SendScintilla(SCI_SETSCROLLWIDTH, pixelWidth);
}

int QsciScintilla::getScrollWidth() const
{
return SendScintilla(SCI_GETSCROLLWIDTH);
}

void QsciScintilla::setScrollWidthTracking(bool enabled)
{
SendScintilla(SCI_SETSCROLLWIDTHTRACKING, enabled);
}

bool QsciScintilla::getScrollWidthTracking() const
{
return SendScintilla(SCI_GETSCROLLWIDTHTRACKING);
}
9 changes: 9 additions & 0 deletions src/sqltextedit.cpp
Expand Up @@ -42,6 +42,15 @@ SqlTextEdit::SqlTextEdit(QWidget* parent) :
errorIndicatorNumber = indicatorDefine(QsciScintilla::SquiggleIndicator);
setIndicatorForegroundColor(Qt::red, errorIndicatorNumber);

// Set a sensible scroll width, so the scroll bar is avoided in
// most cases.
setScrollWidth(80);

// Scroll width is adjusted to ensure that all of the lines
// currently displayed can be completely scrolled. This mode never
// adjusts the scroll width to be narrower.
setScrollWidthTracking(true);

// Do rest of initialisation
reloadSettings();

Expand Down

0 comments on commit d8aeae1

Please sign in to comment.