mirror of
https://github.com/rizinorg/cutter.git
synced 2025-02-20 13:46:06 +00:00
Highlight program counter in Navbar widget (#1095)
Highlight program counter in navbar and add navbar cursor colors to native theme configuration.
This commit is contained in:
parent
f189fb423c
commit
3666c97178
@ -15,6 +15,8 @@ static const QStringList cutterSpecificOptions = {
|
||||
"highlightPC",
|
||||
"highlightWord",
|
||||
"gui.navbar.err",
|
||||
"gui.navbar.seek",
|
||||
"gui.navbar.pc",
|
||||
"gui.navbar.sym",
|
||||
"gui.dataoffset",
|
||||
"gui.navbar.code",
|
||||
|
@ -152,6 +152,8 @@ void Configuration::loadBaseThemeNative()
|
||||
setColor("gui.imports", QColor(50, 140, 255));
|
||||
setColor("gui.main", QColor(0, 128, 0));
|
||||
setColor("gui.navbar.err", QColor(255, 0, 0));
|
||||
setColor("gui.navbar.seek", QColor(233, 86, 86));
|
||||
setColor("gui.navbar.pc", QColor(66, 238, 244));
|
||||
setColor("gui.navbar.code", QColor(104, 229, 69));
|
||||
setColor("gui.navbar.str", QColor(69, 104, 229));
|
||||
setColor("gui.navbar.sym", QColor(229, 150, 69));
|
||||
@ -221,6 +223,8 @@ void Configuration::loadBaseThemeDark()
|
||||
|
||||
// GUI: navbar
|
||||
setColor("gui.navbar.err", QColor(233, 86, 86));
|
||||
setColor("gui.navbar.seek", QColor(233, 86, 86));
|
||||
setColor("gui.navbar.pc", QColor(66, 238, 244));
|
||||
setColor("gui.navbar.code", QColor(130, 200, 111));
|
||||
setColor("angui.navbar.str", QColor(111, 134, 216));
|
||||
setColor("gui.navbar.sym", QColor(221, 163, 104));
|
||||
|
@ -261,6 +261,8 @@ static const QMap<QString, OptionIfo> optionInfoMap = {
|
||||
{ "gui.imports", { "", "gui.imports", true } },
|
||||
{ "highlightPC", { "", "highlightPC", true } },
|
||||
{ "gui.navbar.err", { "", "gui.navbar.err", true } },
|
||||
{ "gui.navbar.seek", { "", "gui.navbar.seek", true } },
|
||||
{ "gui.navbar.pc", { "", "gui.navbar.pc", true } },
|
||||
{ "gui.navbar.sym", { "", "gui.navbar.sym", true } },
|
||||
{
|
||||
"gui.navbar.code", {
|
||||
|
@ -17,7 +17,8 @@
|
||||
VisualNavbar::VisualNavbar(MainWindow *main, QWidget *parent) :
|
||||
QToolBar(main),
|
||||
graphicsView(new QGraphicsView),
|
||||
cursorGraphicsItem(nullptr),
|
||||
seekGraphicsItem(nullptr),
|
||||
PCGraphicsItem(nullptr),
|
||||
main(main)
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
@ -40,6 +41,7 @@ VisualNavbar::VisualNavbar(MainWindow *main, QWidget *parent) :
|
||||
//addWidget(addsCombo);
|
||||
|
||||
connect(Core(), SIGNAL(seekChanged(RVA)), this, SLOT(on_seekChanged(RVA)));
|
||||
connect(Core(), SIGNAL(registersChanged()), this, SLOT(drawPCCursor()));
|
||||
connect(Core(), SIGNAL(refreshAll()), this, SLOT(fetchAndPaintData()));
|
||||
connect(Core(), SIGNAL(functionsChanged()), this, SLOT(fetchAndPaintData()));
|
||||
connect(Core(), SIGNAL(flagsChanged()), this, SLOT(fetchAndPaintData()));
|
||||
@ -116,8 +118,8 @@ void VisualNavbar::updateGraphicsScene()
|
||||
{
|
||||
graphicsScene->clear();
|
||||
xToAddress.clear();
|
||||
cursorGraphicsItem = nullptr;
|
||||
|
||||
seekGraphicsItem = nullptr;
|
||||
PCGraphicsItem = nullptr;
|
||||
graphicsScene->setBackgroundBrush(QBrush(Config()->getColor("gui.navbar.empty")));
|
||||
|
||||
if (stats.to <= stats.from) {
|
||||
@ -191,33 +193,42 @@ void VisualNavbar::updateGraphicsScene()
|
||||
// Update scene width
|
||||
graphicsScene->setSceneRect(0, 0, w, h);
|
||||
|
||||
drawCursor();
|
||||
drawSeekCursor();
|
||||
}
|
||||
|
||||
void VisualNavbar::drawCursor()
|
||||
void VisualNavbar::drawCursor(RVA addr, QColor color, QGraphicsRectItem *&graphicsItem)
|
||||
{
|
||||
RVA offset = Core()->getOffset();
|
||||
double cursor_x = addressToLocalX(offset);
|
||||
if (cursorGraphicsItem != nullptr) {
|
||||
graphicsScene->removeItem(cursorGraphicsItem);
|
||||
delete cursorGraphicsItem;
|
||||
cursorGraphicsItem = nullptr;
|
||||
double cursor_x = addressToLocalX(addr);
|
||||
if (graphicsItem != nullptr) {
|
||||
graphicsScene->removeItem(graphicsItem);
|
||||
delete graphicsItem;
|
||||
graphicsItem = nullptr;
|
||||
}
|
||||
if (std::isnan(cursor_x)) {
|
||||
return;
|
||||
}
|
||||
int h = this->graphicsView->height();
|
||||
cursorGraphicsItem = new QGraphicsRectItem(cursor_x, 0, 2, h);
|
||||
cursorGraphicsItem->setPen(Qt::NoPen);
|
||||
cursorGraphicsItem->setBrush(QBrush(Config()->getColor("gui.navbar.err")));
|
||||
graphicsScene->addItem(cursorGraphicsItem);
|
||||
graphicsItem = new QGraphicsRectItem(cursor_x, 0, 2, h);
|
||||
graphicsItem->setPen(Qt::NoPen);
|
||||
graphicsItem->setBrush(QBrush(color));
|
||||
graphicsScene->addItem(graphicsItem);
|
||||
}
|
||||
|
||||
void VisualNavbar::drawPCCursor()
|
||||
{
|
||||
drawCursor(Core()->getProgramCounterValue(), Config()->getColor("gui.navbar.pc"), PCGraphicsItem);
|
||||
}
|
||||
|
||||
void VisualNavbar::drawSeekCursor()
|
||||
{
|
||||
drawCursor(Core()->getOffset(), Config()->getColor("gui.navbar.err"), seekGraphicsItem);
|
||||
}
|
||||
|
||||
void VisualNavbar::on_seekChanged(RVA addr)
|
||||
{
|
||||
Q_UNUSED(addr);
|
||||
// Update cursor
|
||||
this->drawCursor();
|
||||
this->drawSeekCursor();
|
||||
}
|
||||
|
||||
void VisualNavbar::mousePressEvent(QMouseEvent *event)
|
||||
|
@ -30,13 +30,16 @@ public slots:
|
||||
private slots:
|
||||
void fetchAndPaintData();
|
||||
void fetchStats();
|
||||
void drawCursor();
|
||||
void drawSeekCursor();
|
||||
void drawPCCursor();
|
||||
void drawCursor(RVA addr, QColor color, QGraphicsRectItem *&graphicsItem);
|
||||
void on_seekChanged(RVA addr);
|
||||
|
||||
private:
|
||||
QGraphicsView *graphicsView;
|
||||
QGraphicsScene *graphicsScene;
|
||||
QGraphicsRectItem *cursorGraphicsItem;
|
||||
QGraphicsRectItem *seekGraphicsItem;
|
||||
QGraphicsRectItem *PCGraphicsItem;
|
||||
MainWindow *main;
|
||||
|
||||
BlockStatistics stats;
|
||||
|
Loading…
Reference in New Issue
Block a user