Commits:
-
53c3abd3
by Charlie Jiang
at 2022-09-01T00:46:09+08:00
[ftinspect] Implement zoom for continuous view.
* src/ftinspect/glyphcomponents/glyphcontinuous.cpp,
src/ftinspect/glyphcomponents/glyphcontinuous.hpp:
Support zoom a.k.a scale. Add related signals.
* src/ftinspect/widgets/fontsizeselector.cpp,
src/ftinspect/widgets/fontsizeselector.hpp:
Combine zoom factor into the font size selector.
* src/ftinspect/panels/singular.cpp, src/ftinspect/panels/singular.hpp:
Move out zoom factor widgets.
* src/ftinspect/panels/continuous.cpp, src/ftinspect/panels/continuous.cpp:
Support zoom. Add related connections.
* src/ftinspect/panels/comparator.cpp, src/ftinspect/panels/comparator.hpp:
Support zoom. Add missing connections for wheel events of the canvases.
* src/ftinspect/widgets/customwidgets.cpp,
src/ftinspect/widgets/customwidgets.hpp:
Change `ZoomSpinBox` to inherit `QDoubleSpinBox` and make it fit for both
continuous view and singular view which need different steps and ranges..
-
a37f7509
by Charlie Jiang
at 2022-09-01T00:46:18+08:00
* src/ftinspect/panels/info.cpp: Fix SFNT info tab disabled unexpectedly.
13 changed files:
Changes:
src/ftinspect/glyphcomponents/glyphcontinuous.cpp
... |
... |
@@ -135,6 +135,7 @@ GlyphContinuous::paintEvent(QPaintEvent* event) |
135
|
135
|
{
|
136
|
136
|
QPainter painter(this);
|
137
|
137
|
painter.fillRect(rect(), backgroundColorCache_);
|
|
138
|
+ painter.scale(scale_, scale_);
|
138
|
139
|
|
139
|
140
|
if (glyphCache_.empty())
|
140
|
141
|
fillCache();
|
... |
... |
@@ -148,6 +149,8 @@ GlyphContinuous::wheelEvent(QWheelEvent* event) |
148
|
149
|
int numSteps = event->angleDelta().y() / 120;
|
149
|
150
|
if (event->modifiers() & Qt::ShiftModifier)
|
150
|
151
|
emit wheelResize(numSteps);
|
|
152
|
+ else if (event->modifiers() & Qt::ControlModifier)
|
|
153
|
+ emit wheelZoom(numSteps);
|
151
|
154
|
else if (event->modifiers() == 0)
|
152
|
155
|
emit wheelNavigate(-numSteps);
|
153
|
156
|
}
|
... |
... |
@@ -189,6 +192,7 @@ GlyphContinuous::mouseMoveEvent(QMouseEvent* event) |
189
|
192
|
if (event->buttons() != Qt::LeftButton)
|
190
|
193
|
return;
|
191
|
194
|
auto delta = event->pos() - mouseDownPostition_;
|
|
195
|
+ delta /= scale_;
|
192
|
196
|
if (source_ == SRC_AllGlyphs)
|
193
|
197
|
{
|
194
|
198
|
auto deltaIndex = -delta.x() / HorizontalUnitLength
|
... |
... |
@@ -202,7 +206,9 @@ GlyphContinuous::mouseMoveEvent(QMouseEvent* event) |
202
|
206
|
positionDelta_.setX(0); // Don't move horizontally
|
203
|
207
|
|
204
|
208
|
// but use the renderer
|
205
|
|
- auto horiPos = delta.x() / static_cast<double>(width());
|
|
209
|
+ // purpose for two scale_: one for undoing the `delta /= scale_`
|
|
210
|
+ // the other for effectively dividing width by the scale
|
|
211
|
+ auto horiPos = delta.x() * scale_ * scale_ / static_cast<double>(width());
|
206
|
212
|
horiPos += prevHoriPosition_;
|
207
|
213
|
horiPos = qBound(0.0, horiPos, 1.0);
|
208
|
214
|
stringRenderer_.setPosition(horiPos);
|
... |
... |
@@ -267,7 +273,9 @@ GlyphContinuous::paintByRenderer() |
267
|
273
|
{
|
268
|
274
|
beginSaveLine(pos, size);
|
269
|
275
|
});
|
270
|
|
- displayingCount_ = stringRenderer_.render(width(), height(), beginIndex_);
|
|
276
|
+ displayingCount_ = stringRenderer_.render(static_cast<int>(width() / scale_),
|
|
277
|
+ static_cast<int>(height() / scale_),
|
|
278
|
+ beginIndex_);
|
271
|
279
|
}
|
272
|
280
|
|
273
|
281
|
|
... |
... |
@@ -566,6 +574,7 @@ GlyphContinuous::findGlyphByMouse(QPoint position, |
566
|
574
|
double* outSizePoint)
|
567
|
575
|
{
|
568
|
576
|
position -= positionDelta_;
|
|
577
|
+ position /= scale_;
|
569
|
578
|
for (auto& line : glyphCache_)
|
570
|
579
|
for (auto& entry : line.entries)
|
571
|
580
|
{
|
src/ftinspect/glyphcomponents/glyphcontinuous.hpp
... |
... |
@@ -79,6 +79,7 @@ public: |
79
|
79
|
void setBeginIndex(int index) { beginIndex_ = index; }
|
80
|
80
|
void setSource(Source source);
|
81
|
81
|
void setMode(Mode mode) { mode_ = mode; }
|
|
82
|
+ void setScale(double scale) { scale_ = scale; }
|
82
|
83
|
void setFancyParams(double boldX, double boldY, double slant)
|
83
|
84
|
{
|
84
|
85
|
boldX_ = boldX;
|
... |
... |
@@ -100,6 +101,7 @@ public: |
100
|
101
|
signals:
|
101
|
102
|
void wheelNavigate(int steps);
|
102
|
103
|
void wheelResize(int steps);
|
|
104
|
+ void wheelZoom(int steps);
|
103
|
105
|
void beginIndexChangeRequest(int newIndex);
|
104
|
106
|
void displayingCountUpdated(int newCount);
|
105
|
107
|
void rightClickGlyph(int glyphIndex, double sizePoint);
|
... |
... |
@@ -132,6 +134,7 @@ private: |
132
|
134
|
bool mouseOperationEnabled_ = true;
|
133
|
135
|
int displayingCount_ = 0;
|
134
|
136
|
FT_Fixed strokeRadiusForSize_ = 0;
|
|
137
|
+ double scale_ = 1.0;
|
135
|
138
|
FT_Matrix shearMatrix_;
|
136
|
139
|
|
137
|
140
|
FT_Stroker stroker_;
|
src/ftinspect/panels/comparator.cpp
... |
... |
@@ -86,7 +86,7 @@ ComperatorTab::resizeEvent(QResizeEvent* event) |
86
|
86
|
void
|
87
|
87
|
ComperatorTab::createLayout()
|
88
|
88
|
{
|
89
|
|
- sizeSelector_ = new FontSizeSelector(this);
|
|
89
|
+ sizeSelector_ = new FontSizeSelector(this, true, true);
|
90
|
90
|
charMapLabel_ = new QLabel(tr("Char Map:"), this);
|
91
|
91
|
charMapSelector_ = new CharMapComboBox(this, engine_, false);
|
92
|
92
|
sourceTextEdit_ = new QPlainTextEdit(QString(ComparatorDefaultText), this);
|
... |
... |
@@ -168,6 +168,14 @@ ComperatorTab::createConnections() |
168
|
168
|
connect(panel, &SettingPanel::fontReloadNeeded,
|
169
|
169
|
this, &ComperatorTab::repaintGlyph);
|
170
|
170
|
}
|
|
171
|
+
|
|
172
|
+ for (auto canvas : canvas_)
|
|
173
|
+ {
|
|
174
|
+ connect(canvas, &GlyphContinuous::wheelZoom,
|
|
175
|
+ this, &ComperatorTab::wheelZoom);
|
|
176
|
+ connect(canvas, &GlyphContinuous::wheelResize,
|
|
177
|
+ this, &ComperatorTab::wheelResize);
|
|
178
|
+ }
|
171
|
179
|
}
|
172
|
180
|
|
173
|
181
|
|
... |
... |
@@ -258,11 +266,26 @@ ComperatorTab::syncSettings(int index) |
258
|
266
|
return;
|
259
|
267
|
|
260
|
268
|
auto canvas = canvas_[index];
|
|
269
|
+ canvas->setScale(sizeSelector_->zoomFactor());
|
261
|
270
|
canvas->stringRenderer().setKerning(settingPanel->kerningEnabled());
|
262
|
271
|
canvas->stringRenderer().setLsbRsbDelta(settingPanel->lsbRsbDeltaEnabled());
|
263
|
272
|
}
|
264
|
273
|
|
265
|
274
|
|
|
275
|
+void
|
|
276
|
+ComperatorTab::wheelResize(int steps)
|
|
277
|
+{
|
|
278
|
+ sizeSelector_->handleWheelResizeBySteps(steps);
|
|
279
|
+}
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+void
|
|
283
|
+ComperatorTab::wheelZoom(int steps)
|
|
284
|
+{
|
|
285
|
+ sizeSelector_->handleWheelZoomBySteps(steps);
|
|
286
|
+}
|
|
287
|
+
|
|
288
|
+
|
266
|
289
|
namespace
|
267
|
290
|
{
|
268
|
291
|
const char* ComparatorDefaultText
|
src/ftinspect/panels/comparator.hpp
... |
... |
@@ -64,6 +64,9 @@ private: |
64
|
64
|
void reloadGlyphsAndRepaint();
|
65
|
65
|
void sourceTextChanged();
|
66
|
66
|
void syncSettings(int index);
|
|
67
|
+
|
|
68
|
+ void wheelResize(int steps);
|
|
69
|
+ void wheelZoom(int steps);
|
67
|
70
|
};
|
68
|
71
|
|
69
|
72
|
|
src/ftinspect/panels/continuous.cpp
... |
... |
@@ -80,6 +80,7 @@ ContinuousTab::syncSettings() |
80
|
80
|
canvas_->setMode(mode);
|
81
|
81
|
canvas_->setSource(src);
|
82
|
82
|
canvas_->setBeginIndex(indexSelector_->currentIndex());
|
|
83
|
+ canvas_->setScale(sizeSelector_->zoomFactor());
|
83
|
84
|
auto& sr = canvas_->stringRenderer();
|
84
|
85
|
sr.setWaterfall(waterfallCheckBox_->isChecked());
|
85
|
86
|
sr.setVertical(verticalCheckBox_->isChecked());
|
... |
... |
@@ -280,6 +281,7 @@ ContinuousTab::showToolTip() |
280
|
281
|
QToolTip::showText(mapToGlobal(helpButton_->pos()),
|
281
|
282
|
tr(
|
282
|
283
|
R"(Shift + Scroll: Adjust Font Size
|
|
284
|
+Ctrl + Scroll: Adjust Zoom Factor
|
283
|
285
|
Shift + Plus/Minus: Adjust Font Size
|
284
|
286
|
Shift + 0: Reset Font Size to Default
|
285
|
287
|
Left Click: Show Glyph Details Info
|
... |
... |
@@ -315,6 +317,13 @@ ContinuousTab::wheelNavigate(int steps) |
315
|
317
|
}
|
316
|
318
|
|
317
|
319
|
|
|
320
|
+void
|
|
321
|
+ContinuousTab::wheelZoom(int steps)
|
|
322
|
+{
|
|
323
|
+ sizeSelector_->handleWheelZoomBySteps(steps);
|
|
324
|
+}
|
|
325
|
+
|
|
326
|
+
|
318
|
327
|
void
|
319
|
328
|
ContinuousTab::wheelResize(int steps)
|
320
|
329
|
{
|
... |
... |
@@ -329,7 +338,7 @@ ContinuousTab::createLayout() |
329
|
338
|
canvasFrame_->setFrameStyle(QFrame::StyledPanel | QFrame::Plain);
|
330
|
339
|
|
331
|
340
|
canvas_ = new GlyphContinuous(canvasFrame_, engine_);
|
332
|
|
- sizeSelector_ = new FontSizeSelector(this);
|
|
341
|
+ sizeSelector_ = new FontSizeSelector(this, false, true);
|
333
|
342
|
|
334
|
343
|
indexSelector_ = new GlyphIndexSelector(this);
|
335
|
344
|
indexSelector_->setSingleMode(false);
|
... |
... |
@@ -494,6 +503,8 @@ ContinuousTab::createConnections() |
494
|
503
|
this, &ContinuousTab::wheelResize);
|
495
|
504
|
connect(canvas_, &GlyphContinuous::wheelNavigate,
|
496
|
505
|
this, &ContinuousTab::wheelNavigate);
|
|
506
|
+ connect(canvas_, &GlyphContinuous::wheelZoom,
|
|
507
|
+ this, &ContinuousTab::wheelZoom);
|
497
|
508
|
connect(canvas_, &GlyphContinuous::displayingCountUpdated,
|
498
|
509
|
this, &ContinuousTab::setDisplayingCount);
|
499
|
510
|
connect(canvas_, &GlyphContinuous::rightClickGlyph,
|
src/ftinspect/panels/continuous.hpp
... |
... |
@@ -75,6 +75,7 @@ protected: |
75
|
75
|
|
76
|
76
|
private slots:
|
77
|
77
|
void wheelNavigate(int steps);
|
|
78
|
+ void wheelZoom(int steps);
|
78
|
79
|
void wheelResize(int steps);
|
79
|
80
|
|
80
|
81
|
private:
|
src/ftinspect/panels/info.cpp
... |
... |
@@ -435,8 +435,7 @@ SFNTInfoTab::reloadFont() |
435
|
435
|
{
|
436
|
436
|
engine_->reloadFont();
|
437
|
437
|
auto face = engine_->currentFallbackFtFace();
|
438
|
|
- if (!face || !FT_IS_SFNT(face))
|
439
|
|
- setEnabled(false);
|
|
438
|
+ setEnabled(face && FT_IS_SFNT(face));
|
440
|
439
|
|
441
|
440
|
if (engine_->currentFontSFNTNames() != sfntNamesModel_->storage())
|
442
|
441
|
{
|
... |
... |
@@ -1002,11 +1001,12 @@ CompositeGlyphsTab::forceReloadFont() |
1002
|
1001
|
|
1003
|
1002
|
std::vector<CompositeGlyphInfo> list;
|
1004
|
1003
|
CompositeGlyphInfo::get(engine_, list);
|
1005
|
|
- if (list == compositeModel_->storage())
|
1006
|
|
- return;
|
1007
|
|
- compositeModel_->beginModelUpdate();
|
1008
|
|
- compositeModel_->storage() = std::move(list);
|
1009
|
|
- compositeModel_->endModelUpdate();
|
|
1004
|
+ if (list != compositeModel_->storage())
|
|
1005
|
+ {
|
|
1006
|
+ compositeModel_->beginModelUpdate();
|
|
1007
|
+ compositeModel_->storage() = std::move(list);
|
|
1008
|
+ compositeModel_->endModelUpdate();
|
|
1009
|
+ }
|
1010
|
1010
|
|
1011
|
1011
|
if (compositeModel_->storage().empty())
|
1012
|
1012
|
{
|
src/ftinspect/panels/singular.cpp
... |
... |
@@ -157,7 +157,7 @@ SingularTab::checkShowPoints() |
157
|
157
|
void
|
158
|
158
|
SingularTab::zoom()
|
159
|
159
|
{
|
160
|
|
- int scale = zoomSpinBox_->value();
|
|
160
|
+ int scale = static_cast<int>(sizeSelector_->zoomFactor());
|
161
|
161
|
|
162
|
162
|
QTransform transform;
|
163
|
163
|
transform.scale(scale, scale);
|
... |
... |
@@ -198,10 +198,7 @@ void |
198
|
198
|
SingularTab::wheelZoom(QWheelEvent* event)
|
199
|
199
|
{
|
200
|
200
|
int numSteps = event->angleDelta().y() / 120;
|
201
|
|
- int zoomAfter = zoomSpinBox_->value() + numSteps;
|
202
|
|
- zoomAfter = std::max(zoomSpinBox_->minimum(),
|
203
|
|
- std::min(zoomAfter, zoomSpinBox_->maximum()));
|
204
|
|
- zoomSpinBox_->setValue(zoomAfter);
|
|
201
|
+ sizeSelector_->handleWheelZoomBySteps(numSteps);
|
205
|
202
|
// TODO: Zoom relative to viewport left-bottom?
|
206
|
203
|
}
|
207
|
204
|
|
... |
... |
@@ -276,7 +273,7 @@ SingularTab::resizeEvent(QResizeEvent* event) |
276
|
273
|
|
277
|
274
|
auto viewSize = glyphView_->size();
|
278
|
275
|
auto minViewSide = std::min(viewSize.height(), viewSize.width());
|
279
|
|
- zoomSpinBox_->setValue(static_cast<int>(minViewSide / size * 0.7));
|
|
276
|
+ sizeSelector_->setZoomFactor(static_cast<int>(minViewSide / size * 0.7));
|
280
|
277
|
}
|
281
|
278
|
|
282
|
279
|
|
... |
... |
@@ -323,15 +320,7 @@ SingularTab::createLayout() |
323
|
320
|
indexSelector_ = new GlyphIndexSelector(this);
|
324
|
321
|
indexSelector_->setSingleMode(true);
|
325
|
322
|
|
326
|
|
- sizeSelector_ = new FontSizeSelector(this);
|
327
|
|
-
|
328
|
|
- zoomLabel_ = new QLabel(tr("Zoom Factor"), this);
|
329
|
|
- zoomLabel_->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
330
|
|
- zoomSpinBox_ = new ZoomSpinBox(this);
|
331
|
|
- zoomSpinBox_->setAlignment(Qt::AlignRight);
|
332
|
|
- zoomSpinBox_->setRange(1, 1000 - 1000 % 64);
|
333
|
|
- zoomSpinBox_->setKeyboardTracking(false);
|
334
|
|
- zoomLabel_->setBuddy(zoomSpinBox_);
|
|
323
|
+ sizeSelector_ = new FontSizeSelector(this, false, false);
|
335
|
324
|
|
336
|
325
|
centerGridButton_ = new QPushButton("Go Back to Grid Center", this);
|
337
|
326
|
helpButton_ = new QPushButton("?", this);
|
... |
... |
@@ -345,7 +334,6 @@ SingularTab::createLayout() |
345
|
334
|
showAuxLinesCheckBox_ = new QCheckBox(tr("Show Aux. Lines"), this);
|
346
|
335
|
|
347
|
336
|
// Tooltips
|
348
|
|
- zoomSpinBox_->setToolTip(tr("Adjust grid zoom."));
|
349
|
337
|
centerGridButton_->setToolTip(tr(
|
350
|
338
|
"Move the viewport so the origin point is at the center of the view."));
|
351
|
339
|
showBitmapCheckBox_->setToolTip(tr("Show glyph bitmap."));
|
... |
... |
@@ -367,10 +355,7 @@ SingularTab::createLayout() |
367
|
355
|
|
368
|
356
|
sizeLayout_ = new QHBoxLayout;
|
369
|
357
|
sizeLayout_->addStretch(2);
|
370
|
|
- sizeLayout_->addWidget(sizeSelector_, 3);
|
371
|
|
- sizeLayout_->addStretch(1);
|
372
|
|
- sizeLayout_->addWidget(zoomLabel_);
|
373
|
|
- sizeLayout_->addWidget(zoomSpinBox_);
|
|
358
|
+ sizeLayout_->addWidget(sizeSelector_, 4);
|
374
|
359
|
sizeLayout_->addStretch(1);
|
375
|
360
|
sizeLayout_->addWidget(centerGridButton_);
|
376
|
361
|
sizeLayout_->addStretch(2);
|
... |
... |
@@ -411,9 +396,7 @@ SingularTab::createConnections() |
411
|
396
|
this, &SingularTab::repaintGlyph);
|
412
|
397
|
connect(indexSelector_, &GlyphIndexSelector::currentIndexChanged,
|
413
|
398
|
this, &SingularTab::setGlyphIndex);
|
414
|
|
-
|
415
|
|
- connect(zoomSpinBox_, QOverload<int>::of(&QSpinBox::valueChanged),
|
416
|
|
- this, &SingularTab::zoom);
|
|
399
|
+
|
417
|
400
|
connect(glyphView_, &QGraphicsViewx::shiftWheelEvent,
|
418
|
401
|
this, &SingularTab::wheelResize);
|
419
|
402
|
connect(glyphView_, &QGraphicsViewx::ctrlWheelEvent,
|
... |
... |
@@ -449,6 +432,7 @@ SingularTab::createConnections() |
449
|
432
|
void
|
450
|
433
|
SingularTab::repaintGlyph()
|
451
|
434
|
{
|
|
435
|
+ zoom();
|
452
|
436
|
drawGlyph();
|
453
|
437
|
}
|
454
|
438
|
|
... |
... |
@@ -495,7 +479,6 @@ SingularTab::setDefaults() |
495
|
479
|
{
|
496
|
480
|
currentGlyphIndex_ = 0;
|
497
|
481
|
|
498
|
|
- zoomSpinBox_->setValue(20);
|
499
|
482
|
showBitmapCheckBox_->setChecked(true);
|
500
|
483
|
showOutlinesCheckBox_->setChecked(true);
|
501
|
484
|
showGridCheckBox_->setChecked(true);
|
src/ftinspect/panels/singular.hpp
... |
... |
@@ -79,8 +79,6 @@ private: |
79
|
79
|
|
80
|
80
|
GlyphIndexSelector* indexSelector_;
|
81
|
81
|
FontSizeSelector* sizeSelector_;
|
82
|
|
- QLabel* zoomLabel_;
|
83
|
|
- ZoomSpinBox* zoomSpinBox_;
|
84
|
82
|
QPushButton* centerGridButton_;
|
85
|
83
|
QPushButton* helpButton_;
|
86
|
84
|
|
src/ftinspect/widgets/customwidgets.cpp
... |
... |
@@ -63,18 +63,42 @@ QGraphicsViewx::resizeEvent(QResizeEvent* event) |
63
|
63
|
}
|
64
|
64
|
|
65
|
65
|
// ---------------------------
|
66
|
|
-// >>>>>>>> QSpinBoxx <<<<<<<<
|
|
66
|
+// >>>>>>>> ZoomSpinBox <<<<<<<<
|
67
|
67
|
// ---------------------------
|
68
|
68
|
|
69
|
69
|
// we want to mark the center of a pixel square with a single dot or a small
|
70
|
70
|
// cross; starting with a certain magnification we thus only use even values
|
71
|
71
|
// so that we can do that symmetrically
|
|
72
|
+// This behaviour is only for the singular view grid.
|
72
|
73
|
|
73
|
|
-int
|
74
|
|
-ZoomSpinBox::valueFromText(const QString& text) const
|
|
74
|
+
|
|
75
|
+ZoomSpinBox::ZoomSpinBox(QWidget* parent, bool continuousView)
|
|
76
|
+: QDoubleSpinBox(parent), continuousView_(continuousView)
|
75
|
77
|
{
|
76
|
|
- int val = QSpinBox::valueFromText(text);
|
|
78
|
+ setKeyboardTracking(false);
|
|
79
|
+ if (continuousView)
|
|
80
|
+ {
|
|
81
|
+ setDecimals(2);
|
|
82
|
+ setRange(0.25, 50.0);
|
|
83
|
+ setSingleStep(0.25);
|
|
84
|
+ setValue(1);
|
|
85
|
+ }
|
|
86
|
+ else
|
|
87
|
+ {
|
|
88
|
+ setDecimals(0);
|
|
89
|
+ setRange(1, 1000 - 1000 % 64);
|
|
90
|
+ setSingleStep(1);
|
|
91
|
+ setValue(20);
|
|
92
|
+ }
|
|
93
|
+}
|
|
94
|
+
|
77
|
95
|
|
|
96
|
+double
|
|
97
|
+ZoomSpinBox::valueFromText(const QString& text) const
|
|
98
|
+{
|
|
99
|
+ if (continuousView_)
|
|
100
|
+ return QDoubleSpinBox::valueFromText(text);
|
|
101
|
+ int val = static_cast<int>(QDoubleSpinBox::valueFromText(text));
|
78
|
102
|
if (val > 640)
|
79
|
103
|
val = val - (val % 64);
|
80
|
104
|
else if (val > 320)
|
... |
... |
@@ -92,16 +116,16 @@ ZoomSpinBox::valueFromText(const QString& text) const |
92
|
116
|
}
|
93
|
117
|
|
94
|
118
|
|
95
|
|
-ZoomSpinBox::ZoomSpinBox(QWidget* parent)
|
96
|
|
-: QSpinBox(parent)
|
97
|
|
-{
|
98
|
|
-}
|
99
|
|
-
|
100
|
|
-
|
101
|
119
|
void
|
102
|
120
|
ZoomSpinBox::stepBy(int steps)
|
103
|
121
|
{
|
104
|
|
- int val = value();
|
|
122
|
+ if (continuousView_)
|
|
123
|
+ {
|
|
124
|
+ QDoubleSpinBox::stepBy(steps);
|
|
125
|
+ return;
|
|
126
|
+ }
|
|
127
|
+
|
|
128
|
+ int val = static_cast<int>(value());
|
105
|
129
|
|
106
|
130
|
if (steps > 0)
|
107
|
131
|
{
|
src/ftinspect/widgets/customwidgets.hpp
... |
... |
@@ -45,14 +45,17 @@ private: |
45
|
45
|
|
46
|
46
|
// we want to have our own `stepBy' function for the zoom spin box
|
47
|
47
|
class ZoomSpinBox
|
48
|
|
-: public QSpinBox
|
|
48
|
+: public QDoubleSpinBox
|
49
|
49
|
{
|
50
|
50
|
Q_OBJECT
|
51
|
51
|
|
52
|
52
|
public:
|
53
|
|
- ZoomSpinBox(QWidget* parent);
|
|
53
|
+ ZoomSpinBox(QWidget* parent, bool continuousView);
|
54
|
54
|
void stepBy(int val) override;
|
55
|
|
- int valueFromText(const QString& text) const override;
|
|
55
|
+ double valueFromText(const QString& text) const override;
|
|
56
|
+
|
|
57
|
+private:
|
|
58
|
+ bool continuousView_;
|
56
|
59
|
};
|
57
|
60
|
|
58
|
61
|
|
src/ftinspect/widgets/fontsizeselector.cpp
... |
... |
@@ -8,10 +8,12 @@ |
8
|
8
|
|
9
|
9
|
#include <algorithm>
|
10
|
10
|
|
11
|
|
-FontSizeSelector::FontSizeSelector(QWidget* parent)
|
12
|
|
-: QWidget(parent)
|
|
11
|
+FontSizeSelector::FontSizeSelector(QWidget* parent,
|
|
12
|
+ bool zoomNewLine,
|
|
13
|
+ bool continuousView)
|
|
14
|
+: QWidget(parent), continuousView_(continuousView)
|
13
|
15
|
{
|
14
|
|
- createLayout();
|
|
16
|
+ createLayout(zoomNewLine);
|
15
|
17
|
createConnections();
|
16
|
18
|
setDefaults();
|
17
|
19
|
}
|
... |
... |
@@ -31,6 +33,15 @@ FontSizeSelector::selectedUnit() |
31
|
33
|
}
|
32
|
34
|
|
33
|
35
|
|
|
36
|
+double
|
|
37
|
+FontSizeSelector::zoomFactor()
|
|
38
|
+{
|
|
39
|
+ if (continuousView_)
|
|
40
|
+ return zoomSpinBox_->value();
|
|
41
|
+ return static_cast<int>(zoomSpinBox_->value());
|
|
42
|
+}
|
|
43
|
+
|
|
44
|
+
|
34
|
45
|
void
|
35
|
46
|
FontSizeSelector::setSizePixel(int sizePixel)
|
36
|
47
|
{
|
... |
... |
@@ -47,6 +58,15 @@ FontSizeSelector::setSizePoint(double sizePoint) |
47
|
58
|
}
|
48
|
59
|
|
49
|
60
|
|
|
61
|
+void
|
|
62
|
+FontSizeSelector::setZoomFactor(double zoomFactor)
|
|
63
|
+{
|
|
64
|
+ if (continuousView_)
|
|
65
|
+ zoomSpinBox_->setValue(zoomFactor);
|
|
66
|
+ zoomSpinBox_->setValue(static_cast<int>(zoomFactor));
|
|
67
|
+}
|
|
68
|
+
|
|
69
|
+
|
50
|
70
|
void
|
51
|
71
|
FontSizeSelector::reloadFromFont(Engine* engine)
|
52
|
72
|
{
|
... |
... |
@@ -90,6 +110,17 @@ FontSizeSelector::handleWheelResizeBySteps(int steps) |
90
|
110
|
}
|
91
|
111
|
|
92
|
112
|
|
|
113
|
+void
|
|
114
|
+FontSizeSelector::handleWheelZoomBySteps(int steps)
|
|
115
|
+{
|
|
116
|
+ double zoomAfter = zoomSpinBox_->value()
|
|
117
|
+ + steps * zoomSpinBox_->singleStep();
|
|
118
|
+ zoomAfter = std::max(zoomSpinBox_->minimum(),
|
|
119
|
+ std::min(zoomAfter, zoomSpinBox_->maximum()));
|
|
120
|
+ zoomSpinBox_->setValue(zoomAfter);
|
|
121
|
+}
|
|
122
|
+
|
|
123
|
+
|
93
|
124
|
void
|
94
|
125
|
FontSizeSelector::handleWheelResizeFromGrid(QWheelEvent* event)
|
95
|
126
|
{
|
... |
... |
@@ -173,11 +204,11 @@ FontSizeSelector::checkUnits() |
173
|
204
|
|
174
|
205
|
|
175
|
206
|
void
|
176
|
|
-FontSizeSelector::createLayout()
|
|
207
|
+FontSizeSelector::createLayout(bool zoomNewLine)
|
177
|
208
|
{
|
178
|
209
|
sizeLabel_ = new QLabel(tr("Size "), this);
|
179
|
210
|
sizeLabel_->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
180
|
|
- sizeDoubleSpinBox_ = new QDoubleSpinBox;
|
|
211
|
+ sizeDoubleSpinBox_ = new QDoubleSpinBox(this);
|
181
|
212
|
sizeDoubleSpinBox_->setAlignment(Qt::AlignRight);
|
182
|
213
|
sizeDoubleSpinBox_->setDecimals(1);
|
183
|
214
|
sizeDoubleSpinBox_->setRange(1, 500);
|
... |
... |
@@ -194,6 +225,12 @@ FontSizeSelector::createLayout() |
194
|
225
|
dpiSpinBox_->setRange(10, 600);
|
195
|
226
|
dpiLabel_->setBuddy(dpiSpinBox_);
|
196
|
227
|
|
|
228
|
+ zoomLabel_ = new QLabel(tr("Zoom Factor "), this);
|
|
229
|
+ zoomLabel_->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
|
230
|
+ zoomSpinBox_ = new ZoomSpinBox(this, continuousView_);
|
|
231
|
+ zoomSpinBox_->setAlignment(Qt::AlignRight);
|
|
232
|
+ zoomLabel_->setBuddy(zoomSpinBox_);
|
|
233
|
+
|
197
|
234
|
// Tooltips
|
198
|
235
|
sizeDoubleSpinBox_->setToolTip(
|
199
|
236
|
tr("Size value (will be limited to available sizes if\nthe current font "
|
... |
... |
@@ -202,20 +239,36 @@ FontSizeSelector::createLayout() |
202
|
239
|
"the current font is not scalable)."));
|
203
|
240
|
dpiSpinBox_->setToolTip(
|
204
|
241
|
tr("DPI for the point size value (only valid when the unit is point)."));
|
|
242
|
+ zoomSpinBox_->setToolTip(tr("Adjust zoom."));
|
205
|
243
|
|
206
|
244
|
// Layouting
|
207
|
|
- layout_ = new QHBoxLayout;
|
208
|
|
-
|
209
|
|
- layout_->addStretch(1);
|
210
|
|
- layout_->addWidget(sizeLabel_);
|
211
|
|
- layout_->addWidget(sizeDoubleSpinBox_);
|
212
|
|
- layout_->addWidget(unitsComboBox_);
|
213
|
|
- layout_->addStretch(1);
|
214
|
|
- layout_->addWidget(dpiLabel_);
|
215
|
|
- layout_->addWidget(dpiSpinBox_);
|
216
|
|
- layout_->addStretch(1);
|
217
|
|
-
|
218
|
|
- setLayout(layout_);
|
|
245
|
+ mainLayout_ = new QVBoxLayout;
|
|
246
|
+ upLayout_ = new QHBoxLayout;
|
|
247
|
+ upLayout_->addStretch(1);
|
|
248
|
+ upLayout_->addWidget(sizeLabel_);
|
|
249
|
+ upLayout_->addWidget(sizeDoubleSpinBox_);
|
|
250
|
+ upLayout_->addWidget(unitsComboBox_);
|
|
251
|
+ upLayout_->addStretch(1);
|
|
252
|
+ upLayout_->addWidget(dpiLabel_);
|
|
253
|
+ upLayout_->addWidget(dpiSpinBox_);
|
|
254
|
+ upLayout_->addStretch(1);
|
|
255
|
+ if (!zoomNewLine)
|
|
256
|
+ {
|
|
257
|
+ upLayout_->addWidget(zoomLabel_);
|
|
258
|
+ upLayout_->addWidget(zoomSpinBox_);
|
|
259
|
+ upLayout_->addStretch(1);
|
|
260
|
+ mainLayout_->addLayout(upLayout_);
|
|
261
|
+ }
|
|
262
|
+ else
|
|
263
|
+ {
|
|
264
|
+ downLayout_ = new QHBoxLayout;
|
|
265
|
+ downLayout_->addWidget(zoomLabel_);
|
|
266
|
+ downLayout_->addWidget(zoomSpinBox_, 1);
|
|
267
|
+ mainLayout_->addLayout(upLayout_);
|
|
268
|
+ mainLayout_->addLayout(downLayout_);
|
|
269
|
+ }
|
|
270
|
+
|
|
271
|
+ setLayout(mainLayout_);
|
219
|
272
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
|
220
|
273
|
}
|
221
|
274
|
|
... |
... |
@@ -229,6 +282,8 @@ FontSizeSelector::createConnections() |
229
|
282
|
this, &FontSizeSelector::checkUnits);
|
230
|
283
|
connect(dpiSpinBox_, QOverload<int>::of(&QSpinBox::valueChanged),
|
231
|
284
|
this, &FontSizeSelector::checkFixedSizeAndEmit);
|
|
285
|
+ connect(zoomSpinBox_, QOverload<double>::of(&ZoomSpinBox::valueChanged),
|
|
286
|
+ this, &FontSizeSelector::valueChanged);
|
232
|
287
|
}
|
233
|
288
|
|
234
|
289
|
|
src/ftinspect/widgets/fontsizeselector.hpp
... |
... |
@@ -4,6 +4,8 @@ |
4
|
4
|
|
5
|
5
|
#pragma once
|
6
|
6
|
|
|
7
|
+#include "customwidgets.hpp"
|
|
8
|
+
|
7
|
9
|
#include <QComboBox>
|
8
|
10
|
#include <QDoubleSpinBox>
|
9
|
11
|
#include <QLabel>
|
... |
... |
@@ -17,7 +19,7 @@ class FontSizeSelector : public QWidget |
17
|
19
|
Q_OBJECT
|
18
|
20
|
|
19
|
21
|
public:
|
20
|
|
- FontSizeSelector(QWidget* parent);
|
|
22
|
+ FontSizeSelector(QWidget* parent, bool zoomNewLine, bool continuousView);
|
21
|
23
|
~FontSizeSelector() override = default;
|
22
|
24
|
|
23
|
25
|
enum Units : int
|
... |
... |
@@ -28,12 +30,15 @@ public: |
28
|
30
|
|
29
|
31
|
double selectedSize();
|
30
|
32
|
Units selectedUnit();
|
|
33
|
+ double zoomFactor();
|
31
|
34
|
void setSizePixel(int sizePixel);
|
32
|
35
|
void setSizePoint(double sizePoint);
|
|
36
|
+ void setZoomFactor(double zoomFactor);
|
33
|
37
|
|
34
|
38
|
void reloadFromFont(Engine* engine);
|
35
|
39
|
void applyToEngine(Engine* engine);
|
36
|
40
|
void handleWheelResizeBySteps(int steps);
|
|
41
|
+ void handleWheelZoomBySteps(int steps);
|
37
|
42
|
void handleWheelResizeFromGrid(QWheelEvent* event);
|
38
|
43
|
bool handleKeyEvent(QKeyEvent const* keyEvent);
|
39
|
44
|
void installEventFilterForWidget(QWidget* widget);
|
... |
... |
@@ -50,18 +55,24 @@ private slots: |
50
|
55
|
private:
|
51
|
56
|
QLabel* sizeLabel_;
|
52
|
57
|
QLabel* dpiLabel_;
|
|
58
|
+ QLabel* zoomLabel_;
|
53
|
59
|
|
54
|
60
|
QDoubleSpinBox* sizeDoubleSpinBox_;
|
55
|
61
|
QComboBox* unitsComboBox_;
|
56
|
62
|
QSpinBox* dpiSpinBox_;
|
|
63
|
+ ZoomSpinBox* zoomSpinBox_;
|
57
|
64
|
|
58
|
|
- QHBoxLayout* layout_;
|
|
65
|
+ // Sometimes we need to split 2 lines
|
|
66
|
+ QHBoxLayout* upLayout_;
|
|
67
|
+ QHBoxLayout* downLayout_;
|
|
68
|
+ QVBoxLayout* mainLayout_;
|
59
|
69
|
|
|
70
|
+ bool continuousView_;
|
60
|
71
|
double lastValue_;
|
61
|
72
|
bool bitmapOnly_ = false;
|
62
|
73
|
std::vector<int> fixedSizes_;
|
63
|
74
|
|
64
|
|
- void createLayout();
|
|
75
|
+ void createLayout(bool zoomNewLine);
|
65
|
76
|
void createConnections();
|
66
|
77
|
void setDefaults(bool sizeOnly = false);
|
67
|
78
|
|
|