freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype-demos][reorg-widgets] 2 commits: [ftinspect] Re-


From: Charlie Jiang (@cqjjjzr)
Subject: [Git][freetype/freetype-demos][reorg-widgets] 2 commits: [ftinspect] Re-organize custom widgets.
Date: Wed, 29 Jun 2022 13:52:36 +0000

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

Commits:

  • 8ee2ac78
    by Charlie Jiang at 2022-06-29T21:51:32+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 !).
    
  • e9b7ab6d
    by Charlie Jiang at 2022-06-29T21:52:14+08:00
    [ftinspect] Add documentation to custom widgets.
    
    * src/ftinspect/widgets/custom_widgets.hpp: Add doc at the beginning of the
    file.
    

11 changed files:

Changes:

  • src/ftinspect/CMakeLists.txt
    ... ... @@ -27,10 +27,7 @@ add_executable(ftinspect
    27 27
       "rendering/glyphpoints.cpp"
    
    28 28
       "rendering/grid.cpp"
    
    29 29
     
    
    30
    -  "widgets/qcomboboxx.cpp"
    
    31
    -  "widgets/qgraphicsviewx.cpp"
    
    32
    -  "widgets/qpushbuttonx.cpp"
    
    33
    -  "widgets/qspinboxx.cpp"
    
    30
    +  "widgets/custom_widgets.cpp"
    
    34 31
     )
    
    35 32
     target_link_libraries(ftinspect
    
    36 33
       Qt5::Core Qt5::Widgets
    

  • 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
     
    
    18 15
     #include <QAction>
    
    19 16
     #include <QCheckBox>
    

  • src/ftinspect/meson.build
    ... ... @@ -26,20 +26,14 @@ if qt5_dep.found()
    26 26
         'rendering/glyphpointnumbers.cpp',
    
    27 27
         'rendering/glyphpoints.cpp',
    
    28 28
         'rendering/grid.cpp',
    
    29
    -    'widgets/qcomboboxx.cpp',
    
    30
    -    'widgets/qgraphicsviewx.cpp',
    
    31
    -    'widgets/qpushbuttonx.cpp',
    
    32
    -    'widgets/qspinboxx.cpp',
    
    29
    +    'widgets/custom_widgets.cpp',
    
    33 30
         'ftinspect.cpp',
    
    34 31
         'maingui.cpp',
    
    35 32
       ])
    
    36 33
     
    
    37 34
       moc_files = qt5.preprocess(
    
    38 35
         moc_headers: [
    
    39
    -      'widgets/qcomboboxx.hpp',
    
    40
    -      'widgets/qgraphicsviewx.hpp',
    
    41
    -      'widgets/qpushbuttonx.hpp',
    
    42
    -      'widgets/qspinboxx.hpp',
    
    36
    +      'widgets/custom_widgets.hpp',
    
    43 37
           'maingui.hpp',
    
    44 38
         ],
    
    45 39
         dependencies: qt5_dep)
    

  • 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
    +// >>>>>>>> QComboBoxx <<<<<<<<
    
    13
    +// ----------------------------
    
    14
    +
    
    15
    +void
    
    16
    +QComboBoxx::setItemEnabled(int index,
    
    17
    +                           bool enable)
    
    18
    +{
    
    19
    +  const QStandardItemModel* itemModel =
    
    20
    +    qobject_cast<const QStandardItemModel*>(model());
    
    21
    +  QStandardItem* item = itemModel->item(index);
    
    22
    +
    
    23
    +  if (enable)
    
    24
    +  {
    
    25
    +    item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
    
    26
    +    item->setData(QVariant(),
    
    27
    +                  Qt::TextColorRole);
    
    28
    +  }
    
    29
    +  else
    
    30
    +  {
    
    31
    +    item->setFlags(item->flags()
    
    32
    +                   & ~(Qt::ItemIsSelectable | Qt::ItemIsEnabled));
    
    33
    +    // clear item data in order to use default color;
    
    34
    +    // this visually greys out the item
    
    35
    +    item->setData(palette().color(QPalette::Disabled, QPalette::Text),
    
    36
    +                  Qt::TextColorRole);
    
    37
    +  }
    
    38
    +}
    
    39
    +
    
    40
    +// --------------------------------
    
    41
    +// >>>>>>>> QGraphicsViewx <<<<<<<<
    
    42
    +// --------------------------------
    
    43
    +
    
    44
    +QGraphicsViewx::QGraphicsViewx()
    
    45
    +: lastBottomLeftPointInitialized(false)
    
    46
    +{
    
    47
    +  // empty
    
    48
    +}
    
    49
    +
    
    50
    +
    
    51
    +void
    
    52
    +QGraphicsViewx::scrollContentsBy(int dx,
    
    53
    +                                 int dy)
    
    54
    +{
    
    55
    +  QGraphicsView::scrollContentsBy(dx, dy);
    
    56
    +  lastBottomLeftPoint = viewport()->rect().bottomLeft();
    
    57
    +}
    
    58
    +
    
    59
    +
    
    60
    +void
    
    61
    +QGraphicsViewx::resizeEvent(QResizeEvent* event)
    
    62
    +{
    
    63
    +  QGraphicsView::resizeEvent(event);
    
    64
    +
    
    65
    +  // XXX I don't know how to properly initialize this value,
    
    66
    +  //     thus the hack with the boolean
    
    67
    +  if (!lastBottomLeftPointInitialized)
    
    68
    +  {
    
    69
    +    lastBottomLeftPoint = viewport()->rect().bottomLeft();
    
    70
    +    lastBottomLeftPointInitialized = true;
    
    71
    +  }
    
    72
    +
    
    73
    +  QPointF currentBottomLeftPoint = viewport()->rect().bottomLeft();
    
    74
    +  int verticalPosition = verticalScrollBar()->value();
    
    75
    +  verticalScrollBar()->setValue(static_cast<int>(
    
    76
    +                                  verticalPosition
    
    77
    +                                  - (currentBottomLeftPoint.y()
    
    78
    +                                     - lastBottomLeftPoint.y())));
    
    79
    +}
    
    80
    +
    
    81
    +// ------------------------------
    
    82
    +// >>>>>>>> QPushButtonx <<<<<<<<
    
    83
    +// ------------------------------
    
    84
    +
    
    85
    +// code derived from Qt 4.8.7, function `QPushButton::sizeHint',
    
    86
    +// file `src/gui/widgets/qpushbutton.cpp'
    
    87
    +
    
    88
    +QPushButtonx::QPushButtonx(const QString &text,
    
    89
    +                           QWidget *parent)
    
    90
    +: QPushButton(text, parent)
    
    91
    +{
    
    92
    +  QStyleOptionButton opt;
    
    93
    +  opt.initFrom(this);
    
    94
    +  QString s(this->text());
    
    95
    +  QFontMetrics fm = fontMetrics();
    
    96
    +  QSize sz = fm.size(Qt::TextShowMnemonic, s);
    
    97
    +  opt.rect.setSize(sz);
    
    98
    +
    
    99
    +  sz = style()->sizeFromContents(QStyle::CT_PushButton,
    
    100
    +                                 &opt,
    
    101
    +                                 sz,
    
    102
    +                                 this);
    
    103
    +  setFixedWidth(sz.width());
    
    104
    +}
    
    105
    +
    
    106
    +// ---------------------------
    
    107
    +// >>>>>>>> QSpinBoxx <<<<<<<<
    
    108
    +// ---------------------------
    
    8 109
     
    
    9 110
     // we want to mark the center of a pixel square with a single dot or a small
    
    10 111
     // cross; starting with a certain magnification we thus only use even values
    
    ... ... @@ -82,4 +183,4 @@ QSpinBoxx::stepBy(int steps)
    82 183
     }
    
    83 184
     
    
    84 185
     
    
    85
    -// end of qspinboxx.cpp
    186
    +// 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>
    
    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.
    
    18
    +
    
    19
    +// we want to grey out items in a combo box;
    
    20
    +// since Qt doesn't provide a function for this we derive a class
    
    21
    +class QComboBoxx
    
    22
    +: public QComboBox
    
    23
    +{
    
    24
    +  Q_OBJECT
    
    25
    +
    
    26
    +public:
    
    27
    +  void setItemEnabled(int index,
    
    28
    +                      bool enable);
    
    29
    +};
    
    9 30
     
    
    10 31
     
    
    11 32
     // we want to anchor the view at the bottom left corner
    
    ... ... @@ -29,4 +50,29 @@ private:
    29 50
     };
    
    30 51
     
    
    31 52
     
    
    32
    -// end of qgraphicsviewx.hpp
    53
    +// we want buttons that are horizontally as small as possible
    
    54
    +class QPushButtonx
    
    55
    +: public QPushButton
    
    56
    +{
    
    57
    +  Q_OBJECT
    
    58
    +
    
    59
    +public:
    
    60
    +  QPushButtonx(const QString& text,
    
    61
    +               QWidget* = 0);
    
    62
    +  virtual ~QPushButtonx(){}
    
    63
    +};
    
    64
    +
    
    65
    +
    
    66
    +// we want to have our own `stepBy' function for the zoom spin box
    
    67
    +class QSpinBoxx
    
    68
    +: public QSpinBox
    
    69
    +{
    
    70
    +  Q_OBJECT
    
    71
    +
    
    72
    +public:
    
    73
    +  void stepBy(int val);
    
    74
    +  int valueFromText(const QString& text) const;
    
    75
    +};
    
    76
    +
    
    77
    +
    
    78
    +// 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]