[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] gsoc-2022-chariri-2 afdd953 16/30: [ftinspect] Support
From: |
Werner Lemberg |
Subject: |
[freetype2-demos] gsoc-2022-chariri-2 afdd953 16/30: [ftinspect] Support drag & drop to open font files. |
Date: |
Mon, 11 Jul 2022 07:17:40 -0400 (EDT) |
branch: gsoc-2022-chariri-2
commit afdd95346e45b334778a6de97b59181e812ee4b1
Author: Charlie Jiang <w@chariri.moe>
Commit: Charlie Jiang <w@chariri.moe>
[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`.
---
src/ftinspect/maingui.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++---
src/ftinspect/maingui.hpp | 5 +++++
2 files changed, 54 insertions(+), 3 deletions(-)
diff --git a/src/ftinspect/maingui.cpp b/src/ftinspect/maingui.cpp
index 32e6a01..fadc782 100644
--- a/src/ftinspect/maingui.cpp
+++ b/src/ftinspect/maingui.cpp
@@ -11,6 +11,7 @@
#include <QMessageBox>
#include <QSettings>
#include <QScrollBar>
+#include <QMimeData>
#include <freetype/ftdriver.h>
@@ -24,6 +25,7 @@ MainGUI::MainGUI(Engine* engine)
createActions();
createMenus();
createStatusBar();
+ setupDragDrop();
readSettings();
@@ -48,6 +50,37 @@ MainGUI::closeEvent(QCloseEvent* event)
}
+void
+MainGUI::dragEnterEvent(QDragEnterEvent* event)
+{
+ if (event->mimeData()->hasUrls())
+ event->acceptProposedAction();
+}
+
+
+void
+MainGUI::dropEvent(QDropEvent* event)
+{
+ auto mime = event->mimeData();
+ if (!mime->hasUrls())
+ return;
+
+ QStringList fileNames;
+ for (auto& url : mime->urls())
+ {
+ if (!url.isLocalFile())
+ continue;
+ fileNames.append(url.toLocalFile());
+ }
+
+ if (fileNames.empty())
+ return;
+
+ event->acceptProposedAction();
+ openFonts(fileNames);
+}
+
+
void
MainGUI::about()
{
@@ -82,8 +115,6 @@ MainGUI::aboutQt()
void
MainGUI::loadFonts()
{
- int oldSize = engine_->numberOfOpenedFonts();
-
QStringList files = QFileDialog::getOpenFileNames(
this,
tr("Load one or more fonts"),
@@ -91,8 +122,15 @@ MainGUI::loadFonts()
"",
NULL,
QFileDialog::ReadOnly);
+ openFonts(files);
+}
+
- engine_->openFonts(files);
+void
+MainGUI::openFonts(QStringList const& fileNames)
+{
+ int oldSize = engine_->numberOfOpenedFonts();
+ engine_->openFonts(fileNames);
// if we have new fonts, set the current index to the first new one
if (oldSize < engine_->numberOfOpenedFonts())
@@ -903,6 +941,14 @@ MainGUI::createStatusBar()
}
+void
+MainGUI::setupDragDrop()
+{
+ setAcceptDrops(true);
+ glyphView_->setAcceptDrops(false);
+}
+
+
void
MainGUI::setDefaults()
{
diff --git a/src/ftinspect/maingui.hpp b/src/ftinspect/maingui.hpp
index 13d0503..940fe7f 100644
--- a/src/ftinspect/maingui.hpp
+++ b/src/ftinspect/maingui.hpp
@@ -65,6 +65,8 @@ public:
protected:
void closeEvent(QCloseEvent*);
+ void dragEnterEvent(QDragEnterEvent* event);
+ void dropEvent(QDropEvent* event);
private slots:
void about();
@@ -197,6 +199,8 @@ private:
Units_pt
};
+ void openFonts(QStringList const& fileNames);
+
void syncSettings();
void clearStatusBar();
@@ -206,6 +210,7 @@ private:
void createMenus();
void createStatusBar();
void setGraphicsDefaults();
+ void setupDragDrop();
void readSettings();
void writeSettings();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] gsoc-2022-chariri-2 afdd953 16/30: [ftinspect] Support drag & drop to open font files.,
Werner Lemberg <=