freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype-demos][gsoc-2022-chariri] [ftinspect] Add `Glyph


From: Charlie Jiang (@cqjjjzr)
Subject: [Git][freetype/freetype-demos][gsoc-2022-chariri] [ftinspect] Add `GlyphIndexSelector`, move out related code from `MainGUI`.
Date: Wed, 06 Jul 2022 08:22:13 +0000

Charlie Jiang pushed to branch gsoc-2022-chariri at FreeType / FreeType Demo Programs

Commits:

  • b60d597a
    by Charlie Jiang at 2022-07-06T16:16:10+08:00
    [ftinspect] Add `GlyphIndexSelector`, move out related code from `MainGUI`.
    
    All code creating glyph index selector buttons are moved to a separate
    `GlyphIndexSelector` widget. This new widget also includes a text box (
    actually a `QSpinBox` without buttons) for directing inputing index, and a
    label indicating current & max glyph index.
    
    Removed `QPushButtonx` since those code setting the smallest width for a
    button was moved to `uihelper.[ch]pp`, because we prefer composition over
    inheritance.
    
    * src/ftinspect/widgets/glyphindexselector.cpp,
      src/ftinspect/widgets/glyphindexselector.hpp: New file, as described.
    
    * src/ftinspect/maingui.cpp, src/ftinspect/maingui.cpp: Moved out all
    navigation code, added `GlyphIndexSelector` into the main GUI.
    
    * src/ftinspect/uihelper.cpp, src/ftinspect/uihelper.hpp: New file, include
    `setButtonNarrowest`.
    
    * src/ftinspect/widgets/customwidgets.cpp,
      src/ftinspect/widgets/customwidgets.hpp: Removed `QPushButtonx`.
    
    * src/ftinspect/CMakeLists.txt, src/ftinspect/meson.build: Updated.
    

10 changed files:

Changes:

  • src/ftinspect/CMakeLists.txt
    ... ... @@ -18,6 +18,7 @@ find_package(Freetype REQUIRED)
    18 18
     add_executable(ftinspect
    
    19 19
       "ftinspect.cpp"
    
    20 20
       "maingui.cpp"
    
    21
    +  "uihelper.cpp"
    
    21 22
       
    
    22 23
       "engine/engine.cpp"
    
    23 24
       "engine/fontfilemanager.cpp"
    
    ... ... @@ -29,6 +30,7 @@ add_executable(ftinspect
    29 30
       "rendering/grid.cpp"
    
    30 31
     
    
    31 32
       "widgets/customwidgets.cpp"
    
    33
    +  "widgets/glyphindexselector.cpp"
    
    32 34
     
    
    33 35
       "models/ttsettingscomboboxmodel.cpp"
    
    34 36
     
    

  • src/ftinspect/maingui.cpp
    ... ... @@ -232,7 +232,9 @@ MainGUI::showFont()
    232 232
       auto state = settingPanel_->blockSignals(true);
    
    233 233
       settingPanel_->checkHinting();
    
    234 234
       settingPanel_->blockSignals(state);
    
    235
    -  adjustGlyphIndex(0);
    
    235
    +  indexSelector_->setMin(0);
    
    236
    +  indexSelector_->setMax(currentNumberOfGlyphs_ - 1);
    
    237
    +  indexSelector_->setCurrentIndex(indexSelector_->getCurrentIndex(), true);
    
    236 238
     }
    
    237 239
     
    
    238 240
     
    
    ... ... @@ -283,21 +285,17 @@ MainGUI::checkUnits()
    283 285
     
    
    284 286
     
    
    285 287
     void
    
    286
    -MainGUI::adjustGlyphIndex(int delta)
    
    288
    +MainGUI::setGlyphIndex(int index)
    
    287 289
     {
    
    288 290
       // only adjust current glyph index if we have a valid font
    
    289 291
       if (currentNumberOfGlyphs_ > 0)
    
    290 292
       {
    
    291
    -    currentGlyphIndex_ += delta;
    
    292
    -    currentGlyphIndex_ = qBound(0,
    
    293
    -                               currentGlyphIndex_,
    
    294
    -                               currentNumberOfGlyphs_ - 1);
    
    293
    +    currentGlyphIndex_ = qBound(0, index, currentNumberOfGlyphs_ - 1);
    
    295 294
       }
    
    296 295
     
    
    297 296
       QString upperHex = QString::number(currentGlyphIndex_, 16).toUpper();
    
    298
    -  glyphIndexLabel_->setText(QString("%1 (0x%2)")
    
    299
    -                                   .arg(currentGlyphIndex_)
    
    300
    -                                   .arg(upperHex));
    
    297
    +  glyphIndexLabel_->setText(
    
    298
    +      QString("%1 (0x%2)").arg(currentGlyphIndex_).arg(upperHex));
    
    301 299
       glyphNameLabel_->setText(engine_->glyphName(currentGlyphIndex_));
    
    302 300
     
    
    303 301
       drawGlyph();
    
    ... ... @@ -703,6 +701,9 @@ MainGUI::createLayout()
    703 701
       sizeDoubleSpinBox_->setRange(1, 500);
    
    704 702
       sizeLabel_->setBuddy(sizeDoubleSpinBox_);
    
    705 703
     
    
    704
    +  indexSelector_ = new GlyphIndexSelector(this);
    
    705
    +  indexSelector_->setSingleMode(true);
    
    706
    +
    
    706 707
       unitsComboBox_ = new QComboBox(this);
    
    707 708
       unitsComboBox_->insertItem(Units_px, "px");
    
    708 709
       unitsComboBox_->insertItem(Units_pt, "pt");
    
    ... ... @@ -714,17 +715,6 @@ MainGUI::createLayout()
    714 715
       dpiSpinBox_->setRange(10, 600);
    
    715 716
       dpiLabel_->setBuddy(dpiSpinBox_);
    
    716 717
     
    
    717
    -  toStartButtonx_ = new QPushButtonx("|<", this);
    
    718
    -  toM1000Buttonx_ = new QPushButtonx("-1000", this);
    
    719
    -  toM100Buttonx_ = new QPushButtonx("-100", this);
    
    720
    -  toM10Buttonx_ = new QPushButtonx("-10", this);
    
    721
    -  toM1Buttonx_ = new QPushButtonx("-1", this);
    
    722
    -  toP1Buttonx_ = new QPushButtonx("+1", this);
    
    723
    -  toP10Buttonx_ = new QPushButtonx("+10", this);
    
    724
    -  toP100Buttonx_ = new QPushButtonx("+100", this);
    
    725
    -  toP1000Buttonx_ = new QPushButtonx("+1000", this);
    
    726
    -  toEndButtonx_ = new QPushButtonx(">|", this);
    
    727
    -
    
    728 718
       zoomLabel_ = new QLabel(tr("Zoom Factor"), this);
    
    729 719
       zoomLabel_->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    
    730 720
       zoomSpinBox_ = new QSpinBoxx(this);
    
    ... ... @@ -748,21 +738,6 @@ MainGUI::createLayout()
    748 738
       infoRightLayout->addWidget(glyphNameLabel_, 0, 1);
    
    749 739
       infoRightLayout->addWidget(fontNameLabel_, 0, 2);
    
    750 740
     
    
    751
    -  navigationLayout_ = new QHBoxLayout;
    
    752
    -  navigationLayout_->setSpacing(0);
    
    753
    -  navigationLayout_->addStretch(1);
    
    754
    -  navigationLayout_->addWidget(toStartButtonx_);
    
    755
    -  navigationLayout_->addWidget(toM1000Buttonx_);
    
    756
    -  navigationLayout_->addWidget(toM100Buttonx_);
    
    757
    -  navigationLayout_->addWidget(toM10Buttonx_);
    
    758
    -  navigationLayout_->addWidget(toM1Buttonx_);
    
    759
    -  navigationLayout_->addWidget(toP1Buttonx_);
    
    760
    -  navigationLayout_->addWidget(toP10Buttonx_);
    
    761
    -  navigationLayout_->addWidget(toP100Buttonx_);
    
    762
    -  navigationLayout_->addWidget(toP1000Buttonx_);
    
    763
    -  navigationLayout_->addWidget(toEndButtonx_);
    
    764
    -  navigationLayout_->addStretch(1);
    
    765
    -
    
    766 741
       sizeLayout_ = new QHBoxLayout;
    
    767 742
       sizeLayout_->addStretch(2);
    
    768 743
       sizeLayout_->addWidget(sizeLabel_);
    
    ... ... @@ -793,7 +768,7 @@ MainGUI::createLayout()
    793 768
       rightLayout_ = new QVBoxLayout;
    
    794 769
       rightLayout_->addLayout(infoRightLayout);
    
    795 770
       rightLayout_->addWidget(glyphView_);
    
    796
    -  rightLayout_->addLayout(navigationLayout_);
    
    771
    +  rightLayout_->addWidget(indexSelector_);
    
    797 772
       rightLayout_->addSpacing(10); // XXX px
    
    798 773
       rightLayout_->addLayout(sizeLayout_);
    
    799 774
       rightLayout_->addSpacing(10); // XXX px
    
    ... ... @@ -822,6 +797,8 @@ MainGUI::createConnections()
    822 797
               SLOT(showFont()));
    
    823 798
       connect(settingPanel_, SIGNAL(repaintNeeded()),
    
    824 799
               SLOT(drawGlyph()));
    
    800
    +  connect(indexSelector_, SIGNAL(currentIndexChanged(int)), 
    
    801
    +      this, SLOT(setGlyphIndex(int)));
    
    825 802
       connect(sizeDoubleSpinBox_, SIGNAL(valueChanged(double)),
    
    826 803
               SLOT(drawGlyph()));
    
    827 804
       connect(unitsComboBox_, SIGNAL(currentIndexChanged(int)),
    
    ... ... @@ -856,42 +833,6 @@ MainGUI::createConnections()
    856 833
       connect(nextNamedInstanceButton_, SIGNAL(clicked()),
    
    857 834
               SLOT(nextNamedInstance()));
    
    858 835
     
    
    859
    -  glyphNavigationMapper_ = new QSignalMapper;
    
    860
    -  connect(glyphNavigationMapper_, SIGNAL(mapped(int)),
    
    861
    -          SLOT(adjustGlyphIndex(int)));
    
    862
    -
    
    863
    -  connect(toStartButtonx_, SIGNAL(clicked()),
    
    864
    -          glyphNavigationMapper_, SLOT(map()));
    
    865
    -  connect(toM1000Buttonx_, SIGNAL(clicked()),
    
    866
    -          glyphNavigationMapper_, SLOT(map()));
    
    867
    -  connect(toM100Buttonx_, SIGNAL(clicked()),
    
    868
    -          glyphNavigationMapper_, SLOT(map()));
    
    869
    -  connect(toM10Buttonx_, SIGNAL(clicked()),
    
    870
    -          glyphNavigationMapper_, SLOT(map()));
    
    871
    -  connect(toM1Buttonx_, SIGNAL(clicked()),
    
    872
    -          glyphNavigationMapper_, SLOT(map()));
    
    873
    -  connect(toP1Buttonx_, SIGNAL(clicked()),
    
    874
    -          glyphNavigationMapper_, SLOT(map()));
    
    875
    -  connect(toP10Buttonx_, SIGNAL(clicked()),
    
    876
    -          glyphNavigationMapper_, SLOT(map()));
    
    877
    -  connect(toP100Buttonx_, SIGNAL(clicked()),
    
    878
    -          glyphNavigationMapper_, SLOT(map()));
    
    879
    -  connect(toP1000Buttonx_, SIGNAL(clicked()),
    
    880
    -          glyphNavigationMapper_, SLOT(map()));
    
    881
    -  connect(toEndButtonx_, SIGNAL(clicked()),
    
    882
    -          glyphNavigationMapper_, SLOT(map()));
    
    883
    -
    
    884
    -  glyphNavigationMapper_->setMapping(toStartButtonx_, -0x10000);
    
    885
    -  glyphNavigationMapper_->setMapping(toM1000Buttonx_, -1000);
    
    886
    -  glyphNavigationMapper_->setMapping(toM100Buttonx_, -100);
    
    887
    -  glyphNavigationMapper_->setMapping(toM10Buttonx_, -10);
    
    888
    -  glyphNavigationMapper_->setMapping(toM1Buttonx_, -1);
    
    889
    -  glyphNavigationMapper_->setMapping(toP1Buttonx_, 1);
    
    890
    -  glyphNavigationMapper_->setMapping(toP10Buttonx_, 10);
    
    891
    -  glyphNavigationMapper_->setMapping(toP100Buttonx_, 100);
    
    892
    -  glyphNavigationMapper_->setMapping(toP1000Buttonx_, 1000);
    
    893
    -  glyphNavigationMapper_->setMapping(toEndButtonx_, 0x10000);
    
    894
    -
    
    895 836
       connect(&engine_->fontFileManager(), &FontFileManager::currentFileChanged,
    
    896 837
               this, &MainGUI::watchCurrentFont);
    
    897 838
     }
    
    ... ... @@ -967,7 +908,7 @@ MainGUI::setDefaults()
    967 908
       checkCurrentFontIndex();
    
    968 909
       checkCurrentFaceIndex();
    
    969 910
       checkCurrentNamedInstanceIndex();
    
    970
    -  adjustGlyphIndex(0);
    
    911
    +  indexSelector_->setCurrentIndex(indexSelector_->getCurrentIndex(), true);
    
    971 912
       zoom();
    
    972 913
     }
    
    973 914
     
    

  • src/ftinspect/maingui.hpp
    ... ... @@ -12,6 +12,7 @@
    12 12
     #include "rendering/glyphpoints.hpp"
    
    13 13
     #include "rendering/grid.hpp"
    
    14 14
     #include "widgets/customwidgets.hpp"
    
    15
    +#include "widgets/glyphindexselector.hpp"
    
    15 16
     #include "models/ttsettingscomboboxmodel.hpp"
    
    16 17
     #include "panels/settingpanel.hpp"
    
    17 18
     
    
    ... ... @@ -71,7 +72,7 @@ protected:
    71 72
     private slots:
    
    72 73
       void about();
    
    73 74
       void aboutQt();
    
    74
    -  void adjustGlyphIndex(int);
    
    75
    +  void setGlyphIndex(int);
    
    75 76
       void checkCurrentFaceIndex();
    
    76 77
       void checkCurrentFontIndex();
    
    77 78
       void checkCurrentNamedInstanceIndex();
    
    ... ... @@ -121,6 +122,7 @@ private:
    121 122
       QAction *exitAct_;
    
    122 123
       QAction *loadFontsAct_;
    
    123 124
     
    
    125
    +  GlyphIndexSelector* indexSelector_;
    
    124 126
       QComboBox *unitsComboBox_;
    
    125 127
     
    
    126 128
       QDoubleSpinBox *sizeDoubleSpinBox_;
    
    ... ... @@ -133,7 +135,6 @@ private:
    133 135
     
    
    134 136
       QHBoxLayout *ftinspectLayout_;
    
    135 137
       QHBoxLayout *infoLeftLayout_;
    
    136
    -  QHBoxLayout *navigationLayout_;
    
    137 138
       QHBoxLayout *sizeLayout_;
    
    138 139
     
    
    139 140
       QLabel *dpiLabel_;
    
    ... ... @@ -165,19 +166,6 @@ private:
    165 166
       QPushButton *previousFontButton_;
    
    166 167
       QPushButton *previousNamedInstanceButton_;
    
    167 168
     
    
    168
    -  QPushButtonx *toEndButtonx_;
    
    169
    -  QPushButtonx *toM1000Buttonx_;
    
    170
    -  QPushButtonx *toM100Buttonx_;
    
    171
    -  QPushButtonx *toM10Buttonx_;
    
    172
    -  QPushButtonx *toM1Buttonx_;
    
    173
    -  QPushButtonx *toP1000Buttonx_;
    
    174
    -  QPushButtonx *toP100Buttonx_;
    
    175
    -  QPushButtonx *toP10Buttonx_;
    
    176
    -  QPushButtonx *toP1Buttonx_;
    
    177
    -  QPushButtonx *toStartButtonx_;
    
    178
    -
    
    179
    -  QSignalMapper *glyphNavigationMapper_;
    
    180
    -
    
    181 169
       QSpinBox *dpiSpinBox_;
    
    182 170
       QSpinBoxx *zoomSpinBox_;
    
    183 171
       
    

  • src/ftinspect/meson.build
    ... ... @@ -29,6 +29,7 @@ if qt5_dep.found()
    29 29
         'rendering/glyphpoints.cpp',
    
    30 30
         'rendering/grid.cpp',
    
    31 31
         'widgets/customwidgets.cpp',
    
    32
    +    'widgets/glyphindexselector.cpp',
    
    32 33
     
    
    33 34
         'models/ttsettingscomboboxmodel.cpp',
    
    34 35
     
    
    ... ... @@ -36,12 +37,14 @@ if qt5_dep.found()
    36 37
     
    
    37 38
         'ftinspect.cpp',
    
    38 39
         'maingui.cpp',
    
    40
    +    'uihelper.cpp',
    
    39 41
     ])
    
    40 42
     
    
    41 43
       moc_files = qt5.preprocess(
    
    42 44
         moc_headers: [
    
    43 45
           'engine/fontfilemanager.hpp',
    
    44 46
           'widgets/customwidgets.hpp',
    
    47
    +      'widgets/glyphindexselector.hpp',
    
    45 48
           'models/ttsettingscomboboxmodel.hpp',
    
    46 49
           'panels/settingpanel.hpp',
    
    47 50
           'maingui.hpp',
    

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

  • src/ftinspect/uihelper.hpp
    1
    +// uihelper.hpp
    
    2
    +
    
    3
    +// Copyright (C) 2022 by Charlie Jiang.
    
    4
    +
    
    5
    +#pragma once
    
    6
    +
    
    7
    +#include <QPushButton>
    
    8
    +
    
    9
    +// we want buttons that are horizontally as small as possible
    
    10
    +void setButtonNarrowest(QPushButton* btn);
    
    11
    +
    
    12
    +
    
    13
    +// end of uihelper.hpp

  • src/ftinspect/widgets/customwidgets.cpp
    ... ... @@ -62,31 +62,6 @@ QGraphicsViewx::resizeEvent(QResizeEvent* event)
    62 62
                                          - lastBottomLeftPoint_.y())));
    
    63 63
     }
    
    64 64
     
    
    65
    -// ------------------------------
    
    66
    -// >>>>>>>> QPushButtonx <<<<<<<<
    
    67
    -// ------------------------------
    
    68
    -
    
    69
    -// code derived from Qt 4.8.7, function `QPushButton::sizeHint',
    
    70
    -// file `src/gui/widgets/qpushbutton.cpp'
    
    71
    -
    
    72
    -QPushButtonx::QPushButtonx(const QString &text,
    
    73
    -                           QWidget *parent)
    
    74
    -: QPushButton(text, parent)
    
    75
    -{
    
    76
    -  QStyleOptionButton opt;
    
    77
    -  opt.initFrom(this);
    
    78
    -  QString s(this->text());
    
    79
    -  QFontMetrics fm = fontMetrics();
    
    80
    -  QSize sz = fm.size(Qt::TextShowMnemonic, s);
    
    81
    -  opt.rect.setSize(sz);
    
    82
    -
    
    83
    -  sz = style()->sizeFromContents(QStyle::CT_PushButton,
    
    84
    -                                 &opt,
    
    85
    -                                 sz,
    
    86
    -                                 this);
    
    87
    -  setFixedWidth(sz.width());
    
    88
    -}
    
    89
    -
    
    90 65
     // ---------------------------
    
    91 66
     // >>>>>>>> QSpinBoxx <<<<<<<<
    
    92 67
     // ---------------------------
    

  • src/ftinspect/widgets/customwidgets.hpp
    ... ... @@ -42,19 +42,6 @@ private:
    42 42
     };
    
    43 43
     
    
    44 44
     
    
    45
    -// we want buttons that are horizontally as small as possible
    
    46
    -class QPushButtonx
    
    47
    -: public QPushButton
    
    48
    -{
    
    49
    -  Q_OBJECT
    
    50
    -
    
    51
    -public:
    
    52
    -  QPushButtonx(const QString& text,
    
    53
    -               QWidget* = 0);
    
    54
    -  virtual ~QPushButtonx(){}
    
    55
    -};
    
    56
    -
    
    57
    -
    
    58 45
     // we want to have our own `stepBy' function for the zoom spin box
    
    59 46
     class QSpinBoxx
    
    60 47
     : public QSpinBox
    

  • src/ftinspect/widgets/glyphindexselector.cpp
    1
    +// glyphindexselector.cpp
    
    2
    +
    
    3
    +// Copyright (C) 2022 Charlie Jiang.
    
    4
    +
    
    5
    +#include "glyphindexselector.hpp"
    
    6
    +
    
    7
    +#include "../uihelper.hpp"
    
    8
    +
    
    9
    +GlyphIndexSelector::GlyphIndexSelector(QWidget* parent)
    
    10
    +: QWidget(parent)
    
    11
    +{
    
    12
    +  createLayout();
    
    13
    +  createConnections();
    
    14
    +}
    
    15
    +
    
    16
    +
    
    17
    +void
    
    18
    +GlyphIndexSelector::setMin(int min)
    
    19
    +{
    
    20
    +  indexSpinBox_->setMinimum(min);
    
    21
    +  indexSpinBox_->setValue(qBound(indexSpinBox_->minimum(),
    
    22
    +                                 indexSpinBox_->value(),
    
    23
    +                                 indexSpinBox_->maximum()));
    
    24
    +  // spinBoxChanged will be automatically called
    
    25
    +}
    
    26
    +
    
    27
    +
    
    28
    +void
    
    29
    +GlyphIndexSelector::setMax(int max)
    
    30
    +{
    
    31
    +  indexSpinBox_->setMaximum(max);
    
    32
    +  indexSpinBox_->setValue(qBound(indexSpinBox_->minimum(),
    
    33
    +                                 indexSpinBox_->value(),
    
    34
    +                                 indexSpinBox_->maximum()));
    
    35
    +  // spinBoxChanged will be automatically called
    
    36
    +}
    
    37
    +
    
    38
    +
    
    39
    +void
    
    40
    +GlyphIndexSelector::setShowingCount(int showingCount)
    
    41
    +{
    
    42
    +  showingCount_ = showingCount;
    
    43
    +  updateLabel();
    
    44
    +}
    
    45
    +
    
    46
    +
    
    47
    +void
    
    48
    +GlyphIndexSelector::setSingleMode(bool singleMode)
    
    49
    +{
    
    50
    +  singleMode_ = singleMode;
    
    51
    +  updateLabel();
    
    52
    +}
    
    53
    +
    
    54
    +
    
    55
    +void
    
    56
    +GlyphIndexSelector::setCurrentIndex(int index, bool forceUpdate)
    
    57
    +{
    
    58
    +  indexSpinBox_->setValue(index);
    
    59
    +  updateLabel();
    
    60
    +  if (forceUpdate)
    
    61
    +    emit currentIndexChanged(indexSpinBox_->value());
    
    62
    +}
    
    63
    +
    
    64
    +
    
    65
    +int
    
    66
    +GlyphIndexSelector::getCurrentIndex()
    
    67
    +{
    
    68
    +  return indexSpinBox_->value();
    
    69
    +}
    
    70
    +
    
    71
    +
    
    72
    +void
    
    73
    +GlyphIndexSelector::adjustIndex(int delta)
    
    74
    +{
    
    75
    +  indexSpinBox_->setValue(qBound(indexSpinBox_->minimum(),
    
    76
    +                                 indexSpinBox_->value() + delta,
    
    77
    +                                 indexSpinBox_->maximum()));
    
    78
    +  emitValueChanged();
    
    79
    +}
    
    80
    +
    
    81
    +
    
    82
    +void
    
    83
    +GlyphIndexSelector::emitValueChanged()
    
    84
    +{
    
    85
    +  emit currentIndexChanged(indexSpinBox_->value());
    
    86
    +  updateLabel();
    
    87
    +}
    
    88
    +
    
    89
    +
    
    90
    +void
    
    91
    +GlyphIndexSelector::updateLabel()
    
    92
    +{
    
    93
    +  if (singleMode_)
    
    94
    +    indexLabel_->setText(QString("%1\nLimit: %2")
    
    95
    +                             .arg(indexSpinBox_->value())
    
    96
    +                             .arg(indexSpinBox_->maximum()));
    
    97
    +  else
    
    98
    +    indexLabel_->setText(QString("%1~%2\nCount: %3\nLimit: %4")
    
    99
    +                             .arg(indexSpinBox_->value())
    
    100
    +                             .arg(indexSpinBox_->value() + showingCount_ - 1)
    
    101
    +                             .arg(showingCount_, indexSpinBox_->maximum()));
    
    102
    +}
    
    103
    +
    
    104
    +
    
    105
    +void
    
    106
    +GlyphIndexSelector::createLayout()
    
    107
    +{
    
    108
    +  toStartButton_ = new QPushButton("|<", this);
    
    109
    +  toM1000Button_ = new QPushButton("-1000", this);
    
    110
    +  toM100Button_ = new QPushButton("-100", this);
    
    111
    +  toM10Button_ = new QPushButton("-10", this);
    
    112
    +  toM1Button_ = new QPushButton("-1", this);
    
    113
    +  toP1Button_ = new QPushButton("+1", this);
    
    114
    +  toP10Button_ = new QPushButton("+10", this);
    
    115
    +  toP100Button_ = new QPushButton("+100", this);
    
    116
    +  toP1000Button_ = new QPushButton("+1000", this);
    
    117
    +  toEndButton_ = new QPushButton(">|", this);
    
    118
    +  
    
    119
    +  indexSpinBox_ = new QSpinBox(this);
    
    120
    +  indexSpinBox_->setCorrectionMode(QAbstractSpinBox::CorrectToNearestValue);
    
    121
    +  indexSpinBox_->setButtonSymbols(QAbstractSpinBox::NoButtons);
    
    122
    +  indexSpinBox_->setRange(0, 0);
    
    123
    +  indexSpinBox_->setFixedWidth(80);
    
    124
    +  indexSpinBox_->setWrapping(true);
    
    125
    +
    
    126
    +  indexLabel_ = new QLabel("0\nCount: 0\nLimit: 0");
    
    127
    +
    
    128
    +  setButtonNarrowest(toStartButton_);
    
    129
    +  setButtonNarrowest(toM1000Button_);
    
    130
    +  setButtonNarrowest(toM100Button_);
    
    131
    +  setButtonNarrowest(toM10Button_);
    
    132
    +  setButtonNarrowest(toM1Button_);
    
    133
    +  setButtonNarrowest(toP1Button_);
    
    134
    +  setButtonNarrowest(toP10Button_);
    
    135
    +  setButtonNarrowest(toP100Button_);
    
    136
    +  setButtonNarrowest(toP1000Button_);
    
    137
    +  setButtonNarrowest(toEndButton_);
    
    138
    +
    
    139
    +  navigationLayout_ = new QHBoxLayout;
    
    140
    +  navigationLayout_->setSpacing(0);
    
    141
    +  navigationLayout_->addStretch(3);
    
    142
    +  navigationLayout_->addWidget(toStartButton_);
    
    143
    +  navigationLayout_->addWidget(toM1000Button_);
    
    144
    +  navigationLayout_->addWidget(toM100Button_);
    
    145
    +  navigationLayout_->addWidget(toM10Button_);
    
    146
    +  navigationLayout_->addWidget(toM1Button_);
    
    147
    +  navigationLayout_->addWidget(toP1Button_);
    
    148
    +  navigationLayout_->addWidget(toP10Button_);
    
    149
    +  navigationLayout_->addWidget(toP100Button_);
    
    150
    +  navigationLayout_->addWidget(toP1000Button_);
    
    151
    +  navigationLayout_->addWidget(toEndButton_);
    
    152
    +  navigationLayout_->addStretch(1);
    
    153
    +  navigationLayout_->addWidget(indexSpinBox_);
    
    154
    +  navigationLayout_->addStretch(1);
    
    155
    +  navigationLayout_->addWidget(indexLabel_);
    
    156
    +  navigationLayout_->addStretch(3);
    
    157
    +
    
    158
    +  setLayout(navigationLayout_);
    
    159
    +}
    
    160
    +
    
    161
    +void
    
    162
    +GlyphIndexSelector::createConnections()
    
    163
    +{
    
    164
    +  connect(indexSpinBox_, QOverload<int>::of(&QSpinBox::valueChanged), 
    
    165
    +          this, &GlyphIndexSelector::emitValueChanged);
    
    166
    +
    
    167
    +  glyphNavigationMapper_ = new QSignalMapper(this);
    
    168
    +  connect(glyphNavigationMapper_, SIGNAL(mapped(int)), SLOT(adjustIndex(int)));
    
    169
    +
    
    170
    +  connect(toStartButton_, &QPushButton::clicked,
    
    171
    +          glyphNavigationMapper_, QOverload<>::of(&QSignalMapper::map));
    
    172
    +  connect(toM1000Button_, &QPushButton::clicked,
    
    173
    +          glyphNavigationMapper_, QOverload<>::of(&QSignalMapper::map));
    
    174
    +  connect(toM100Button_, &QPushButton::clicked,
    
    175
    +          glyphNavigationMapper_, QOverload<>::of(&QSignalMapper::map));
    
    176
    +  connect(toM10Button_, &QPushButton::clicked,
    
    177
    +          glyphNavigationMapper_, QOverload<>::of(&QSignalMapper::map));
    
    178
    +  connect(toM1Button_, &QPushButton::clicked,
    
    179
    +          glyphNavigationMapper_, QOverload<>::of(&QSignalMapper::map));
    
    180
    +  connect(toP1Button_, &QPushButton::clicked,
    
    181
    +          glyphNavigationMapper_, QOverload<>::of(&QSignalMapper::map));
    
    182
    +  connect(toP10Button_, &QPushButton::clicked,
    
    183
    +          glyphNavigationMapper_, QOverload<>::of(&QSignalMapper::map));
    
    184
    +  connect(toP100Button_, &QPushButton::clicked,
    
    185
    +          glyphNavigationMapper_, QOverload<>::of(&QSignalMapper::map));
    
    186
    +  connect(toP1000Button_, &QPushButton::clicked,
    
    187
    +          glyphNavigationMapper_, QOverload<>::of(&QSignalMapper::map));
    
    188
    +  connect(toEndButton_, &QPushButton::clicked,
    
    189
    +          glyphNavigationMapper_, QOverload<>::of(&QSignalMapper::map));
    
    190
    +
    
    191
    +  glyphNavigationMapper_->setMapping(toStartButton_, -0x10000);
    
    192
    +  glyphNavigationMapper_->setMapping(toM1000Button_, -1000);
    
    193
    +  glyphNavigationMapper_->setMapping(toM100Button_, -100);
    
    194
    +  glyphNavigationMapper_->setMapping(toM10Button_, -10);
    
    195
    +  glyphNavigationMapper_->setMapping(toM1Button_, -1);
    
    196
    +  glyphNavigationMapper_->setMapping(toP1Button_, 1);
    
    197
    +  glyphNavigationMapper_->setMapping(toP10Button_, 10);
    
    198
    +  glyphNavigationMapper_->setMapping(toP100Button_, 100);
    
    199
    +  glyphNavigationMapper_->setMapping(toP1000Button_, 1000);
    
    200
    +  glyphNavigationMapper_->setMapping(toEndButton_, 0x10000);
    
    201
    +}
    
    202
    +
    
    203
    +
    
    204
    +// end of glyphindexselector.cpp

  • src/ftinspect/widgets/glyphindexselector.hpp
    1
    +// glyphindexselector.hpp
    
    2
    +
    
    3
    +// Copyright (C) 2022 by Charlie Jiang.
    
    4
    +
    
    5
    +#pragma once
    
    6
    +
    
    7
    +#include <QWidget>
    
    8
    +#include <QPushButton>
    
    9
    +#include <QSpinBox>
    
    10
    +#include <QSignalMapper>
    
    11
    +#include <QHBoxLayout>
    
    12
    +#include <QLabel>
    
    13
    +
    
    14
    +class GlyphIndexSelector
    
    15
    +: public QWidget
    
    16
    +{
    
    17
    +  Q_OBJECT
    
    18
    +public:
    
    19
    +  GlyphIndexSelector(QWidget* parent);
    
    20
    +  virtual ~GlyphIndexSelector() = default;
    
    21
    +
    
    22
    +  void setMin(int min);
    
    23
    +  void setMax(int max);
    
    24
    +  void setShowingCount(int showingCount);
    
    25
    +  void setSingleMode(bool singleMode);
    
    26
    +
    
    27
    +  void setCurrentIndex(int index, bool forceUpdate = false);
    
    28
    +  int getCurrentIndex();
    
    29
    +
    
    30
    +signals:
    
    31
    +  void currentIndexChanged(int index);
    
    32
    +
    
    33
    +private slots:
    
    34
    +  void adjustIndex(int delta);
    
    35
    +  void emitValueChanged();
    
    36
    +  void updateLabel();
    
    37
    +
    
    38
    +private:
    
    39
    +  bool singleMode_ = true;
    
    40
    +  int showingCount_;
    
    41
    +
    
    42
    +  // min, max and current status are held by `indexSpinBox_`
    
    43
    +
    
    44
    +  QPushButton* toEndButton_;
    
    45
    +  QPushButton* toM1000Button_;
    
    46
    +  QPushButton* toM100Button_;
    
    47
    +  QPushButton* toM10Button_;
    
    48
    +  QPushButton* toM1Button_;
    
    49
    +  QPushButton* toP1000Button_;
    
    50
    +  QPushButton* toP100Button_;
    
    51
    +  QPushButton* toP10Button_;
    
    52
    +  QPushButton* toP1Button_;
    
    53
    +  QPushButton* toStartButton_;
    
    54
    +
    
    55
    +  QLabel* indexLabel_;
    
    56
    +  QSpinBox* indexSpinBox_;
    
    57
    +
    
    58
    +  QHBoxLayout* navigationLayout_;
    
    59
    +
    
    60
    +  QSignalMapper* glyphNavigationMapper_;
    
    61
    +
    
    62
    +  void createLayout();
    
    63
    +  void createConnections();
    
    64
    +};
    
    65
    +
    
    66
    +
    
    67
    +// end of glyphindexselector.hpp


  • reply via email to

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