Skip to content

Commit a61582f

Browse files
author
Mich
committed
Merge - v1.3
2 parents 71dc646 + 701cefb commit a61582f

13 files changed

+597
-126
lines changed

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<p align="center">
22
<h1 align="left">QtSerialMonitor </h1>
33
<p align="left">
4-
<a href="https://github.com/mich-w/QtSerialMonitor/blob/master/LICENSE"> <img alt="license" src="https://img.shields.io/github/license/mich-w/QtSerialMonitor"> </a>
5-
<a href="https://github.com/mich-w/QtSerialMonitor/releases"> <img alt="downloads" src="https://img.shields.io/github/downloads/mich-w/QtSerialMonitor/total"></a>
6-
<a href="https://github.com/mich-w/QtSerialMonitor/releases"> <img alt="latest release" src="https://img.shields.io/github/v/release/mich-w/QtSerialMonitor"></a>
4+
<a href="https://github.com/mich-w/QtSerialMonitor/blob/master/LICENSE"> <img alt="license" src="https://img.shields.io/github/license/mich-w/QtSerialMonitor?style=flat-square"> </a>
5+
<a href="https://github.com/mich-w/QtSerialMonitor/releases"> <img alt="downloads" src="https://img.shields.io/github/downloads/mich-w/QtSerialMonitor/total?style=flat-square"></a>
6+
<a href="https://github.com/mich-w/QtSerialMonitor/releases"> <img alt="latest release" src="https://img.shields.io/github/v/release/mich-w/QtSerialMonitor?style=flat-square"></a>
77
</p>
88
</p>
99

