Fix OTS warning about `maxp.maxSizeOfInstructions`.
[ttfautohint.git] / frontend / ddlineedit.cpp
blobb68f5773dfaead0442f430ffa2bf507935683c73
1 // ddlineedit.cpp
3 // Copyright (C) 2012-2022 by Werner Lemberg.
4 //
5 // This file is part of the ttfautohint library, and may only be used,
6 // modified, and distributed under the terms given in `COPYING'. By
7 // continuing to use, modify, or distribute this file you indicate that you
8 // have read `COPYING' and understand and accept it fully.
9 //
10 // The file `COPYING' mentioned in the previous paragraph is distributed
11 // with the ttfautohint library.
14 // Derived class `Drag_Drop_Line_Edit' is Tooltip_Line_Edit
15 // that accepts drag and drop.
17 #include <config.h>
19 #include "ddlineedit.h"
21 Drag_Drop_Line_Edit::Drag_Drop_Line_Edit(Drag_Drop_File_Type ft,
22 QWidget* parent)
23 : Tooltip_Line_Edit(parent),
24 file_type(ft)
26 // empty
30 // XXX: There are no standardized MIME types for TTFs and TTCs
31 // that work everywhere. So we rely on the extension.
33 void
34 Drag_Drop_Line_Edit::dragEnterEvent(QDragEnterEvent* event)
36 QList<QUrl> url_list;
37 QString file_name;
39 if (event->mimeData()->hasUrls())
41 url_list = event->mimeData()->urls();
43 // if just text was dropped, url_list is empty
44 if (url_list.size())
46 file_name = url_list[0].toLocalFile();
48 switch (file_type)
50 case DRAG_DROP_TRUETYPE:
51 if (file_name.endsWith(".ttf")
52 || file_name.endsWith(".TTF")
53 || file_name.endsWith(".ttc")
54 || file_name.endsWith(".TTC"))
55 event->acceptProposedAction();
56 break;
58 case DRAG_DROP_ANY:
59 event->acceptProposedAction();
60 break;
67 void
68 Drag_Drop_Line_Edit::dropEvent(QDropEvent* event)
70 QList<QUrl> url_list;
71 QString file_name;
72 QFileInfo info;
74 if (event->mimeData()->hasUrls())
76 url_list = event->mimeData()->urls();
78 // if just text was dropped, url_list is empty
79 if (url_list.size())
81 file_name = url_list[0].toLocalFile();
83 // check whether `file_name' is valid
84 info.setFile(file_name);
85 if (info.isFile())
86 setText(file_name);
90 event->acceptProposedAction();
93 // end of ddlineedit.cpp