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] Improve mo


From: Charlie Jiang (@cqjjjzr)
Subject: [Git][freetype/freetype-demos][gsoc-2022-chariri] [ftinspect] Improve mouse scrolling.
Date: Sun, 03 Jul 2022 06:09:15 +0000

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

Commits:

  • ece202dc
    by Charlie Jiang at 2022-07-03T14:06:16+08:00
    [ftinspect] Improve mouse scrolling.
    
    Now Ctrl+Scroll zooms the view, and Shift+Scroll changes the font size.
    
    Added a button to quickly go back to center.
    
    * src/ftinspect/widgets/custom_widgets.hpp,
      src/ftinspect/widgets/custom_widgets.cpp: Intercept Ctrl/Shift+Scroll events
      as separate events to emit.
    
    * src/ftinspect/maingui.hpp, src/ftinspect/maingui.cpp: Add Ctrl/Shift+Scroll
    event handlers; add a hint at top-left; add "go back to center" button.
    

4 changed files:

Changes:

  • src/ftinspect/maingui.cpp
    ... ... @@ -432,6 +432,40 @@ MainGUI::zoom()
    432 432
     }
    
    433 433
     
    
    434 434
     
    
    435
    +void
    
    436
    +MainGUI::backToCenter()
    
    437
    +{
    
    438
    +  glyphView_->centerOn(0, 0);
    
    439
    +  if (currentGlyphBitmapItem_)
    
    440
    +    glyphView_->ensureVisible(currentGlyphBitmapItem_);
    
    441
    +  else if (currentGlyphPointsItem_)
    
    442
    +    glyphView_->ensureVisible(currentGlyphPointsItem_);
    
    443
    +}
    
    444
    +
    
    445
    +
    
    446
    +void
    
    447
    +MainGUI::wheelZoom(QWheelEvent* event)
    
    448
    +{
    
    449
    +  int numSteps = event->angleDelta().y() / 120;
    
    450
    +  int zoomAfter = zoomSpinBox_->value() + numSteps;
    
    451
    +  zoomAfter = std::max(zoomSpinBox_->minimum(),
    
    452
    +                       std::min(zoomAfter, zoomSpinBox_->maximum()));
    
    453
    +  zoomSpinBox_->setValue(zoomAfter);
    
    454
    +  // TODO: Zoom relative to viewport left-bottom?
    
    455
    +}
    
    456
    +
    
    457
    +
    
    458
    +void
    
    459
    +MainGUI::wheelResize(QWheelEvent* event)
    
    460
    +{
    
    461
    +  int numSteps = event->angleDelta().y() / 120;
    
    462
    +  double sizeAfter = sizeDoubleSpinBox_->value() + numSteps * 0.5;
    
    463
    +  sizeAfter = std::max(sizeDoubleSpinBox_->minimum(),
    
    464
    +                       std::min(sizeAfter, sizeDoubleSpinBox_->maximum()));
    
    465
    +  sizeDoubleSpinBox_->setValue(sizeAfter);
    
    466
    +}
    
    467
    +
    
    468
    +
    
    435 469
     void
    
    436 470
     MainGUI::setGraphicsDefaults()
    
    437 471
     {
    
    ... ... @@ -597,8 +631,19 @@ MainGUI::createLayout()
    597 631
       glyphView_->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
    
    598 632
       glyphView_->setScene(glyphScene_);
    
    599 633
     
    
    634
    +  // Don't use QGraphicsTextItem: We want this hint to be anchored at the
    
    635
    +  // top-left corner.
    
    636
    +  mouseUsageHint_ = new QLabel(tr("Scroll: Grid Up/Down\n"
    
    637
    +    "Alt + Scroll: Grid Left/Right\n"
    
    638
    +    "Ctrl + Scroll: Adjust Zoom (Relative to cursor)\n"
    
    639
    +    "Shift + Scroll: Adjust Font Size"), glyphView_);
    
    640
    +  mouseUsageHint_->setMargin(10);
    
    641
    +  auto hintFont = font();
    
    642
    +  hintFont.setPixelSize(24);
    
    643
    +  mouseUsageHint_->setFont(hintFont);
    
    644
    +
    
    600 645
       sizeLabel_ = new QLabel(tr("Size "), this);
    
    601
    -  sizeLabel_->setAlignment(Qt::AlignRight);
    
    646
    +  sizeLabel_->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    
    602 647
       sizeDoubleSpinBox_ = new QDoubleSpinBox;
    
    603 648
       sizeDoubleSpinBox_->setAlignment(Qt::AlignRight);
    
    604 649
       sizeDoubleSpinBox_->setDecimals(1);
    
    ... ... @@ -610,7 +655,7 @@ MainGUI::createLayout()
    610 655
       unitsComboBox_->insertItem(Units_pt, "pt");
    
    611 656
     
    
    612 657
       dpiLabel_ = new QLabel(tr("DPI "), this);
    
    613
    -  dpiLabel_->setAlignment(Qt::AlignRight);
    
    658
    +  dpiLabel_->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    
    614 659
       dpiSpinBox_ = new QSpinBox(this);
    
    615 660
       dpiSpinBox_->setAlignment(Qt::AlignRight);
    
    616 661
       dpiSpinBox_->setRange(10, 600);
    
    ... ... @@ -628,13 +673,15 @@ MainGUI::createLayout()
    628 673
       toEndButtonx_ = new QPushButtonx(">|", this);
    
    629 674
     
    
    630 675
       zoomLabel_ = new QLabel(tr("Zoom Factor"), this);
    
    631
    -  zoomLabel_->setAlignment(Qt::AlignRight);
    
    676
    +  zoomLabel_->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    
    632 677
       zoomSpinBox_ = new QSpinBoxx(this);
    
    633 678
       zoomSpinBox_->setAlignment(Qt::AlignRight);
    
    634 679
       zoomSpinBox_->setRange(1, 1000 - 1000 % 64);
    
    635 680
       zoomSpinBox_->setKeyboardTracking(false);
    
    636 681
       zoomLabel_->setBuddy(zoomSpinBox_);
    
    637 682
     
    
    683
    +  centerGridButton_ = new QPushButton("Go Back to Grid Center", this);
    
    684
    +
    
    638 685
       previousFontButton_ = new QPushButton(tr("Previous Font"), this);
    
    639 686
       nextFontButton_ = new QPushButton(tr("Next Font"), this);
    
    640 687
       previousFaceButton_ = new QPushButton(tr("Previous Face"), this);
    
    ... ... @@ -674,6 +721,8 @@ MainGUI::createLayout()
    674 721
       sizeLayout_->addStretch(1);
    
    675 722
       sizeLayout_->addWidget(zoomLabel_);
    
    676 723
       sizeLayout_->addWidget(zoomSpinBox_);
    
    724
    +  sizeLayout_->addStretch(1);
    
    725
    +  sizeLayout_->addWidget(centerGridButton_);
    
    677 726
       sizeLayout_->addStretch(2);
    
    678 727
     
    
    679 728
       fontLayout = new QGridLayout;
    
    ... ... @@ -729,6 +778,13 @@ MainGUI::createConnections()
    729 778
     
    
    730 779
       connect(zoomSpinBox_, SIGNAL(valueChanged(int)),
    
    731 780
               SLOT(zoom()));
    
    781
    +  connect(glyphView_, SIGNAL(shiftWheelEvent(QWheelEvent*)), 
    
    782
    +          SLOT(wheelResize(QWheelEvent*)));
    
    783
    +  connect(glyphView_, SIGNAL(ctrlWheelEvent(QWheelEvent*)), 
    
    784
    +          SLOT(wheelZoom(QWheelEvent*)));
    
    785
    +
    
    786
    +  connect(centerGridButton_, SIGNAL(clicked()),
    
    787
    +          SLOT(backToCenter()));
    
    732 788
     
    
    733 789
       connect(previousFontButton_, SIGNAL(clicked()),
    
    734 790
               SLOT(previousFont()));
    

  • src/ftinspect/maingui.hpp
    ... ... @@ -85,6 +85,9 @@ private slots:
    85 85
       void previousNamedInstance();
    
    86 86
       void watchCurrentFont();
    
    87 87
       void zoom();
    
    88
    +  void backToCenter();
    
    89
    +  void wheelZoom(QWheelEvent* event);
    
    90
    +  void wheelResize(QWheelEvent* event);
    
    88 91
     
    
    89 92
     private:
    
    90 93
       Engine* engine_;
    
    ... ... @@ -105,6 +108,7 @@ private:
    105 108
       GlyphPoints *currentGlyphPointsItem_;
    
    106 109
       GlyphPointNumbers *currentGlyphPointNumbersItem_;
    
    107 110
       GlyphBitmap *currentGlyphBitmapItem_;
    
    111
    +  QLabel* mouseUsageHint_;
    
    108 112
     
    
    109 113
       QAction *aboutAct_;
    
    110 114
       QAction *aboutQtAct_;
    
    ... ... @@ -148,6 +152,7 @@ private:
    148 152
       QPen outlinePen_;
    
    149 153
       QPen segmentPen_;
    
    150 154
     
    
    155
    +  QPushButton *centerGridButton_;
    
    151 156
       QPushButton *nextFaceButton_;
    
    152 157
       QPushButton *nextFontButton_;
    
    153 158
       QPushButton *nextNamedInstanceButton_;
    

  • src/ftinspect/widgets/custom_widgets.cpp
    ... ... @@ -4,6 +4,7 @@
    4 4
     
    
    5 5
     #include "custom_widgets.hpp"
    
    6 6
     
    
    7
    +#include <qevent.h>
    
    7 8
     #include <QStandardItemModel>
    
    8 9
     #include <QScrollBar>
    
    9 10
     #include <QStyleOptionButton>
    
    ... ... @@ -19,6 +20,18 @@ QGraphicsViewx::QGraphicsViewx(QWidget* parent)
    19 20
     }
    
    20 21
     
    
    21 22
     
    
    23
    +void
    
    24
    +QGraphicsViewx::wheelEvent(QWheelEvent* event)
    
    25
    +{
    
    26
    +  if (event->modifiers() & Qt::ShiftModifier)
    
    27
    +    emit shiftWheelEvent(event);
    
    28
    +  else if (event->modifiers() & Qt::ControlModifier)
    
    29
    +    emit ctrlWheelEvent(event);
    
    30
    +  else
    
    31
    +    QGraphicsView::wheelEvent(event);
    
    32
    +}
    
    33
    +
    
    34
    +
    
    22 35
     void
    
    23 36
     QGraphicsViewx::scrollContentsBy(int dx,
    
    24 37
                                      int dy)
    

  • src/ftinspect/widgets/custom_widgets.hpp
    ... ... @@ -26,7 +26,12 @@ class QGraphicsViewx
    26 26
     public:
    
    27 27
       QGraphicsViewx(QWidget* parent);
    
    28 28
     
    
    29
    +signals:
    
    30
    +  void shiftWheelEvent(QWheelEvent* event);
    
    31
    +  void ctrlWheelEvent(QWheelEvent* event);
    
    32
    +
    
    29 33
     protected:
    
    34
    +  void wheelEvent(QWheelEvent* event);
    
    30 35
       void resizeEvent(QResizeEvent* event);
    
    31 36
       void scrollContentsBy(int dx,
    
    32 37
                             int dy);
    


  • reply via email to

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