Changeset View
Changeset View
Standalone View
Standalone View
src/scriptengines/qml/plasmoid/dropmenu.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2008 Chani Armitage <chani@kde.org> | ||||
3 | * Copyright 2008, 2009 Aaron Seigo <aseigo@kde.org> | ||||
4 | * Copyright 2010 Marco Martin <mart@kde.org> | ||||
5 | * | ||||
6 | * This program is free software; you can redistribute it and/or modify | ||||
7 | * it under the terms of the GNU Library General Public License as | ||||
8 | * published by the Free Software Foundation; either version 2, or | ||||
9 | * (at your option) any later version. | ||||
10 | * | ||||
11 | * This program is distributed in the hope that it will be useful, | ||||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
14 | * GNU General Public License for more details | ||||
15 | * | ||||
16 | * You should have received a copy of the GNU Library General Public | ||||
17 | * License along with this program; if not, write to the | ||||
18 | * Free Software Foundation, Inc., | ||||
19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
20 | */ | ||||
21 | | ||||
22 | #include "dropmenu.h" | ||||
23 | #include "containmentinterface.h" | ||||
24 | | ||||
25 | #include <QApplication> | ||||
26 | #include <QUrl> | ||||
27 | #include <QPoint> | ||||
28 | #include <QMenu> | ||||
29 | #include <QJSValue> | ||||
30 | #include <QAction> | ||||
31 | #include <QList> | ||||
32 | | ||||
33 | #include <KIO/DropJob> | ||||
34 | #include <klocalizedstring.h> | ||||
35 | | ||||
36 | DropMenu::DropMenu(KIO::DropJob *dropJob, const QPoint &dropPoint, ContainmentInterface *parent) | ||||
37 | : QObject(parent), | ||||
38 | m_dropJob(dropJob), | ||||
39 | m_dropPoint(dropPoint) | ||||
40 | { | ||||
41 | if (!dropJob) { | ||||
42 | m_menu = new QMenu(i18n("Content dropped")); | ||||
43 | if (m_menu->winId()) { | ||||
44 | m_menu->windowHandle()->setTransientParent(parent->window()); | ||||
45 | } | ||||
46 | connect(m_menu, &QMenu::aboutToHide, this, &QObject::deleteLater); | ||||
47 | } else { | ||||
48 | connect(m_dropJob, &QObject::destroyed, this, &QObject::deleteLater); | ||||
49 | } | ||||
50 | } | ||||
51 | | ||||
52 | DropMenu::~DropMenu() | ||||
53 | { | ||||
54 | if (m_menu) { | ||||
55 | delete m_menu; | ||||
56 | } | ||||
57 | } | ||||
58 | | ||||
59 | QList<QUrl> DropMenu::urls() const | ||||
60 | { | ||||
61 | return m_urls; | ||||
62 | } | ||||
63 | | ||||
64 | void DropMenu::setUrls(const QList<QUrl> &urls) | ||||
65 | { | ||||
66 | m_urls = urls; | ||||
67 | } | ||||
68 | | ||||
69 | QPoint DropMenu::dropPoint() const | ||||
70 | { | ||||
71 | return m_dropPoint; | ||||
72 | } | ||||
73 | | ||||
74 | void DropMenu::show() | ||||
75 | { | ||||
76 | if (m_dropJob) { | ||||
77 | m_dropJob->setApplicationActions(m_dropActions); | ||||
78 | m_dropJob->showMenu(m_dropPoint); | ||||
79 | } else if (m_menu) { | ||||
80 | foreach (QAction *action, m_dropActions) { | ||||
81 | m_menu->addAction(action); | ||||
82 | } | ||||
83 | m_menu->popup(m_dropPoint); | ||||
84 | } | ||||
85 | } | ||||
86 | | ||||
87 | void DropMenu::addAction(QAction *action) | ||||
88 | { | ||||
89 | m_dropActions << action; | ||||
90 | } | ||||
91 | | ||||
92 | bool DropMenu::isDropjobMenu() const | ||||
93 | { | ||||
94 | return (m_dropJob? true : false); | ||||
95 | } | ||||
96 | | ||||
97 | void DropMenu::setMultipleMimetypes(bool multipleMimetypes) | ||||
98 | { | ||||
99 | if (m_multipleMimetypes != multipleMimetypes) { | ||||
100 | m_multipleMimetypes = multipleMimetypes; | ||||
101 | } | ||||
102 | } | ||||
103 | | ||||
104 | bool DropMenu::isMultipleMimetypes() const | ||||
105 | { | ||||
106 | return m_multipleMimetypes; | ||||
107 | } | ||||
108 | | ||||
109 | | ||||
110 | #include "moc_dropmenu.cpp" |