Skip to content

Commit 088c3dc

Browse files
committed
HydraTool first public version import (v0.3.1.0)
1 parent b7c2634 commit 088c3dc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+5551
-2
lines changed

LiberationSans-Regular.ttf

342 KB
Binary file not shown.

README.md

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
1-
# hydratool
2-
HydraBus host tool with GUI (Qt)
1+
HydraTool
2+
======
3+
4+
This repository contains host software (Linux/Windows) for HydraBus with HydraFW firmware, a project to
5+
produce a low cost, open source multi-tool hardware for anyone interested in Learning/Developping/Debugging/Hacking/Penetration Testing
6+
for basic or advanced embedded hardware.
7+
8+
HydraBus: https://www.hydrabus.com & https://github.com/hydrabus
9+
10+
HydraFW: https://github.com/hydrabus/hydrafw
11+
12+
## How to build host software on Windows:
13+
14+
### Prerequisites Windows, GNU/Linux:
15+
16+
* Qt5.6.x or more (with QtCreator)
17+
* See Qt5.x Online Installer http://download.qt.io/official_releases/online_installers/qt-unified-windows-x86-online.exe
18+
* See also http://download.qt.io/official_releases/qt/
19+
* Tested with success on Qt5.6 & Qt5.9.1 on Ubuntu 16 LTS & Windows7 SP1
20+
21+
### Build the project with QtCreator on Windows, GNU/Linux:
22+
23+
* Import hydratool.pro project in Qt Creator
24+
* Configure the Project for MinGW and/or MSVC2013 or more
25+
* Build the project
26+

connect_qaction.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "connect_qaction.h"
2+
3+
Connect_QAction::Connect_QAction(QObject *parent) :
4+
QAction(parent)
5+
{
6+
this->disconnect();
7+
}
8+
9+
void StateAction::connect()
10+
{
11+
this->setIcon(QIcon(":/images/connect.png"));
12+
}
13+
14+
void StateAction::disconnect()
15+
{
16+
this->setIcon(QIcon(":/images/disconnect.png"));
17+
}

connect_qaction.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef CONNECT_QACTION_H
2+
#define CONNECT_QACTION_H
3+
4+
5+
class Connect_QAction : public QAction
6+
{
7+
Q_OBJECT
8+
public:
9+
explicit Connect_QAction(QObject *parent = 0);
10+
11+
public slots:
12+
void connect();
13+
void disconnect();
14+
15+
};
16+
17+
#endif // CONNECT_QACTION_H

console.cpp

