mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-18 19:06:10 +00:00
Basic Block Highlight (#1533)
This commit is contained in:
parent
214e6f4264
commit
31838a3a35
@ -7,6 +7,7 @@
|
|||||||
#include "common/CrashHandler.h"
|
#include "common/CrashHandler.h"
|
||||||
|
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Migrate Settings used before Cutter 1.8
|
* @brief Migrate Settings used before Cutter 1.8
|
||||||
|
@ -8,8 +8,8 @@
|
|||||||
#include "common/Configuration.h"
|
#include "common/Configuration.h"
|
||||||
|
|
||||||
const QStringList ColorThemeWorker::cutterSpecificOptions = {
|
const QStringList ColorThemeWorker::cutterSpecificOptions = {
|
||||||
"linehl",
|
"wordHighlight",
|
||||||
"wordhl",
|
"lineHighlight",
|
||||||
"gui.main",
|
"gui.main",
|
||||||
"gui.imports",
|
"gui.imports",
|
||||||
"highlightPC",
|
"highlightPC",
|
||||||
@ -31,6 +31,8 @@ const QStringList ColorThemeWorker::cutterSpecificOptions = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const QStringList ColorThemeWorker::radare2UnusedOptions = {
|
const QStringList ColorThemeWorker::radare2UnusedOptions = {
|
||||||
|
"linehl",
|
||||||
|
"wordhl",
|
||||||
"graph.box",
|
"graph.box",
|
||||||
"graph.box2",
|
"graph.box2",
|
||||||
"graph.box3",
|
"graph.box3",
|
||||||
@ -115,20 +117,26 @@ QString ColorThemeWorker::save(const QJsonDocument &theme, const QString &themeN
|
|||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject obj = theme.object();
|
QJsonObject obj = theme.object();
|
||||||
|
QString line;
|
||||||
|
QColor::NameFormat format;
|
||||||
for (auto it = obj.constBegin(); it != obj.constEnd(); it++) {
|
for (auto it = obj.constBegin(); it != obj.constEnd(); it++) {
|
||||||
QString line;
|
|
||||||
if (cutterSpecificOptions.contains(it.key())) {
|
if (cutterSpecificOptions.contains(it.key())) {
|
||||||
line = "#~%1 %2\n";
|
line = "#~%1 %2\n";
|
||||||
|
format = QColor::HexArgb;
|
||||||
} else {
|
} else {
|
||||||
line = "ec %1 %2\n";
|
line = "ec %1 %2\n";
|
||||||
|
format = QColor::HexRgb;
|
||||||
}
|
}
|
||||||
QJsonArray arr = it.value().toArray();
|
QJsonArray arr = it.value().toArray();
|
||||||
if (arr.isEmpty()) {
|
if (arr.isEmpty()) {
|
||||||
fOut.write(line.arg(it.key())
|
fOut.write(line.arg(it.key())
|
||||||
.arg(it.value().toVariant().value<QColor>().name()).toUtf8());
|
.arg(it.value().toVariant().value<QColor>().name(format)).toUtf8());
|
||||||
|
} else if (arr.size() == 4) {
|
||||||
|
fOut.write(line.arg(it.key())
|
||||||
|
.arg(QColor(arr[0].toInt(), arr[1].toInt(), arr[2].toInt(), arr[3].toInt()).name(format)).toUtf8());
|
||||||
} else if (arr.size() == 3) {
|
} else if (arr.size() == 3) {
|
||||||
fOut.write(line.arg(it.key())
|
fOut.write(line.arg(it.key())
|
||||||
.arg(QColor(arr[0].toInt(), arr[1].toInt(), arr[2].toInt()).name()).toUtf8());
|
.arg(QColor(arr[0].toInt(), arr[1].toInt(), arr[2].toInt()).name(format)).toUtf8());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +157,7 @@ bool ColorThemeWorker::isThemeExist(const QString &name) const
|
|||||||
|
|
||||||
QJsonDocument ColorThemeWorker::getTheme(const QString& themeName) const
|
QJsonDocument ColorThemeWorker::getTheme(const QString& themeName) const
|
||||||
{
|
{
|
||||||
int r, g, b;
|
int r, g, b, a;
|
||||||
QJsonObject theme;
|
QJsonObject theme;
|
||||||
QString curr = Config()->getColorTheme();
|
QString curr = Config()->getColorTheme();
|
||||||
|
|
||||||
@ -172,14 +180,23 @@ QJsonDocument ColorThemeWorker::getTheme(const QString& themeName) const
|
|||||||
if (sl.size() != 3 || sl[0][0] == '#') {
|
if (sl.size() != 3 || sl[0][0] == '#') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
QColor(sl[2]).getRgb(&r, &g, &b);
|
QColor(sl[2]).getRgb(&r, &g, &b, &a);
|
||||||
theme.insert(sl[1], QJsonArray({r, g, b}));
|
theme.insert(sl[1], QJsonArray({r, g, b, a}));
|
||||||
|
}
|
||||||
|
for (auto &it : cutterSpecificOptions) {
|
||||||
|
if (!theme.contains(it)) {
|
||||||
|
mergeColors(Config()->getColor(it),
|
||||||
|
Config()->getColor("gui.background")).getRgb(&r, &g, &b, &a);
|
||||||
|
Config()->getColor(it).getRgb(&r, &g, &b, &a);
|
||||||
|
theme.insert(it, QJsonArray({r, g, b, a}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (auto &it : cutterSpecificOptions) {
|
for (auto &it : cutterSpecificOptions) {
|
||||||
mergeColors(Config()->getColor(it),
|
mergeColors(Config()->getColor(it),
|
||||||
Config()->getColor("gui.background")).getRgb(&r, &g, &b);
|
Config()->getColor("gui.background")).getRgb(&r, &g, &b, &a);
|
||||||
theme.insert(it, QJsonArray({r, g, b}));
|
Config()->getColor(it).getRgb(&r, &g, &b, &a);
|
||||||
|
theme.insert(it, QJsonArray({r, g, b, a}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,7 +294,7 @@ bool ColorThemeWorker::isFileTheme(const QString& filePath, bool* ok) const
|
|||||||
QString options = (Core()->cmdj("ecj").object().keys() << cutterSpecificOptions)
|
QString options = (Core()->cmdj("ecj").object().keys() << cutterSpecificOptions)
|
||||||
.join('|')
|
.join('|')
|
||||||
.replace(".", "\\.");
|
.replace(".", "\\.");
|
||||||
QRegExp regexp = QRegExp(QString("((ec\\s+(%1)\\s+(((rgb:|#)([0-9a-fA-F]{3}){1,2})|(%2))))\\s*")
|
QRegExp regexp = QRegExp(QString("((ec\\s+(%1)\\s+(((rgb:|#)[0-9a-fA-F]{3,8})|(%2))))\\s*")
|
||||||
.arg(options)
|
.arg(options)
|
||||||
.arg(colors));
|
.arg(colors));
|
||||||
|
|
||||||
|
@ -248,8 +248,8 @@ void Configuration::loadNativeTheme()
|
|||||||
setColor("gui.background", QColor(30, 30, 30));
|
setColor("gui.background", QColor(30, 30, 30));
|
||||||
setColor("gui.alt_background", QColor(42, 42, 42));
|
setColor("gui.alt_background", QColor(42, 42, 42));
|
||||||
setColor("gui.disass_selected", QColor(35, 35, 35));
|
setColor("gui.disass_selected", QColor(35, 35, 35));
|
||||||
setColor("linehl", QColor(255, 255, 255, 15));
|
setColor("lineHighlight", QColor(255, 255, 255, 15));
|
||||||
setColor("wordhl", QColor(20, 20, 20, 255));
|
setColor("wordHighlight", QColor(20, 20, 20, 255));
|
||||||
setColor("highlightPC", QColor(87, 26, 7));
|
setColor("highlightPC", QColor(87, 26, 7));
|
||||||
setColor("gui.tooltip.background", QColor(42, 44, 46));
|
setColor("gui.tooltip.background", QColor(42, 44, 46));
|
||||||
setColor("gui.tooltip.foreground", QColor(250, 252, 254));
|
setColor("gui.tooltip.foreground", QColor(250, 252, 254));
|
||||||
@ -259,8 +259,8 @@ void Configuration::loadNativeTheme()
|
|||||||
setColor("gui.background", QColor(255, 255, 255));
|
setColor("gui.background", QColor(255, 255, 255));
|
||||||
setColor("gui.alt_background", QColor(245, 250, 255));
|
setColor("gui.alt_background", QColor(245, 250, 255));
|
||||||
setColor("gui.disass_selected", QColor(255, 255, 255));
|
setColor("gui.disass_selected", QColor(255, 255, 255));
|
||||||
setColor("linehl", QColor(210, 210, 255, 150));
|
setColor("lineHighlight", QColor(210, 210, 255, 150));
|
||||||
setColor("wordhl", QColor(179, 119, 214, 60));
|
setColor("wordHighlight", QColor(179, 119, 214, 60));
|
||||||
setColor("highlightPC", QColor(214, 255, 210));
|
setColor("highlightPC", QColor(214, 255, 210));
|
||||||
setColor("gui.dataoffset", QColor(0, 0, 0));
|
setColor("gui.dataoffset", QColor(0, 0, 0));
|
||||||
}
|
}
|
||||||
@ -291,8 +291,8 @@ void Configuration::loadLightTheme()
|
|||||||
setColor("gui.background", QColor(255, 255, 255));
|
setColor("gui.background", QColor(255, 255, 255));
|
||||||
setColor("gui.alt_background", QColor(245, 250, 255));
|
setColor("gui.alt_background", QColor(245, 250, 255));
|
||||||
setColor("gui.disass_selected", QColor(255, 255, 255));
|
setColor("gui.disass_selected", QColor(255, 255, 255));
|
||||||
setColor("linehl", QColor(210, 210, 255, 150));
|
setColor("lineHighlight", QColor(210, 210, 255, 150));
|
||||||
setColor("wordhl", QColor(179, 119, 214, 60));
|
setColor("wordHighlight", QColor(179, 119, 214, 60));
|
||||||
setColor("highlightPC", QColor(214, 255, 210));
|
setColor("highlightPC", QColor(214, 255, 210));
|
||||||
setColor("gui.navbar.empty", QColor(220, 236, 245));
|
setColor("gui.navbar.empty", QColor(220, 236, 245));
|
||||||
setColor("gui.navbar.err", QColor(3, 170, 245));
|
setColor("gui.navbar.err", QColor(3, 170, 245));
|
||||||
@ -363,8 +363,8 @@ void Configuration::loadDarkTheme()
|
|||||||
// Disassembly line selected
|
// Disassembly line selected
|
||||||
setColor("gui.tooltip.background", QColor(42, 44, 46));
|
setColor("gui.tooltip.background", QColor(42, 44, 46));
|
||||||
setColor("gui.tooltip.foreground", QColor(250, 252, 254));
|
setColor("gui.tooltip.foreground", QColor(250, 252, 254));
|
||||||
setColor("linehl", QColor(21, 29, 29, 150));
|
setColor("lineHighlight", QColor(21, 29, 29, 150));
|
||||||
setColor("wordhl", QColor(52, 58, 71, 255));
|
setColor("wordHighlight", QColor(52, 58, 71, 255));
|
||||||
}
|
}
|
||||||
|
|
||||||
const QFont Configuration::getFont() const
|
const QFont Configuration::getFont() const
|
||||||
@ -462,10 +462,10 @@ void Configuration::setColorTheme(const QString &theme)
|
|||||||
QJsonObject colorTheme = ThemeWorker().getTheme(theme).object();
|
QJsonObject colorTheme = ThemeWorker().getTheme(theme).object();
|
||||||
for (auto it = colorTheme.constBegin(); it != colorTheme.constEnd(); it++) {
|
for (auto it = colorTheme.constBegin(); it != colorTheme.constEnd(); it++) {
|
||||||
QJsonArray rgb = it.value().toArray();
|
QJsonArray rgb = it.value().toArray();
|
||||||
if (rgb.size() != 3) {
|
if (rgb.size() != 4) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
setColor(it.key(), QColor(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt()));
|
setColor(it.key(), QColor(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt(), rgb[3].toInt()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trick Cutter to load colors that are not specified in standard theme
|
// Trick Cutter to load colors that are not specified in standard theme
|
||||||
|
@ -118,7 +118,7 @@ void XrefsDialog::highlightCurrentLine()
|
|||||||
if (ui->previewTextEdit->isReadOnly()) {
|
if (ui->previewTextEdit->isReadOnly()) {
|
||||||
QTextEdit::ExtraSelection selection = QTextEdit::ExtraSelection();
|
QTextEdit::ExtraSelection selection = QTextEdit::ExtraSelection();
|
||||||
|
|
||||||
selection.format.setBackground(ConfigColor("linehl"));
|
selection.format.setBackground(ConfigColor("lineHighlight"));
|
||||||
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
|
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
|
||||||
selection.cursor = ui->previewTextEdit->textCursor();
|
selection.cursor = ui->previewTextEdit->textCursor();
|
||||||
selection.cursor.clearSelection();
|
selection.cursor.clearSelection();
|
||||||
|
@ -35,7 +35,15 @@ ColorThemeEditDialog::ColorThemeEditDialog(QWidget *parent) :
|
|||||||
previewDisasmWidget, &DisassemblyWidget::colorsUpdatedSlot);
|
previewDisasmWidget, &DisassemblyWidget::colorsUpdatedSlot);
|
||||||
|
|
||||||
connect(ui->colorThemeListView, &ColorThemeListView::itemChanged,
|
connect(ui->colorThemeListView, &ColorThemeListView::itemChanged,
|
||||||
ui->colorPicker, &ColorPicker::updateColor);
|
this, [this](const QColor& color) {
|
||||||
|
ui->colorPicker->updateColor(color);
|
||||||
|
QString optionName = ui->colorThemeListView->currentIndex()
|
||||||
|
.data(Qt::UserRole)
|
||||||
|
.value<ColorOption>()
|
||||||
|
.optionName;
|
||||||
|
ui->colorPicker->setAlphaEnabled(optionName == "wordHighlight" || optionName == "lineHighlight");
|
||||||
|
});
|
||||||
|
|
||||||
ui->colorThemeListView->setCurrentIndex(ui->colorThemeListView->model()->index(0, 0));
|
ui->colorThemeListView->setCurrentIndex(ui->colorThemeListView->model()->index(0, 0));
|
||||||
|
|
||||||
connect(ui->colorPicker, &ColorPicker::colorChanged, this, &ColorThemeEditDialog::colorOptionChanged);
|
connect(ui->colorPicker, &ColorPicker::colorChanged, this, &ColorThemeEditDialog::colorOptionChanged);
|
||||||
|
@ -33,11 +33,24 @@ void ColorPickArea::paintEvent(QPaintEvent* event)
|
|||||||
|
|
||||||
p.setPen(QPen(Qt::black, 3));
|
p.setPen(QPen(Qt::black, 3));
|
||||||
QPoint curr = colorToPoint(currColor);
|
QPoint curr = colorToPoint(currColor);
|
||||||
p.drawLine(curr - QPoint(0, 10), curr + QPoint(0, 10));
|
p.drawLine(curr - QPoint(0, 8), curr + QPoint(0, 8));
|
||||||
p.drawLine(curr - QPoint(10, 0), curr + QPoint(10, 0));
|
p.drawLine(curr - QPoint(8, 0), curr + QPoint(8, 0));
|
||||||
|
|
||||||
p.end();
|
p.end();
|
||||||
QWidget::paintEvent(event);
|
}
|
||||||
|
|
||||||
|
void ColorPickArea::setColor(const QColor& c)
|
||||||
|
{
|
||||||
|
if (c == currColor) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QPoint p1 = colorToPoint(currColor);
|
||||||
|
QPoint p2 = colorToPoint(c);
|
||||||
|
currColor = c;
|
||||||
|
repaint(QRect(p2 - QPoint(10, 10), p2 + QPoint(10, 10)));
|
||||||
|
repaint(QRect(p1 - QPoint(10, 10), p1 + QPoint(10, 10)));
|
||||||
|
|
||||||
|
emit colorChanged(currColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorPickerWidget::ColorPickerWidget(QWidget* parent) : ColorPickWidgetAbstract(parent)
|
ColorPickerWidget::ColorPickerWidget(QWidget* parent) : ColorPickWidgetAbstract(parent)
|
||||||
@ -63,11 +76,11 @@ void ColorPickerWidget::mouseMoveEvent(QMouseEvent* event)
|
|||||||
QColor ColorPickArea::pointToColor(int x, int y) const
|
QColor ColorPickArea::pointToColor(int x, int y) const
|
||||||
{
|
{
|
||||||
QColor color;
|
QColor color;
|
||||||
qreal h, s, v;
|
qreal h, s, v, a;
|
||||||
currColor.getHsvF(&h, &s, &v);
|
currColor.getHsvF(&h, &s, &v, &a);
|
||||||
color.setHsvF((qreal)x / width(),
|
color.setHsvF(qreal(x) / width(),
|
||||||
1.0 - (qreal)y / height(),
|
1.0 - qreal(y) / height(),
|
||||||
v);
|
v, a);
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +88,7 @@ QPoint ColorPickArea::colorToPoint(const QColor& color) const
|
|||||||
{
|
{
|
||||||
qreal h, s, v;
|
qreal h, s, v;
|
||||||
color.getHsvF(&h, &s, &v);
|
color.getHsvF(&h, &s, &v);
|
||||||
return QPoint(h * width(), (1.0 - s) * height());
|
return QPointF(h * width(), (1.0 - s) * height()).toPoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorPickerWidget::mouseEvent(QMouseEvent* event)
|
void ColorPickerWidget::mouseEvent(QMouseEvent* event)
|
||||||
@ -91,15 +104,18 @@ void ColorPickerWidget::mouseEvent(QMouseEvent* event)
|
|||||||
? rect().bottom() + 1
|
? rect().bottom() + 1
|
||||||
: rect().y());
|
: rect().y());
|
||||||
}
|
}
|
||||||
currColor = pointToColor(pos.x(), pos.y());
|
setColor(pointToColor(pos.x(), pos.y()));
|
||||||
emit colorChanged(currColor);
|
|
||||||
repaint(QRect(event->pos() - QPoint(10, 10), event->pos() + QPoint(10, 10)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorPickWidgetAbstract::setColor(const QColor& color)
|
void ColorValueBar::setColor(const QColor& c)
|
||||||
{
|
{
|
||||||
currColor = color;
|
if (c == currColor) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
currColor = c;
|
||||||
repaint();
|
repaint();
|
||||||
|
|
||||||
|
emit colorChanged(currColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorValueBar::paintEvent(QPaintEvent* event)
|
void ColorValueBar::paintEvent(QPaintEvent* event)
|
||||||
@ -110,22 +126,19 @@ void ColorValueBar::paintEvent(QPaintEvent* event)
|
|||||||
currColor.getHsvF(&h, &s, &v);
|
currColor.getHsvF(&h, &s, &v);
|
||||||
v = 1.0 - v;
|
v = 1.0 - v;
|
||||||
|
|
||||||
const int trianleSize = 10;
|
const int triangleSize = 10;
|
||||||
QRect barRect = rect();
|
QRect barRect = rect();
|
||||||
barRect.setWidth(barRect.width() - trianleSize);
|
barRect.setWidth(barRect.width() - triangleSize);
|
||||||
|
|
||||||
|
|
||||||
for (int y = barRect.y(); y <= barRect.bottom(); y++) {
|
for (int y = barRect.y(); y <= barRect.bottom(); y++) {
|
||||||
color.setHsvF(h, s, 1.0 - (qreal)y / height());
|
color.setHsvF(h, s, 1.0 - qreal(y) / height());
|
||||||
p.setPen(color);
|
p.setPen(color);
|
||||||
p.drawLine(barRect.x(), y, barRect.right(), y);
|
p.drawLine(barRect.x(), y, barRect.right(), y);
|
||||||
}
|
}
|
||||||
|
|
||||||
p.setPen(palette().alternateBase().color());
|
QRectF triangleRect = QRectF(barRect.right(), v * height() - triangleSize / 2,
|
||||||
p.drawRect(rect());
|
triangleSize, triangleSize);
|
||||||
|
|
||||||
QRectF triangleRect = QRectF(barRect.right(), v * height() - trianleSize / 2,
|
|
||||||
trianleSize, trianleSize);
|
|
||||||
|
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
path.moveTo(triangleRect.left(), triangleRect.top() + triangleRect.height() / 2);
|
path.moveTo(triangleRect.left(), triangleRect.top() + triangleRect.height() / 2);
|
||||||
@ -143,9 +156,9 @@ QColor ColorValueBar::pointToColor(int x, int y) const
|
|||||||
{
|
{
|
||||||
Q_UNUSED(x)
|
Q_UNUSED(x)
|
||||||
QColor color = currColor;
|
QColor color = currColor;
|
||||||
qreal h, s, v;
|
qreal h, s, v, a;
|
||||||
color.getHsvF(&h, &s, &v);
|
color.getHsvF(&h, &s, &v, &a);
|
||||||
color.setHsvF(h, s, 1.0 - (qreal)y / height());
|
color.setHsvF(h, s, 1.0 - qreal(y) / height(), a);
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +166,7 @@ QPoint ColorValueBar::colorToPoint(const QColor& color) const
|
|||||||
{
|
{
|
||||||
qreal h, s, v;
|
qreal h, s, v;
|
||||||
color.getHsvF(&h, &s, &v);
|
color.getHsvF(&h, &s, &v);
|
||||||
return QPoint(rect().x(), (1.0 - v) * height());
|
return QPoint(rect().x(), int((1.0 - v) * height()));
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorPicker::ColorPicker(QWidget* parent) :
|
ColorPicker::ColorPicker(QWidget* parent) :
|
||||||
@ -166,12 +179,16 @@ ColorPicker::ColorPicker(QWidget* parent) :
|
|||||||
this, &ColorPicker::setColor);
|
this, &ColorPicker::setColor);
|
||||||
connect(ui->valuePickBar, &ColorValueBar::colorChanged,
|
connect(ui->valuePickBar, &ColorValueBar::colorChanged,
|
||||||
this, &ColorPicker::setColor);
|
this, &ColorPicker::setColor);
|
||||||
|
connect(ui->alphaChannelBar, &AlphaChannelBar::colorChanged,
|
||||||
|
this, [this](const QColor& color) { emit colorChanged(color); });
|
||||||
connect(this, &ColorPicker::colorChanged,
|
connect(this, &ColorPicker::colorChanged,
|
||||||
ui->colorPickArea, &ColorPickArea::setColor);
|
ui->colorPickArea, &ColorPickArea::setColor);
|
||||||
connect(this, &ColorPicker::colorChanged,
|
connect(this, &ColorPicker::colorChanged,
|
||||||
ui->valuePickBar, &ColorValueBar::setColor);
|
ui->valuePickBar, &ColorValueBar::setColor);
|
||||||
connect(this, &ColorPicker::colorChanged,
|
connect(this, &ColorPicker::colorChanged,
|
||||||
ui->colorShow, &ColorShowWidget::setColor);
|
ui->colorShow, &ColorShowWidget::setColor);
|
||||||
|
connect(this, &ColorPicker::colorChanged,
|
||||||
|
ui->alphaChannelBar, &AlphaChannelBar::setColor);
|
||||||
|
|
||||||
connect(ui->hueSpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
|
connect(ui->hueSpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
|
||||||
this, &ColorPicker::colorChannelChanged);
|
this, &ColorPicker::colorChannelChanged);
|
||||||
@ -247,6 +264,12 @@ void ColorPicker::updateColor(const QColor& color)
|
|||||||
QSignalBlocker s5(ui->hueSpinBox);
|
QSignalBlocker s5(ui->hueSpinBox);
|
||||||
|
|
||||||
QSignalBlocker s6(ui->hexLineEdit);
|
QSignalBlocker s6(ui->hexLineEdit);
|
||||||
|
|
||||||
|
QSignalBlocker s7(ui->alphaChannelBar);
|
||||||
|
QSignalBlocker s8(ui->colorPickArea);
|
||||||
|
QSignalBlocker s9(ui->colorShow);
|
||||||
|
QSignalBlocker s10(ui->valuePickBar);
|
||||||
|
|
||||||
currColor = color;
|
currColor = color;
|
||||||
|
|
||||||
ui->hexLineEdit->setText(currColor.name());
|
ui->hexLineEdit->setText(currColor.name());
|
||||||
@ -266,6 +289,7 @@ void ColorPicker::updateColor(const QColor& color)
|
|||||||
ui->valuePickBar->setColor(color);
|
ui->valuePickBar->setColor(color);
|
||||||
ui->colorPickArea->setColor(color);
|
ui->colorPickArea->setColor(color);
|
||||||
ui->colorShow->setColor(color);
|
ui->colorShow->setColor(color);
|
||||||
|
ui->alphaChannelBar->setColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorPicker::startPickingFromScreen()
|
void ColorPicker::startPickingFromScreen()
|
||||||
@ -311,6 +335,11 @@ bool ColorPicker::isPickingFromScreen() const
|
|||||||
return pickingFromScreen;
|
return pickingFromScreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ColorPicker::setAlphaEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
ui->alphaChannelBar->setVisible(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
void ColorPicker::stopPickingFromScreen()
|
void ColorPicker::stopPickingFromScreen()
|
||||||
{
|
{
|
||||||
if (pickingFromScreen) {
|
if (pickingFromScreen) {
|
||||||
@ -323,11 +352,89 @@ void ColorPicker::stopPickingFromScreen()
|
|||||||
|
|
||||||
ColorShowWidget::ColorShowWidget(QWidget* parent) : ColorPickWidgetAbstract(parent) { }
|
ColorShowWidget::ColorShowWidget(QWidget* parent) : ColorPickWidgetAbstract(parent) { }
|
||||||
|
|
||||||
|
void ColorShowWidget::setColor(const QColor& c)
|
||||||
|
{
|
||||||
|
currColor = c;
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
void ColorShowWidget::paintEvent(QPaintEvent* event)
|
void ColorShowWidget::paintEvent(QPaintEvent* event)
|
||||||
{
|
{
|
||||||
QPainter p(this);
|
QPainter p(this);
|
||||||
|
const int miniRectWidth = rect().width() / 2;
|
||||||
|
for (int y = rect().topLeft().ry(); y < rect().bottomRight().ry(); y++) {
|
||||||
|
for (int x = rect().topLeft().rx(); x < rect().bottomRight().rx(); x++) {
|
||||||
|
p.setPen(((x % miniRectWidth) / (miniRectWidth / 2)) == ((y % miniRectWidth) / (miniRectWidth / 2))
|
||||||
|
? Qt::white
|
||||||
|
: Qt::black);
|
||||||
|
p.drawPoint(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
p.setPen(currColor);
|
p.setPen(currColor);
|
||||||
p.setBrush(QBrush(currColor));
|
p.setBrush(QBrush(currColor));
|
||||||
p.drawRect(event->rect());
|
p.drawRect(event->rect());
|
||||||
p.end();
|
p.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AlphaChannelBar::setColor(const QColor& c)
|
||||||
|
{
|
||||||
|
if (c == currColor) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
currColor = c;
|
||||||
|
repaint();
|
||||||
|
emit colorChanged(currColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AlphaChannelBar::paintEvent(QPaintEvent* event)
|
||||||
|
{
|
||||||
|
QPainter p(this);
|
||||||
|
QRect barRect = rect();
|
||||||
|
|
||||||
|
qreal h, s, v, a;
|
||||||
|
currColor.getHsvF(&h, &s, &v, &a);
|
||||||
|
a = 1.0 - a;
|
||||||
|
const int triangleSize = 10;
|
||||||
|
|
||||||
|
barRect.setWidth(barRect.width() - triangleSize);
|
||||||
|
|
||||||
|
const int miniRectWidth = barRect.width() / 2;
|
||||||
|
for (int y = barRect.topLeft().ry(); y < barRect.bottomRight().ry(); y++) {
|
||||||
|
for (int x = barRect.topLeft().rx(); x < barRect.bottomRight().rx(); x++) {
|
||||||
|
p.setPen(((x % miniRectWidth) / (miniRectWidth / 2)) == ((y % miniRectWidth) / (miniRectWidth / 2))
|
||||||
|
? Qt::white
|
||||||
|
: Qt::black);
|
||||||
|
p.drawPoint(x, y);
|
||||||
|
p.setPen(pointToColor(x, y));
|
||||||
|
p.drawPoint(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF triangleRect = QRectF(barRect.right(), a * height() - triangleSize / 2,
|
||||||
|
triangleSize, triangleSize);
|
||||||
|
|
||||||
|
QPainterPath path;
|
||||||
|
path.moveTo(triangleRect.left(), triangleRect.top() + triangleRect.height() / 2);
|
||||||
|
path.lineTo(triangleRect.topRight());
|
||||||
|
path.lineTo(triangleRect.bottomRight());
|
||||||
|
path.lineTo(triangleRect.left(), triangleRect.top() + triangleRect.height() / 2);
|
||||||
|
p.fillPath(path, palette().text().color());
|
||||||
|
|
||||||
|
p.end();
|
||||||
|
QWidget::paintEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor AlphaChannelBar::pointToColor(int x, int y) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(x)
|
||||||
|
QColor color = currColor;
|
||||||
|
qreal h, s, v;
|
||||||
|
color.getHsvF(&h, &s, &v);
|
||||||
|
color.setHsvF(h, s, v, 1.0 - qreal(y) / height());
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPoint AlphaChannelBar::colorToPoint(const QColor &) const
|
||||||
|
{
|
||||||
|
return QPoint();
|
||||||
|
}
|
||||||
|
@ -19,7 +19,7 @@ signals:
|
|||||||
void colorChanged(const QColor& color);
|
void colorChanged(const QColor& color);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void setColor(const QColor& color);
|
virtual void setColor(const QColor& color) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QColor currColor;
|
QColor currColor;
|
||||||
@ -46,6 +46,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool isPickingFromScreen() const;
|
bool isPickingFromScreen() const;
|
||||||
|
|
||||||
|
void setAlphaEnabled(bool enabled);
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/**
|
/**
|
||||||
@ -101,8 +103,7 @@ protected:
|
|||||||
void mousePressEvent(QMouseEvent* event) override;
|
void mousePressEvent(QMouseEvent* event) override;
|
||||||
void mouseMoveEvent(QMouseEvent* event) override;
|
void mouseMoveEvent(QMouseEvent* event) override;
|
||||||
|
|
||||||
private:
|
virtual void mouseEvent(QMouseEvent* event);
|
||||||
void mouseEvent(QMouseEvent* event);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief pointToColor converts coordinates on widget to color these coordinates represents.
|
* @brief pointToColor converts coordinates on widget to color these coordinates represents.
|
||||||
@ -121,6 +122,8 @@ class ColorShowWidget : public ColorPickWidgetAbstract
|
|||||||
public:
|
public:
|
||||||
explicit ColorShowWidget(QWidget *parent = nullptr);
|
explicit ColorShowWidget(QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
void setColor(const QColor& c) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
};
|
};
|
||||||
@ -135,6 +138,25 @@ class ColorPickArea : public ColorPickerWidget
|
|||||||
public:
|
public:
|
||||||
explicit ColorPickArea(QWidget *parent = nullptr);
|
explicit ColorPickArea(QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
void setColor(const QColor& c) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QColor pointToColor(int x, int y) const override;
|
||||||
|
|
||||||
|
QPoint colorToPoint(const QColor& color) const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class AlphaChannelBar : public ColorPickerWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
AlphaChannelBar(QWidget *parent = nullptr) : ColorPickerWidget(parent) {}
|
||||||
|
|
||||||
|
void setColor(const QColor& c) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
||||||
@ -154,6 +176,8 @@ class ColorValueBar : public ColorPickerWidget
|
|||||||
public:
|
public:
|
||||||
ColorValueBar(QWidget *parent = nullptr) : ColorPickerWidget(parent) {}
|
ColorValueBar(QWidget *parent = nullptr) : ColorPickerWidget(parent) {}
|
||||||
|
|
||||||
|
void setColor(const QColor& c) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
||||||
|
@ -48,6 +48,16 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="ColorPickerHelpers::AlphaChannelBar" name="alphaChannelBar" native="true">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>30</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@ -343,6 +353,12 @@
|
|||||||
<header>widgets/ColorPicker.h</header>
|
<header>widgets/ColorPicker.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>ColorPickerHelpers::AlphaChannelBar</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>widgets/ColorPicker.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
@ -336,10 +336,10 @@ void ColorSettingsModel::updateTheme()
|
|||||||
|
|
||||||
for (auto it = obj.constBegin(); it != obj.constEnd(); it++) {
|
for (auto it = obj.constBegin(); it != obj.constEnd(); it++) {
|
||||||
QJsonArray rgb = it.value().toArray();
|
QJsonArray rgb = it.value().toArray();
|
||||||
if (rgb.size() != 3) {
|
if (rgb.size() != 4) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
theme.push_back({it.key(), QColor(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt()), false});
|
theme.push_back({it.key(), QColor(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt(), rgb[3].toInt()), false});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!theme.isEmpty()) {
|
if (!theme.isEmpty()) {
|
||||||
@ -350,10 +350,10 @@ void ColorSettingsModel::updateTheme()
|
|||||||
QJsonDocument ColorSettingsModel::getTheme() const
|
QJsonDocument ColorSettingsModel::getTheme() const
|
||||||
{
|
{
|
||||||
QJsonObject obj;
|
QJsonObject obj;
|
||||||
int r, g, b;
|
int r, g, b, a;
|
||||||
for (auto &it : theme) {
|
for (auto &it : theme) {
|
||||||
it.color.getRgb(&r, &g, &b);
|
it.color.getRgb(&r, &g, &b, &a);
|
||||||
obj.insert(it.optionName, QJsonArray({r, g, b}));
|
obj.insert(it.optionName, QJsonArray({r, g, b, a}));
|
||||||
}
|
}
|
||||||
return QJsonDocument(obj);
|
return QJsonDocument(obj);
|
||||||
}
|
}
|
||||||
@ -739,13 +739,13 @@ const QMap<QString, OptionInfo> optionInfoMap__ = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"linehl", {
|
"lineHighlight", {
|
||||||
QObject::tr("Selected line background color"),
|
QObject::tr("Selected line background color"),
|
||||||
QObject::tr("Line highlight")
|
QObject::tr("Line highlight")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"wordhl", {
|
"wordHighlight", {
|
||||||
QObject::tr("Background color of selected word"),
|
QObject::tr("Background color of selected word"),
|
||||||
QObject::tr("Word higlight")
|
QObject::tr("Word higlight")
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "common/SyntaxHighlighter.h"
|
#include "common/SyntaxHighlighter.h"
|
||||||
#include "common/BasicBlockHighlighter.h"
|
#include "common/BasicBlockHighlighter.h"
|
||||||
|
|
||||||
|
#include <QColorDialog>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
@ -113,6 +114,39 @@ DisassemblerGraphView::DisassemblerGraphView(QWidget *parent)
|
|||||||
contextMenu->addSeparator();
|
contextMenu->addSeparator();
|
||||||
contextMenu->addAction(&actionSyncOffset);
|
contextMenu->addAction(&actionSyncOffset);
|
||||||
|
|
||||||
|
|
||||||
|
QAction *highlightBB = new QAction(this);
|
||||||
|
actionUnhighlight.setVisible(false);
|
||||||
|
|
||||||
|
highlightBB->setText(tr("Highlight block"));
|
||||||
|
connect(highlightBB, &QAction::triggered, this, [this]() {
|
||||||
|
auto bbh = Core()->getBBHighlighter();
|
||||||
|
RVA currBlockEntry = blockForAddress(this->seekable->getOffset())->entry;
|
||||||
|
|
||||||
|
QColor background = disassemblyBackgroundColor;
|
||||||
|
if (auto block = bbh->getBasicBlock(currBlockEntry)) {
|
||||||
|
background = block->color;
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor c = QColorDialog::getColor(background, this, QString(),
|
||||||
|
QColorDialog::DontUseNativeDialog);
|
||||||
|
if (c.isValid()) {
|
||||||
|
bbh->highlight(currBlockEntry, c);
|
||||||
|
}
|
||||||
|
Config()->colorsUpdated();
|
||||||
|
});
|
||||||
|
|
||||||
|
actionUnhighlight.setText(tr("Unhighlight block"));
|
||||||
|
connect(&actionUnhighlight, &QAction::triggered, this, [this]() {
|
||||||
|
auto bbh = Core()->getBBHighlighter();
|
||||||
|
bbh->clear(blockForAddress(this->seekable->getOffset())->entry);
|
||||||
|
Config()->colorsUpdated();
|
||||||
|
});
|
||||||
|
|
||||||
|
blockMenu->addAction(highlightBB);
|
||||||
|
blockMenu->addAction(&actionUnhighlight);
|
||||||
|
|
||||||
|
|
||||||
// Include all actions from generic context menu in block specific menu
|
// Include all actions from generic context menu in block specific menu
|
||||||
blockMenu->addSeparator();
|
blockMenu->addSeparator();
|
||||||
blockMenu->addActions(contextMenu->actions());
|
blockMenu->addActions(contextMenu->actions());
|
||||||
@ -455,9 +489,7 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block)
|
|||||||
auto bb = Core()->getBBHighlighter()->getBasicBlock(block.entry);
|
auto bb = Core()->getBBHighlighter()->getBasicBlock(block.entry);
|
||||||
if (bb) {
|
if (bb) {
|
||||||
QColor color(bb->color);
|
QColor color(bb->color);
|
||||||
color.setAlphaF(0.5);
|
|
||||||
p.setBrush(color);
|
p.setBrush(color);
|
||||||
// Add basic block highlighting transparent color
|
|
||||||
p.drawRect(blockX, blockY,
|
p.drawRect(blockX, blockY,
|
||||||
block.width, block.height);
|
block.width, block.height);
|
||||||
}
|
}
|
||||||
@ -507,7 +539,7 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block)
|
|||||||
highlightWidth = block.width - widthBefore - (10 + 2 * padding);
|
highlightWidth = block.width - widthBefore - (10 + 2 * padding);
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor selectionColor = ConfigColor("wordhl");
|
QColor selectionColor = ConfigColor("wordHighlight");
|
||||||
|
|
||||||
p.fillRect(QRectF(blockX + charWidth * 3 + widthBefore, y, highlightWidth,
|
p.fillRect(QRectF(blockX + charWidth * 3 + widthBefore, y, highlightWidth,
|
||||||
charHeight), selectionColor);
|
charHeight), selectionColor);
|
||||||
@ -714,7 +746,7 @@ void DisassemblerGraphView::colorsUpdatedSlot()
|
|||||||
mDisabledBreakpointColor = disassemblyBackgroundColor;
|
mDisabledBreakpointColor = disassemblyBackgroundColor;
|
||||||
graphNodeColor = ConfigColor("gui.border");
|
graphNodeColor = ConfigColor("gui.border");
|
||||||
backgroundColor = ConfigColor("gui.background");
|
backgroundColor = ConfigColor("gui.background");
|
||||||
disassemblySelectionColor = ConfigColor("linehl");
|
disassemblySelectionColor = ConfigColor("lineHighlight");
|
||||||
PCSelectionColor = ConfigColor("highlightPC");
|
PCSelectionColor = ConfigColor("highlightPC");
|
||||||
|
|
||||||
jmpColor = ConfigColor("graph.trufae");
|
jmpColor = ConfigColor("graph.trufae");
|
||||||
@ -947,6 +979,7 @@ void DisassemblerGraphView::blockClicked(GraphView::GraphBlock &block, QMouseEve
|
|||||||
blockMenu->setCurHighlightedWord(highlight_token->content);
|
blockMenu->setCurHighlightedWord(highlight_token->content);
|
||||||
}
|
}
|
||||||
if (event->button() == Qt::RightButton) {
|
if (event->button() == Qt::RightButton) {
|
||||||
|
actionUnhighlight.setVisible(Core()->getBBHighlighter()->getBasicBlock(block.entry));
|
||||||
event->accept();
|
event->accept();
|
||||||
blockMenu->exec(event->globalPos());
|
blockMenu->exec(event->globalPos());
|
||||||
}
|
}
|
||||||
|
@ -204,6 +204,7 @@ private:
|
|||||||
QColor mDisabledBreakpointColor;
|
QColor mDisabledBreakpointColor;
|
||||||
|
|
||||||
QAction actionExportGraph;
|
QAction actionExportGraph;
|
||||||
|
QAction actionUnhighlight;
|
||||||
QAction actionSyncOffset;
|
QAction actionSyncOffset;
|
||||||
|
|
||||||
QLabel *emptyText = nullptr;
|
QLabel *emptyText = nullptr;
|
||||||
|
@ -354,7 +354,7 @@ void DisassemblyWidget::highlightCurrentLine()
|
|||||||
{
|
{
|
||||||
QList<QTextEdit::ExtraSelection> extraSelections;
|
QList<QTextEdit::ExtraSelection> extraSelections;
|
||||||
|
|
||||||
QColor highlightColor = ConfigColor("linehl");
|
QColor highlightColor = ConfigColor("lineHighlight");
|
||||||
QColor highlightPCColor = ConfigColor("highlightPC");
|
QColor highlightPCColor = ConfigColor("highlightPC");
|
||||||
|
|
||||||
// Highlight the current word
|
// Highlight the current word
|
||||||
@ -600,7 +600,7 @@ QList<QTextEdit::ExtraSelection> DisassemblyWidget::getSameWordsSelections()
|
|||||||
QList<QTextEdit::ExtraSelection> selections;
|
QList<QTextEdit::ExtraSelection> selections;
|
||||||
QTextEdit::ExtraSelection highlightSelection;
|
QTextEdit::ExtraSelection highlightSelection;
|
||||||
QTextDocument *document = mDisasTextEdit->document();
|
QTextDocument *document = mDisasTextEdit->document();
|
||||||
QColor highlightWordColor = ConfigColor("wordhl");
|
QColor highlightWordColor = ConfigColor("wordHighlight");
|
||||||
|
|
||||||
if (curHighlightedWord.isNull()) {
|
if (curHighlightedWord.isNull()) {
|
||||||
return QList<QTextEdit::ExtraSelection>();
|
return QList<QTextEdit::ExtraSelection>();
|
||||||
|
Loading…
Reference in New Issue
Block a user