File: ddlineedit.cpp

package info (click to toggle)
ttfautohint 1.8.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,120 kB
  • sloc: ansic: 42,761; sh: 5,584; cpp: 4,222; perl: 340; javascript: 78; sed: 52; makefile: 34
file content (93 lines) | stat: -rw-r--r-- 2,146 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// ddlineedit.cpp

// Copyright (C) 2012-2021 by Werner Lemberg.
//
// This file is part of the ttfautohint library, and may only be used,
// modified, and distributed under the terms given in `COPYING'.  By
// continuing to use, modify, or distribute this file you indicate that you
// have read `COPYING' and understand and accept it fully.
//
// The file `COPYING' mentioned in the previous paragraph is distributed
// with the ttfautohint library.


// Derived class `Drag_Drop_Line_Edit' is Tooltip_Line_Edit
// that accepts drag and drop.

#include <config.h>

#include "ddlineedit.h"

Drag_Drop_Line_Edit::Drag_Drop_Line_Edit(Drag_Drop_File_Type ft,
                                         QWidget* parent)
: Tooltip_Line_Edit(parent),
  file_type(ft)
{
  // empty
}


// XXX: There are no standardized MIME types for TTFs and TTCs
//      that work everywhere.  So we rely on the extension.

void
Drag_Drop_Line_Edit::dragEnterEvent(QDragEnterEvent* event)
{
  QList<QUrl> url_list;
  QString file_name;

  if (event->mimeData()->hasUrls())
  {
    url_list = event->mimeData()->urls();

    // if just text was dropped, url_list is empty
    if (url_list.size())
    {
      file_name = url_list[0].toLocalFile();

      switch (file_type)
      {
      case DRAG_DROP_TRUETYPE:
        if (file_name.endsWith(".ttf")
            || file_name.endsWith(".TTF")
            || file_name.endsWith(".ttc")
            || file_name.endsWith(".TTC"))
          event->acceptProposedAction();
        break;

      case DRAG_DROP_ANY:
        event->acceptProposedAction();
        break;
      }
    }
  }
}


void
Drag_Drop_Line_Edit::dropEvent(QDropEvent* event)
{
  QList<QUrl> url_list;
  QString file_name;
  QFileInfo info;

  if (event->mimeData()->hasUrls())
  {
    url_list = event->mimeData()->urls();

    // if just text was dropped, url_list is empty
    if (url_list.size())
    {
      file_name = url_list[0].toLocalFile();

      // check whether `file_name' is valid
      info.setFile(file_name);
      if (info.isFile())
        setText(file_name);
    }
  }

  event->acceptProposedAction();
}

// end of ddlineedit.cpp