Changeset View
Changeset View
Standalone View
Standalone View
src/wrtembed/KReportDesignerSectionScene.cpp
Show All 23 Lines | |||||
24 | #include "kreport_debug.h" | 24 | #include "kreport_debug.h" | ||
25 | 25 | | |||
26 | #include <QPainter> | 26 | #include <QPainter> | ||
27 | #include <QApplication> | 27 | #include <QApplication> | ||
28 | #include <QGraphicsItem> | 28 | #include <QGraphicsItem> | ||
29 | #include <QGraphicsSceneMouseEvent> | 29 | #include <QGraphicsSceneMouseEvent> | ||
30 | 30 | | |||
31 | KReportDesignerSectionScene::KReportDesignerSectionScene(qreal w, qreal h, KReportDesigner *rd) | 31 | KReportDesignerSectionScene::KReportDesignerSectionScene(qreal w, qreal h, KReportDesigner *rd) | ||
32 | : QGraphicsScene(0, 0, w, h, rd) | 32 | : QGraphicsScene(0, 0, w, h, rd), m_rd(rd) | ||
33 | { | 33 | { | ||
34 | m_rd = rd; | | |||
35 | m_minorSteps = 0; | | |||
36 | m_dpiX = KReportPrivate::dpiX(); | 34 | m_dpiX = KReportPrivate::dpiX(); | ||
37 | m_dpiY = KReportPrivate::dpiY(); | 35 | m_dpiY = KReportPrivate::dpiY(); | ||
38 | 36 | | |||
39 | if (m_unit.type() != m_rd->pageUnit().type()) { | 37 | if (m_unit.type() != m_rd->pageUnit().type()) { | ||
40 | m_unit = m_rd->pageUnit(); | 38 | m_unit = m_rd->pageUnit(); | ||
41 | if (m_unit.type() == KReportUnit::Cicero || | 39 | if (m_unit.type() == KReportUnit::Cicero || | ||
42 | m_unit.type() == KReportUnit::Pica || | 40 | m_unit.type() == KReportUnit::Pica || | ||
43 | m_unit.type() == KReportUnit::Millimeter) { | 41 | m_unit.type() == KReportUnit::Millimeter) { | ||
Show All 31 Lines | 72 | } else if (m_unit.type() == KReportUnit::Point) { | |||
75 | m_majorX = POINT_TO_INCH(m_unit.fromUserValue(100)) * m_dpiX; | 73 | m_majorX = POINT_TO_INCH(m_unit.fromUserValue(100)) * m_dpiX; | ||
76 | m_majorY = POINT_TO_INCH(m_unit.fromUserValue(100)) * m_dpiY; | 74 | m_majorY = POINT_TO_INCH(m_unit.fromUserValue(100)) * m_dpiY; | ||
77 | } else { | 75 | } else { | ||
78 | m_majorX = POINT_TO_INCH(m_unit.fromUserValue(1)) * m_dpiX; | 76 | m_majorX = POINT_TO_INCH(m_unit.fromUserValue(1)) * m_dpiX; | ||
79 | m_majorY = POINT_TO_INCH(m_unit.fromUserValue(1)) * m_dpiY; | 77 | m_majorY = POINT_TO_INCH(m_unit.fromUserValue(1)) * m_dpiY; | ||
80 | } | 78 | } | ||
81 | 79 | | |||
82 | } | 80 | } | ||
83 | m_minorSteps = m_rd->propertySet()->property("grid-divisions").value().toInt(); | 81 | int minorSteps = m_rd->propertySet()->property("grid-divisions").value().toInt(); | ||
84 | m_pixelIncrementX = (m_majorX / m_minorSteps); | 82 | m_pixelIncrementX = (m_majorX / minorSteps); | ||
85 | m_pixelIncrementY = (m_majorY / m_minorSteps); | 83 | m_pixelIncrementY = (m_majorY / minorSteps); | ||
86 | 84 | | |||
87 | QPen pen = painter->pen(); | 85 | QPen pen = painter->pen(); | ||
88 | painter->setPen(Qt::lightGray); | 86 | painter->setPen(Qt::lightGray); | ||
89 | 87 | | |||
90 | //kreportDebug() << "dpix" << KReportPrivate::dpiX() << "dpiy" << KReportPrivate::dpiY() << "mayorx:" << majorx << "majory" << majory << "pix:" << pixel_incrementx << "piy:" << pixel_incrementy; | 88 | //kreportDebug() << "dpix" << KReportPrivate::dpiX() << "dpiy" << KReportPrivate::dpiY() << "mayorx:" << majorx << "majory" << majory << "pix:" << pixel_incrementx << "piy:" << pixel_incrementy; | ||
91 | 89 | | |||
92 | QVector<QLine> lines; | 90 | QVector<QLine> lines; | ||
93 | QVector<QPoint> points; | 91 | QVector<QPoint> points; | ||
94 | 92 | | |||
95 | if (m_pixelIncrementX > 2) { // do not bother painting points if increments are so small | 93 | if (m_pixelIncrementX > 2) { // do not bother painting points if increments are so small | ||
96 | int wpoints = qRound(sceneRect().width() / m_pixelIncrementX); | 94 | int wpoints = qRound(sceneRect().width() / m_pixelIncrementX); | ||
97 | int hpoints = qRound(sceneRect().height() / m_pixelIncrementY); | 95 | int hpoints = qRound(sceneRect().height() / m_pixelIncrementY); | ||
98 | for (int i = 0; i < wpoints; ++i) { | 96 | for (int i = 0; i < wpoints; ++i) { | ||
99 | for (int j = 0; j < hpoints; ++j) { | 97 | for (int j = 0; j < hpoints; ++j) { | ||
100 | //if (clip.contains(i * pixel_incrementx, j * pixel_incrementy)){ | 98 | //if (clip.contains(i * pixel_incrementx, j * pixel_incrementy)){ | ||
101 | if (i % m_minorSteps == 0 && j % m_minorSteps == 0) { | 99 | if (i % minorSteps == 0 && j % minorSteps == 0) { | ||
102 | lines << QLine(QPoint(i * m_pixelIncrementX, j * m_pixelIncrementY), QPoint(i * m_pixelIncrementX, j * m_pixelIncrementY + m_majorX)); | 100 | lines << QLine(QPoint(i * m_pixelIncrementX, j * m_pixelIncrementY), QPoint(i * m_pixelIncrementX, j * m_pixelIncrementY + m_majorX)); | ||
103 | //painter->drawLine(); | 101 | //painter->drawLine(); | ||
104 | lines << QLine(QPoint(i * m_pixelIncrementX, j * m_pixelIncrementY), QPoint(i * m_pixelIncrementX + m_majorY, j * m_pixelIncrementY)); | 102 | lines << QLine(QPoint(i * m_pixelIncrementX, j * m_pixelIncrementY), QPoint(i * m_pixelIncrementX + m_majorY, j * m_pixelIncrementY)); | ||
105 | //painter->drawLine(); | 103 | //painter->drawLine(); | ||
106 | } else { | 104 | } else { | ||
107 | points << QPoint(i * m_pixelIncrementX, j * m_pixelIncrementY); | 105 | points << QPoint(i * m_pixelIncrementX, j * m_pixelIncrementY); | ||
108 | //painter->drawPoint(); | 106 | //painter->drawPoint(); | ||
109 | } | 107 | } | ||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | 163 | } else if (m_unit.type() == KReportUnit::Point) { | |||
167 | m_majorY = POINT_TO_INCH(m_unit.fromUserValue(100)) * m_dpiY; | 165 | m_majorY = POINT_TO_INCH(m_unit.fromUserValue(100)) * m_dpiY; | ||
168 | } else { | 166 | } else { | ||
169 | m_majorX = POINT_TO_INCH(m_unit.fromUserValue(1)) * m_dpiX; | 167 | m_majorX = POINT_TO_INCH(m_unit.fromUserValue(1)) * m_dpiX; | ||
170 | m_majorY = POINT_TO_INCH(m_unit.fromUserValue(1)) * m_dpiY; | 168 | m_majorY = POINT_TO_INCH(m_unit.fromUserValue(1)) * m_dpiY; | ||
171 | } | 169 | } | ||
172 | 170 | | |||
173 | } | 171 | } | ||
174 | } | 172 | } | ||
175 | m_minorSteps = m_rd->propertySet()->property("grid-divisions").value().toInt(); | 173 | int minorSteps = m_rd->propertySet()->property("grid-divisions").value().toInt(); | ||
176 | m_pixelIncrementX = (m_majorX / m_minorSteps); | 174 | m_pixelIncrementX = (m_majorX / minorSteps); | ||
177 | m_pixelIncrementY = (m_majorY / m_minorSteps); | 175 | m_pixelIncrementY = (m_majorY / minorSteps); | ||
178 | 176 | | |||
179 | return QPointF(qRound((p.x() / m_pixelIncrementX)) * m_pixelIncrementX, qRound((p.y() / m_pixelIncrementY)) * m_pixelIncrementY); | 177 | return QPointF(qRound((p.x() / m_pixelIncrementX)) * m_pixelIncrementX, qRound((p.y() / m_pixelIncrementY)) * m_pixelIncrementY); | ||
180 | } | 178 | } | ||
181 | 179 | | |||
182 | void KReportDesignerSectionScene::focusOutEvent(QFocusEvent * focusEvent) | 180 | void KReportDesignerSectionScene::focusOutEvent(QFocusEvent * focusEvent) | ||
183 | { | 181 | { | ||
184 | exitInlineEditingModeInItems(0); | 182 | exitInlineEditingModeInItems(0); | ||
185 | 183 | | |||
▲ Show 20 Lines • Show All 75 Lines • Show Last 20 Lines |