Skip to content

Commit

Permalink
feat(terminal): 1.修复终端光标位置不正确问题; 2.优化选取和clear
Browse files Browse the repository at this point in the history
  • Loading branch information
HoGC committed Apr 16, 2022
1 parent bfc7d20 commit 6719dc3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion SerialTool/include/version.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef __VERSION_H
#define __VERSION_H

#define MAIN_VERSION 1.5.6
#define MAIN_VERSION 1.5.7

#define SOFTWARE_NAME "SerialTool"
#define COPYRIGHT "Copyleft 2017-2018, Wenliang Guan"
Expand Down
34 changes: 15 additions & 19 deletions SerialTool/src/views/terminal/qvterminal/qvterminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ void QVTerminal::toggleCursor()

void QVTerminal::clearToEnd()
{
_layout->lineAt(_cursorPos.y()).reserve(_cursorPos.x());
_layout->lineAt(_cursorPos.y()).clear();
}

bool QVTerminal::crlf() const
Expand Down Expand Up @@ -467,11 +467,9 @@ void QVTerminal::paintEvent(QPaintEvent */* paintEvent */)


QPoint curPos(0, (_cursorPos.y() - firstLine) * _ch);
int cur_x = 0;
for (int index = 0; index < _cursorPos.x(); ++index) {
cur_x = (_layout->lineAt(_layout->lineCount()-1).chars()[index].c()>255?2:1) * _cw;
}
curPos.setX(cur_x);
curPos.setX(curPos.x() + (_layout->lineAt(_layout->lineCount() - 1).chars()[0].c()>255?2:1) * _cw);
}

// draw cursor
if (_cvisible && _chooseSatus != 2 && _chooseSatus != 3) {
Expand Down Expand Up @@ -542,21 +540,19 @@ void QVTerminal::mouseReleaseEvent(QMouseEvent *event){
if (event->button() == Qt::RightButton) {

}else if (event->button() == Qt::LeftButton) {
if(_chooseSatus == 2){
if((abs(_choosePosEnd.x() - _choosePosStart.x()) < 3) && (abs(_choosePosEnd.y() - _choosePosStart.y()) < 5)){
_chooseSatus = 0;
if(abs(_choosePosEnd.x() - _choosePosStart.x()) < 5 && abs(_choosePosEnd.y() - _choosePosStart.y()) < 5){
_chooseSatus = 0;
}else{
_chooseSatus = 3;
if(event->pos().x() < 0){
_choosePosEnd.setX(0);
}else{
_chooseSatus = 3;
if(event->pos().x() < 0){
_choosePosEnd.setX(0);
}else{
_choosePosEnd.setX(event->pos().x());
}
if(event->pos().y() < 0){
_choosePosEnd.setY(verticalScrollBar()->value());
}else{
_choosePosEnd.setY(verticalScrollBar()->value()+event->pos().y());
}
_choosePosEnd.setX(event->pos().x());
}
if(event->pos().y() < 0){
_choosePosEnd.setY(verticalScrollBar()->value());
}else{
_choosePosEnd.setY(verticalScrollBar()->value()+event->pos().y());
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions SerialTool/src/views/terminal/qvterminal/qvtline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ void QVTLine::reserve(int size)
_chars.resize(size);
}

void QVTLine::clear(void)
{
_chars.clear();
}

int QVTLine::size() const
{
return _chars.size();
Expand Down
1 change: 1 addition & 0 deletions SerialTool/src/views/terminal/qvterminal/qvtline.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class QVTLine
void append(const QVTChar &c, int position = -1);
void reduce(int position);
void reserve(int size);
void clear(void);
const QVector<QVTChar> &chars() const;
int size() const;

Expand Down

0 comments on commit 6719dc3

Please sign in to comment.