r15179 by jghali - #9116: can't draw at integral coordinates with certain display dpi settings
scribus-commit
scribus-commit at lists.scribus.net
Fri Jun 11 23:30:47 CEST 2010
Revision: 15179
Author: jghali
Date: 2010-06-11T21:23:35.404869Z
Commit message: #9116: can't draw at integral coordinates with certain display dpi settings
Changeset:
M /trunk/Scribus/scribus/canvasmode_normal.cpp
M /trunk/Scribus/scribus/scclocale.cpp
M /trunk/Scribus/scribus/prefsmanager.cpp
M /trunk/Scribus/scribus/canvas.cpp
M /trunk/Scribus/scribus/ui/vruler.cpp
M /trunk/Scribus/scribus/scclocale.h
M /trunk/Scribus/scribus/ui/hruler.cpp
M /trunk/Scribus/scribus/ui/vruler.h
M /trunk/Scribus/scribus/canvasmode_create.cpp
M /trunk/Scribus/scribus/ui/hruler.h
M /trunk/Scribus/scribus/scribusview.cpp
Diffs:
Index: scribus/canvasmode_create.cpp
===================================================================
--- scribus/canvasmode_create.cpp (revision 15178)
+++ scribus/canvasmode_create.cpp (revision 15179)
@@ -233,8 +233,8 @@
return;
if (GetItem(&currItem))
{
- newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
- newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
+ newX = mousePointDoc.x(); //m_view->translateToDoc(m->x(), m->y()).x());
+ newY = mousePointDoc.y(); //m_view->translateToDoc(m->x(), m->y()).y());
if (m_doc->DragP)
return;
@@ -243,8 +243,8 @@
{
if ((m_MouseButtonPressed) && (m->buttons() & Qt::LeftButton))
{
- newX = qRound(mousePointDoc.x());
- newY = qRound(mousePointDoc.y());
+ newX = mousePointDoc.x();
+ newY = mousePointDoc.y();
if (createObjectMode == modeDrawLine)
{
if (m_doc->useRaster)
Index: scribus/prefsmanager.cpp
===================================================================
--- scribus/prefsmanager.cpp (revision 15178)
+++ scribus/prefsmanager.cpp (revision 15179)
@@ -1355,7 +1355,7 @@
deDisplay.setAttribute("PageBorderColor",appPrefs.displayPrefs.pageBorderColor.name());
deDisplay.setAttribute("ControlCharColor",appPrefs.displayPrefs.controlCharColor.name());
deDisplay.setAttribute("ShowMarginsFilled", static_cast<int>(appPrefs.displayPrefs.marginColored));
- deDisplay.setAttribute("DisplayScale", ScCLocale::toQStringC(appPrefs.displayPrefs.displayScale));
+ deDisplay.setAttribute("DisplayScale", ScCLocale::toQStringC(appPrefs.displayPrefs.displayScale, 8));
deDisplay.setAttribute("ShowVerifierWarningsOnCanvas",static_cast<int>(appPrefs.displayPrefs.showVerifierWarningsOnCanvas));
deDisplay.setAttribute("ToolTips", static_cast<int>(appPrefs.displayPrefs.showToolTips));
deDisplay.setAttribute("ShowMouseCoordinates", static_cast<int>(appPrefs.displayPrefs.showMouseCoordinates));
@@ -1928,7 +1928,7 @@
appPrefs.displayPrefs.pageBorderColor = QColor(dc.attribute("PageBorderColor","#ff0000"));
appPrefs.displayPrefs.controlCharColor = QColor(dc.attribute("ControlCharColor","#800000"));
appPrefs.displayPrefs.marginColored = static_cast<bool>(dc.attribute("ShowMarginsFilled", "0").toInt());
- appPrefs.displayPrefs.displayScale = ScCLocale::toDoubleC(dc.attribute("DisplayScale"), appPrefs.displayPrefs.displayScale);
+ appPrefs.displayPrefs.displayScale = qRound(ScCLocale::toDoubleC(dc.attribute("DisplayScale"), appPrefs.displayPrefs.displayScale)*72)/72.0;
appPrefs.displayPrefs.showVerifierWarningsOnCanvas = static_cast<bool>(dc.attribute("ShowVerifierWarningsOnCanvas", "1").toInt());
appPrefs.displayPrefs.showToolTips = static_cast<bool>(dc.attribute("ToolTips", "1").toInt());
appPrefs.displayPrefs.showMouseCoordinates = static_cast<bool>(dc.attribute("ShowMouseCoordinates", "1").toInt());
Index: scribus/canvas.cpp
===================================================================
--- scribus/canvas.cpp (revision 15178)
+++ scribus/canvas.cpp (revision 15179)
@@ -23,7 +23,6 @@
#include "canvas.h"
#include "canvasmode.h"
-#include "ui/hruler.h"
#include "page.h"
#include "pageitem_textframe.h"
#include "prefsmanager.h"
@@ -31,6 +30,8 @@
#include "scpainter.h"
#include "scribusview.h"
#include "selection.h"
+#include "ui/hruler.h"
+#include "ui/vruler.h"
#include "util.h"
#include "util_math.h"
#include "units.h"
@@ -119,8 +120,49 @@
FPoint Canvas::localToCanvas(QPoint p) const
{
- return FPoint(p.x() / m_viewMode.scale + m_doc->minCanvasCoordinate.x() ,
- p.y() / m_viewMode.scale + m_doc->minCanvasCoordinate.y());
+
+/* Allow the user to select the exact coordinate represented by a ruler mark
+ when the mouse is lined up with the ruler, rather than returning the
+ coordinate represented by the mathematical centre of the pixel which
+ may not be exactly the same as the coordinate represented by the ruler.
+*/
+
+// (xmin, xmax) = canvas top-left
+ double xmin = m_doc->minCanvasCoordinate.x();
+ double ymin = m_doc->minCanvasCoordinate.y();
+
+// (xoff, yoff) = ruler origin relative to canvas top-left
+ double xoff = m_doc->rulerXoffset - xmin;
+ double yoff = m_doc->rulerYoffset - ymin;
+ if (m_doc->guidesPrefs().rulerMode) {
+ xoff += m_doc->currentPage()->xOffset();
+ yoff += m_doc->currentPage()->yOffset();
+ }
+// (xsp, ysp) = spacing of ruler divisions
+ double xsp = m_doc->view()->horizRuler->ruleSpacing();
+ double ysp = m_doc->view()->vertRuler->ruleSpacing();
+
+ double sc = m_viewMode.scale;
+
+// number of ruler divisions from ruler origin to ruler mark closest to the
+// selected mouse coordinate
+ double xn = qRound((p.x()/sc - xoff)/xsp);
+ double yn = qRound((p.y()/sc - yoff)/ysp);
+
+// xn*xsp + xoff, yn*ysp + yoff = distance in canvas coordinates
+// from canvas top-left to ruler mark closest to selected mouse coordinate
+
+// If these round to the selected mouse coordinate, use these to define
+// (x,y), the coordinates of the desired point relative to the canvas top-left.
+// Otherwise, simply scale the mouse coordinates.
+ double x = ( qRound(sc*(xn*xsp + xoff)) == p.x() ?
+ xn*xsp + xoff : p.x()/sc );
+ double y = ( qRound(sc*(yn*ysp + yoff)) == p.y() ?
+ yn*ysp + yoff : p.y()/sc );
+
+// Finally, add xmin,ymin to get the absolute canvas coordinates of the
+// desired point.
+ return FPoint(x + xmin, y + ymin);
}
Index: scribus/scclocale.cpp
===================================================================
--- scribus/scclocale.cpp (revision 15178)
+++ scribus/scclocale.cpp (revision 15179)
@@ -87,9 +87,9 @@
return ret;
}
-QString ScCLocale::toQStringC(double d)
+QString ScCLocale::toQStringC(double d, int prec)
{
- return that()->qLocale.toString(d, 'f', 3);
+ return that()->qLocale.toString(d, 'f', prec);
}
double ScCLocale::strtod ( const char * str, char ** endptr )
Index: scribus/scribusview.cpp
===================================================================
--- scribus/scribusview.cpp (revision 15178)
+++ scribus/scribusview.cpp (revision 15179)
@@ -4307,8 +4307,8 @@
if (obj == widget() && event->type() == QEvent::MouseMove)
{
QMouseEvent* m = static_cast<QMouseEvent*> (event);
- emit MousePos(m->x() / m_canvas->scale() + Doc->minCanvasCoordinate.x(),
- m->y() / m_canvas->scale() + Doc->minCanvasCoordinate.y());
+ FPoint p = m_canvas->localToCanvas(QPoint(m->x(),m->y()));
+ emit MousePos(p.x(),p.y());
horizRuler->Draw(m->x() + qRound(Doc->minCanvasCoordinate.x() * m_canvas->scale())); // - 2 * contentsX());
vertRuler->Draw(m->y() + qRound(Doc->minCanvasCoordinate.y() * m_canvas->scale()));
m_canvasMode->mouseMoveEvent(m);
Index: scribus/ui/vruler.cpp
===================================================================
--- scribus/ui/vruler.cpp (revision 15178)
+++ scribus/ui/vruler.cpp (revision 15179)
@@ -247,6 +247,10 @@
}
}
+double Vruler::ruleSpacing() {
+ return iter;
+}
+
void Vruler::Draw(int where)
{
// erase old marker
Index: scribus/ui/hruler.cpp
===================================================================
--- scribus/ui/hruler.cpp (revision 15178)
+++ scribus/ui/hruler.cpp (revision 15179)
@@ -803,6 +803,10 @@
#endif
}
+double Hruler::ruleSpacing() {
+ return iter;
+}
+
void Hruler::Draw(int where)
{
// erase old marker
Index: scribus/ui/hruler.h
===================================================================
--- scribus/ui/hruler.h (revision 15178)
+++ scribus/ui/hruler.h (revision 15179)
@@ -67,6 +67,7 @@
double ItemEndPos;
double offs;
+ double ruleSpacing();
void setItem(PageItem * item);
private:
Index: scribus/ui/vruler.h
===================================================================
--- scribus/ui/vruler.h (revision 15178)
+++ scribus/ui/vruler.h (revision 15179)
@@ -53,6 +53,7 @@
bool repainted;
int oldMark;
bool Mpressed;
+ double ruleSpacing();
private: // Private attributes
/** Zeichensatz des Lineals */
ScribusDoc *currDoc;
Index: scribus/canvasmode_normal.cpp
===================================================================
--- scribus/canvasmode_normal.cpp (revision 15178)
+++ scribus/canvasmode_normal.cpp (revision 15179)
@@ -303,13 +303,13 @@
qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
}
}
- else if (!mouseIsOnPage)
- {
- QCursor* cursor = qApp->overrideCursor();
- if (cursor && ((cursor->shape() == Qt::SplitHCursor) || (cursor->shape() == Qt::SplitVCursor)))
- {
- qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
- }
+ else if (!mouseIsOnPage)
+ {
+ QCursor* cursor = qApp->overrideCursor();
+ if (cursor && ((cursor->shape() == Qt::SplitHCursor) || (cursor->shape() == Qt::SplitVCursor)))
+ {
+ qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+ }
}
if ((GetItem(&currItem)) && (!shiftSelItems))
{
Index: scribus/scclocale.h
===================================================================
--- scribus/scclocale.h (revision 15178)
+++ scribus/scclocale.h (revision 15179)
@@ -52,7 +52,7 @@
static double toDoubleC(const QString& str, double defValue);
static float toFloatC(const QString& str, bool * ok = 0);
static float toFloatC(const QString& str, float defValue);
- static QString toQStringC(double d);
+ static QString toQStringC(double d, int prec = 3);
static double strtod ( const char * str, char ** endptr );
};
More information about the scribus-commit
mailing list