freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Git][freetype/freetype-demos][reorg-maingui] 3 commits: [ftinspect] Re-


From: Charlie Jiang (@cqjjjzr)
Subject: [Git][freetype/freetype-demos][reorg-maingui] 3 commits: [ftinspect] Re-organize custom widgets.
Date: Sat, 02 Jul 2022 11:57:54 +0000

Charlie Jiang pushed to branch reorg-maingui at FreeType / FreeType Demo Programs

Commits:

  • 3a53026e
    by Charlie Jiang at 2022-07-02T19:57:31+08:00
    [ftinspect] Re-organize custom widgets.
    
    (pure mechnical commit)
    
    * src/ftinspect/maingui.hpp: Switch from individual widget files to the newly
    merged one.
    
    * src/ftinspect/widgets/custom_widgets.{cpp, hpp}: All 4 custom widgets.
    
    * src/ftinspect/widgets/qcomboboxx.{cpp, hpp}: Merged into custom_widgets..
    
    * src/ftinspect/widgets/qgraphicsviewx.{cpp, hpp}: Merged into custom_widgets.
    
    * src/ftinspect/widgets/qpushbottonx.{cpp, hpp}: Merged into custom_widgets.
    
    * src/ftinspect/widgets/qspinbox.{cpp, hpp}: Merged into custom_widgets.
    
    Those widgets could be considered "auxiliary components", and are pretty far
    from the core logic. Therefore, they should be made less "loud" (it's 8 source
    files out of 23 in total - more than 1/3 !).
    
  • 6b4321d0
    by Charlie Jiang at 2022-07-02T19:57:35+08:00
    [ftinspect] Add documentation to custom widgets.
    
    * src/ftinspect/widgets/custom_widgets.hpp: Add doc at the beginning of the
    file.
    
  • 0976b852
    by Charlie Jiang at 2022-07-02T19:57:35+08:00
    [ftinspect] Remove `QComboBoxx`
    
    We no longer need a custom `QComboBox` for disabling individual items in the
    combo box. Our custom `QAbstractListModel` has done this already.
    
    * src/ftinspect/widgets/custom_widgets.cpp,
      src/ftinspect/widgets/custom_widgets.hpp: Remove `QComboBoxx`.
    

11 changed files:

