Hi there!
So, this patch is a bit more than a proof-of-concept but not really a full-
blown feature (yet)
Play with it, break it and give me some feedback!
Thanks,
Thomas
P.S.: Maybe you are lucky and some very preliminary form of printing might
work also for you ;-)
Index: NativeRenderDialog.ui
===================================================================
--- NativeRenderDialog.ui (Revision 20077)
+++ NativeRenderDialog.ui (Arbeitskopie)
@@ -1,345 +1,352 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>NativeRenderDialog</class>
- <widget class="QDialog" name="NativeRenderDialog">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>446</width>
- <height>205</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Native rendering</string>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <widget class="QGroupBox" name="groupBox_2">
- <property name="title">
- <string>Render type</string>
- </property>
- <layout class="QGridLayout" name="gridLayout">
- <item row="0" column="0">
- <widget class="QRadioButton" name="rbSVG">
- <property name="text">
- <string>SVG</string>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QRadioButton" name="rbBitmap">
- <property name="text">
- <string>Bitmap</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- <item>
- <widget class="QGroupBox" name="groupBox">
- <property name="title">
- <string>Render options</string>
- </property>
- <layout class="QVBoxLayout">
- <item>
- <layout class="QHBoxLayout">
- <item>
- <layout class="QVBoxLayout">
- <item>
- <layout class="QHBoxLayout">
- <item>
- <widget class="QLabel" name="label_3">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="minimumSize">
- <size>
- <width>60</width>
- <height>0</height>
- </size>
- </property>
- <property name="text">
- <string>min lat/Lon</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QDoubleSpinBox" name="sbMinLat">
- <property name="minimumSize">
- <size>
- <width>60</width>
- <height>0</height>
- </size>
- </property>
- <property name="decimals">
- <number>6</number>
- </property>
- <property name="minimum">
- <double>-90.000000000000000</double>
- </property>
- <property name="maximum">
- <double>90.000000000000000</double>
- </property>
- <property name="singleStep">
- <double>0.010000000000000</double>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QDoubleSpinBox" name="sbMinLon">
- <property name="minimumSize">
- <size>
- <width>60</width>
- <height>0</height>
- </size>
- </property>
- <property name="decimals">
- <number>6</number>
- </property>
- <property name="minimum">
- <double>-180.000000000000000</double>
- </property>
- <property name="maximum">
- <double>180.000000000000000</double>
- </property>
- <property name="singleStep">
- <double>0.010000000000000</double>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <layout class="QHBoxLayout">
- <item>
- <widget class="QLabel" name="label_4">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="minimumSize">
- <size>
- <width>60</width>
- <height>0</height>
- </size>
- </property>
- <property name="text">
- <string>max lat/Lon</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QDoubleSpinBox" name="sbMaxLat">
- <property name="minimumSize">
- <size>
- <width>60</width>
- <height>0</height>
- </size>
- </property>
- <property name="decimals">
- <number>6</number>
- </property>
- <property name="minimum">
- <double>-90.000000000000000</double>
- </property>
- <property name="maximum">
- <double>90.000000000000000</double>
- </property>
- <property name="singleStep">
- <double>0.010000000000000</double>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QDoubleSpinBox" name="sbMaxLon">
- <property name="minimumSize">
- <size>
- <width>60</width>
- <height>0</height>
- </size>
- </property>
- <property name="decimals">
- <number>6</number>
- </property>
- <property name="minimum">
- <double>-180.000000000000000</double>
- </property>
- <property name="maximum">
- <double>180.000000000000000</double>
- </property>
- <property name="singleStep">
- <double>0.010000000000000</double>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
- </item>
- <item>
- <widget class="Line" name="line">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- </widget>
- </item>
- <item>
- <layout class="QVBoxLayout">
- <item>
- <widget class="QCheckBox" name="cbShowScale">
- <property name="enabled">
- <bool>false</bool>
- </property>
- <property name="text">
- <string>Show Scale</string>
- </property>
- <property name="tristate">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QCheckBox" name="cbShowGrid">
- <property name="enabled">
- <bool>false</bool>
- </property>
- <property name="text">
- <string>Show Grid</string>
- </property>
- <property name="tristate">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QCheckBox" name="cbShowBorders">
- <property name="enabled">
- <bool>false</bool>
- </property>
- <property name="text">
- <string>Show Borders</string>
- </property>
- <property name="tristate">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QCheckBox" name="cbShowLicense">
- <property name="enabled">
- <bool>false</bool>
- </property>
- <property name="text">
- <string>Show License</string>
- </property>
- <property name="tristate">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
- </item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <widget class="QLabel" name="label">
- <property name="text">
- <string>Width x Height (px)</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QSpinBox" name="sbPreviewWidth">
- <property name="maximum">
- <number>99999</number>
- </property>
- <property name="singleStep">
- <number>32</number>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLabel" name="label_2">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string>X</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QSpinBox" name="sbPreviewHeight">
- <property name="maximum">
- <number>99999</number>
- </property>
- <property name="singleStep">
- <number>32</number>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
- </widget>
- </item>
- <item>
- <widget class="QDialogButtonBox" name="buttonBox">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="standardButtons">
- <set>QDialogButtonBox::Close</set>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- <resources/>
- <connections>
- <connection>
- <sender>buttonBox</sender>
- <signal>accepted()</signal>
- <receiver>NativeRenderDialog</receiver>
- <slot>accept()</slot>
- <hints>
- <hint type="sourcelabel">
- <x>275</x>
- <y>193</y>
- </hint>
- <hint type="destinationlabel">
- <x>157</x>
- <y>274</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>buttonBox</sender>
- <signal>rejected()</signal>
- <receiver>NativeRenderDialog</receiver>
- <slot>reject()</slot>
- <hints>
- <hint type="sourcelabel">
- <x>343</x>
- <y>193</y>
- </hint>
- <hint type="destinationlabel">
- <x>286</x>
- <y>274</y>
- </hint>
- </hints>
- </connection>
- </connections>
-</ui>
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>NativeRenderDialog</class>
+ <widget class="QDialog" name="NativeRenderDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>446</width>
+ <height>286</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Native rendering</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QGroupBox" name="groupBox_2">
+ <property name="title">
+ <string>Render type</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QRadioButton" name="rbSVG">
+ <property name="text">
+ <string>SVG</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QRadioButton" name="rbBitmap">
+ <property name="text">
+ <string>Bitmap</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2">
+ <widget class="QRadioButton" name="rbPDF">
+ <property name="text">
+ <string>PDF</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>Render options</string>
+ </property>
+ <layout class="QVBoxLayout">
+ <item>
+ <layout class="QHBoxLayout">
+ <item>
+ <layout class="QVBoxLayout">
+ <item>
+ <layout class="QHBoxLayout">
+ <item>
+ <widget class="QLabel" name="label_3">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>60</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>min lat/Lon</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QDoubleSpinBox" name="sbMinLat">
+ <property name="minimumSize">
+ <size>
+ <width>60</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="decimals">
+ <number>6</number>
+ </property>
+ <property name="minimum">
+ <double>-90.000000000000000</double>
+ </property>
+ <property name="maximum">
+ <double>90.000000000000000</double>
+ </property>
+ <property name="singleStep">
+ <double>0.010000000000000</double>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QDoubleSpinBox" name="sbMinLon">
+ <property name="minimumSize">
+ <size>
+ <width>60</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="decimals">
+ <number>6</number>
+ </property>
+ <property name="minimum">
+ <double>-180.000000000000000</double>
+ </property>
+ <property name="maximum">
+ <double>180.000000000000000</double>
+ </property>
+ <property name="singleStep">
+ <double>0.010000000000000</double>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout">
+ <item>
+ <widget class="QLabel" name="label_4">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>60</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>max lat/Lon</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QDoubleSpinBox" name="sbMaxLat">
+ <property name="minimumSize">
+ <size>
+ <width>60</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="decimals">
+ <number>6</number>
+ </property>
+ <property name="minimum">
+ <double>-90.000000000000000</double>
+ </property>
+ <property name="maximum">
+ <double>90.000000000000000</double>
+ </property>
+ <property name="singleStep">
+ <double>0.010000000000000</double>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QDoubleSpinBox" name="sbMaxLon">
+ <property name="minimumSize">
+ <size>
+ <width>60</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="decimals">
+ <number>6</number>
+ </property>
+ <property name="minimum">
+ <double>-180.000000000000000</double>
+ </property>
+ <property name="maximum">
+ <double>180.000000000000000</double>
+ </property>
+ <property name="singleStep">
+ <double>0.010000000000000</double>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="Line" name="line">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QVBoxLayout">
+ <item>
+ <widget class="QCheckBox" name="cbShowScale">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Show Scale</string>
+ </property>
+ <property name="tristate">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="cbShowGrid">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Show Grid</string>
+ </property>
+ <property name="tristate">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="cbShowBorders">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Show Borders</string>
+ </property>
+ <property name="tristate">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="cbShowLicense">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Show License</string>
+ </property>
+ <property name="tristate">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Width x Height (px)</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSpinBox" name="sbPreviewWidth">
+ <property name="maximum">
+ <number>99999</number>
+ </property>
+ <property name="singleStep">
+ <number>32</number>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_2">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>X</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSpinBox" name="sbPreviewHeight">
+ <property name="maximum">
+ <number>99999</number>
+ </property>
+ <property name="singleStep">
+ <number>32</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Close</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>NativeRenderDialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>279</x>
+ <y>281</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>NativeRenderDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>347</x>
+ <y>281</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
Index: NativeRenderDialog.cpp
===================================================================
--- NativeRenderDialog.cpp (Revision 20077)
+++ NativeRenderDialog.cpp (Arbeitskopie)
@@ -24,6 +24,8 @@
#include <QProgressDialog>
#include <QPainter>
#include <QSvgGenerator>
+#include <QPrinter>
+#include <QPrintPreviewDialog>
NativeRenderDialog::NativeRenderDialog(Document *aDoc, const CoordBox& aCoordBox, QWidget *parent)
:QDialog(parent), theDoc(aDoc)
@@ -39,6 +41,7 @@
rbSVG->setChecked(Sets->value("rbSVG", true).toBool());
rbBitmap->setChecked(Sets->value("rbBitmap", false).toBool());
+ rbPDF->setChecked(Sets->value("rbPDF", false).toBool());
cbShowScale->setCheckState((Qt::CheckState)Sets->value("cbShowScale", "1").toInt());
cbShowGrid->setCheckState((Qt::CheckState)Sets->value("cbShowGrid", "1").toInt());
@@ -65,6 +68,7 @@
if (buttonBox->buttonRole(button) == QDialogButtonBox::ActionRole) {
Sets->setValue("rbSVG", rbSVG->isChecked());
Sets->setValue("rbBitmap", rbBitmap->isChecked());
+ Sets->setValue("rbPDF", rbPDF->isChecked());
Sets->setValue("cbShowScale", cbShowScale->checkState());
Sets->setValue("cbShowGrid", cbShowGrid->checkState());
Sets->setValue("cbShowBorders", cbShowBorders->checkState());
@@ -76,30 +80,11 @@
}
}
-void NativeRenderDialog::render()
+void NativeRenderDialog::renderMap(QPainter& P)
{
- QSvgGenerator svgg;
- QPixmap bitmap;
- QPainter P;
-
int w = sbPreviewWidth->value();
int h = sbPreviewHeight->value();
- if (rbSVG->isChecked()) {
- svgg.setFileName(QDir::tempPath()+"/tmp.svg");
- svgg.setSize(QSize(w,h));
-#if QT_VERSION >= 0x040500
- svgg.setViewBox(QRect(0, 0, w, h));
-#endif
-
- P.begin(&svgg);
- } else {
- QPixmap pix(w, h);
- bitmap = pix;
- P.begin(&bitmap);
- P.setRenderHint(QPainter::Antialiasing);
- }
-
MainWindow* mw = dynamic_cast<MainWindow*>(parentWidget());
MapView* vw = new MapView(NULL);
vw->setDocument(mw->document());
@@ -138,7 +123,6 @@
vw->drawFeatures(P, aProj);
M_PREFS->setTileToRegionThreshold(oldTileToRegionThreshold);
- P.end();
delete vw;
@@ -146,16 +130,81 @@
#ifndef Q_OS_SYMBIAN
QApplication::restoreOverrideCursor();
#endif
+}
+
+void NativeRenderDialog::render()
+{
+ QSvgGenerator svgg;
+ QPixmap bitmap;
+ QPrinter pdfPrinter(QPrinter::HighResolution);
+ //QPrinter pdfPrinter(QPrinter::ScreenResolution);
+ QPainter P;
+
+ int w = sbPreviewWidth->value();
+ int h = sbPreviewHeight->value();
+
if (rbSVG->isChecked()) {
+ svgg.setFileName(QDir::tempPath()+"/tmp.svg");
+ svgg.setSize(QSize(w,h));
+#if QT_VERSION >= 0x040500
+ svgg.setViewBox(QRect(0, 0, w, h));
+#endif
+
+ P.begin(&svgg);
+ } else if (rbBitmap->isChecked()) {
+ QPixmap pix(w, h);
+ bitmap = pix;
+ P.begin(&bitmap);
+ P.setRenderHint(QPainter::Antialiasing);
+ }
+
+ renderMap(P);
+
+ P.end();
+
+ if (rbSVG->isChecked()) {
PictureViewerDialog vwDlg(tr("Native rendering"), QDir::tempPath()+"/tmp.svg", this);
vwDlg.exec();
- } else {
+ } else if (rbBitmap->isChecked()) {
PictureViewerDialog vwDlg(tr("Native rendering"), bitmap, this);
vwDlg.exec();
+ } else if (rbPDF->isChecked()) {
+ pdfPrinter.setOutputFormat(QPrinter::PdfFormat);
+ pdfPrinter.setOutputFileName(QDir::tempPath() + "/tmp.pdf");
+ pdfPrinter.setOrientation((w > h ? QPrinter::Landscape : QPrinter::Portrait));
+ pdfPrinter.setFullPage(true);
+ //pdfPrinter.setPaperSize(QSizeF(w, h), QPrinter::DevicePixel);
+
+ QPrintPreviewDialog preview(&pdfPrinter, this);
+ connect(&preview, SIGNAL(paintRequested(QPrinter*)), this, SLOT(renderPDF(QPrinter*)));
+ preview.exec();
}
}
+void NativeRenderDialog::renderPDF(QPrinter* printer)
+{
+ QPainter P;
+ P.begin(printer);
+ P.setRenderHint(QPainter::Antialiasing);
+
+ int w = sbPreviewWidth->value();
+ int h = sbPreviewHeight->value();
+
+ QRect paperSize = printer->paperRect();
+
+ qreal wScale = paperSize.width() / static_cast<qreal>(w);
+ qreal hScale = paperSize.height() / static_cast<qreal>(h);
+
+ qreal scale = qMin(wScale, hScale);
+
+ P.scale(scale, scale);
+
+ renderMap(P);
+
+ P.end();
+}
+
void NativeRenderDialog::calcRatio()
{
CoordBox theB(Coord(
Index: NativeRenderDialog.h
===================================================================
--- NativeRenderDialog.h (Revision 20077)
+++ NativeRenderDialog.h (Arbeitskopie)
@@ -42,7 +42,11 @@
protected:
void calcRatio();
+ void renderMap(QPainter&);
+protected slots:
+ void renderPDF(QPrinter*);
+
private:
Document* theDoc;
QSettings* Sets;
_______________________________________________
Merkaartor mailing list
[email protected]
http://lists.openstreetmap.org/listinfo/merkaartor