2017-03-29 10:18:37 +00:00
|
|
|
#include "codegraphic.h"
|
|
|
|
|
2017-10-01 19:09:42 +00:00
|
|
|
#include "MainWindow.h"
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-04-13 15:14:02 +00:00
|
|
|
#include <QGraphicsView>
|
2017-03-29 10:18:37 +00:00
|
|
|
#include <QComboBox>
|
|
|
|
#include <QGraphicsScene>
|
|
|
|
#include <QGraphicsRectItem>
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QJsonParseError>
|
|
|
|
|
|
|
|
GraphicsBar::GraphicsBar(MainWindow *main, QWidget *parent) :
|
2017-10-01 18:08:12 +00:00
|
|
|
QToolBar(main),
|
|
|
|
codeGraphic(new QGraphicsView),
|
|
|
|
main(main)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-10-01 18:08:12 +00:00
|
|
|
Q_UNUSED(parent);
|
2017-04-09 17:09:35 +00:00
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
setObjectName("codeGraphics");
|
2017-04-13 15:14:02 +00:00
|
|
|
setWindowTitle(tr("Code bar"));
|
2017-04-09 19:55:06 +00:00
|
|
|
// setMovable(false);
|
2017-03-29 10:18:37 +00:00
|
|
|
setContentsMargins(0, 0, 0, 0);
|
2017-04-07 15:34:24 +00:00
|
|
|
// If line below is used, with the dark theme the paintEvent is not called
|
|
|
|
// and the result is wrong. Something to do with overwriting the style sheet :/
|
|
|
|
//setStyleSheet("QToolBar { border: 0px; border-bottom: 0px; border-top: 0px; border-width: 0px;}");
|
2017-03-29 10:18:37 +00:00
|
|
|
|
|
|
|
this->codeGraphic->setAlignment(Qt::AlignLeft);
|
|
|
|
this->codeGraphic->setMinimumHeight(20);
|
|
|
|
this->codeGraphic->setMaximumHeight(20);
|
|
|
|
this->codeGraphic->setFrameShape(QFrame::NoFrame);
|
|
|
|
|
|
|
|
/*
|
|
|
|
QComboBox *addsCombo = new QComboBox();
|
|
|
|
addsCombo->addItem("");
|
|
|
|
addsCombo->addItem("Entry points");
|
|
|
|
addsCombo->addItem("Marks");
|
|
|
|
*/
|
|
|
|
addWidget(this->codeGraphic);
|
|
|
|
//addWidget(addsCombo);
|
|
|
|
}
|
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
void GraphicsBar::paintEvent(QPaintEvent *event)
|
|
|
|
{
|
2017-10-01 18:08:12 +00:00
|
|
|
Q_UNUSED(event);
|
2017-04-09 17:09:35 +00:00
|
|
|
|
|
|
|
QPainter painter(this);
|
|
|
|
this->fillData();
|
|
|
|
}
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
void GraphicsBar::fillData()
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
|
|
|
|
// Prepare the graph scene
|
|
|
|
int w = this->codeGraphic->width();
|
|
|
|
int h = this->codeGraphic->height();
|
2017-04-13 15:14:02 +00:00
|
|
|
QGraphicsScene *scene = new QGraphicsScene(this);
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
const QBrush bg = QBrush(QColor(74, 74, 74));
|
2017-03-29 10:18:37 +00:00
|
|
|
|
|
|
|
scene->setBackgroundBrush(bg);
|
|
|
|
this->codeGraphic->setRenderHints(0);
|
|
|
|
this->codeGraphic->setScene(scene);
|
|
|
|
this->codeGraphic->setRenderHints(QPainter::Antialiasing);
|
|
|
|
this->codeGraphic->setToolTip("gap");
|
|
|
|
|
|
|
|
// Parse JSON data
|
|
|
|
QString jsonData = this->main->core->cmd("p-j");
|
|
|
|
QJsonDocument doc = QJsonDocument::fromJson(jsonData.toUtf8());
|
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
if (doc.isNull())
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
qDebug() << "Invalid json in p-j command";
|
|
|
|
}
|
2017-04-09 19:55:06 +00:00
|
|
|
else if (doc.isObject())
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
//get the jsonObject
|
|
|
|
QJsonObject jObject = doc.object();
|
|
|
|
|
|
|
|
//convert the json object to variantmap
|
|
|
|
QVariantMap mainMap = jObject.toVariantMap();
|
|
|
|
|
|
|
|
int from = mainMap["from"].toInt();
|
|
|
|
int to = mainMap["to"].toInt();
|
|
|
|
int block = mainMap["blocksize"].toInt();
|
|
|
|
int size = (to - from);
|
|
|
|
int num = size / block;
|
2017-04-09 19:55:06 +00:00
|
|
|
if (num < 1)
|
|
|
|
{
|
2017-04-03 08:23:21 +00:00
|
|
|
num = 1;
|
|
|
|
}
|
|
|
|
int graph_block = w / num;
|
2017-03-29 10:18:37 +00:00
|
|
|
int counter = 0;
|
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
for (auto i : mainMap["blocks"].toList())
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
QMap<QString, QVariant> map = i.toMap();
|
2017-04-09 19:55:06 +00:00
|
|
|
if (map.empty())
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
// Fill empty color
|
|
|
|
// addRect(qreal x, qreal y, qreal w, qreal h, const QPen &pen = QPen(), const QBrush &brush = QBrush())
|
|
|
|
//scene->addRect(counter * graph_block, 0, graph_block ,h, QPen(Qt::NoPen), QBrush(QColor(252, 249, 190)));
|
2017-04-09 19:55:06 +00:00
|
|
|
QGraphicsRectItem *rect = new QGraphicsRectItem(counter * graph_block, 0, graph_block, h);
|
2017-03-29 10:18:37 +00:00
|
|
|
rect->setPen(Qt::NoPen);
|
|
|
|
rect->setBrush(QBrush(QColor(252, 249, 190)));
|
|
|
|
rect->setToolTip("Data");
|
|
|
|
scene->addItem(rect);
|
2017-04-09 19:55:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
// Fill type of color
|
|
|
|
//scene->addRect(counter * graph_block, 0, graph_block ,h, QPen(Qt::NoPen), QBrush(QColor(69, 104, 229)));
|
2017-04-09 19:55:06 +00:00
|
|
|
QGraphicsRectItem *rect = new QGraphicsRectItem(counter * graph_block, 0, graph_block, h);
|
2017-03-29 10:18:37 +00:00
|
|
|
rect->setPen(Qt::NoPen);
|
2017-04-09 19:55:06 +00:00
|
|
|
if (i.toMap()["functions"].toInt() == 0)
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
rect->setBrush(QBrush(QColor(190, 190, 190)));
|
2017-04-09 19:55:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
rect->setBrush(QBrush(QColor(69, 104, 229)));
|
|
|
|
}
|
2017-04-09 19:55:06 +00:00
|
|
|
rect->setToolTip("Offset: 0x" + QString::number(i.toMap()["offset"].toInt(), 16) + "\nFunctions: " + QString::number(i.toMap()["functions"].toInt()) + "\nFlags: " + QString::number(i.toMap()["flags"].toInt()));
|
2017-03-29 10:18:37 +00:00
|
|
|
scene->addItem(rect);
|
|
|
|
}
|
|
|
|
counter += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|