r15181 by jghali - #9116: can't draw at integral coordinates with certain display dpi settings
scribus-commit
scribus-commit at lists.scribus.net
Sat Jun 12 11:30:45 CEST 2010
Revision: 15181
Author: jghali
Date: 2010-06-12T09:23:41.442624Z
Commit message: #9116: can't draw at integral coordinates with certain display dpi settings
Changeset:
M /branches/Version135/Scribus/scribus/scclocale.cpp
M /branches/Version135/Scribus/scribus/prefsmanager.cpp
M /branches/Version135/Scribus/scribus/canvas.cpp
M /branches/Version135/Scribus/scribus/scclocale.h
M /branches/Version135/Scribus/scribus/vruler.cpp
M /branches/Version135/Scribus/scribus/hruler.cpp
M /branches/Version135/Scribus/scribus/canvasmode_create.cpp
M /branches/Version135/Scribus/scribus/vruler.h
M /branches/Version135/Scribus/scribus/scribusview.cpp
M /branches/Version135/Scribus/scribus/hruler.h
Diffs:
Index: scribus/prefsmanager.cpp
===================================================================
--- scribus/prefsmanager.cpp (revision 15180)
+++ scribus/prefsmanager.cpp (revision 15181)
@@ -1293,7 +1293,7 @@
dc1a.setAttribute("DControlCharColor",appPrefs.DControlCharColor.name());
dc1a.setAttribute("MARGC",appPrefs.guidesSettings.margColor.name());
dc1a.setAttribute("RANDF", static_cast<int>(appPrefs.marginColored));
- dc1a.setAttribute("DScale", ScCLocale::toQStringC(appPrefs.DisScale));
+ dc1a.setAttribute("DScale", ScCLocale::toQStringC(appPrefs.DisScale, 6));
elem.appendChild(dc1a);
// Font information must be written before FONTS element so that face "usable"
// member is set properly before one try to set default font. Allows to check
@@ -1834,7 +1834,7 @@
appPrefs.DControlCharColor = QColor(dc.attribute("DControlCharColor","#800000"));
appPrefs.guidesSettings.margColor = QColor(dc.attribute("MARGC","#0000ff"));
appPrefs.marginColored = static_cast<bool>(dc.attribute("RANDF", "0").toInt());
- appPrefs.DisScale = ScCLocale::toDoubleC(dc.attribute("DScale"), appPrefs.DisScale);
+ appPrefs.DisScale = qRound(ScCLocale::toDoubleC(dc.attribute("DScale"), appPrefs.DisScale)*72)/72.0;
}
if (dc.tagName()=="TYPO")
{
Index: scribus/scribusview.cpp
===================================================================
--- scribus/scribusview.cpp (revision 15180)
+++ scribus/scribusview.cpp (revision 15181)
@@ -4766,8 +4766,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/scclocale.h
===================================================================
--- scribus/scclocale.h (revision 15180)
+++ scribus/scclocale.h (revision 15181)
@@ -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 );
};
Index: scribus/vruler.cpp
===================================================================
--- scribus/vruler.cpp (revision 15180)
+++ scribus/vruler.cpp (revision 15181)
@@ -245,6 +245,10 @@
}
}
+double Vruler::ruleSpacing() {
+ return iter;
+}
+
void Vruler::Draw(int where)
{
// erase old marker
Index: scribus/canvasmode_create.cpp
===================================================================
--- scribus/canvasmode_create.cpp (revision 15180)
+++ scribus/canvasmode_create.cpp (revision 15181)
@@ -232,8 +232,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;
@@ -242,8 +242,8 @@
{
if ((m_MouseButtonPressed) && (m->buttons() & Qt::LeftButton))
{
- 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();
+ newY = mousePointDoc.y();
if (createObjectMode == modeDrawLine)
{
if (m_doc->useRaster)
Index: scribus/hruler.cpp
===================================================================
--- scribus/hruler.cpp (revision 15180)
+++ scribus/hruler.cpp (revision 15181)
@@ -801,6 +801,10 @@
#endif
}
+double Hruler::ruleSpacing() {
+ return iter;
+}
+
void Hruler::Draw(int where)
{
// erase old marker
Index: scribus/hruler.h
===================================================================
--- scribus/hruler.h (revision 15180)
+++ scribus/hruler.h (revision 15181)
@@ -67,6 +67,7 @@
double ItemEndPos;
double offs;
+ double ruleSpacing();
void setItem(PageItem * item);
private:
Index: scribus/canvas.cpp
===================================================================
--- scribus/canvas.cpp (revision 15180)
+++ scribus/canvas.cpp (revision 15181)
@@ -29,6 +29,7 @@
#include "selection.h"
#include "util.h"
#include "units.h"
+#include "vruler.h"
#define DRAW_DEBUG_LINES 0
@@ -114,8 +115,50 @@
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->guidesSettings.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/vruler.h
===================================================================
--- scribus/vruler.h (revision 15180)
+++ scribus/vruler.h (revision 15181)
@@ -53,6 +53,7 @@
bool repainted;
int oldMark;
bool Mpressed;
+ double ruleSpacing();
private: // Private attributes
/** Zeichensatz des Lineals */
ScribusDoc *currDoc;
Index: scribus/scclocale.cpp
===================================================================
--- scribus/scclocale.cpp (revision 15180)
+++ scribus/scclocale.cpp (revision 15181)
@@ -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 )
More information about the scribus-commit
mailing list