Plasma-framework

dropmenu.cpp
1/*
2 SPDX-FileCopyrightText: 2008 Chani Armitage <chani@kde.org>
3 SPDX-FileCopyrightText: 2008, 2009 Aaron Seigo <aseigo@kde.org>
4 SPDX-FileCopyrightText: 2010 Marco Martin <mart@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "dropmenu.h"
10#include "containmentitem.h"
11
12#include <QAction>
13#include <QApplication>
14#include <QJSValue>
15#include <QList>
16#include <QMenu>
17#include <QUrl>
18
19#include <KIO/DropJob>
20#include <KLocalizedString>
21
22DropMenu::DropMenu(KIO::DropJob *dropJob, const QPoint &dropPoint, ContainmentItem *parent)
23 : QObject(parent)
24 , m_dropPoint(dropPoint)
25 , m_dropJob(dropJob)
26{
27 if (!dropJob) {
28 m_menu = new QMenu(i18n("Content dropped"));
29
30 // Polish before creating a native window below. The style could want change the surface format
31 // of the window which will have no effect when the native window has already been created.
32 m_menu->ensurePolished();
33
34 if (m_menu->winId()) {
35 m_menu->windowHandle()->setTransientParent(parent->window());
36 }
38 } else {
40 }
41}
42
43DropMenu::~DropMenu()
44{
45 if (m_menu) {
46 delete m_menu;
47 }
48}
49
50QList<QUrl> DropMenu::urls() const
51{
52 return m_urls;
53}
54
55void DropMenu::setUrls(const QList<QUrl> &urls)
56{
57 m_urls = urls;
58}
59
60QPoint DropMenu::dropPoint() const
61{
62 return m_dropPoint;
63}
64
65void DropMenu::show()
66{
67 if (m_dropJob) {
68 m_dropJob->setApplicationActions(m_dropActions);
69 m_dropJob->showMenu(m_dropPoint);
70 } else if (m_menu) {
71 m_menu->addActions(m_dropActions);
72 m_menu->popup(m_dropPoint);
73 }
74}
75
76void DropMenu::addAction(QAction *action)
77{
78 m_dropActions << action;
79}
80
81bool DropMenu::isDropjobMenu() const
82{
83 return (m_dropJob ? true : false);
84}
85
86void DropMenu::setMultipleMimetypes(bool multipleMimetypes)
87{
88 if (m_multipleMimetypes != multipleMimetypes) {
89 m_multipleMimetypes = multipleMimetypes;
90 }
91}
92
93bool DropMenu::isMultipleMimetypes() const
94{
95 return m_multipleMimetypes;
96}
97
98#include "moc_dropmenu.cpp"
This class is exposed to containments QML as the attached property Plasmoid.
void setApplicationActions(const QList< QAction * > &actions)
void showMenu(const QPoint &p, QAction *atAction=nullptr)
QString i18n(const char *text, const TYPE &arg...)
void aboutToHide()
void popup(const QPoint &p, QAction *atAction)
void deleteLater()
void destroyed(QObject *obj)
QQuickWindow * window() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void addActions(const QList< QAction * > &actions)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:54:11 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.