Skip to content

Commit

Permalink
Improve code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
direc85 committed Apr 24, 2021
1 parent ecad73f commit 51e8ca2
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/keyloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ KeyLoader::KeyLoader(QObject *parent) :
QObject(parent),
iVkbRows(0),
iVkbColumns(0),
iUtil(0)
iUtil(nullptr)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/keyloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class KeyLoader : public QObject
{
Q_OBJECT
public:
explicit KeyLoader(QObject *parent = 0);
explicit KeyLoader(QObject *parent = nullptr);
virtual ~KeyLoader();

void setUtil(Util* util) { iUtil = util; }
Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ int main(int argc, char *argv[])

// fork the child process before creating QGuiApplication
int socketM;
int pid = forkpty(&socketM,NULL,NULL,NULL);
int pid = forkpty(&socketM,nullptr,nullptr,nullptr);
if( pid==-1 ) {
qFatal("forkpty failed");
exit(1);
//exit(1);
} else if( pid==0 ) {
setenv("TERM", settings->value("terminal/envVarTERM").toByteArray(), 1);

Expand Down
14 changes: 7 additions & 7 deletions src/ptyiface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static int childProcessPid = 0;
void sighandler(int sig)
{
if(sig==SIGCHLD) {
int pid = wait(NULL);
int pid = wait(nullptr);

if(pid > 0 && childProcessPid > 0 && pid==childProcessPid) {
childProcessQuit = true;
Expand All @@ -58,8 +58,8 @@ PtyIFace::PtyIFace(int pid, int masterFd, Terminal *term, QString charset, QObje
iPid(pid),
iMasterFd(masterFd),
iFailed(false),
iReadNotifier(0),
iTextCodec(0)
iReadNotifier(nullptr),
iTextCodec(nullptr)
{
childProcessPid = iPid;

Expand Down Expand Up @@ -116,8 +116,8 @@ void PtyIFace::resize(QSize newSize)
return;

winsize winp;
winp.ws_col = newSize.width();
winp.ws_row = newSize.height();
winp.ws_col = static_cast<unsigned short>(newSize.width());
winp.ws_row = static_cast<unsigned short>(newSize.height());

ioctl(iMasterFd, TIOCSWINSZ, &winp);
}
Expand All @@ -132,7 +132,7 @@ void PtyIFace::writeTerm(const QByteArray &chars)
if(childProcessQuit)
return;

int ret = write(iMasterFd, chars, chars.size());
int ret = write(iMasterFd, chars, static_cast<unsigned int>(chars.size()));
if(ret != chars.size())
qDebug() << "write error!";
}
Expand All @@ -147,6 +147,6 @@ void PtyIFace::readTerm(QByteArray &chars)
while(ret != -1) {
ret = read(iMasterFd, &ch, 64);
if(ret > 0)
chars.append((char*)&ch, ret);
chars.append(static_cast<const char*>(ch), ret);
}
}
2 changes: 1 addition & 1 deletion src/ptyiface.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class PtyIFace : public QObject
{
Q_OBJECT
public:
explicit PtyIFace(int pid, int masterFd, Terminal *term, QString charset, QObject *parent = 0);
explicit PtyIFace(int pid, int masterFd, Terminal *term, QString charset, QObject *parent = nullptr);
virtual ~PtyIFace();

void writeTerm(const QString &chars);
Expand Down
10 changes: 5 additions & 5 deletions src/terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "util.h"

Terminal::Terminal(QObject *parent) :
QObject(parent), iRenderer(0), iPtyIFace(0), iUtil(0),
QObject(parent), iRenderer(nullptr), iPtyIFace(nullptr), iUtil(nullptr),
iTermSize(0,0), iEmitCursorChangeSignal(true),
iShowCursor(true), iUseAltScreenBuffer(false), iAppCursorKeys(false)
{
Expand Down Expand Up @@ -176,7 +176,7 @@ void Terminal::putString(QString str, bool unEscape)
iPtyIFace->writeTerm(str);
}

void Terminal::keyPress(int key, int modifiers)
void Terminal::keyPress(int key, unsigned int modifiers)
{
QChar c(key);

Expand Down Expand Up @@ -343,13 +343,13 @@ void Terminal::insertInBuffer(const QString& chars)
else if (latin==ch_ESC) {
escape = 0;
}
else if( escape=='[' || multiCharEscapes.contains(escape) ) {
else if( escape=='[' || multiCharEscapes.contains(static_cast<char>(escape)) ) {
escSeq += ch;
}
else if( escape==']' ) {
oscSeq += ch;
}
else if( multiCharEscapes.contains(escape) ) {
else if( multiCharEscapes.contains(static_cast<char>(escape)) ) {
escSeq += ch;
}
else {
Expand All @@ -362,7 +362,7 @@ void Terminal::insertInBuffer(const QString& chars)
escape=-1;
escSeq.clear();
}
if( multiCharEscapes.contains(escape) && escSeq.length()>=2 ) {
if( multiCharEscapes.contains(static_cast<char>(escape)) && escSeq.length()>=2 ) {
escControlChar(escSeq);
escape=-1;
escSeq.clear();
Expand Down
4 changes: 2 additions & 2 deletions src/terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Terminal : public QObject
// See http://www.calmar.ws/vim/256-xterm-24bit-rgb-color-chart.html
// for a map of index -> color

explicit Terminal(QObject *parent = 0);
explicit Terminal(QObject *parent = nullptr);
virtual ~Terminal() {}
void setRenderer(TextRender* tr);
void setPtyIFace(PtyIFace* pty);
Expand All @@ -80,7 +80,7 @@ class Terminal : public QObject

QList<TermChar>& currentLine();

Q_INVOKABLE void keyPress(int key, int modifiers);
Q_INVOKABLE void keyPress(int key, unsigned int modifiers);
Q_INVOKABLE const QStringList printableLinesFromCursor(int lines, bool withEmptyLines);
Q_INVOKABLE void putString(QString str, bool unEscape=false);

Expand Down
14 changes: 7 additions & 7 deletions src/textrender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

TextRender::TextRender(QQuickItem *parent) :
QQuickPaintedItem(parent),
iTerm(0),
iUtil(0)
iTerm(nullptr),
iUtil(nullptr)
{
setFlag(ItemHasContents);
connect(this,SIGNAL(myWidthChanged(int)),this,SLOT(updateTermSize()));
Expand Down Expand Up @@ -218,14 +218,14 @@ void TextRender::paintFromBuffer(QPainter* painter, QList<QList<TermChar> >& buf
TermChar tmp = iTerm->zeroChar;
TermChar nextAttrib = iTerm->zeroChar;
TermChar currAttrib = iTerm->zeroChar;
float currentX = leftmargin;
int currentX = leftmargin;
for(int i=from; i<to; i++) {
y += iFontHeight;

if(y >= cutAfter)
painter->setOpacity(0.3);
painter->setOpacity(static_cast<qreal>(0.3));
else
painter->setOpacity(1.0);
painter->setOpacity(static_cast<qreal>(1.0));

int xcount = qMin(buffer.at(i).count(), iTerm->termSize().width());

Expand Down Expand Up @@ -287,7 +287,7 @@ void TextRender::paintFromBuffer(QPainter* painter, QList<QList<TermChar> >& buf
}
}

void TextRender::drawBgFragment(QPainter* painter, float x, float y, float width, TermChar style)
void TextRender::drawBgFragment(QPainter* painter, int x, int y, int width, TermChar style)
{
int bg = style.bgColor;
int fg = style.fgColor;
Expand All @@ -304,7 +304,7 @@ void TextRender::drawBgFragment(QPainter* painter, float x, float y, float width
painter->drawRect(x, y, width, iFontHeight);
}

void TextRender::drawTextFragment(QPainter* painter, float x, float y, QString text, TermChar style)
void TextRender::drawTextFragment(QPainter* painter, int x, int y, QString text, TermChar style)
{
int bg = style.bgColor;
int fg = style.fgColor;
Expand Down
24 changes: 12 additions & 12 deletions src/textrender.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TextRender : public QQuickPaintedItem

Q_OBJECT
public:
explicit TextRender(QQuickItem *parent = 0);
explicit TextRender(QQuickItem *parent = nullptr);
virtual ~TextRender();
void paint(QPainter*);

Expand All @@ -49,11 +49,11 @@ class TextRender : public QQuickPaintedItem
int myHeight() { return iHeight; }
void setMyWidth(int w) { if(iWidth!=w) { iWidth=w; emit myWidthChanged(w); } }
void setMyHeight(int h) { if(iHeight!=h) { iHeight=h; emit myHeightChanged(h); } }
float fontWidth() { return iFontWidth; }
float fontHeight() { return iFontHeight; }
float fontDescent() { return iFontDescent; }
float fontAscent() { return iFontAscent; }
float fontPointSize() { return iFont.pointSize(); }
int fontWidth() { return iFontWidth; }
int fontHeight() { return iFontHeight; }
int fontDescent() { return iFontDescent; }
int fontAscent() { return iFontAscent; }
int fontPointSize() { return iFont.pointSize(); }
void setFontPointSize(int psize);
bool showBufferScrollIndicator() { return iShowBufferScrollIndicator; }
void setShowBufferScrollIndicator(bool s) { if(iShowBufferScrollIndicator!=s) { iShowBufferScrollIndicator=s; emit showBufferScrollIndicatorChanged(); } }
Expand Down Expand Up @@ -81,17 +81,17 @@ public slots:
Q_DISABLE_COPY(TextRender)

void paintFromBuffer(QPainter* painter, QList<QList<TermChar> >& buffer, int from, int to, int &y);
void drawBgFragment(QPainter* painter, float x, float y, float width, TermChar style);
void drawTextFragment(QPainter* painter, float x, float y, QString text, TermChar style);
void drawBgFragment(QPainter* painter, int x, int y, int width, TermChar style);
void drawTextFragment(QPainter* painter, int x, int y, QString text, TermChar style);
QPoint charsToPixels(QPoint pos);

int iWidth;
int iHeight;
QFont iFont;
float iFontWidth;
float iFontHeight;
float iFontDescent;
float iFontAscent;
int iFontWidth;
int iFontHeight;
int iFontDescent;
int iFontAscent;
bool iShowBufferScrollIndicator;

Terminal *iTerm;
Expand Down
8 changes: 4 additions & 4 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Util::Util(QSettings *settings, QString version, QObject *parent) :
newSelection(true),
iVersionString(version),
iSettings(settings),
iRenderer(0)
iRenderer(nullptr)
{
swipeModeSet = false;
swipeAllowed = true;
Expand Down Expand Up @@ -183,8 +183,8 @@ void Util::mouseRelease(float eventX, float eventY) {
return;

if(settingsValue("ui/dragMode")=="gestures") {
int xdist = qAbs(eventPos.x() - dragOrigin.x());
int ydist = qAbs(eventPos.y() - dragOrigin.y());
int xdist = static_cast<int>(qAbs(eventPos.x() - dragOrigin.x()));
int ydist = static_cast<int>(qAbs(eventPos.y() - dragOrigin.y()));
if(eventPos.x() < dragOrigin.x()-reqDragLength && xdist > ydist*2)
doGesture(PanLeft);
else if(eventPos.x() > dragOrigin.x()+reqDragLength && xdist > ydist*2)
Expand Down Expand Up @@ -229,7 +229,7 @@ bool Util::scrollBackBuffer(QPointF now, QPointF last)
if (iRenderer->fontHeight() < 1)
return false;

int nbLines = ydist / iRenderer->fontHeight();
int nbLines = qFloor(ydist / iRenderer->fontHeight());

if (nbLines < 1)
return false;
Expand Down

0 comments on commit 51e8ca2

Please sign in to comment.