ui: Fixed exporting images from the graph resulted in too large images (issue #511)

* Fixed style issue in save dialog on Linux
* Fixed wrong dialog used on Mac and Windows
* Improved image quality

bug id = 511
This commit is contained in:
Eberhard Graether
2017-11-17 22:41:43 +01:00
parent b887a4a89e
commit 37b6453644
3 changed files with 14 additions and 5 deletions
+10 -3
View File
@@ -92,6 +92,13 @@ void QtGraphicsView::setAppZoomFactor(float appZoomFactor)
updateTransform();
}
void QtGraphicsView::setSceneRect(const QRectF& rect)
{
QGraphicsView::setSceneRect(rect);
scene()->setSceneRect(rect);
}
QtGraphNode* QtGraphicsView::getNodeAtCursorPosition() const
{
QtGraphNode* node = nullptr;
@@ -409,11 +416,11 @@ void QtGraphicsView::stopTimer()
void QtGraphicsView::exportGraph()
{
QString fileName = QtFileDialog::showSaveFileDialog(
this, "Save image", QDir::homePath(), "PNG (*.png);;JPEG (*.JPEG);;BMP Files (*.bmp)");
nullptr, "Save image", QDir::homePath(), "PNG (*.png);;JPEG (*.JPEG);;BMP Files (*.bmp)");
if (!fileName.isNull())
{
QImage image(scene()->sceneRect().size().toSize(), QImage::Format_ARGB32);
QImage image(scene()->sceneRect().size().toSize() * 2, QImage::Format_ARGB32);
image.fill(Qt::transparent);
QPainter painter(&image);
@@ -421,7 +428,7 @@ void QtGraphicsView::exportGraph()
scene()->render(&painter);
image.save(fileName);
// different approach
// different approach: only currently visible part
// QPixmap pixMap = grab();
// pixMap.save(fileName);
}
+2
View File
@@ -22,6 +22,8 @@ public:
float getZoomFactor() const;
void setAppZoomFactor(float appZoomFactor);
void setSceneRect(const QRectF& rect);
QtGraphNode* getNodeAtCursorPosition() const;
void ensureVisibleAnimated(const QRectF& rect, int xmargin = 50, int ymargin = 50);
+2 -2
View File
@@ -51,7 +51,7 @@ QString QtFileDialog::getOpenFileName(QWidget* parent, const QString& caption, c
QString QtFileDialog::showSaveFileDialog(
QWidget *parent, const QString& title, const QString& directory, const QString& filter)
{
#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
return QFileDialog::getSaveFileName(parent, title, directory, filter);
@@ -92,7 +92,7 @@ QString QtFileDialog::showSaveFileDialog(
{
return QString();
}
#endif // Q_WS_MAC || Q_WS_WIN
#endif // Q_OS_MAC || Q_OS_WIN
}
QString QtFileDialog::getDir(QString dir)