Document's pageDpi is now stored in UBDocumentProxy rather than in UBSettings

This fixes an issue where if one document was imported with a different
DPI than the current one, any document created thereafter would have
this same value (which could then cause problems if a PDF was added to
that new document).

Saving this value to UBDocumentProxy not only makes more sense, it also
fixes this issue.
preferencesAboutTextFull
Craig Watson 9 years ago
parent 9ed35d1d0d
commit 3995d007a3
  1. 3
      src/adaptors/UBExportFullPDF.cpp
  2. 27
      src/adaptors/UBSvgSubsetAdaptor.cpp
  3. 6
      src/adaptors/UBSvgSubsetAdaptor.h
  4. 4
      src/core/UBSettings.cpp
  5. 2
      src/core/UBSettings.h
  6. 11
      src/document/UBDocumentProxy.cpp
  7. 5
      src/document/UBDocumentProxy.h

@ -211,7 +211,8 @@ bool UBExportFullPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, const QS
// If the PDF was scaled when added to the scene (e.g if it was loaded from a document with a different DPI // If the PDF was scaled when added to the scene (e.g if it was loaded from a document with a different DPI
// than the current one), it should also be scaled here. // than the current one), it should also be scaled here.
qreal currentDpi = (UBApplication::desktop()->physicalDpiX() + UBApplication::desktop()->physicalDpiY()) / 2; qreal currentDpi = (UBApplication::desktop()->physicalDpiX() + UBApplication::desktop()->physicalDpiY()) / 2;
qreal pdfScale = qreal(UBSettings::pageDpi)/currentDpi; qreal documentDpi = pDocumentProxy->pageDpi();
qreal pdfScale = documentDpi != 0 ? documentDpi/currentDpi : 1;
TransformationDescription pdfTransform(xPdfOffset, yPdfOffset, scaleFactor * pdfScale, 0); TransformationDescription pdfTransform(xPdfOffset, yPdfOffset, scaleFactor * pdfScale, 0);
TransformationDescription annotationTransform(xAnnotationsOffset, yAnnotationsOffset, 1, 0); TransformationDescription annotationTransform(xAnnotationsOffset, yAnnotationsOffset, 1, 0);

