... |
... |
@@ -144,13 +144,25 @@ GlyphBitmapWidget::paintEvent(QPaintEvent* event) |
144
|
144
|
QPoint(std::max(rect_.right(), placeholderRect_.right()),
|
145
|
145
|
std::max(rect_.bottom(), placeholderRect_.bottom())));
|
146
|
146
|
|
147
|
|
- double xScale = 0.9 * s.width() / br.right();
|
148
|
|
- double yScale = 0.9 * s.height() / br.bottom();
|
|
147
|
+ double xScale = 0.9 * s.width() / br.width();
|
|
148
|
+ double yScale = 0.9 * s.height() / br.height();
|
|
149
|
+ auto margin = br.width() * 0.05;
|
149
|
150
|
auto scale = std::min(xScale, yScale);
|
150
|
151
|
|
151
|
152
|
QPainter painter(this);
|
152
|
153
|
painter.fillRect(rect(), Qt::white);
|
|
154
|
+ painter.save(); // push before scaling
|
153
|
155
|
painter.scale(scale, scale);
|
|
156
|
+ painter.translate(-br.topLeft() + QPointF(margin, margin));
|
|
157
|
+
|
|
158
|
+ double scaledLineWidth = 4 / scale;
|
|
159
|
+ double scaledLineWidthHalf = scaledLineWidth / 2;
|
|
160
|
+ painter.setPen(QPen(Qt::blue, scaledLineWidth));
|
|
161
|
+ painter.drawRect(QRectF(rect_).adjusted(-scaledLineWidthHalf,
|
|
162
|
+ -scaledLineWidthHalf,
|
|
163
|
+ scaledLineWidthHalf,
|
|
164
|
+ scaledLineWidthHalf));
|
|
165
|
+
|
154
|
166
|
painter.save(); // push before translating
|
155
|
167
|
painter.translate(rect_.topLeft());
|
156
|
168
|
|
... |
... |
@@ -159,23 +171,27 @@ GlyphBitmapWidget::paintEvent(QPaintEvent* event) |
159
|
171
|
bitmapItem_->paint(&painter, &ogi, this);
|
160
|
172
|
|
161
|
173
|
painter.restore(); // undo translating.
|
162
|
|
- double scaledLineWidth = 4 / scale;
|
163
|
|
- double scaledLineWidthHalf = scaledLineWidth / 2;
|
164
|
|
- painter.setPen(QPen(Qt::black, scaledLineWidth));
|
165
|
|
- painter.drawRect(QRectF(br).adjusted(scaledLineWidthHalf,
|
166
|
|
- scaledLineWidthHalf,
|
167
|
|
- -scaledLineWidthHalf,
|
168
|
|
- -scaledLineWidthHalf));
|
169
|
|
- painter.setPen(QPen(Qt::red, scaledLineWidth));
|
170
|
|
- painter.drawRect(QRectF(placeholderRect_).adjusted(scaledLineWidthHalf,
|
171
|
|
- scaledLineWidthHalf,
|
|
174
|
+
|
|
175
|
+ scaledLineWidth /= 2;
|
|
176
|
+ scaledLineWidthHalf /= 2;
|
|
177
|
+ painter.setPen(QPen(Qt::lightGray, scaledLineWidth));
|
|
178
|
+ painter.drawRect(QRectF(placeholderRect_).adjusted(-scaledLineWidthHalf,
|
172
|
179
|
-scaledLineWidthHalf,
|
173
|
|
- -scaledLineWidthHalf));
|
174
|
|
- painter.setPen(QPen(Qt::blue, scaledLineWidth));
|
175
|
|
- painter.drawRect(QRectF(rect_).adjusted(scaledLineWidthHalf,
|
176
|
|
- scaledLineWidthHalf,
|
177
|
|
- -scaledLineWidthHalf,
|
178
|
|
- -scaledLineWidthHalf));
|
|
180
|
+ scaledLineWidthHalf,
|
|
181
|
+ scaledLineWidthHalf));
|
|
182
|
+
|
|
183
|
+ auto tfForAxis = painter.transform().inverted();
|
|
184
|
+ painter.setPen(QPen(Qt::black, scaledLineWidth / 2));
|
|
185
|
+ painter.drawLine(QPointF(tfForAxis.map(QPointF(0, 0)).x(), 0),
|
|
186
|
+ QPointF(tfForAxis.map(QPointF(s.width(), 0)).x(), 0));
|
|
187
|
+ painter.drawLine(QPointF(0, tfForAxis.map(QPointF(0, 0)).y()),
|
|
188
|
+ QPointF(0, tfForAxis.map(QPointF(0, s.height())).y()));
|
|
189
|
+
|
|
190
|
+ painter.restore(); // undo scaling.
|
|
191
|
+
|
|
192
|
+ // main border
|
|
193
|
+ painter.setPen(QPen(Qt::black, 4));
|
|
194
|
+ painter.drawRect(rect().adjusted(2, 2, -2, -2));
|
179
|
195
|
}
|
180
|
196
|
|
181
|
197
|
|