mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-19 13:46:13 +00:00
Changed: #1301 Completed snapshot dialog.
This commit is contained in:
parent
7d1a286de8
commit
6cbabaa652
6 changed files with 100 additions and 57 deletions
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>286</width>
|
||||
<height>182</height>
|
||||
<width>230</width>
|
||||
<height>187</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -15,19 +15,33 @@
|
|||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QRadioButton" name="originalSizeRadioButton">
|
||||
<property name="text">
|
||||
<string>Original size</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="originalSizeRadioButton">
|
||||
<property name="text">
|
||||
<string>Original size</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<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 row="1" column="0">
|
||||
<widget class="QRadioButton" name="customSizeRadioButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Custom size</string>
|
||||
|
@ -59,7 +73,7 @@
|
|||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
<string>Height:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>heightSpinBox</cstring>
|
||||
|
@ -82,7 +96,7 @@
|
|||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
<string>Width:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>widthSpinBox</cstring>
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue