Initialize properties of `globals' object.
[ttfautohint.git] / frontend / lineedit.cpp
blob019976a58314ec3a71532bafcb58c3d6863798c7
1 // lineedit.cpp
3 // Copyright (C) 2012 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 `Line_Edit' is QLineEdit which accepts drag and drop.
16 #include <config.h>
18 #include "lineedit.h"
20 Line_Edit::Line_Edit(QWidget* parent)
21 : QLineEdit(parent)
23 // empty
27 // XXX: There are no standardized MIME types for TTFs and TTCs
28 // which work everywhere. So we rely on the extension.
30 void
31 Line_Edit::dragEnterEvent(QDragEnterEvent* event)
33 QList<QUrl> url_list;
34 QString file_name;
36 if (event->mimeData()->hasUrls())
38 url_list = event->mimeData()->urls();
40 // if just text was dropped, url_list is empty
41 if (url_list.size())
43 file_name = url_list[0].toLocalFile();
45 if (file_name.endsWith(".ttf")
46 || file_name.endsWith(".TTF")
47 || file_name.endsWith(".ttc")
48 || file_name.endsWith(".TTC"))
49 event->acceptProposedAction();
55 void
56 Line_Edit::dropEvent(QDropEvent* event)
58 QList<QUrl> url_list;
59 QString file_name;
60 QFileInfo info;
62 if (event->mimeData()->hasUrls())
64 url_list = event->mimeData()->urls();
66 // if just text was dropped, url_list is empty
67 if (url_list.size())
69 file_name = url_list[0].toLocalFile();
71 // check whether `file_name' is valid
72 info.setFile(file_name);
73 if (info.isFile())
74 setText(file_name);
78 event->acceptProposedAction();
81 // end of lineedit.cpp