summaryrefslogtreecommitdiffstats
path: root/examples/widgets/widgets/codeeditor
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2019-10-14 17:46:16 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2019-10-14 17:46:34 +0200
commit440286655e0ca271506cf7cc02ad0dbf4baef9ca (patch)
tree896fa81adb8b14a69355a3a6cf64d06ec8173c9a /examples/widgets/widgets/codeeditor
parent1e27ad1697187549151657ba187928e439300db7 (diff)
parente164d61ca8263fc4b46fdd916e1ea77c7dd2b735 (diff)
Merge remote-tracking branch 'origin/dev' into wip/cmake
Diffstat (limited to 'examples/widgets/widgets/codeeditor')
-rw-r--r--examples/widgets/widgets/codeeditor/codeeditor.cpp11
-rw-r--r--examples/widgets/widgets/codeeditor/codeeditor.h13
-rw-r--r--examples/widgets/widgets/codeeditor/main.cpp2
3 files changed, 14 insertions, 12 deletions
diff --git a/examples/widgets/widgets/codeeditor/codeeditor.cpp b/examples/widgets/widgets/codeeditor/codeeditor.cpp
index 8e29860669..e93a0251e5 100644
--- a/examples/widgets/widgets/codeeditor/codeeditor.cpp
+++ b/examples/widgets/widgets/codeeditor/codeeditor.cpp
@@ -48,10 +48,11 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "codeeditor.h"
+#include <QPainter>
+#include <QTextBlock>
+
//![constructor]
CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent)
@@ -157,8 +158,8 @@ void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
//![extraAreaPaintEvent_1]
QTextBlock block = firstVisibleBlock();
int blockNumber = block.blockNumber();
- int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top();
- int bottom = top + (int) blockBoundingRect(block).height();
+ int top = qRound(blockBoundingGeometry(block).translated(contentOffset()).top());
+ int bottom = top + qRound(blockBoundingRect(block).height());
//![extraAreaPaintEvent_1]
//![extraAreaPaintEvent_2]
@@ -172,7 +173,7 @@ void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
block = block.next();
top = bottom;
- bottom = top + (int) blockBoundingRect(block).height();
+ bottom = top + qRound(blockBoundingRect(block).height());
++blockNumber;
}
}
diff --git a/examples/widgets/widgets/codeeditor/codeeditor.h b/examples/widgets/widgets/codeeditor/codeeditor.h
index 5a48abafc4..283a4e0bdf 100644
--- a/examples/widgets/widgets/codeeditor/codeeditor.h
+++ b/examples/widgets/widgets/codeeditor/codeeditor.h
@@ -80,7 +80,7 @@ protected:
private slots:
void updateLineNumberAreaWidth(int newBlockCount);
void highlightCurrentLine();
- void updateLineNumberArea(const QRect &, int);
+ void updateLineNumberArea(const QRect &rect, int dy);
private:
QWidget *lineNumberArea;
@@ -92,16 +92,17 @@ private:
class LineNumberArea : public QWidget
{
public:
- LineNumberArea(CodeEditor *editor) : QWidget(editor) {
- codeEditor = editor;
- }
+ LineNumberArea(CodeEditor *editor) : QWidget(editor), codeEditor(editor)
+ {}
- QSize sizeHint() const override {
+ QSize sizeHint() const override
+ {
return QSize(codeEditor->lineNumberAreaWidth(), 0);
}
protected:
- void paintEvent(QPaintEvent *event) override {
+ void paintEvent(QPaintEvent *event) override
+ {
codeEditor->lineNumberAreaPaintEvent(event);
}
diff --git a/examples/widgets/widgets/codeeditor/main.cpp b/examples/widgets/widgets/codeeditor/main.cpp
index e17acb87cd..72d186553a 100644
--- a/examples/widgets/widgets/codeeditor/main.cpp
+++ b/examples/widgets/widgets/codeeditor/main.cpp
@@ -48,7 +48,7 @@
**
****************************************************************************/
-#include <QtWidgets>
+#include <QApplication>
#include "codeeditor.h"