mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-28 01:56:24 +00:00
Changed: #1301 Completed snapshot dialog.
--HG-- branch : gsoc2011-worldeditorqt
This commit is contained in:
parent
5d2c7b0a89
commit
808d0f1b8e
6 changed files with 100 additions and 57 deletions
|
@ -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;
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
QImage image(width, height, QImage::Format_RGB888);
|
|
||||||
QPainter painter(&image);
|
QPainter painter(&image);
|
||||||
painter.setRenderHint(QPainter::Antialiasing, true);
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||||
|
|
||||||
// add white background
|
// Add white background
|
||||||
painter.setBrush(QBrush(Qt::white));
|
painter.setBrush(QBrush(Qt::white));
|
||||||
painter.setPen(Qt::NoPen);
|
painter.setPen(Qt::NoPen);
|
||||||
painter.drawRect(0, 0, width, height);
|
painter.drawRect(0, 0, landRect.width(), landRect.height());
|
||||||
|
|
||||||
render(&painter, QRectF(0, 0, width, height),
|
// Paint landscape
|
||||||
QRectF(regionMinX * m_cellSize, abs(regionMaxY) * m_cellSize, regionWidth * m_cellSize, regionHeight * m_cellSize));
|
render(&painter, QRectF(0, 0, landRect.width(), landRect.height()), landRect);
|
||||||
|
|
||||||
image.save(fileName);
|
QImage scaledImage = image.scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||||
*/
|
scaledImage.save(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LandscapeScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
void LandscapeScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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,6 +15,8 @@
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_2">
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
<widget class="QRadioButton" name="originalSizeRadioButton">
|
<widget class="QRadioButton" name="originalSizeRadioButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Original size</string>
|
<string>Original size</string>
|
||||||
|
@ -24,10 +26,22 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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">
|
<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>
|
||||||
|
|
|
@ -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 */
|
||||||
|
|
|
@ -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:
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue