[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master 75504d3 06/41: [ftinspect] Re-organize custom w
From: |
Werner Lemberg |
Subject: |
[freetype2-demos] master 75504d3 06/41: [ftinspect] Re-organize custom widgets. |
Date: |
Mon, 3 Oct 2022 11:27:00 -0400 (EDT) |
branch: master
commit 75504d30d1d14bd9d641ece257c21b453bf0e15a
Author: Charlie Jiang <w@chariri.moe>
Commit: Werner Lemberg <wl@gnu.org>
[ftinspect] Re-organize custom widgets.
* src/ftinspect/widgets/customwidgets.cpp,
src/ftinspect/widgets/customwidgets.cpp: New files.
Include `QGraphicsViewx`, `ZoomSpinBox` and `UnboundScrollArea` (for later
use).
* src/ftinspect/widgets/qspinboxx.hpp, src/ftinspect/widgets/qspinboxx.hpp:
Changed into `ZoomSpinBox` in `customwidgets.cpp`.
* src/ftinspect/widgets/qgraphicsviewx.cpp,
src/ftinspect/widgets/qgraphicsviewx.hpp:
Merged into `customwidgets.cpp`
* src/ftinspect/widgets/qcomboboxx.hpp,
src/ftinspect/widgets/qcomboboxx.cpp: Removed. No longer needed.
We're using custom `QAbstractListModel`'s `flags` func to disable items.
* src/ftinspect/widgets/qpushbuttonx.hpp,
src/ftinspect/widgets/qpushbuttonx.cpp: Removed. No longer needed.
We're using `setButtonNarrowest` in `uihelper.cpp`.
* src/ftinspect/maingui.cpp, src/ftinspect/maingui.hpp: Updated to use new
custom widgets.
* src/ftinspect/CMakeLists.txt, src/ftinspect/meson.build: Updated.
---
src/ftinspect/CMakeLists.txt | 6 +-
src/ftinspect/maingui.cpp | 40 +++---
src/ftinspect/maingui.hpp | 27 ++--
src/ftinspect/meson.build | 11 +-
src/ftinspect/uihelper.cpp | 80 ++++++++++++
src/ftinspect/uihelper.hpp | 33 +++++
src/ftinspect/widgets/customwidgets.cpp | 203 +++++++++++++++++++++++++++++++
src/ftinspect/widgets/customwidgets.hpp | 78 ++++++++++++
src/ftinspect/widgets/qcomboboxx.cpp | 37 ------
src/ftinspect/widgets/qcomboboxx.hpp | 24 ----
src/ftinspect/widgets/qgraphicsviewx.cpp | 49 --------
src/ftinspect/widgets/qgraphicsviewx.hpp | 32 -----
src/ftinspect/widgets/qpushbuttonx.cpp | 33 -----
src/ftinspect/widgets/qpushbuttonx.hpp | 24 ----
src/ftinspect/widgets/qspinboxx.cpp | 85 -------------
src/ftinspect/widgets/qspinboxx.hpp | 24 ----
16 files changed, 437 insertions(+), 349 deletions(-)
diff --git a/src/ftinspect/CMakeLists.txt b/src/ftinspect/CMakeLists.txt
index a49d652..4b34fe0 100644
--- a/src/ftinspect/CMakeLists.txt
+++ b/src/ftinspect/CMakeLists.txt
@@ -18,6 +18,7 @@ find_package(Freetype REQUIRED)
add_executable(ftinspect
"ftinspect.cpp"
"maingui.cpp"
+ "uihelper.cpp"
"engine/engine.cpp"
"engine/fontfilemanager.cpp"
@@ -28,10 +29,7 @@ add_executable(ftinspect
"rendering/glyphpoints.cpp"
"rendering/grid.cpp"
- "widgets/qcomboboxx.cpp"
- "widgets/qgraphicsviewx.cpp"
- "widgets/qpushbuttonx.cpp"
- "widgets/qspinboxx.cpp"
+ "widgets/customwidgets.cpp"
"models/customcomboboxmodels.cpp"
)
diff --git a/src/ftinspect/maingui.cpp b/src/ftinspect/maingui.cpp
index c3da941..4071412 100644
--- a/src/ftinspect/maingui.cpp
+++ b/src/ftinspect/maingui.cpp
@@ -5,6 +5,7 @@
#include "maingui.hpp"
#include "rendering/grid.hpp"
+#include "uihelper.hpp"
#include <QApplication>
#include <QFileDialog>
@@ -586,7 +587,7 @@ MainGUI::nextNamedInstance()
void
MainGUI::zoom()
{
- int scale = zoomSpinBox_->value();
+ int scale = static_cast<int>(zoomSpinBox_->value());
QTransform transform;
transform.scale(scale, scale);
@@ -886,7 +887,7 @@ MainGUI::createLayout()
currentGlyphPointsItem_ = NULL;
currentGlyphPointNumbersItem_ = NULL;
- glyphView_ = new QGraphicsViewx;
+ glyphView_ = new QGraphicsViewx(this);
glyphView_->setRenderHint(QPainter::Antialiasing, true);
glyphView_->setDragMode(QGraphicsView::ScrollHandDrag);
glyphView_->setOptimizationFlags(QGraphicsView::DontSavePainterState);
@@ -913,20 +914,31 @@ MainGUI::createLayout()
dpiSpinBox_->setRange(10, 600);
dpiLabel_->setBuddy(dpiSpinBox_);
- toStartButtonx_ = new QPushButtonx("|<");
- toM1000Buttonx_ = new QPushButtonx("-1000");
- toM100Buttonx_ = new QPushButtonx("-100");
- toM10Buttonx_ = new QPushButtonx("-10");
- toM1Buttonx_ = new QPushButtonx("-1");
- toP1Buttonx_ = new QPushButtonx("+1");
- toP10Buttonx_ = new QPushButtonx("+10");
- toP100Buttonx_ = new QPushButtonx("+100");
- toP1000Buttonx_ = new QPushButtonx("+1000");
- toEndButtonx_ = new QPushButtonx(">|");
+ toStartButtonx_ = new QPushButton("|<");
+ toM1000Buttonx_ = new QPushButton("-1000");
+ toM100Buttonx_ = new QPushButton("-100");
+ toM10Buttonx_ = new QPushButton("-10");
+ toM1Buttonx_ = new QPushButton("-1");
+ toP1Buttonx_ = new QPushButton("+1");
+ toP10Buttonx_ = new QPushButton("+10");
+ toP100Buttonx_ = new QPushButton("+100");
+ toP1000Buttonx_ = new QPushButton("+1000");
+ toEndButtonx_ = new QPushButton(">|");
+
+ setButtonNarrowest(toStartButtonx_);
+ setButtonNarrowest(toM1000Buttonx_);
+ setButtonNarrowest(toM100Buttonx_ );
+ setButtonNarrowest(toM10Buttonx_ );
+ setButtonNarrowest(toM1Buttonx_ );
+ setButtonNarrowest(toP1Buttonx_ );
+ setButtonNarrowest(toP10Buttonx_ );
+ setButtonNarrowest(toP100Buttonx_ );
+ setButtonNarrowest(toP1000Buttonx_);
+ setButtonNarrowest(toEndButtonx_ );
zoomLabel_ = new QLabel(tr("Zoom Factor"));
zoomLabel_->setAlignment(Qt::AlignRight);
- zoomSpinBox_ = new QSpinBoxx;
+ zoomSpinBox_ = new ZoomSpinBox(this, false);
zoomSpinBox_->setAlignment(Qt::AlignRight);
zoomSpinBox_->setRange(1, 1000 - 1000 % 64);
zoomSpinBox_->setKeyboardTracking(false);
@@ -1040,7 +1052,7 @@ MainGUI::createConnections()
connect(dpiSpinBox_, SIGNAL(valueChanged(int)),
SLOT(drawGlyph()));
- connect(zoomSpinBox_, SIGNAL(valueChanged(int)),
+ connect(zoomSpinBox_, SIGNAL(valueChanged(double)),
SLOT(zoom()));
connect(previousFontButton_, SIGNAL(clicked()),
diff --git a/src/ftinspect/maingui.hpp b/src/ftinspect/maingui.hpp
index 536f702..2be65b9 100644
--- a/src/ftinspect/maingui.hpp
+++ b/src/ftinspect/maingui.hpp
@@ -10,10 +10,7 @@
#include "rendering/glyphoutline.hpp"
#include "rendering/glyphpointnumbers.hpp"
#include "rendering/glyphpoints.hpp"
-#include "widgets/qcomboboxx.hpp"
-#include "widgets/qgraphicsviewx.hpp"
-#include "widgets/qpushbuttonx.hpp"
-#include "widgets/qspinboxx.hpp"
+#include "widgets/customwidgets.hpp"
#include "models/customcomboboxmodels.hpp"
#include <QAction>
@@ -196,23 +193,23 @@ private:
QPushButton *previousFontButton_;
QPushButton *previousNamedInstanceButton_;
- QPushButtonx *toEndButtonx_;
- QPushButtonx *toM1000Buttonx_;
- QPushButtonx *toM100Buttonx_;
- QPushButtonx *toM10Buttonx_;
- QPushButtonx *toM1Buttonx_;
- QPushButtonx *toP1000Buttonx_;
- QPushButtonx *toP100Buttonx_;
- QPushButtonx *toP10Buttonx_;
- QPushButtonx *toP1Buttonx_;
- QPushButtonx *toStartButtonx_;
+ QPushButton *toEndButtonx_;
+ QPushButton *toM1000Buttonx_;
+ QPushButton *toM100Buttonx_;
+ QPushButton *toM10Buttonx_;
+ QPushButton *toM1Buttonx_;
+ QPushButton *toP1000Buttonx_;
+ QPushButton *toP100Buttonx_;
+ QPushButton *toP10Buttonx_;
+ QPushButton *toP1Buttonx_;
+ QPushButton *toStartButtonx_;
QSignalMapper *glyphNavigationMapper_;
QSlider *gammaSlider_;
QSpinBox *dpiSpinBox_;
- QSpinBoxx *zoomSpinBox_;
+ ZoomSpinBox *zoomSpinBox_;
QTabWidget *tabWidget_;
diff --git a/src/ftinspect/meson.build b/src/ftinspect/meson.build
index 1191f91..182372b 100644
--- a/src/ftinspect/meson.build
+++ b/src/ftinspect/meson.build
@@ -30,24 +30,19 @@ if qt5_dep.found()
'rendering/glyphpoints.cpp',
'rendering/grid.cpp',
- 'widgets/qcomboboxx.cpp',
- 'widgets/qgraphicsviewx.cpp',
- 'widgets/qpushbuttonx.cpp',
- 'widgets/qspinboxx.cpp',
+ 'widgets/customwidgets.cpp',
'models/customcomboboxmodels.cpp',
'ftinspect.cpp',
'maingui.cpp',
+ 'uihelper.cpp',
])
moc_files = qt5.preprocess(
moc_headers: [
'engine/fontfilemanager.hpp',
- 'widgets/qcomboboxx.hpp',
- 'widgets/qgraphicsviewx.hpp',
- 'widgets/qpushbuttonx.hpp',
- 'widgets/qspinboxx.hpp',
+ 'widgets/customwidgets.hpp',
'maingui.hpp',
'models/customcomboboxmodels.hpp',
],
diff --git a/src/ftinspect/uihelper.cpp b/src/ftinspect/uihelper.cpp
new file mode 100644
index 0000000..c79454b
--- /dev/null
+++ b/src/ftinspect/uihelper.cpp
@@ -0,0 +1,80 @@
+// uihelper.cpp
+
+// Copyright (C) 2022 by Charlie Jiang.
+
+#include "uihelper.hpp"
+
+#include <QStyleOptionButton>
+#include <QFontMetrics>
+#include <QString>
+
+// code derived from Qt 4.8.7, function `QPushButton::sizeHint',
+// file `src/gui/widgets/qpushbutton.cpp'
+
+void
+setButtonNarrowest(QPushButton* btn)
+{
+ QStyleOptionButton opt;
+ opt.initFrom(btn);
+ QString s(btn->text());
+ QFontMetrics fm = btn->fontMetrics();
+ QSize sz = fm.size(Qt::TextShowMnemonic, s);
+ opt.rect.setSize(sz);
+
+ sz = btn->style()->sizeFromContents(QStyle::CT_PushButton, &opt, sz, btn);
+ btn->setFixedWidth(sz.width());
+}
+
+
+void
+setLabelSelectable(QLabel* label)
+{
+
+ label->setTextInteractionFlags(Qt::TextSelectableByMouse
+ | Qt::TextSelectableByKeyboard);
+ label->setCursor(Qt::IBeamCursor);
+}
+
+
+int
+gridLayout2ColAddLayout(QGridLayout* layout,
+ QLayout* layoutSingle)
+{
+ auto r = layout->rowCount();
+ layout->addLayout(layoutSingle, r, 0, 1, 2);
+ return r;
+}
+
+
+int
+gridLayout2ColAddWidget(QGridLayout* layout,
+ QWidget* widgetSingle)
+{
+ auto r = layout->rowCount();
+ layout->addWidget(widgetSingle, r, 0, 1, 2);
+ return r;
+}
+
+
+int
+gridLayout2ColAddWidget(QGridLayout* layout,
+ QWidget* widgetL, QWidget* widgetR)
+{
+ auto r = layout->rowCount();
+ layout->addWidget(widgetL, r, 0);
+ layout->addWidget(widgetR, r, 1);
+ return r;
+}
+
+
+int
+gridLayout2ColAddItem(QGridLayout* layout,
+ QLayoutItem* item)
+{
+ auto r = layout->rowCount();
+ layout->addItem(item, r, 0, 1, 2);
+ return r;
+}
+
+
+// end of uihelper.cpp
diff --git a/src/ftinspect/uihelper.hpp b/src/ftinspect/uihelper.hpp
new file mode 100644
index 0000000..4db867d
--- /dev/null
+++ b/src/ftinspect/uihelper.hpp
@@ -0,0 +1,33 @@
+// uihelper.hpp
+
+// Copyright (C) 2022 by Charlie Jiang.
+
+#pragma once
+
+#include <QPushButton>
+#include <QLabel>
+#include <QLayoutItem>
+#include <QWidget>
+#include <QGridLayout>
+
+// we want buttons that are horizontally as small as possible
+void setButtonNarrowest(QPushButton* btn);
+void setLabelSelectable(QLabel* label);
+
+/*
+ * All those grid layout functions rely on `QGridLayout::rowCount`, which isn't
+ * so reliable since it returns the count of rows *allocated internally* inside
+ * the layout, but not the actual number of rows occupied by layout items.
+ * Always use the returned value to refer to the row position, and never mix
+ * code using hard-coded row index with these functions.
+ * If you need to add your own rows, use `rowCount` func as well or you can
+ * increment the last returned row position.
+ */
+int gridLayout2ColAddLayout(QGridLayout* layout, QLayout* layoutSingle);
+int gridLayout2ColAddWidget(QGridLayout* layout, QWidget* widgetSingle);
+int gridLayout2ColAddWidget(QGridLayout* layout,
+ QWidget* widgetL, QWidget* widgetR);
+int gridLayout2ColAddItem(QGridLayout* layout, QLayoutItem* item);
+
+
+// end of uihelper.hpp
diff --git a/src/ftinspect/widgets/customwidgets.cpp
b/src/ftinspect/widgets/customwidgets.cpp
new file mode 100644
index 0000000..2a02573
--- /dev/null
+++ b/src/ftinspect/widgets/customwidgets.cpp
@@ -0,0 +1,203 @@
+// custom_widgets.cpp
+
+// Copyright (C) 2016-2022 by Werner Lemberg.
+
+#include "customwidgets.hpp"
+
+#include <qevent.h>
+#include <QStandardItemModel>
+#include <QScrollBar>
+#include <QStyleOptionButton>
+
+// --------------------------------
+// >>>>>>>> QGraphicsViewx <<<<<<<<
+// --------------------------------
+
+QGraphicsViewx::QGraphicsViewx(QWidget* parent)
+: QGraphicsView(parent), lastBottomLeftPointInitialized_(false)
+{
+ // empty
+}
+
+
+void
+QGraphicsViewx::wheelEvent(QWheelEvent* event)
+{
+ if (event->modifiers() & Qt::ShiftModifier)
+ emit shiftWheelEvent(event);
+ else if (event->modifiers() & Qt::ControlModifier)
+ emit ctrlWheelEvent(event);
+ else
+ QGraphicsView::wheelEvent(event);
+}
+
+
+void
+QGraphicsViewx::scrollContentsBy(int dx,
+ int dy)
+{
+ QGraphicsView::scrollContentsBy(dx, dy);
+ lastBottomLeftPoint_ = viewport()->rect().bottomLeft();
+}
+
+
+void
+QGraphicsViewx::resizeEvent(QResizeEvent* event)
+{
+ QGraphicsView::resizeEvent(event);
+
+ // XXX I don't know how to properly initialize this value,
+ // thus the hack with the boolean
+ if (!lastBottomLeftPointInitialized_)
+ {
+ lastBottomLeftPoint_ = viewport()->rect().bottomLeft();
+ lastBottomLeftPointInitialized_ = true;
+ }
+
+ QPointF currentBottomLeftPoint = viewport()->rect().bottomLeft();
+ int verticalPosition = verticalScrollBar()->value();
+ verticalScrollBar()->setValue(static_cast<int>(
+ verticalPosition
+ - (currentBottomLeftPoint.y()
+ - lastBottomLeftPoint_.y())));
+}
+
+// ---------------------------
+// >>>>>>>> ZoomSpinBox <<<<<<<<
+// ---------------------------
+
+// we want to mark the center of a pixel square with a single dot or a small
+// cross; starting with a certain magnification we thus only use even values
+// so that we can do that symmetrically
+// This behaviour is only for the singular view grid.
+
+
+ZoomSpinBox::ZoomSpinBox(QWidget* parent, bool continuousView)
+: QDoubleSpinBox(parent), continuousView_(continuousView)
+{
+ setKeyboardTracking(false);
+ if (continuousView)
+ {
+ setDecimals(2);
+ setRange(0.25, 50.0);
+ setSingleStep(0.25);
+ setValue(1);
+ }
+ else
+ {
+ setDecimals(0);
+ setRange(1, 1000 - 1000 % 64);
+ setSingleStep(1);
+ setValue(20);
+ }
+}
+
+
+double
+ZoomSpinBox::valueFromText(const QString& text) const
+{
+ if (continuousView_)
+ return QDoubleSpinBox::valueFromText(text);
+ int val = static_cast<int>(QDoubleSpinBox::valueFromText(text));
+ if (val > 640)
+ val = val - (val % 64);
+ else if (val > 320)
+ val = val - (val % 32);
+ else if (val > 160)
+ val = val - (val % 16);
+ else if (val > 80)
+ val = val - (val % 8);
+ else if (val > 40)
+ val = val - (val % 4);
+ else if (val > 20)
+ val = val - (val % 2);
+
+ return val;
+}
+
+
+void
+ZoomSpinBox::stepBy(int steps)
+{
+ if (continuousView_)
+ {
+ QDoubleSpinBox::stepBy(steps);
+ return;
+ }
+
+ int val = static_cast<int>(value());
+
+ if (steps > 0)
+ {
+ for (int i = 0; i < steps; i++)
+ {
+ if (val >= 640)
+ val = val + 64;
+ else if (val >= 320)
+ val = val + 32;
+ else if (val >= 160)
+ val = val + 16;
+ else if (val >= 80)
+ val = val + 8;
+ else if (val >= 40)
+ val = val + 4;
+ else if (val >= 20)
+ val = val + 2;
+ else
+ val++;
+ }
+ }
+ else if (steps < 0)
+ {
+ for (int i = 0; i < -steps; i++)
+ {
+ if (val > 640)
+ val = val - 64;
+ else if (val > 320)
+ val = val - 32;
+ else if (val > 160)
+ val = val - 16;
+ else if (val > 80)
+ val = val - 8;
+ else if (val > 40)
+ val = val - 4;
+ else if (val > 20)
+ val = val - 2;
+ else
+ val--;
+ }
+ }
+
+ setValue(val);
+}
+
+
+UnboundScrollArea::UnboundScrollArea(QWidget* parent)
+: QScrollArea(parent)
+{
+}
+
+
+QSize
+UnboundScrollArea::sizeHint() const
+{
+ int fw = 2 * frameWidth();
+ QSize sz(fw, fw);
+
+ int h = fontMetrics().height();
+
+ auto w = widget();
+ if (w)
+ sz += widgetResizable() ? w->sizeHint() : w->size();
+ else
+ sz += QSize(12 * h, 8 * h);
+
+ if (verticalScrollBarPolicy() == Qt::ScrollBarAlwaysOn)
+ sz.setWidth(sz.width() + verticalScrollBar()->sizeHint().width());
+ if (horizontalScrollBarPolicy() == Qt::ScrollBarAlwaysOn)
+ sz.setHeight(sz.height() + horizontalScrollBar()->sizeHint().height());
+ return sz;
+}
+
+
+// end of custom_widgets.cpp
diff --git a/src/ftinspect/widgets/customwidgets.hpp
b/src/ftinspect/widgets/customwidgets.hpp
new file mode 100644
index 0000000..a584ffb
--- /dev/null
+++ b/src/ftinspect/widgets/customwidgets.hpp
@@ -0,0 +1,78 @@
+// custom_widgets.hpp
+
+// Copyright (C) 2016-2022 by Werner Lemberg.
+
+#pragma once
+
+#include <QComboBox>
+#include <QGraphicsView>
+#include <QPushButton>
+#include <QSpinBox>
+#include <QScrollArea>
+#include <QString>
+
+// We need to define a series of custom Qt widgets to satisfy.
+// Basically those custom widgets are derived classes from Qt-provided
components,
+// with minor changes.
+// Because all those derived classes are pretty tiny and not core logic,
they're
+// organized into one single hpp/cpp pair.
+
+// we want to anchor the view at the bottom left corner
+// while the windows gets resized
+class QGraphicsViewx
+: public QGraphicsView
+{
+ Q_OBJECT
+
+public:
+ QGraphicsViewx(QWidget* parent);
+
+signals:
+ void shiftWheelEvent(QWheelEvent* event);
+ void ctrlWheelEvent(QWheelEvent* event);
+
+protected:
+ void wheelEvent(QWheelEvent* event) override;
+ void resizeEvent(QResizeEvent* event) override;
+ void scrollContentsBy(int dx,
+ int dy) override;
+
+private:
+ QPointF lastBottomLeftPoint_;
+ bool lastBottomLeftPointInitialized_;
+};
+
+
+// we want to have our own `stepBy' function for the zoom spin box
+class ZoomSpinBox
+: public QDoubleSpinBox
+{
+ Q_OBJECT
+
+public:
+ /*
+ * The ContinuousView mode for `ZoomSpinBox` will change the range to
+ * 0.25~50, and the single step to 0.25.
+ */
+ ZoomSpinBox(QWidget* parent, bool continuousView);
+ void stepBy(int val) override;
+ double valueFromText(const QString& text) const override;
+
+private:
+ bool continuousView_;
+};
+
+
+// https://bugreports.qt.io/browse/QTBUG-10459
+// https://phabricator.kde.org/D14692
+class UnboundScrollArea : public QScrollArea
+{
+ Q_OBJECT
+
+public:
+ UnboundScrollArea(QWidget* parent);
+ QSize sizeHint() const override;
+};
+
+
+// end of custom_widgets.hpp
diff --git a/src/ftinspect/widgets/qcomboboxx.cpp
b/src/ftinspect/widgets/qcomboboxx.cpp
deleted file mode 100644
index 6b3a792..0000000
--- a/src/ftinspect/widgets/qcomboboxx.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-// qcomboboxx.cpp
-
-// Copyright (C) 2016-2022 by Werner Lemberg.
-
-
-#include "qcomboboxx.hpp"
-
-#include <QStandardItemModel>
-
-
-void
-QComboBoxx::setItemEnabled(int index,
- bool enable)
-{
- const QStandardItemModel* itemModel =
- qobject_cast<const QStandardItemModel*>(model());
- QStandardItem* item = itemModel->item(index);
-
- if (enable)
- {
- item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- item->setData(QVariant(),
- Qt::TextColorRole);
- }
- else
- {
- item->setFlags(item->flags()
- & ~(Qt::ItemIsSelectable | Qt::ItemIsEnabled));
- // clear item data in order to use default color;
- // this visually greys out the item
- item->setData(palette().color(QPalette::Disabled, QPalette::Text),
- Qt::TextColorRole);
- }
-}
-
-
-// end of qcomboboxx.cpp
diff --git a/src/ftinspect/widgets/qcomboboxx.hpp
b/src/ftinspect/widgets/qcomboboxx.hpp
deleted file mode 100644
index f660d67..0000000
--- a/src/ftinspect/widgets/qcomboboxx.hpp
+++ /dev/null
@@ -1,24 +0,0 @@
-// qcomboboxx.hpp
-
-// Copyright (C) 2016-2022 by Werner Lemberg.
-
-
-#pragma once
-
-#include <QComboBox>
-
-
-// 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
-: public QComboBox
-{
- Q_OBJECT
-
-public:
- void setItemEnabled(int index,
- bool enable);
-};
-
-
-// end of qcomboboxx.hpp
diff --git a/src/ftinspect/widgets/qgraphicsviewx.cpp
b/src/ftinspect/widgets/qgraphicsviewx.cpp
deleted file mode 100644
index 4752181..0000000
--- a/src/ftinspect/widgets/qgraphicsviewx.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
-// qgraphicsviewx.hpp
-
-// Copyright (C) 2016-2022 by Werner Lemberg.
-
-
-#include "qgraphicsviewx.hpp"
-
-#include <QScrollBar>
-
-
-QGraphicsViewx::QGraphicsViewx()
-: lastBottomLeftPointInitialized_(false)
-{
- // empty
-}
-
-
-void
-QGraphicsViewx::scrollContentsBy(int dx,
- int dy)
-{
- QGraphicsView::scrollContentsBy(dx, dy);
- lastBottomLeftPoint_ = viewport()->rect().bottomLeft();
-}
-
-
-void
-QGraphicsViewx::resizeEvent(QResizeEvent* event)
-{
- QGraphicsView::resizeEvent(event);
-
- // XXX I don't know how to properly initialize this value,
- // thus the hack with the boolean
- if (!lastBottomLeftPointInitialized_)
- {
- lastBottomLeftPoint_ = viewport()->rect().bottomLeft();
- lastBottomLeftPointInitialized_ = true;
- }
-
- QPointF currentBottomLeftPoint = viewport()->rect().bottomLeft();
- int verticalPosition = verticalScrollBar()->value();
- verticalScrollBar()->setValue(static_cast<int>(
- verticalPosition
- - (currentBottomLeftPoint.y()
- - lastBottomLeftPoint_.y())));
-}
-
-
-// end of qgraphicsviewx.cpp
diff --git a/src/ftinspect/widgets/qgraphicsviewx.hpp
b/src/ftinspect/widgets/qgraphicsviewx.hpp
deleted file mode 100644
index 6ddbf12..0000000
--- a/src/ftinspect/widgets/qgraphicsviewx.hpp
+++ /dev/null
@@ -1,32 +0,0 @@
-// qgraphicsviewx.hpp
-
-// Copyright (C) 2016-2022 by Werner Lemberg.
-
-
-#pragma once
-
-#include <QGraphicsView>
-
-
-// we want to anchor the view at the bottom left corner
-// while the windows gets resized
-class QGraphicsViewx
-: public QGraphicsView
-{
- Q_OBJECT
-
-public:
- QGraphicsViewx();
-
-protected:
- void resizeEvent(QResizeEvent* event);
- void scrollContentsBy(int dx,
- int dy);
-
-private:
- QPointF lastBottomLeftPoint_;
- bool lastBottomLeftPointInitialized_;
-};
-
-
-// end of qgraphicsviewx.hpp
diff --git a/src/ftinspect/widgets/qpushbuttonx.cpp
b/src/ftinspect/widgets/qpushbuttonx.cpp
deleted file mode 100644
index c92464b..0000000
--- a/src/ftinspect/widgets/qpushbuttonx.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-// qpushbuttonx.cpp
-
-// Copyright (C) 2016-2022 by Werner Lemberg.
-
-
-#include "qpushbuttonx.hpp"
-
-#include <QStyleOptionButton>
-
-
-// code derived from Qt 4.8.7, function `QPushButton::sizeHint',
-// file `src/gui/widgets/qpushbutton.cpp'
-
-QPushButtonx::QPushButtonx(const QString &text,
- QWidget *parent)
-: QPushButton(text, parent)
-{
- QStyleOptionButton opt;
- opt.initFrom(this);
- QString s(this->text());
- QFontMetrics fm = fontMetrics();
- QSize sz = fm.size(Qt::TextShowMnemonic, s);
- opt.rect.setSize(sz);
-
- sz = style()->sizeFromContents(QStyle::CT_PushButton,
- &opt,
- sz,
- this);
- setFixedWidth(sz.width());
-}
-
-
-// end of qpushbuttonx.cpp
diff --git a/src/ftinspect/widgets/qpushbuttonx.hpp
b/src/ftinspect/widgets/qpushbuttonx.hpp
deleted file mode 100644
index 76c6b79..0000000
--- a/src/ftinspect/widgets/qpushbuttonx.hpp
+++ /dev/null
@@ -1,24 +0,0 @@
-// qpushbuttonx.hpp
-
-// Copyright (C) 2016-2022 by Werner Lemberg.
-
-
-#pragma once
-
-#include <QPushButton>
-
-
-// we want buttons that are horizontally as small as possible
-class QPushButtonx
-: public QPushButton
-{
- Q_OBJECT
-
-public:
- QPushButtonx(const QString& text,
- QWidget* = 0);
- virtual ~QPushButtonx(){}
-};
-
-
-// end of qpushbuttonx.hpp
diff --git a/src/ftinspect/widgets/qspinboxx.cpp
b/src/ftinspect/widgets/qspinboxx.cpp
deleted file mode 100644
index 3d40422..0000000
--- a/src/ftinspect/widgets/qspinboxx.cpp
+++ /dev/null
@@ -1,85 +0,0 @@
-// qspinboxx.cpp
-
-// Copyright (C) 2016-2022 by Werner Lemberg.
-
-
-#include "qspinboxx.hpp"
-
-
-// we want to mark the center of a pixel square with a single dot or a small
-// cross; starting with a certain magnification we thus only use even values
-// so that we can do that symmetrically
-
-int
-QSpinBoxx::valueFromText(const QString& text) const
-{
- int val = QSpinBox::valueFromText(text);
-
- if (val > 640)
- val = val - (val % 64);
- else if (val > 320)
- val = val - (val % 32);
- else if (val > 160)
- val = val - (val % 16);
- else if (val > 80)
- val = val - (val % 8);
- else if (val > 40)
- val = val - (val % 4);
- else if (val > 20)
- val = val - (val % 2);
-
- return val;
-}
-
-
-void
-QSpinBoxx::stepBy(int steps)
-{
- int val = value();
-
- if (steps > 0)
- {
- for (int i = 0; i < steps; i++)
- {
- if (val >= 640)
- val = val + 64;
- else if (val >= 320)
- val = val + 32;
- else if (val >= 160)
- val = val + 16;
- else if (val >= 80)
- val = val + 8;
- else if (val >= 40)
- val = val + 4;
- else if (val >= 20)
- val = val + 2;
- else
- val++;
- }
- }
- else if (steps < 0)
- {
- for (int i = 0; i < -steps; i++)
- {
- if (val > 640)
- val = val - 64;
- else if (val > 320)
- val = val - 32;
- else if (val > 160)
- val = val - 16;
- else if (val > 80)
- val = val - 8;
- else if (val > 40)
- val = val - 4;
- else if (val > 20)
- val = val - 2;
- else
- val--;
- }
- }
-
- setValue(val);
-}
-
-
-// end of qspinboxx.cpp
diff --git a/src/ftinspect/widgets/qspinboxx.hpp
b/src/ftinspect/widgets/qspinboxx.hpp
deleted file mode 100644
index 98a081a..0000000
--- a/src/ftinspect/widgets/qspinboxx.hpp
+++ /dev/null
@@ -1,24 +0,0 @@
-// qspinboxx.hpp
-
-// Copyright (C) 2016-2022 by Werner Lemberg.
-
-
-#pragma once
-
-#include <QSpinBox>
-#include <QString>
-
-
-// we want to have our own `stepBy' function for the zoom spin box
-class QSpinBoxx
-: public QSpinBox
-{
- Q_OBJECT
-
-public:
- void stepBy(int val);
- int valueFromText(const QString& text) const;
-};
-
-
-// qspinboxx.hpp
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master 75504d3 06/41: [ftinspect] Re-organize custom widgets.,
Werner Lemberg <=