[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master ec274ce 2/2: [ftinspect] Display grid.
From: |
Werner LEMBERG |
Subject: |
[freetype2-demos] master ec274ce 2/2: [ftinspect] Display grid. |
Date: |
Sun, 8 May 2016 14:25:45 +0000 (UTC) |
branch: master
commit ec274ce9cd504f248a789927cff4d0661dcad28b
Author: Werner Lemberg <address@hidden>
Commit: Werner Lemberg <address@hidden>
[ftinspect] Display grid.
The dimensions are still arbitrary, though.
We now need Qt 4.6 or newer.
* src/ftinspect.h (Engine): Remove `zoom' member. It doesn't belong
here.
(Grid): New class, derived from `QGraphicsItem'. We need this to
disable drawing of the grid if the zoom factor is too small.
(MainGUI): Add a `QGraphicsScene' member.
Add a `zoom' method.
* src/ftinspect.cpp (Engine::update): Updated.
(Grid::Grid, Grid::boundingRect, Grid::paint): New methods.
(MainGUI::createLayout): Initialize `glyphView' and `glyphScene';
add a grid object.
Change zoomSpinBox to display an integer zoom factor instead of a
percentage. This simplifies code since we don't have to bother with
scaling values < 1.
(MainGUI::createConnections, MainGUI::setDefaults): Updated.
---
ChangeLog | 30 +++++++++++++++++--
src/ftinspect.cpp | 83 +++++++++++++++++++++++++++++++++++++++++++++++++----
src/ftinspect.h | 19 +++++++++++-
3 files changed, 122 insertions(+), 10 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c3894e0..47653db 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,33 @@
2016-05-08 Werner Lemberg <address@hidden>
- [ftinspect] Provide some drawing colors.
+ [ftinspect] Display grid.
+
+ The dimensions are still arbitrary, though.
+
+ We now need Qt 4.6 or newer.
+
+ * src/ftinspect.h (Engine): Remove `zoom' member. It doesn't belong
+ here.
+ (Grid): New class, derived from `QGraphicsItem'. We need this to
+ disable drawing of the grid if the zoom factor is too small.
+ (MainGUI): Add a `QGraphicsScene' member.
+ Add a `zoom' method.
+
+ * src/ftinspect.cpp (Engine::update): Updated.
+ (Grid::Grid, Grid::boundingRect, Grid::paint): New methods.
+ (MainGUI::createLayout): Initialize `glyphView' and `glyphScene';
+ add a grid object.
+ Change zoomSpinBox to display an integer zoom factor instead of a
+ percentage. This simplifies code since we don't have to bother with
+ scaling values < 1.
+ (MainGUI::createConnections, MainGUI::setDefaults): Updated.
+
+2016-05-08 Werner Lemberg <address@hidden>
+
+ [ftinspect] Provide some drawing pens.
- * src/ftinspect.h (MainGUI): Provide colors for axes, blue zones,
- grid lines, on and off points, outlines, and segment lines.
+ * src/ftinspect.h (MainGUI): Provide colored pens for axes, blue
+ zones, grid lines, on and off points, outlines, and segment lines.
* src/ftinspect.cpp (MainGUI::setGraphicsDefaults): New method.
(MainGUI::MainGUI): Updated.
diff --git a/src/ftinspect.cpp b/src/ftinspect.cpp
index 2b219e9..91e4d82 100644
--- a/src/ftinspect.cpp
+++ b/src/ftinspect.cpp
@@ -346,7 +346,6 @@ void
Engine::update()
{
dpi = gui->dpiSpinBox->value();
- zoom = gui->zoomSpinBox->value();
if (gui->unitsComboBox->currentIndex() == MainGUI::Units_px)
{
@@ -447,6 +446,48 @@ Engine::update()
}
+Grid::Grid(const QPen& p)
+: pen(p)
+{
+ // empty
+}
+
+
+QRectF
+Grid::boundingRect() const
+{
+ // XXX fix size
+
+ // no need to take care of pen width
+ return QRectF(0, 0,
+ 100, 100);
+}
+
+
+void
+Grid::paint(QPainter* painter,
+ const QStyleOptionGraphicsItem* option,
+ QWidget*)
+{
+ const qreal lod = option->levelOfDetailFromTransform(
+ painter->worldTransform());
+
+ painter->setPen(pen);
+
+ // don't draw grid if magnification is too small
+ if (lod >= 5)
+ {
+ // XXX fix size
+ for (qreal x = 0; x <= 100; x++ )
+ painter->drawLine(x, 0,
+ x, 100);
+ for (qreal y = 0; y <= 100; y++)
+ painter->drawLine(0, y,
+ 100, y);
+ }
+}
+
+
MainGUI::MainGUI()
{
setGraphicsDefaults();
@@ -970,6 +1011,24 @@ MainGUI::nextInstance()
void
+MainGUI::zoom()
+{
+ int scale = zoomSpinBox->value();
+
+ QTransform transform;
+ transform.scale(scale, scale);
+
+ // we want horizontal and vertical 1px lines displayed with full pixels;
+ // we thus have to shift the coordinate system accordingly, using a value
+ // that represents 0.5px (i.e., half the 1px line width) after the scaling
+ qreal shift = 0.5 / scale;
+ transform.translate(shift, shift);
+
+ glyphView->setTransform(transform);
+}
+
+
+void
MainGUI::setGraphicsDefaults()
{
// XXX make this user-configurable
@@ -1174,7 +1233,16 @@ MainGUI::createLayout()
leftWidget->setSizePolicy(leftWidgetPolicy);
// right side
+ glyphScene = new QGraphicsScene;
+ glyphScene->addItem(new Grid(gridPen));
+
glyphView = new QGraphicsView;
+ glyphView->setRenderHint(QPainter::Antialiasing, true);
+ glyphView->setDragMode(QGraphicsView::ScrollHandDrag);
+ glyphView->setOptimizationFlags(QGraphicsView::DontSavePainterState);
+ glyphView->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
+ glyphView->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
+ glyphView->setScene(glyphScene);
sizeLabel = new QLabel(tr("Size "));
sizeLabel->setAlignment(Qt::AlignRight);
@@ -1207,13 +1275,12 @@ MainGUI::createLayout()
toP1000Buttonx = new QPushButtonx("+1000");
toEndButtonx = new QPushButtonx(">|");
- zoomLabel = new QLabel(tr("Zoom "));
+ zoomLabel = new QLabel(tr("Zoom Factor"));
zoomLabel->setAlignment(Qt::AlignRight);
zoomSpinBox = new QSpinBox;
zoomSpinBox->setAlignment(Qt::AlignRight);
- zoomSpinBox->setRange(1, 10000);
- zoomSpinBox->setSuffix("%");
- zoomSpinBox->setSingleStep(10);
+ zoomSpinBox->setRange(1, 1000);
+ zoomSpinBox->setSingleStep(1);
zoomLabel->setBuddy(zoomSpinBox);
previousFontButton = new QPushButton(tr("Previous Font"));
@@ -1308,6 +1375,9 @@ MainGUI::createConnections()
connect(unitsComboBox, SIGNAL(currentIndexChanged(int)),
SLOT(checkUnits()));
+ connect(zoomSpinBox, SIGNAL(valueChanged(int)),
+ SLOT(zoom()));
+
connect(previousFontButton, SIGNAL(clicked()),
SLOT(previousFont()));
connect(nextFontButton, SIGNAL(clicked()),
@@ -1478,7 +1548,7 @@ MainGUI::setDefaults()
gammaSlider->setValue(18); // 1.8
sizeDoubleSpinBox->setValue(20);
dpiSpinBox->setValue(96);
- zoomSpinBox->setValue(100);
+ zoomSpinBox->setValue(20);
checkHinting();
checkHintingMode();
@@ -1490,6 +1560,7 @@ MainGUI::setDefaults()
checkCurrentFontIndex();
checkCurrentFaceIndex();
checkCurrentInstanceIndex();
+ zoom();
}
diff --git a/src/ftinspect.h b/src/ftinspect.h
index 8f14f6f..435aaeb 100644
--- a/src/ftinspect.h
+++ b/src/ftinspect.h
@@ -22,6 +22,8 @@
#include <QDir>
#include <QDoubleSpinBox>
#include <QFileDialog>
+#include <QGraphicsItem>
+#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGridLayout>
#include <QHash>
@@ -43,6 +45,7 @@
#include <QStandardItemModel>
#include <QStatusBar>
#include <QTabWidget>
+#include <QTransform>
#include <QVariant>
#include <QVBoxLayout>
#include <QWidget>
@@ -130,7 +133,6 @@ private:
double pointSize;
double pixelSize;
int dpi;
- int zoom;
bool doHinting;
bool doAutoHinting;
@@ -151,6 +153,19 @@ private:
};
+class Grid
+: public QGraphicsItem
+{
+public:
+ Grid(const QPen&);
+ QRectF boundingRect() const;
+ void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*);
+
+private:
+ QPen pen;
+};
+
+
// we want to grey out items in a combo box;
// since Qt doesn't provide a function for this we derive a class
class QComboBoxx
@@ -217,6 +232,7 @@ private slots:
void previousFace();
void previousFont();
void previousInstance();
+ void zoom();
private:
Engine* engine;
@@ -258,6 +274,7 @@ private:
QDoubleSpinBox *sizeDoubleSpinBox;
+ QGraphicsScene *glyphScene;
QGraphicsView *glyphView;
QGridLayout *fontLayout;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master ec274ce 2/2: [ftinspect] Display grid.,
Werner LEMBERG <=