Add scaling and background transparency options to graph export (#2089)

This commit is contained in:
NIRMAL MANOJ C 2020-03-10 02:29:03 +05:30 committed by GitHub
parent a327a33c3e
commit d12aae2ac0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 106 additions and 11 deletions

View File

@ -707,3 +707,24 @@ void Configuration::setDecompilerAutoRefreshEnabled(bool enabled)
{
s.setValue("decompilerAutoRefresh", enabled);
}
bool Configuration::getBitmapTransparentState()
{
return s.value("bitmapGraphExportTransparency", false).value<bool>();
}
double Configuration::getBitmapExportScaleFactor()
{
return s.value("bitmapGraphExportScale", 1.0).value<double>();
}
void Configuration::setBitmapTransparentState(bool inputValueGraph)
{
s.setValue("bitmapGraphExportTransparency", inputValueGraph);
}
void Configuration::setBitmapExportScaleFactor(double inputValueGraph)
{
s.setValue("bitmapGraphExportScale", inputValueGraph);
}

View File

@ -18,6 +18,7 @@ namespace KSyntaxHighlighting {
class QSyntaxHighlighter;
class QTextDocument;
enum ColorFlags {
LightFlag = 1,
DarkFlag = 2,
@ -171,6 +172,15 @@ public:
bool getDecompilerAutoRefreshEnabled();
void setDecompilerAutoRefreshEnabled(bool enabled);
/**
* @brief Getters and setters for the transaparent option state and scale factor for bitmap graph exports.
*/
bool getBitmapTransparentState();
double getBitmapExportScaleFactor();
void setBitmapTransparentState(bool inputValueGraph);
void setBitmapExportScaleFactor(double inputValueGraph);
public slots:
void refreshFont();
signals:

View File

@ -14,9 +14,13 @@ GraphOptionsWidget::GraphOptionsWidget(PreferencesDialog *dialog)
ui(new Ui::GraphOptionsWidget)
{
ui->setupUi(this);
ui->checkTransparent->setChecked(Config()->getBitmapTransparentState());
ui->bitmapGraphScale->setValue(Config()->getBitmapExportScaleFactor()*100.0);
updateOptionsFromVars();
connect<void(QDoubleSpinBox::*)(double)>(ui->bitmapGraphScale, (&QDoubleSpinBox::valueChanged), this, &GraphOptionsWidget::bitmapGraphScaleValueChanged);
connect(ui->checkTransparent, &QCheckBox::stateChanged, this, &GraphOptionsWidget::checkTransparentStateChanged);
connect(Core(), SIGNAL(graphOptionsChanged()), this, SLOT(updateOptionsFromVars()));
}
@ -50,3 +54,15 @@ void GraphOptionsWidget::on_graphOffsetCheckBox_toggled(bool checked)
Config()->setConfig("graph.offset", checked);
triggerOptionsChanged();
}
void GraphOptionsWidget::checkTransparentStateChanged(int checked)
{
Config()->setBitmapTransparentState(checked);
}
void GraphOptionsWidget::bitmapGraphScaleValueChanged(double value)
{
double value_decimal = value/(double)100.0;
Config()->setBitmapExportScaleFactor(value_decimal);
}

View File

@ -21,7 +21,6 @@ class GraphOptionsWidget : public QDialog
public:
explicit GraphOptionsWidget(PreferencesDialog *dialog);
~GraphOptionsWidget();
private:
std::unique_ptr<Ui::GraphOptionsWidget> ui;
@ -32,6 +31,10 @@ private slots:
void on_maxColsSpinBox_valueChanged(int value);
void on_graphOffsetCheckBox_toggled(bool checked);
void checkTransparentStateChanged(int checked);
void bitmapGraphScaleValueChanged(double value);
};

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>567</width>
<height>79</height>
<width>557</width>
<height>175</height>
</rect>
</property>
<property name="windowTitle">
@ -36,6 +36,32 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="bitmapGraphScaleLabel">
<property name="text">
<string>Graph Bitmap Export Scale: </string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="bitmapGraphScale">
<property name="suffix">
<string>%</string>
</property>
<property name="decimals">
<number>0</number>
</property>
<property name="minimum">
<double>100.000000000000000</double>
</property>
<property name="maximum">
<double>30000.000000000000000</double>
</property>
<property name="singleStep">
<double>50.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
@ -59,6 +85,19 @@
<string>Show offsets (graph.offset)</string>
</property>
</widget>
<widget class="QCheckBox" name="checkTransparent">
<property name="geometry">
<rect>
<x>0</x>
<y>30</y>
<width>361</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Export Transparent Bitmap Graphs</string>
</property>
</widget>
</widget>
</item>
</layout>

View File

@ -1157,12 +1157,14 @@ void DisassemblerGraphView::onActionUnhighlightBITriggered()
void DisassemblerGraphView::exportGraph(QString filePath, GraphExportType type)
{
bool graphTransparent = Config()->getBitmapTransparentState();
double graphScaleFactor = Config()->getBitmapExportScaleFactor();
switch (type) {
case GraphExportType::Png:
this->saveAsBitmap(filePath, "png");
this->saveAsBitmap(filePath, "png", graphScaleFactor, graphTransparent);
break;
case GraphExportType::Jpeg:
this->saveAsBitmap(filePath, "jpg");
this->saveAsBitmap(filePath, "jpg", graphScaleFactor, false);
break;
case GraphExportType::Svg:
this->saveAsSvg(filePath);

View File

@ -397,13 +397,17 @@ void GraphView::paint(QPainter &p, QPoint offset, QRect viewport, qreal scale, b
}
}
void GraphView::saveAsBitmap(QString path, const char *format)
void GraphView::saveAsBitmap(QString path, const char *format, double scaler, bool transparent)
{
QImage image(width, height, QImage::Format_RGB32);
image.fill(backgroundColor);
QImage image(width*scaler, height*scaler, QImage::Format_ARGB32);
if(transparent){
image.fill(qRgba(0, 0, 0, 0));
}else{
image.fill(backgroundColor);
}
QPainter p;
p.begin(&image);
paint(p, QPoint(0, 0), image.rect(), 1.0, false);
paint(p, QPoint(0, 0), image.rect(), scaler, false);
p.end();
if (!image.save(path, format)) {
qWarning() << "Could not save image";

View File

@ -82,7 +82,7 @@ public:
void paint(QPainter &p, QPoint offset, QRect area, qreal scale = 1.0, bool interactive = true);
void saveAsBitmap(QString path, const char *format = nullptr);
void saveAsBitmap(QString path, const char *format = nullptr, double scaler = 1.0, bool transparent = false);
void saveAsSvg(QString path);
protected:
std::unordered_map<ut64, GraphBlock> blocks;