@@ -12,10 +12,10 @@ Universal serial monitor with data plotting capabilities, based on [Qt](https://
1212
<img src="https://raw.githubusercontent.com/mich-w/QtSerialMonitor/master/docs/_screenshots/Sines3.gif">
1313

1414
**Features:**
15-
1615
- In/out serial data terminal with command history,
1716
- UDP network protocol support,
18-
- Advanced data plotter with multiple graphs support and basic data filtering - uses [QCustomPlot](https://www.qcustomplot.com/),
17+
- Resizable UI widgets,
18+
- Data plotter with multiple graphs support and basic data filtering - uses [QCustomPlot](https://www.qcustomplot.com/),
1919
- Printer support, ability to save graph as image,
2020
- Read/write ".txt" data logs,
2121
- many more...
@@ -26,14 +26,12 @@ Universal serial monitor with data plotting capabilities, based on [Qt](https://
2626

2727
**Work in progress:**
2828

29-
29+
- Linux compatibility
3030

3131
- 3D Orientation Demo - for IMU testing (user will be able to toggle between chart view
3232
and a simple 3D scene containing an object rotating accordingly to received roll,
3333
pitch and yaw values, representing the sensor's orientation),
3434

35-
- "What’s this ?" popups for less obvious widgets,
36-
3735
- Improvements, fixes etc.
3836

3937
----

src/QtSerialMonitor.pro

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ DEFINES += QT_DEPRECATED_WARNINGS
3030
CONFIG += c++11
3131

3232
SOURCES += \
33+
codeeditor.cpp \
3334
filereader.cpp \
35+
highlighter.cpp \
3436
infodialog.cpp \
3537
logger.cpp \
3638
main.cpp \
@@ -42,8 +44,10 @@ SOURCES += \
4244

4345
HEADERS += \
4446
../../../../../../Downloads/QCustomPlot.tar/qcustomplot/qcustomplot.h \
47+
codeeditor.h \
4548
config.h \
4649
filereader.h \
50+
highlighter.h \
4751
infodialog.h \
4852
logger.h \
4953
mainwindow.h \
@@ -64,7 +68,8 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
6468
!isEmpty(target.path): INSTALLS += target
6569

6670
DISTFILES += \
67-
QtSM.ico
71+
QtSM.ico \
72+
TODO
6873

6974
RESOURCES += \
7075
3dres.qrc

src/TODO

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

src/codeeditor.cpp

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/****************************************************************************
2+
**
3+
** Copyright (C) 2016 The Qt Company Ltd.
4+
** Contact: https://www.qt.io/licensing/
5+
**
6+
** This file is part of the examples of the Qt Toolkit.
7+
**
8+
** $QT_BEGIN_LICENSE:BSD$
9+
** Commercial License Usage
10+
** Licensees holding valid commercial Qt licenses may use this file in
11+
** accordance with the commercial license agreement provided with the
12+
** Software or, alternatively, in accordance with the terms contained in
13+
** a written agreement between you and The Qt Company. For licensing terms
14+
** and conditions see https://www.qt.io/terms-conditions. For further
15+
** information use the contact form at https://www.qt.io/contact-us.
16+
**
17+
** BSD License Usage
18+
** Alternatively, you may use this file under the terms of the BSD license
19+
** as follows:
20+
**
21+
** "Redistribution and use in source and binary forms, with or without
22+
** modification, are permitted provided that the following conditions are
23+
** met:
24+
** * Redistributions of source code must retain the above copyright
25+
** notice, this list of conditions and the following disclaimer.
26+
** * Redistributions in binary form must reproduce the above copyright
27+
** notice, this list of conditions and the following disclaimer in
28+
** the documentation and/or other materials provided with the
29+
** distribution.
30+
** * Neither the name of The Qt Company Ltd nor the names of its
31+
** contributors may be used to endorse or promote products derived
32+
** from this software without specific prior written permission.
33+
**
34+
**
35+
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36+
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37+
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38+
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39+
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40+
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41+
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42+
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43+
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44+
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45+
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46+
**
47+
** $QT_END_LICENSE$
48+
**
49+
****************************************************************************/
50+
51+
#include <QtWidgets>
52+
#include "codeeditor.h"
53+
54+
CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent)
55+
{
56+
lineNumberArea = new LineNumberArea(this);
57+
58+
connect(this, &CodeEditor::blockCountChanged, this, &CodeEditor::updateLineNumberAreaWidth);
59+
connect(this, &CodeEditor::updateRequest, this, &CodeEditor::updateLineNumberArea);
60+
connect(this, &CodeEditor::cursorPositionChanged, this, &CodeEditor::highlightCurrentLine);
61+
62+
updateLineNumberAreaWidth(0);
63+
}
64+
65+
int CodeEditor::lineNumberAreaWidth()
66+
{
67+
int digits = 1;
68+
int max = qMax(1, blockCount());
69+
70+
while (max >= 10)
71+
{
72+
max /= 10;
73+
++digits;
74+
}
75+
76+
int space = 10 + fontMetrics().horizontalAdvance(" ") * digits;
77+
78+
return space;
79+
}
80+
81+
void CodeEditor::updateLineNumberAreaWidth(int /* newBlockCount */)
82+
{
83+
setViewportMargins(lineNumberAreaWidth(), 0, 0, 0);
84+
}
85+
86+
void CodeEditor::updateLineNumberArea(const QRect &rect, int dy)
87+
{
88+
if (dy)
89+
lineNumberArea->scroll(0, dy);
90+
else
91+
lineNumberArea->update(0, rect.y(), lineNumberArea->width(), rect.height());
92+
93+
if (rect.contains(viewport()->rect()))
94+
updateLineNumberAreaWidth(0);
95+
}
96+
97+
void CodeEditor::resizeEvent(QResizeEvent *e)
98+
{
99+
QPlainTextEdit::resizeEvent(e);
100+
101+
QRect cr = contentsRect();
102+
lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
103+
}
104+
105+
void CodeEditor::highlightCurrentLine()
106+
{
107+
QList<QTextEdit::ExtraSelection> extraSelections;
108+
QTextEdit::ExtraSelection selection;
109+
QColor lineColor = QColor(Qt::yellow).lighter(160);
110+
111+
selection.format.setBackground(lineColor);
112+
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
113+
selection.cursor = textCursor();
114+
selection.cursor.clearSelection();
115+
extraSelections.append(selection);
116+
117+
setExtraSelections(extraSelections);
118+
119+
selection.cursor.clearSelection();
120+
121+
}
122+
123+
void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
124+
{
125+
QPainter painter(lineNumberArea);
126+
painter.fillRect(event->rect(), Qt::lightGray);
127+
128+
QTextBlock block = firstVisibleBlock();
129+
int blockNumber = block.blockNumber();
130+
int top = (int)blockBoundingGeometry(block).translated(contentOffset()).top();
131+
int bottom = top + (int)blockBoundingRect(block).height();
132+
133+
while (block.isValid() && top <= event->rect().bottom())
134+
{
135+
if (block.isVisible() && bottom >= event->rect().top())
136+
{
137+
QString number = QString::number(blockNumber + 1);
138+
painter.setPen(Qt::black);
139+
painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(), Qt::AlignLeft, number);
140+
}
141+
142+
block = block.next();
143+
top = bottom;
144+
bottom = top + (int)blockBoundingRect(block).height();
145+
++blockNumber;
146+
}
147+
}

src/codeeditor.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#ifndef CODEEDITOR_H
2+
#define CODEEDITOR_H
3+
4+
#include <QPlainTextEdit>
5+
6+
QT_BEGIN_NAMESPACE
7+
class QPaintEvent;
8+
class QResizeEvent;
9+
class QSize;
10+
class QWidget;
11+
QT_END_NAMESPACE
12+
13+
class LineNumberArea;
14+
15+
class CodeEditor : public QPlainTextEdit
16+
{
17+
Q_OBJECT
18+
19+
public:
20+
CodeEditor(QWidget *parent = nullptr);
21+
22+
void lineNumberAreaPaintEvent(QPaintEvent *event);
23+
int lineNumberAreaWidth();
24+
25+
protected:
26+
void resizeEvent(QResizeEvent *event) override;
27+
28+
private slots:
29+
void updateLineNumberAreaWidth(int newBlockCount);
30+
void highlightCurrentLine();
31+
void updateLineNumberArea(const QRect &, int);
32+
33+
private:
34+
QWidget *lineNumberArea;
35+
};
36+
37+
class LineNumberArea : public QWidget
38+
{
39+
public:
40+
LineNumberArea(CodeEditor *editor) : QWidget(editor)
41+
{
42+
codeEditor = editor;
43+
}
44+
45+
QSize sizeHint() const override
46+
{
47+
return QSize(codeEditor->lineNumberAreaWidth(), 0);
48+
}
49+
50+
protected:
51+
void paintEvent(QPaintEvent *event) override
52+
{
53+
codeEditor->lineNumberAreaPaintEvent(event);
54+
}
55+
56+
private:
57+
CodeEditor *codeEditor;
58+
};
59+
60+
#endif

src/config.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
#ifndef CONFIG_H
22
#define CONFIG_H
33

4-
#define VERSION "1.2"
4+
#define VERSION "1.3"
55

66
#define CHANGELOG_TEXT "" //"Changelog - version " VERSION ": \n"
77

88
#define INTRO_TEXT "" \
99
"Welcome to QtSerialMonitor, \n" \
1010
"Press F1 to activate \"What's this\" mode. In this mode, clicked widget \r" \
1111
"will display an explanation about its function. \n"
12+
13+
#define RADIO_BUTTON_UPDATE_SERIAL_DEVICES_ON_INTERVAL 100
14+
#define SERIAL_DEVICE_CHECK_TIMER_INTERVAL 500
15+
1216
#endif // CONFIG_H

0 commit comments

Comments
 (0)