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] Support dr


From: Charlie Jiang (@cqjjjzr)
Subject: [Git][freetype/freetype-demos][gsoc-2022-chariri] [ftinspect] Support drag & drop to open font files.
Date: Sun, 03 Jul 2022 12:15:06 +0000

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

Commits:

  • f29dba43
    by Charlie Jiang at 2022-07-03T20:12:37+08:00
    [ftinspect] Support drag & drop to open font files.
    
    A possible issue is that no checking is performed to ensure the dropped files
    are real font files.
    
    * src/ftinspect/maingui.cpp, src/ftinspect/maingui.hpp: Use custom
    `dragEnterEvent` and `dropEvent` to accept drop operations. Dropping was set
    to unaccepted for `glyphView_` to let the event pass down to `MainGUI`.
    

2 changed files:

Changes:

  • src/ftinspect/maingui.cpp
    ... ... @@ -11,6 +11,7 @@
    11 11
     #include <QMessageBox>
    
    12 12
     #include <QSettings>
    
    13 13
     #include <QScrollBar>
    
    14
    +#include <QMimeData>
    
    14 15
     
    
    15 16
     #include <freetype/ftdriver.h>
    
    16 17
     
    
    ... ... @@ -24,6 +25,7 @@ MainGUI::MainGUI(Engine* engine)
    24 25
       createActions();
    
    25 26
       createMenus();
    
    26 27
       createStatusBar();
    
    28
    +  setupDragDrop();
    
    27 29
     
    
    28 30
       readSettings();
    
    29 31
     
    
    ... ... @@ -48,6 +50,37 @@ MainGUI::closeEvent(QCloseEvent* event)
    48 50
     }
    
    49 51
     
    
    50 52
     
    
    53
    +void
    
    54
    +MainGUI::dragEnterEvent(QDragEnterEvent* event)
    
    55
    +{
    
    56
    +  if (event->mimeData()->hasUrls())
    
    57
    +    event->acceptProposedAction();
    
    58
    +}
    
    59
    +
    
    60
    +
    
    61
    +void
    
    62
    +MainGUI::dropEvent(QDropEvent* event)
    
    63
    +{
    
    64
    +  auto mime = event->mimeData();
    
    65
    +  if (!mime->hasUrls())
    
    66
    +    return;
    
    67
    +
    
    68
    +  QStringList fileNames;
    
    69
    +  for (auto& url : mime->urls())
    
    70
    +  {
    
    71
    +    if (!url.isLocalFile())
    
    72
    +      continue;
    
    73
    +    fileNames.append(url.toLocalFile());
    
    74
    +  }
    
    75
    +
    
    76
    +  if (fileNames.empty())
    
    77
    +    return;
    
    78
    +
    
    79
    +  event->acceptProposedAction();
    
    80
    +  openFonts(fileNames);
    
    81
    +}
    
    82
    +
    
    83
    +
    
    51 84
     void
    
    52 85
     MainGUI::about()
    
    53 86
     {
    
    ... ... @@ -82,8 +115,6 @@ MainGUI::aboutQt()
    82 115
     void
    
    83 116
     MainGUI::loadFonts()
    
    84 117
     {
    
    85
    -  int oldSize = engine_->numberOfOpenedFonts();
    
    86
    -
    
    87 118
       QStringList files = QFileDialog::getOpenFileNames(
    
    88 119
                             this,
    
    89 120
                             tr("Load one or more fonts"),
    
    ... ... @@ -91,8 +122,15 @@ MainGUI::loadFonts()
    91 122
                             "",
    
    92 123
                             NULL,
    
    93 124
                             QFileDialog::ReadOnly);
    
    125
    +  openFonts(files);
    
    126
    +}
    
    127
    +
    
    94 128
     
    
    95
    -  engine_->openFonts(files);
    
    129
    +void
    
    130
    +MainGUI::openFonts(QStringList const& fileNames)
    
    131
    +{
    
    132
    +  int oldSize = engine_->numberOfOpenedFonts();
    
    133
    +  engine_->openFonts(fileNames);
    
    96 134
     
    
    97 135
       // if we have new fonts, set the current index to the first new one
    
    98 136
       if (oldSize < engine_->numberOfOpenedFonts())
    
    ... ... @@ -903,6 +941,14 @@ MainGUI::createStatusBar()
    903 941
     }
    
    904 942
     
    
    905 943
     
    
    944
    +void
    
    945
    +MainGUI::setupDragDrop()
    
    946
    +{
    
    947
    +  setAcceptDrops(true);
    
    948
    +  glyphView_->setAcceptDrops(false);
    
    949
    +}
    
    950
    +
    
    951
    +
    
    906 952
     void
    
    907 953
     MainGUI::setDefaults()
    
    908 954
     {
    

  • src/ftinspect/maingui.hpp
    ... ... @@ -65,6 +65,8 @@ public:
    65 65
     
    
    66 66
     protected:
    
    67 67
       void closeEvent(QCloseEvent*);
    
    68
    +  void dragEnterEvent(QDragEnterEvent* event);
    
    69
    +  void dropEvent(QDropEvent* event);
    
    68 70
     
    
    69 71
     private slots:
    
    70 72
       void about();
    
    ... ... @@ -197,6 +199,8 @@ private:
    197 199
         Units_pt
    
    198 200
       };
    
    199 201
     
    
    202
    +  void openFonts(QStringList const& fileNames);
    
    203
    +
    
    200 204
       void syncSettings();
    
    201 205
       void clearStatusBar();
    
    202 206
     
    
    ... ... @@ -206,6 +210,7 @@ private:
    206 210
       void createMenus();
    
    207 211
       void createStatusBar();
    
    208 212
       void setGraphicsDefaults();
    
    213
    +  void setupDragDrop();
    
    209 214
     
    
    210 215
       void readSettings();
    
    211 216
       void writeSettings();
    


  • reply via email to

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