Changes:

  • src/ftinspect/CMakeLists.txt
    ... ... @@ -28,10 +28,7 @@ add_executable(ftinspect
    28 28
       "rendering/glyphpoints.cpp"
    
    29 29
       "rendering/grid.cpp"
    
    30 30
     
    
    31
    -  "widgets/qcomboboxx.cpp"
    
    32
    -  "widgets/qgraphicsviewx.cpp"
    
    33
    -  "widgets/qpushbuttonx.cpp"
    
    34
    -  "widgets/qspinboxx.cpp"
    
    31
    +  "widgets/custom_widgets.cpp"
    
    35 32
     
    
    36 33
       "models/ttsettingscomboboxmodel.cpp"
    
    37 34
     
    

  • src/ftinspect/maingui.hpp
    ... ... @@ -10,10 +10,7 @@
    10 10
     #include "rendering/glyphoutline.hpp"
    
    11 11
     #include "rendering/glyphpointnumbers.hpp"
    
    12 12
     #include "rendering/glyphpoints.hpp"
    
    13
    -#include "widgets/qcomboboxx.hpp"
    
    14
    -#include "widgets/qgraphicsviewx.hpp"
    
    15
    -#include "widgets/qpushbuttonx.hpp"
    
    16
    -#include "widgets/qspinboxx.hpp"
    
    13
    +#include "widgets/custom_widgets.hpp"
    
    17 14
     #include "models/ttsettingscomboboxmodel.hpp"
    
    18 15
     #include "panels/settingpanel.hpp"
    
    19 16
     
    

  • src/ftinspect/meson.build
    ... ... @@ -28,11 +28,7 @@ if qt5_dep.found()
    28 28
         'rendering/glyphpointnumbers.cpp',
    
    29 29
         'rendering/glyphpoints.cpp',
    
    30 30
         'rendering/grid.cpp',
    
    31
    -
    
    32
    -    'widgets/qcomboboxx.cpp',
    
    33
    -    'widgets/qgraphicsviewx.cpp',
    
    34
    -    'widgets/qpushbuttonx.cpp',
    
    35
    -    'widgets/qspinboxx.cpp',
    
    31
    +    'widgets/custom_widgets.cpp',
    
    36 32
     
    
    37 33
         'models/ttsettingscomboboxmodel.cpp',
    
    38 34
     
    
    ... ... @@ -44,13 +40,10 @@ if qt5_dep.found()
    44 40
     
    
    45 41
       moc_files = qt5.preprocess(
    
    46 42
         moc_headers: [
    
    47
    -      'widgets/qcomboboxx.hpp',
    
    48
    -      'widgets/qgraphicsviewx.hpp',
    
    49
    -      'widgets/qpushbuttonx.hpp',
    
    50
    -      'widgets/qspinboxx.hpp',
    
    51
    -      'maingui.hpp',
    
    43
    +      'widgets/custom_widgets.hpp',
    
    52 44
           'models/ttsettingscomboboxmodel.cpp',
    
    53 45
           'panels/settingpanel.cpp',
    
    46
    +      'maingui.hpp',
    
    54 47
         ],
    
    55 48
         dependencies: qt5_dep)
    
    56 49
     
    

  • src/ftinspect/widgets/qspinboxx.cppsrc/ftinspect/widgets/custom_widgets.cpp
    1
    -// qspinboxx.cpp
    
    1
    +// custom_widgets.cpp
    
    2 2
     
    
    3 3
     // Copyright (C) 2016-2022 by Werner Lemberg.
    
    4 4
     
    
    5
    +#include "custom_widgets.hpp"
    
    5 6
     
    
    6
    -#include "qspinboxx.hpp"
    
    7
    +#include <QStandardItemModel>
    
    8
    +#include <QScrollBar>
    
    9
    +#include <QStyleOptionButton>
    
    7 10
     
    
    11
    +// --------------------------------
    
    12
    +// >>>>>>>> QGraphicsViewx <<<<<<<<
    
    13
    +// --------------------------------
    
    14
    +
    
    15
    +QGraphicsViewx::QGraphicsViewx()
    
    16
    +: lastBottomLeftPointInitialized_(false)
    
    17
    +{
    
    18
    +  // empty
    
    19
    +}
    
    20
    +
    
    21
    +
    
    22
    +void
    
    23
    +QGraphicsViewx::scrollContentsBy(int dx,
    
    24
    +                                 int dy)
    
    25
    +{
    
    26
    +  QGraphicsView::scrollContentsBy(dx, dy);
    
    27
    +  lastBottomLeftPoint_ = viewport()->rect().bottomLeft();
    
    28
    +}
    
    29
    +
    
    30
    +
    
    31
    +void
    
    32
    +QGraphicsViewx::resizeEvent(QResizeEvent* event)
    
    33
    +{
    
    34
    +  QGraphicsView::resizeEvent(event);
    
    35
    +
    
    36
    +  // XXX I don't know how to properly initialize this value,
    
    37
    +  //     thus the hack with the boolean
    
    38
    +  if (!lastBottomLeftPointInitialized_)
    
    39
    +  {
    
    40
    +    lastBottomLeftPoint_ = viewport()->rect().bottomLeft();
    
    41
    +    lastBottomLeftPointInitialized_ = true;
    
    42
    +  }
    
    43
    +
    
    44
    +  QPointF currentBottomLeftPoint = viewport()->rect().bottomLeft();
    
    45
    +  int verticalPosition = verticalScrollBar()->value();
    
    46
    +  verticalScrollBar()->setValue(static_cast<int>(
    
    47
    +                                  verticalPosition
    
    48
    +                                  - (currentBottomLeftPoint.y()
    
    49
    +                                     - lastBottomLeftPoint_.y())));
    
    50
    +}
    
    51
    +
    
    52
    +// ------------------------------
    
    53
    +// >>>>>>>> QPushButtonx <<<<<<<<
    
    54
    +// ------------------------------
    
    55
    +
    
    56
    +// code derived from Qt 4.8.7, function `QPushButton::sizeHint',
    
    57
    +// file `src/gui/widgets/qpushbutton.cpp'
    
    58
    +
    
    59
    +QPushButtonx::QPushButtonx(const QString &text,
    
    60
    +                           QWidget *parent)
    
    61
    +: QPushButton(text, parent)
    
    62
    +{
    
    63
    +  QStyleOptionButton opt;
    
    64
    +  opt.initFrom(this);
    
    65
    +  QString s(this->text());
    
    66
    +  QFontMetrics fm = fontMetrics();
    
    67
    +  QSize sz = fm.size(Qt::TextShowMnemonic, s);
    
    68
    +  opt.rect.setSize(sz);
    
    69
    +
    
    70
    +  sz = style()->sizeFromContents(QStyle::CT_PushButton,
    
    71
    +                                 &opt,
    
    72
    +                                 sz,
    
    73
    +                                 this);
    
    74
    +  setFixedWidth(sz.width());
    
    75
    +}
    
    76
    +
    
    77
    +// ---------------------------
    
    78
    +// >>>>>>>> QSpinBoxx <<<<<<<<
    
    79
    +// ---------------------------
    
    8 80
     
    
    9 81
     // we want to mark the center of a pixel square with a single dot or a small
    
    10 82
     // cross; starting with a certain magnification we thus only use even values
    
    ... ... @@ -82,4 +154,4 @@ QSpinBoxx::stepBy(int steps)
    82 154
     }
    
    83 155
     
    
    84 156
     
    
    85
    -// end of qspinboxx.cpp
    157
    +// end of custom_widgets.cpp

  • src/ftinspect/widgets/qgraphicsviewx.hppsrc/ftinspect/widgets/custom_widgets.hpp
    1
    -// qgraphicsviewx.hpp
    
    1
    +// custom_widgets.hpp
    
    2 2
     
    
    3 3
     // Copyright (C) 2016-2022 by Werner Lemberg.
    
    4 4
     
    
    5
    -
    
    6 5
     #pragma once
    
    7 6
     
    
    7
    +#include <QComboBox>
    
    8 8
     #include <QGraphicsView>
    
    9
    +#include <QPushButton>
    
    10
    +#include <QSpinBox>
    
    11
    +#include <QString>
    
    9 12
     
    
    13
    +// We need to define a series of custom Qt widgets to satisfy.
    
    14
    +// Basically those custom widgets are derived classes from Qt-provided components,
    
    15
    +// with minor changes.
    
    16
    +// Because all those derived classes are pretty tiny and not core logic, they're
    
    17
    +// organized into one single hpp/cpp pair.
    
    10 18
     
    
    11 19
     // we want to anchor the view at the bottom left corner
    
    12 20
     // while the windows gets resized
    
    ... ... @@ -29,4 +37,29 @@ private:
    29 37
     };
    
    30 38
     
    
    31 39
     
    
    32
    -// end of qgraphicsviewx.hpp
    40
    +// we want buttons that are horizontally as small as possible
    
    41
    +class QPushButtonx
    
    42
    +: public QPushButton
    
    43
    +{
    
    44
    +  Q_OBJECT
    
    45
    +
    
    46
    +public:
    
    47
    +  QPushButtonx(const QString& text,
    
    48
    +               QWidget* = 0);
    
    49
    +  virtual ~QPushButtonx(){}
    
    50
    +};
    
    51
    +
    
    52
    +
    
    53
    +// we want to have our own `stepBy' function for the zoom spin box
    
    54
    +class QSpinBoxx
    
    55
    +: public QSpinBox
    
    56
    +{
    
    57
    +  Q_OBJECT
    
    58
    +
    
    59
    +public:
    
    60
    +  void stepBy(int val);
    
    61
    +  int valueFromText(const QString& text) const;
    
    62
    +};
    
    63
    +
    
    64
    +
    
    65
    +// end of custom_widgets.hpp

  • src/ftinspect/widgets/qcomboboxx.cpp deleted
    1
    -// qcomboboxx.cpp
    
    2
    -
    
    3
    -// Copyright (C) 2016-2022 by Werner Lemberg.
    
    4
    -
    
    5
    -
    
    6
    -#include "qcomboboxx.hpp"
    
    7
    -
    
    8
    -#include <QStandardItemModel>
    
    9
    -
    
    10
    -
    
    11
    -void
    
    12
    -QComboBoxx::setItemEnabled(int index,
    
    13
    -                           bool enable)
    
    14
    -{
    
    15
    -  const QStandardItemModel* itemModel =
    
    16
    -    qobject_cast<const QStandardItemModel*>(model());
    
    17
    -  QStandardItem* item = itemModel->item(index);
    
    18
    -
    
    19
    -  if (enable)
    
    20
    -  {
    
    21
    -    item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
    
    22
    -    item->setData(QVariant(),
    
    23
    -                  Qt::TextColorRole);
    
    24
    -  }
    
    25
    -  else
    
    26
    -  {
    
    27
    -    item->setFlags(item->flags()
    
    28
    -                   & ~(Qt::ItemIsSelectable | Qt::ItemIsEnabled));
    
    29
    -    // clear item data in order to use default color;
    
    30
    -    // this visually greys out the item
    
    31
    -    item->setData(palette().color(QPalette::Disabled, QPalette::Text),
    
    32
    -                  Qt::TextColorRole);
    
    33
    -  }
    
    34
    -}
    
    35
    -
    
    36
    -
    
    37
    -// end of qcomboboxx.cpp

  • src/ftinspect/widgets/qcomboboxx.hpp deleted
    1
    -// qcomboboxx.hpp
    
    2
    -
    
    3
    -// Copyright (C) 2016-2022 by Werner Lemberg.
    
    4
    -
    
    5
    -
    
    6
    -#pragma once
    
    7
    -
    
    8
    -#include <QComboBox>
    
    9
    -
    
    10
    -
    
    11
    -// we want to grey out items in a combo box;
    
    12
    -// since Qt doesn't provide a function for this we derive a class
    
    13
    -class QComboBoxx
    
    14
    -: public QComboBox
    
    15
    -{
    
    16
    -  Q_OBJECT
    
    17
    -
    
    18
    -public:
    
    19
    -  void setItemEnabled(int index,
    
    20
    -                      bool enable);
    
    21
    -};
    
    22
    -
    
    23
    -
    
    24
    -// end of qcomboboxx.hpp

  • src/ftinspect/widgets/qgraphicsviewx.cpp deleted
    1
    -// qgraphicsviewx.hpp
    
    2
    -
    
    3
    -// Copyright (C) 2016-2022 by Werner Lemberg.
    
    4
    -
    
    5
    -
    
    6
    -#include "qgraphicsviewx.hpp"
    
    7
    -
    
    8
    -#include <QScrollBar>
    
    9
    -
    
    10
    -
    
    11
    -QGraphicsViewx::QGraphicsViewx()
    
    12
    -: lastBottomLeftPointInitialized_(false)
    
    13
    -{
    
    14
    -  // empty
    
    15
    -}
    
    16
    -
    
    17
    -
    
    18
    -void
    
    19
    -QGraphicsViewx::scrollContentsBy(int dx,
    
    20
    -                                 int dy)
    
    21
    -{
    
    22
    -  QGraphicsView::scrollContentsBy(dx, dy);
    
    23
    -  lastBottomLeftPoint_ = viewport()->rect().bottomLeft();
    
    24
    -}
    
    25
    -
    
    26
    -
    
    27
    -void
    
    28
    -QGraphicsViewx::resizeEvent(QResizeEvent* event)
    
    29
    -{
    
    30
    -  QGraphicsView::resizeEvent(event);
    
    31
    -
    
    32
    -  // XXX I don't know how to properly initialize this value,
    
    33
    -  //     thus the hack with the boolean
    
    34
    -  if (!lastBottomLeftPointInitialized_)
    
    35
    -  {
    
    36
    -    lastBottomLeftPoint_ = viewport()->rect().bottomLeft();
    
    37
    -    lastBottomLeftPointInitialized_ = true;
    
    38
    -  }
    
    39
    -
    
    40
    -  QPointF currentBottomLeftPoint = viewport()->rect().bottomLeft();
    
    41
    -  int verticalPosition = verticalScrollBar()->value();
    
    42
    -  verticalScrollBar()->setValue(static_cast<int>(
    
    43
    -                                  verticalPosition
    
    44
    -                                  - (currentBottomLeftPoint.y()
    
    45
    -                                     - lastBottomLeftPoint_.y())));
    
    46
    -}
    
    47
    -
    
    48
    -
    
    49
    -// end of qgraphicsviewx.cpp

  • src/ftinspect/widgets/qpushbuttonx.cpp deleted
    1
    -// qpushbuttonx.cpp
    
    2
    -
    
    3
    -// Copyright (C) 2016-2022 by Werner Lemberg.
    
    4
    -
    
    5
    -
    
    6
    -#include "qpushbuttonx.hpp"
    
    7
    -
    
    8
    -#include <QStyleOptionButton>
    
    9
    -
    
    10
    -
    
    11
    -// code derived from Qt 4.8.7, function `QPushButton::sizeHint',
    
    12
    -// file `src/gui/widgets/qpushbutton.cpp'
    
    13
    -
    
    14
    -QPushButtonx::QPushButtonx(const QString &text,
    
    15
    -                           QWidget *parent)
    
    16
    -: QPushButton(text, parent)
    
    17
    -{
    
    18
    -  QStyleOptionButton opt;
    
    19
    -  opt.initFrom(this);
    
    20
    -  QString s(this->text());
    
    21
    -  QFontMetrics fm = fontMetrics();
    
    22
    -  QSize sz = fm.size(Qt::TextShowMnemonic, s);
    
    23
    -  opt.rect.setSize(sz);
    
    24
    -
    
    25
    -  sz = style()->sizeFromContents(QStyle::CT_PushButton,
    
    26
    -                                 &opt,
    
    27
    -                                 sz,
    
    28
    -                                 this);
    
    29
    -  setFixedWidth(sz.width());
    
    30
    -}
    
    31
    -
    
    32
    -
    
    33
    -// end of qpushbuttonx.cpp

  • src/ftinspect/widgets/qpushbuttonx.hpp deleted
    1
    -// qpushbuttonx.hpp
    
    2
    -
    
    3
    -// Copyright (C) 2016-2022 by Werner Lemberg.
    
    4
    -
    
    5
    -
    
    6
    -#pragma once
    
    7
    -
    
    8
    -#include <QPushButton>
    
    9
    -
    
    10
    -
    
    11
    -// we want buttons that are horizontally as small as possible
    
    12
    -class QPushButtonx
    
    13
    -: public QPushButton
    
    14
    -{
    
    15
    -  Q_OBJECT
    
    16
    -
    
    17
    -public:
    
    18
    -  QPushButtonx(const QString& text,
    
    19
    -               QWidget* = 0);
    
    20
    -  virtual ~QPushButtonx(){}
    
    21
    -};
    
    22
    -
    
    23
    -
    
    24
    -// end of qpushbuttonx.hpp

  • src/ftinspect/widgets/qspinboxx.hpp deleted
    1
    -// qspinboxx.hpp
    
    2
    -
    
    3
    -// Copyright (C) 2016-2022 by Werner Lemberg.
    
    4
    -
    
    5
    -
    
    6
    -#pragma once
    
    7
    -
    
    8
    -#include <QSpinBox>
    
    9
    -#include <QString>
    
    10
    -
    
    11
    -
    
    12
    -// we want to have our own `stepBy' function for the zoom spin box
    
    13
    -class QSpinBoxx
    
    14
    -: public QSpinBox
    
    15
    -{
    
    16
    -  Q_OBJECT
    
    17
    -
    
    18
    -public:
    
    19
    -  void stepBy(int val);
    
    20
    -  int valueFromText(const QString& text) const;
    
    21
    -};
    
    22
    -
    
    23
    -
    
    24
    -// qspinboxx.hpp


  • reply via email to

    [Prev in Thread] Current Thread [Next in Thread]