@ -334,7 +334,7 @@ QUuid UBSvgSubsetAdaptor::sceneUuid(UBDocumentProxy* proxy, const int pageIndex)
UBGraphicsScene* UBSvgSubsetAdaptor::loadScene(UBDocumentProxy* proxy, const QByteArray& pArray) UBGraphicsScene* UBSvgSubsetAdaptor::loadScene(UBDocumentProxy* proxy, const QByteArray& pArray)
{ {
UBSvgSubsetReader reader(proxy, UBTextTools::cleanHtmlCData(QString(pArray)).toUtf8()); UBSvgSubsetReader reader(proxy, UBTextTools::cleanHtmlCData(QString(pArray)).toUtf8());
return reader.loadScene(); return reader.loadScene(proxy);
} }
UBSvgSubsetAdaptor::UBSvgSubsetReader::UBSvgSubsetReader(UBDocumentProxy* pProxy, const QByteArray& pXmlData) UBSvgSubsetAdaptor::UBSvgSubsetReader::UBSvgSubsetReader(UBDocumentProxy* pProxy, const QByteArray& pXmlData)
@ -347,7 +347,7 @@ UBSvgSubsetAdaptor::UBSvgSubsetReader::UBSvgSubsetReader(UBDocumentProxy* pProxy
} }
UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene(UBDocumentProxy* proxy)
{ {
qDebug() << "loadScene() : starting reading..."; qDebug() << "loadScene() : starting reading...";
QTime time; QTime time;
@ -435,9 +435,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
QStringRef pageDpi = mXmlReader.attributes().value("pageDpi"); QStringRef pageDpi = mXmlReader.attributes().value("pageDpi");
if (!pageDpi.isNull()) if (!pageDpi.isNull())
UBSettings::pageDpi = pageDpi.toInt(); proxy->setPageDpi(pageDpi.toInt());
else else
UBSettings::pageDpi = (UBApplication::desktop()->physicalDpiX() + UBApplication::desktop()->physicalDpiY())/2; proxy->setPageDpi((UBApplication::desktop()->physicalDpiX() + UBApplication::desktop()->physicalDpiY())/2);
bool darkBackground = false; bool darkBackground = false;
bool crossedBackground = false; bool crossedBackground = false;
@ -769,7 +769,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
QDesktopWidget* desktop = UBApplication::desktop(); QDesktopWidget* desktop = UBApplication::desktop();
qreal currentDpi = (desktop->physicalDpiX() + desktop->physicalDpiY()) / 2; qreal currentDpi = (desktop->physicalDpiX() + desktop->physicalDpiY()) / 2;
qDebug() << "currentDpi (" << desktop->physicalDpiX() << " + " << desktop->physicalDpiY() << ")/2 = " << currentDpi; qDebug() << "currentDpi (" << desktop->physicalDpiX() << " + " << desktop->physicalDpiY() << ")/2 = " << currentDpi;
qreal pdfScale = qreal(UBSettings::pageDpi)/currentDpi; qreal pdfScale = qreal(proxy->pageDpi())/currentDpi;
qDebug() << "pdfScale " << pdfScale; qDebug() << "pdfScale " << pdfScale;
pdfItem->setScale(pdfScale); pdfItem->setScale(pdfScale);
pdfItem->setFlag(QGraphicsItem::ItemIsMovable, true); pdfItem->setFlag(QGraphicsItem::ItemIsMovable, true);
@ -829,7 +829,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
{ {
QDesktopWidget* desktop = UBApplication::desktop(); QDesktopWidget* desktop = UBApplication::desktop();
qreal currentDpi = (desktop->physicalDpiX() + desktop->physicalDpiY()) / 2; qreal currentDpi = (desktop->physicalDpiX() + desktop->physicalDpiY()) / 2;
qreal textSizeMultiplier = qreal(UBSettings::pageDpi)/currentDpi; qreal textSizeMultiplier = qreal(proxy->pageDpi())/currentDpi;
//textDelegate->scaleTextSize(textSizeMultiplier); //textDelegate->scaleTextSize(textSizeMultiplier);
} }
@ -1013,7 +1013,7 @@ QGraphicsItem *UBSvgSubsetAdaptor::UBSvgSubsetReader::readElementFromGroup()
void UBSvgSubsetAdaptor::persistScene(UBDocumentProxy* proxy, UBGraphicsScene* pScene, const int pageIndex) void UBSvgSubsetAdaptor::persistScene(UBDocumentProxy* proxy, UBGraphicsScene* pScene, const int pageIndex)
{ {
UBSvgSubsetWriter writer(proxy, pScene, pageIndex); UBSvgSubsetWriter writer(proxy, pScene, pageIndex);
writer.persistScene(pageIndex); writer.persistScene(proxy, pageIndex);
} }
@ -1027,7 +1027,7 @@ UBSvgSubsetAdaptor::UBSvgSubsetWriter::UBSvgSubsetWriter(UBDocumentProxy* proxy,
} }
void UBSvgSubsetAdaptor::UBSvgSubsetWriter::writeSvgElement() void UBSvgSubsetAdaptor::UBSvgSubsetWriter::writeSvgElement(UBDocumentProxy* proxy)
{ {
mXmlWriter.writeStartElement("svg"); mXmlWriter.writeStartElement("svg");
@ -1053,10 +1053,11 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::writeSvgElement()
QDesktopWidget* desktop = UBApplication::desktop(); QDesktopWidget* desktop = UBApplication::desktop();
if (UBSettings::pageDpi == 0) if (proxy->pageDpi() == 0)
UBSettings::pageDpi = (desktop->physicalDpiX() + desktop->physicalDpiY()) / 2; proxy->setPageDpi((desktop->physicalDpiX() + desktop->physicalDpiY()) / 2);
mXmlWriter.writeAttribute("pageDpi", QString::number(proxy->pageDpi()));
mXmlWriter.writeAttribute("pageDpi", QString::number(UBSettings::pageDpi));
mXmlWriter.writeStartElement("rect"); mXmlWriter.writeStartElement("rect");
mXmlWriter.writeAttribute("fill", mScene->isDarkBackground() ? "black" : "white"); mXmlWriter.writeAttribute("fill", mScene->isDarkBackground() ? "black" : "white");
@ -1068,7 +1069,7 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::writeSvgElement()
mXmlWriter.writeEndElement(); mXmlWriter.writeEndElement();
} }
bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex) bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(UBDocumentProxy* proxy, int pageIndex)
{ {
Q_UNUSED(pageIndex); Q_UNUSED(pageIndex);
@ -1089,7 +1090,7 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex)
mXmlWriter.writeNamespace(UBSettings::uniboardDocumentNamespaceUri, "ub"); mXmlWriter.writeNamespace(UBSettings::uniboardDocumentNamespaceUri, "ub");
mXmlWriter.writeNamespace(nsXHtml, "xhtml"); mXmlWriter.writeNamespace(nsXHtml, "xhtml");
writeSvgElement(); writeSvgElement(proxy);
// Get the items from the scene // Get the items from the scene
QList<QGraphicsItem*> items = mScene->items(); QList<QGraphicsItem*> items = mScene->items();

@ -114,7 +114,7 @@ class UBSvgSubsetAdaptor
virtual ~UBSvgSubsetReader(){} virtual ~UBSvgSubsetReader(){}
UBGraphicsScene* loadScene(); UBGraphicsScene* loadScene(UBDocumentProxy *proxy);
private: private:
@ -180,7 +180,7 @@ class UBSvgSubsetAdaptor
UBSvgSubsetWriter(UBDocumentProxy* proxy, UBGraphicsScene* pScene, const int pageIndex); UBSvgSubsetWriter(UBDocumentProxy* proxy, UBGraphicsScene* pScene, const int pageIndex);
bool persistScene(int pageIndex); bool persistScene(UBDocumentProxy *proxy, int pageIndex);
virtual ~UBSvgSubsetWriter(){} virtual ~UBSvgSubsetWriter(){}
@ -249,7 +249,7 @@ class UBSvgSubsetAdaptor
void protractorToSvg(UBGraphicsProtractor *item); void protractorToSvg(UBGraphicsProtractor *item);
void cacheToSvg(UBGraphicsCache* item); void cacheToSvg(UBGraphicsCache* item);
void triangleToSvg(UBGraphicsTriangle *item); void triangleToSvg(UBGraphicsTriangle *item);
void writeSvgElement(); void writeSvgElement(UBDocumentProxy *proxy);
private: private:

@ -112,8 +112,6 @@ const int UBSettings::longClickInterval = 1200;
const qreal UBSettings::minScreenRatio = 1.33; // 800/600 or 1024/768 const qreal UBSettings::minScreenRatio = 1.33; // 800/600 or 1024/768
int UBSettings::pageDpi = 0;
QStringList UBSettings::bitmapFileExtensions; QStringList UBSettings::bitmapFileExtensions;
QStringList UBSettings::vectoFileExtensions; QStringList UBSettings::vectoFileExtensions;
QStringList UBSettings::imageFileExtensions; QStringList UBSettings::imageFileExtensions;
@ -274,8 +272,6 @@ void UBSettings::init()
pageSize = new UBSetting(this, "Board", "DefaultPageSize", documentSizes.value(DocumentSizeRatio::Ratio4_3)); pageSize = new UBSetting(this, "Board", "DefaultPageSize", documentSizes.value(DocumentSizeRatio::Ratio4_3));
pageDpi = (UBApplication::desktop()->physicalDpiX() + UBApplication::desktop()->physicalDpiY())/ 2;
QStringList penLightBackgroundColors; QStringList penLightBackgroundColors;
penLightBackgroundColors << "#000000" << "#FF0000" <<"#004080" << "#008000" << "#FFDD00" << "#C87400" << "#800040" << "#008080" << "#5F2D0A" << "#FFFFFF"; penLightBackgroundColors << "#000000" << "#FF0000" <<"#004080" << "#008000" << "#FFDD00" << "#C87400" << "#800040" << "#008080" << "#5F2D0A" << "#FFFFFF";
boardPenLightBackgroundColors = new UBColorListSetting(this, "Board", "PenLightBackgroundColors", penLightBackgroundColors, 1.0); boardPenLightBackgroundColors = new UBColorListSetting(this, "Board", "PenLightBackgroundColors", penLightBackgroundColors, 1.0);

@ -232,8 +232,6 @@ class UBSettings : public QObject
static QString appPingMessage; static QString appPingMessage;
static int pageDpi;
UBSetting* productWebUrl; UBSetting* productWebUrl;
QString softwareHomeUrl; QString softwareHomeUrl;

@ -41,6 +41,7 @@
UBDocumentProxy::UBDocumentProxy() UBDocumentProxy::UBDocumentProxy()
: mPageCount(0) : mPageCount(0)
, mPageDpi(0)
{ {
init(); init();
} }
@ -48,6 +49,7 @@ UBDocumentProxy::UBDocumentProxy()
UBDocumentProxy::UBDocumentProxy(const QString& pPersistancePath) UBDocumentProxy::UBDocumentProxy(const QString& pPersistancePath)
: mPageCount(0) : mPageCount(0)
, mPageDpi(0)
{ {
init(); init();
setPersistencePath(pPersistancePath); setPersistencePath(pPersistancePath);
@ -98,6 +100,15 @@ void UBDocumentProxy::setPageCount(int pPageCount)
mPageCount = pPageCount; mPageCount = pPageCount;
} }
int UBDocumentProxy::pageDpi()
{
return mPageDpi;
}
void UBDocumentProxy::setPageDpi(int dpi)
{
mPageDpi = dpi;
}
int UBDocumentProxy::incPageCount() int UBDocumentProxy::incPageCount()
{ {

@ -79,6 +79,9 @@ class UBDocumentProxy : public QObject
int pageCount(); int pageCount();
int pageDpi();
void setPageDpi(int dpi);
protected: protected:
void setPageCount(int pPageCount); void setPageCount(int pPageCount);
int incPageCount(); int incPageCount();
@ -96,6 +99,8 @@ class UBDocumentProxy : public QObject
int mPageCount; int mPageCount;
int mPageDpi;
}; };
inline bool operator==(const UBDocumentProxy &proxy1, const UBDocumentProxy &proxy2) inline bool operator==(const UBDocumentProxy &proxy1, const UBDocumentProxy &proxy2)

Loading…
Cancel
Save