From 6cbabaa652e1e07ec158c722c8d1bf7b3727cb10 Mon Sep 17 00:00:00 2001 From: dnk-88 Date: Wed, 6 Jul 2011 04:38:38 +0300 Subject: [PATCH] Changed: #1301 Completed snapshot dialog. --- .../landscape_editor_window.cpp | 28 +++++++++- .../landscape_editor/landscape_scene.cpp | 54 +++++-------------- .../landscape_editor/landscape_scene.h | 3 +- .../landscape_editor/shapshot_dialog.ui | 40 +++++++++----- .../landscape_editor/snapshot_dialog.cpp | 26 +++++++++ .../landscape_editor/snapshot_dialog.h | 6 +++ 6 files changed, 100 insertions(+), 57 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.cpp index f2e2773be..5f5fad552 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.cpp @@ -152,7 +152,33 @@ void LandscapeEditorWindow::openSnapshotDialog() tr("Image file (*.png)")); setCursor(Qt::WaitCursor); - m_landscapeScene->snapshot(fileName, 128); + + NLLIGO::CZoneRegion &zoneRegion = m_zoneBuilder->currentZoneRegion()->ligoZoneRegion(); + sint32 regionMinX = zoneRegion.getMinX(); + sint32 regionMaxX = zoneRegion.getMaxX(); + sint32 regionMinY = zoneRegion.getMinY(); + sint32 regionMaxY = zoneRegion.getMaxY(); + + int regionWidth = (regionMaxX - regionMinX + 1); + int regionHeight = (regionMaxY - regionMinY + 1); + + int cellSize = m_landscapeScene->cellSize(); + QRectF rect(regionMinX * cellSize, abs(regionMaxY) * cellSize, regionWidth * cellSize, regionHeight * cellSize); + + if (dialog->isCustomSize()) + { + int widthSnapshot = dialog->widthSnapshot(); + int heightSnapshot = dialog->heightSnapshot(); + if (dialog->isKeepRatio()) + heightSnapshot = (widthSnapshot / regionWidth) * regionHeight; + + m_landscapeScene->snapshot(fileName, widthSnapshot, heightSnapshot, rect); + } + else + { + m_landscapeScene->snapshot(fileName, regionWidth * dialog->resolutionZone(), + regionHeight * dialog->resolutionZone(), rect); + } setCursor(Qt::ArrowCursor); } delete dialog; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.cpp index 82606f74a..81a94fb1f 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.cpp @@ -218,7 +218,6 @@ void LandscapeScene::addZoneRegion(const NLLIGO::CZoneRegion &zoneRegion) for (sint32 j = zoneRegion.getMinY(); j <= zoneRegion.getMaxY(); ++j) { - //nlinfo(QString("%1 %2 %3").arg(i).arg(j).arg(zoneRegion.getName(i, j).c_str()).toStdString().c_str()); std::string zoneName = zoneRegion.getName(i, j); if (zoneName == STRING_UNUSED) { @@ -251,53 +250,26 @@ void LandscapeScene::delZoneRegion(const NLLIGO::CZoneRegion &zoneRegion) } } -void LandscapeScene::snapshot(const QString &fileName, int sizeSource) -{ - /* if (m_zoneRegion == 0) - return; - - sint32 regionMinX = m_zoneRegion->getMinX(); - sint32 regionMaxX = m_zoneRegion->getMaxX(); - sint32 regionMinY = m_zoneRegion->getMinY(); - sint32 regionMaxY = m_zoneRegion->getMaxY(); - - int regionWidth = (regionMaxX - regionMinX + 1); - int regionHeight = (regionMaxY - regionMinY + 1); - - snapshot(fileName, regionWidth * sizeSource, regionHeight * sizeSource); - */ -} - -void LandscapeScene::snapshot(const QString &fileName, int width, int height) +void LandscapeScene::snapshot(const QString &fileName, int width, int height, const QRectF &landRect) { if (m_zoneBuilder == 0) return; - /* if (m_zoneRegion == 0) - return; + // Create image + QImage image(landRect.width(), landRect.height(), QImage::Format_RGB888); + QPainter painter(&image); + painter.setRenderHint(QPainter::Antialiasing, true); - sint32 regionMinX = m_zoneRegion->getMinX(); - sint32 regionMaxX = m_zoneRegion->getMaxX(); - sint32 regionMinY = m_zoneRegion->getMinY(); - sint32 regionMaxY = m_zoneRegion->getMaxY(); + // Add white background + painter.setBrush(QBrush(Qt::white)); + painter.setPen(Qt::NoPen); + painter.drawRect(0, 0, landRect.width(), landRect.height()); - int regionWidth = (regionMaxX - regionMinX + 1); - int regionHeight = (regionMaxY - regionMinY + 1); + // Paint landscape + render(&painter, QRectF(0, 0, landRect.width(), landRect.height()), landRect); - QImage image(width, height, QImage::Format_RGB888); - QPainter painter(&image); - painter.setRenderHint(QPainter::Antialiasing, true); - - // add white background - painter.setBrush(QBrush(Qt::white)); - painter.setPen(Qt::NoPen); - painter.drawRect(0, 0, width, height); - - render(&painter, QRectF(0, 0, width, height), - QRectF(regionMinX * m_cellSize, abs(regionMaxY) * m_cellSize, regionWidth * m_cellSize, regionHeight * m_cellSize)); - - image.save(fileName); - */ + QImage scaledImage = image.scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + scaledImage.save(fileName); } void LandscapeScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.h index 7e60febaf..34fe50e05 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.h @@ -57,8 +57,7 @@ public: void addZoneRegion(const NLLIGO::CZoneRegion &zoneRegion); void delZoneRegion(const NLLIGO::CZoneRegion &zoneRegion); - void snapshot(const QString &fileName, int sizeSource); - void snapshot(const QString &fileName, int width, int height); + void snapshot(const QString &fileName, int width, int height, const QRectF &landRect); protected: virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/shapshot_dialog.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/shapshot_dialog.ui index 792d9f7a4..1c25a2ace 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/shapshot_dialog.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/shapshot_dialog.ui @@ -6,8 +6,8 @@ 0 0 - 286 - 182 + 230 + 187 @@ -15,19 +15,33 @@ - - - Original size - - - true - - + + + + + Original size + + + true + + + + + + + 1024 + + + 128 + + + + - false + true Custom size @@ -59,7 +73,7 @@ false - TextLabel + Height: heightSpinBox @@ -82,7 +96,7 @@ - TextLabel + Width: widthSpinBox diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/snapshot_dialog.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/snapshot_dialog.cpp index ff6ef1673..ab2579722 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/snapshot_dialog.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/snapshot_dialog.cpp @@ -36,10 +36,36 @@ SnapshotDialog::SnapshotDialog(QWidget *parent) : QDialog(parent) { m_ui.setupUi(this); + setFixedHeight(sizeHint().height()); } SnapshotDialog::~SnapshotDialog() { } +bool SnapshotDialog::isCustomSize() const +{ + return m_ui.customSizeRadioButton->isChecked(); +} + +bool SnapshotDialog::isKeepRatio() const +{ + return m_ui.keepRatioCheckBox->isChecked(); +} + +int SnapshotDialog::resolutionZone() const +{ + return m_ui.resSpinBox->value(); +} + +int SnapshotDialog::widthSnapshot() const +{ + return m_ui.widthSpinBox->value(); +} + +int SnapshotDialog::heightSnapshot() const +{ + return m_ui.heightSpinBox->value(); +} + } /* namespace LandscapeEditor */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/snapshot_dialog.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/snapshot_dialog.h index 906d59498..b66133a07 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/snapshot_dialog.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/snapshot_dialog.h @@ -34,6 +34,12 @@ public: SnapshotDialog(QWidget *parent = 0); ~SnapshotDialog(); + bool isCustomSize() const; + bool isKeepRatio() const; + int resolutionZone() const; + int widthSnapshot() const; + int heightSnapshot() const; + private Q_SLOTS: