mirror of
https://github.com/Serial-Studio/Serial-Studio.git
synced 2025-01-15 05:22:53 +08:00
Fix autoscroll issues
This commit is contained in:
parent
5844ec3e5b
commit
e32c276303
@ -33,6 +33,7 @@ Control {
|
||||
//
|
||||
property alias port: _portText.text
|
||||
property alias address: _ipText.text
|
||||
property alias addressLookup: _addrLookup.text
|
||||
property alias socketType: _typeCombo.currentIndex
|
||||
|
||||
//
|
||||
@ -149,8 +150,8 @@ Control {
|
||||
Layout.fillWidth: true
|
||||
opacity: enabled ? 1 : 0.5
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
enabled: !Cpp_IO_Manager.connected
|
||||
onAccepted: Cpp_IO_Network.findIp(text)
|
||||
enabled: !Cpp_IO_Manager.connected && !Cpp_IO_Network.lookupActive
|
||||
onAccepted: Cpp_IO_Network.lookup(text)
|
||||
placeholderText: qsTr("Enter address (e.g. google.com)")
|
||||
|
||||
Behavior on opacity {NumberAnimation{}}
|
||||
@ -162,8 +163,8 @@ Control {
|
||||
Layout.maximumWidth: height
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
icon.source: "qrc:/icons/search.svg"
|
||||
onClicked: Cpp_IO_Network.findIp(_addrLookup.text)
|
||||
enabled: _addrLookup.text.length > 0 && !Cpp_IO_Manager.connected
|
||||
onClicked: Cpp_IO_Network.lookup(_addrLookup.text)
|
||||
enabled: _addrLookup.text.length > 0 && !Cpp_IO_Manager.connected && !Cpp_IO_Network.lookupActive
|
||||
|
||||
Behavior on opacity {NumberAnimation{}}
|
||||
}
|
||||
|
@ -45,24 +45,25 @@ Control {
|
||||
//
|
||||
property alias auto: commAuto.checked
|
||||
property alias manual: commManual.checked
|
||||
property alias csvExport: csvLogging.checked
|
||||
property alias tabIndex: tab.currentIndex
|
||||
property alias csvExport: csvLogging.checked
|
||||
|
||||
//
|
||||
// Serial settings
|
||||
//
|
||||
property alias baudRate: serial.baudRate
|
||||
property alias stopBits: serial.stopBits
|
||||
property alias parity: serial.parity
|
||||
property alias flowControl: serial.flowControl
|
||||
property alias baudRate: serial.baudRate
|
||||
property alias dataBits: serial.dataBits
|
||||
property alias stopBits: serial.stopBits
|
||||
property alias flowControl: serial.flowControl
|
||||
|
||||
//
|
||||
// Network settings
|
||||
//
|
||||
property alias address: network.address
|
||||
property alias port: network.port
|
||||
property alias address: network.address
|
||||
property alias socketType: network.socketType
|
||||
property alias addressLookup: network.addressLookup
|
||||
|
||||
//
|
||||
// App settings
|
||||
|
@ -45,7 +45,7 @@ Console::Console()
|
||||
, m_historyItem(0)
|
||||
, m_echo(false)
|
||||
, m_autoscroll(true)
|
||||
, m_showTimestamp(true)
|
||||
, m_showTimestamp(false)
|
||||
, m_isStartingLine(true)
|
||||
{
|
||||
// Clear buffer & reserve memory
|
||||
|
@ -33,6 +33,8 @@ static Network *INSTANCE = nullptr;
|
||||
*/
|
||||
Network::Network()
|
||||
{
|
||||
m_lookupActive = false;
|
||||
|
||||
setHost("");
|
||||
setPort(defaultPort());
|
||||
setSocketType(QAbstractSocket::TcpSocket);
|
||||
@ -75,6 +77,14 @@ quint16 Network::port() const
|
||||
return m_port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns @c true if we are currently performing a DNS lookup
|
||||
*/
|
||||
bool Network::lookupActive() const
|
||||
{
|
||||
return m_lookupActive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current socket type as an index of the list returned by the @c socketType
|
||||
* function.
|
||||
@ -207,8 +217,10 @@ void Network::setHost(const QString &host)
|
||||
/**
|
||||
* Performs a DNS lookup for the given @a host name
|
||||
*/
|
||||
void Network::findIp(const QString &host)
|
||||
void Network::lookup(const QString &host)
|
||||
{
|
||||
m_lookupActive = true;
|
||||
emit lookupActiveChanged();
|
||||
QHostInfo::lookupHost(host.simplified(), this, &Network::lookupFinished);
|
||||
}
|
||||
|
||||
@ -251,6 +263,9 @@ void Network::setSocketType(const QAbstractSocket::SocketType type)
|
||||
*/
|
||||
void Network::lookupFinished(const QHostInfo &info)
|
||||
{
|
||||
m_lookupActive = false;
|
||||
emit lookupActiveChanged();
|
||||
|
||||
if (info.error() == QHostInfo::NoError)
|
||||
{
|
||||
auto addresses = info.addresses();
|
||||
|
@ -50,25 +50,29 @@ class Network : public QObject
|
||||
Q_PROPERTY(quint16 defaultPort
|
||||
READ defaultPort
|
||||
CONSTANT)
|
||||
Q_PROPERTY(bool lookupActive
|
||||
READ lookupActive
|
||||
NOTIFY lookupActiveChanged)
|
||||
// clang-format on
|
||||
|
||||
signals:
|
||||
void hostChanged();
|
||||
void portChanged();
|
||||
void socketTypeChanged();
|
||||
void lookupActiveChanged();
|
||||
|
||||
public:
|
||||
static Network *getInstance();
|
||||
|
||||
QString host() const;
|
||||
quint16 port() const;
|
||||
bool lookupActive() const;
|
||||
int socketTypeIndex() const;
|
||||
bool configurationOk() const;
|
||||
QStringList socketTypes() const;
|
||||
QAbstractSocket::SocketType socketType() const;
|
||||
|
||||
static QString defaultHost() { return "127.0.0.1"; }
|
||||
|
||||
static quint16 defaultPort() { return 23; }
|
||||
|
||||
QIODevice *openNetworkPort();
|
||||
@ -79,7 +83,7 @@ public slots:
|
||||
void disconnectDevice();
|
||||
void setPort(const quint16 port);
|
||||
void setHost(const QString &host);
|
||||
void findIp(const QString &host);
|
||||
void lookup(const QString &host);
|
||||
void setSocketTypeIndex(const int index);
|
||||
void setSocketType(const QAbstractSocket::SocketType type);
|
||||
|
||||
@ -94,6 +98,7 @@ private:
|
||||
private:
|
||||
QString m_host;
|
||||
quint16 m_port;
|
||||
bool m_lookupActive;
|
||||
QIODevice *m_device;
|
||||
QTcpSocket m_tcpSocket;
|
||||
QUdpSocket m_udpSocket;
|
||||
|
@ -563,7 +563,7 @@ void QmlPlainTextEdit::scrollToBottom(const bool repaint)
|
||||
// Get scrollbar pointer, calculate line count & visible text lines
|
||||
auto *bar = textEdit()->verticalScrollBar();
|
||||
auto lineCount = textEdit()->document()->blockCount();
|
||||
auto visibleLines = qCeil(height() / textEdit()->fontMetrics().height());
|
||||
auto visibleLines = qFloor(height() / textEdit()->fontMetrics().height());
|
||||
|
||||
// Abort operation if control is not visible
|
||||
if (visibleLines <= 0)
|
||||
@ -571,11 +571,11 @@ void QmlPlainTextEdit::scrollToBottom(const bool repaint)
|
||||
|
||||
// Update scrolling range
|
||||
bar->setMinimum(0);
|
||||
bar->setMaximum(lineCount);
|
||||
bar->setMaximum(lineCount + 1);
|
||||
|
||||
// Do not scroll to bottom if all text fits in current window
|
||||
if (lineCount > visibleLines)
|
||||
bar->setValue(lineCount - visibleLines);
|
||||
bar->setValue(lineCount - visibleLines + 1);
|
||||
else
|
||||
bar->setValue(0);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user