+181
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
#include <QtWidgets>
2+
3+
#include "console.h"
4+
5+
#include <QScrollBar>
6+
7+
//#include <QtCore/QDebug>
8+
9+
Console::Console(QWidget *parent)
10+
: QPlainTextEdit(parent)
11+
{
12+
lineNumberArea = new LineNumberArea(this);
13+
14+
updateLineNumberAreaWidth(0);
15+
highlightCurrentLine();
16+
17+
//document()->setMaximumBlockCount(100);
18+
document()->setMaximumBlockCount(-1);
19+
//QPalette p = palette();
20+
//p.setColor(QPalette::Base, Qt::black);
21+
//p.setColor(QPalette::Text, Qt::green);
22+
//setPalette(p);
23+
24+
QFont font;
25+
font.setFamily(QStringLiteral("Courier New"));
26+
this->setFont(font);
27+
//this->setTextInteractionFlags(Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse);
28+
29+
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
30+
connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int)));
31+
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine()));
32+
33+
t.start();
34+
}
35+
36+
void Console::putData(const QByteArray &data)
37+
{
38+
appendPlainText(data);
39+
if(localVerticalAutoScrollEnabled == true)
40+
{
41+
QScrollBar *bar = verticalScrollBar();
42+
bar->setValue(bar->maximum());
43+
}
44+
}
45+
46+
void Console::setLocalEchoEnabled(bool set)
47+
{
48+
localEchoEnabled = set;
49+
}
50+
51+
void Console::setLocalVerticalScrollBarMaxEnabled(bool set)
52+
{
53+
localVerticalAutoScrollEnabled = set;
54+
}
55+
56+
void Console::keyPressEvent(QKeyEvent *e)
57+
{
58+
//Q_UNUSED(e);
59+
QPlainTextEdit::keyPressEvent(e);
60+
/*
61+
switch (e->key()) {
62+
case Qt::Key_Backspace:
63+
case Qt::Key_Left:
64+
case Qt::Key_Right:
65+
case Qt::Key_Up:
66+
case Qt::Key_Down:
67+
break;
68+
default:
69+
if (localEchoEnabled)
70+
QPlainTextEdit::keyPressEvent(e);
71+
emit getData(e->text().toLocal8Bit());
72+
}
73+
*/
74+
}
75+
76+
void Console::mousePressEvent(QMouseEvent *e)
77+
{
78+
QPlainTextEdit::mousePressEvent(e);
79+
//Q_UNUSED(e)
80+
//setFocus();
81+
}
82+
83+
void Console::mouseDoubleClickEvent(QMouseEvent *e)
84+
{
85+
//QPlainTextEdit::mouseDoubleClickEvent(e);
86+
Q_UNUSED(e)
87+
}
88+
89+
void Console::contextMenuEvent(QContextMenuEvent *e)
90+
{
91+
QPlainTextEdit::contextMenuEvent(e);
92+
//Q_UNUSED(e)
93+
}
94+
95+
void Console::highlightCurrentLine()
96+
{
97+
QList<QTextEdit::ExtraSelection> extraSelections;
98+
99+
/*
100+
if (!isReadOnly())
101+
*/
102+
{
103+
QTextEdit::ExtraSelection selection;
104+
105+
QColor lineColor = QColor(Qt::yellow).lighter(160);
106+
107+
selection.format.setBackground(lineColor);
108+
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
109+
selection.cursor = textCursor();
110+
selection.cursor.clearSelection();
111+
extraSelections.append(selection);
112+
}
113+
114+
setExtraSelections(extraSelections);
115+
}
116+
117+
int Console::lineNumberAreaWidth()
118+
{
119+
int digits = 1;
120+
int max = qMax(1, blockCount());
121+
while (max >= 10) {
122+
max /= 10;
123+
++digits;
124+
}
125+
126+
int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits;
127+
//int space = 80 + fontMetrics().width(QLatin1Char('9')) * digits;
128+
129+
return space;
130+
}
131+
132+
void Console::updateLineNumberAreaWidth(int /* newBlockCount */)
133+
{
134+
setViewportMargins(lineNumberAreaWidth(), 0, 0, 0);
135+
}
136+
137+
void Console::updateLineNumberArea(const QRect &rect, int dy)
138+
{
139+
if (dy)
140+
lineNumberArea->scroll(0, dy);
141+
else
142+
lineNumberArea->update(0, rect.y(), lineNumberArea->width(), rect.height());
143+
144+
if (rect.contains(viewport()->rect()))
145+
updateLineNumberAreaWidth(0);
146+
}
147+
148+
void Console::resizeEvent(QResizeEvent *e)
149+
{
150+
QPlainTextEdit::resizeEvent(e);
151+
152+
QRect cr = contentsRect();
153+
lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
154+
}
155+
156+
void Console::lineNumberAreaPaintEvent(QPaintEvent *event)
157+
{
158+
QPainter painter(lineNumberArea);
159+
painter.fillRect(event->rect(), Qt::lightGray);
160+
161+
QTextBlock block = firstVisibleBlock();
162+
int blockNumber = block.blockNumber();
163+
int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top();
164+
int bottom = top + (int) blockBoundingRect(block).height();
165+
166+
while (block.isValid() && top <= event->rect().bottom()) {
167+
if (block.isVisible() && bottom >= event->rect().top()) {
168+
QString number = QString::number(blockNumber + 1);
169+
//QString number = QString::asprintf("%d %dms", (blockNumber + 1), t.elapsed());
170+
painter.setPen(Qt::black);
171+
painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(),
172+
Qt::AlignRight, number);
173+
}
174+
175+
block = block.next();
176+
top = bottom;
177+
bottom = top + (int) blockBoundingRect(block).height();
178+
++blockNumber;
179+
}
180+
}
181+

console.h

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/****************************************************************************
2+
**
3+
** Copyright (C) 2015 Benjamin Vernoux
4+
**
5+
****************************************************************************/
6+
7+
#ifndef CONSOLE_H
8+
#define CONSOLE_H
9+
10+
#include <QPlainTextEdit>
11+
#include <QObject>
12+
#include <QTime>
13+
14+
QT_BEGIN_NAMESPACE
15+
class QPaintEvent;
16+
class QResizeEvent;
17+
class QSize;
18+
class QWidget;
19+
QT_END_NAMESPACE
20+
21+
class LineNumberArea;
22+
23+
class Console : public QPlainTextEdit
24+
{
25+
Q_OBJECT
26+
27+
signals:
28+
void getData(const QByteArray &data);
29+
30+
public:
31+
Console(QWidget *parent = 0);
32+
33+
void putData(const QByteArray &data);
34+
35+
void setLocalEchoEnabled(bool set);
36+
void setLocalVerticalScrollBarMaxEnabled(bool set);
37+
38+
void lineNumberAreaPaintEvent(QPaintEvent *event);
39+
int lineNumberAreaWidth();
40+
41+
protected:
42+
virtual void keyPressEvent(QKeyEvent *e);
43+
virtual void mousePressEvent(QMouseEvent *e);
44+
virtual void mouseDoubleClickEvent(QMouseEvent *e);
45+
virtual void contextMenuEvent(QContextMenuEvent *e);
46+
47+
void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
48+
49+
private slots:
50+
void updateLineNumberAreaWidth(int newBlockCount);
51+
void highlightCurrentLine();
52+
void updateLineNumberArea(const QRect &, int);
53+
54+
private:
55+
bool localEchoEnabled;
56+
bool localVerticalAutoScrollEnabled;
57+
QWidget *lineNumberArea;
58+
QTime t;
59+
};
60+
61+
class LineNumberArea : public QWidget
62+
{
63+
public:
64+
LineNumberArea(Console *editor) : QWidget(editor) {
65+
console = editor;
66+
}
67+
68+
QSize sizeHint() const Q_DECL_OVERRIDE {
69+
return QSize(console->lineNumberAreaWidth(), 0);
70+
}
71+
72+
protected:
73+
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE {
74+
console->lineNumberAreaPaintEvent(event);
75+
}
76+
77+
private:
78+
Console *console;
79+
};
80+
81+
#endif // CONSOLE_H

0 commit comments

Comments
 (0)