Changed: #1301 Completed snapshot dialog.

This commit is contained in:
dnk-88 2011-07-06 04:38:38 +03:00
parent 712349f7f5
commit 46b4ff3a6d
6 changed files with 100 additions and 57 deletions

View file

@ -152,7 +152,33 @@ void LandscapeEditorWindow::openSnapshotDialog()
tr("Image file (*.png)")); tr("Image file (*.png)"));
setCursor(Qt::WaitCursor); 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); setCursor(Qt::ArrowCursor);
} }
delete dialog; delete dialog;

View file

@ -218,7 +218,6 @@ void LandscapeScene::addZoneRegion(const NLLIGO::CZoneRegion &zoneRegion)
for (sint32 j = zoneRegion.getMinY(); j <= zoneRegion.getMaxY(); ++j) 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); std::string zoneName = zoneRegion.getName(i, j);
if (zoneName == STRING_UNUSED) if (zoneName == STRING_UNUSED)
{ {
@ -251,53 +250,26 @@ void LandscapeScene::delZoneRegion(const NLLIGO::CZoneRegion &zoneRegion)
} }
} }
void LandscapeScene::snapshot(const QString &fileName, int sizeSource) void LandscapeScene::snapshot(const QString &fileName, int width, int height, const QRectF &landRect)
{
/* 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)
{ {
if (m_zoneBuilder == 0) if (m_zoneBuilder == 0)
return; return;
/* if (m_zoneRegion == 0) // Create image
return; QImage image(landRect.width(), landRect.height(), QImage::Format_RGB888);
QPainter painter(&image);
painter.setRenderHint(QPainter::Antialiasing, true);
sint32 regionMinX = m_zoneRegion->getMinX(); // Add white background
sint32 regionMaxX = m_zoneRegion->getMaxX(); painter.setBrush(QBrush(Qt::white));
sint32 regionMinY = m_zoneRegion->getMinY(); painter.setPen(Qt::NoPen);
sint32 regionMaxY = m_zoneRegion->getMaxY(); painter.drawRect(0, 0, landRect.width(), landRect.height());
int regionWidth = (regionMaxX - regionMinX + 1); // Paint landscape
int regionHeight = (regionMaxY - regionMinY + 1); render(&painter, QRectF(0, 0, landRect.width(), landRect.height()), landRect);
QImage image(width, height, QImage::Format_RGB888); QImage scaledImage = image.scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
QPainter painter(&image); scaledImage.save(fileName);
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);
*/
} }
void LandscapeScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) void LandscapeScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)

View file

@ -57,8 +57,7 @@ public:
void addZoneRegion(const NLLIGO::CZoneRegion &zoneRegion); void addZoneRegion(const NLLIGO::CZoneRegion &zoneRegion);
void delZoneRegion(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, const QRectF &landRect);
void snapshot(const QString &fileName, int width, int height);
protected: protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent); virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);

View file

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>286</width> <width>230</width>
<height>182</height> <height>187</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -15,19 +15,33 @@
</property> </property>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QRadioButton" name="originalSizeRadioButton"> <layout class="QHBoxLayout" name="horizontalLayout">
<property name="text"> <item>
<string>Original size</string> <widget class="QRadioButton" name="originalSizeRadioButton">
</property> <property name="text">
<property name="checked"> <string>Original size</string>
<bool>true</bool> </property>
</property> <property name="checked">
</widget> <bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="resSpinBox">
<property name="maximum">
<number>1024</number>
</property>
<property name="value">
<number>128</number>
</property>
</widget>
</item>
</layout>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QRadioButton" name="customSizeRadioButton"> <widget class="QRadioButton" name="customSizeRadioButton">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>true</bool>
</property> </property>
<property name="text"> <property name="text">
<string>Custom size</string> <string>Custom size</string>
@ -59,7 +73,7 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="text"> <property name="text">
<string>TextLabel</string> <string>Height:</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>heightSpinBox</cstring> <cstring>heightSpinBox</cstring>
@ -82,7 +96,7 @@
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>TextLabel</string> <string>Width:</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>widthSpinBox</cstring> <cstring>widthSpinBox</cstring>

View file

@ -36,10 +36,36 @@ SnapshotDialog::SnapshotDialog(QWidget *parent)
: QDialog(parent) : QDialog(parent)
{ {
m_ui.setupUi(this); m_ui.setupUi(this);
setFixedHeight(sizeHint().height());
} }
SnapshotDialog::~SnapshotDialog() 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 */ } /* namespace LandscapeEditor */

View file

@ -34,6 +34,12 @@ public:
SnapshotDialog(QWidget *parent = 0); SnapshotDialog(QWidget *parent = 0);
~SnapshotDialog(); ~SnapshotDialog();
bool isCustomSize() const;
bool isKeepRatio() const;
int resolutionZone() const;
int widthSnapshot() const;
int heightSnapshot() const;
private Q_SLOTS: private Q_SLOTS: