Libplasma

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 <KJobWindows>
21#include <KLocalizedString>
22
23DropMenu::DropMenu(KIO::DropJob *dropJob, const QPoint &dropPoint, ContainmentItem *parent)
24 : QObject(parent)
25 , m_dropPoint(dropPoint)
26 , m_dropJob(dropJob)
27{
28 if (!dropJob) {
29 m_menu = new QMenu(i18n("Content dropped"));
30
31 // Polish before creating a native window below. The style could want change the surface format
32 // of the window which will have no effect when the native window has already been created.
33 m_menu->ensurePolished();
34
36 } else {
38 }
39}
40
41DropMenu::~DropMenu()
42{
43 if (m_menu) {
44 delete m_menu;
45 }
46}
47
48QList<QUrl> DropMenu::urls() const
49{
50 return m_urls;
51}
52
53void DropMenu::setUrls(const QList<QUrl> &urls)
54{
55 m_urls = urls;
56}
57
58QPoint DropMenu::dropPoint() const
59{
60 return m_dropPoint;
61}
62
63void DropMenu::show()
64{
65 QWindow *transientParent = nullptr;
66 if (auto containmentItem = qobject_cast<ContainmentItem *>(parent())) {
67 transientParent = containmentItem->window();
68 }
69
70 if (m_dropJob) {
71 KJobWindows::setWindow(m_dropJob, transientParent);
72
73 m_dropJob->setApplicationActions(m_dropActions);
74 m_dropJob->showMenu(m_dropPoint);
75 } else if (m_menu) {
76 if (m_menu->winId()) {
77 m_menu->windowHandle()->setTransientParent(transientParent);
78 }
79 m_menu->addActions(m_dropActions);
80 m_menu->popup(m_dropPoint);
81 }
82}
83
84void DropMenu::addAction(QAction *action)
85{
86 m_dropActions << action;
87}
88
89bool DropMenu::isDropjobMenu() const
90{
91 return (m_dropJob ? true : false);
92}
93
94void DropMenu::setMultipleMimetypes(bool multipleMimetypes)
95{
96 if (m_multipleMimetypes != multipleMimetypes) {
97 m_multipleMimetypes = multipleMimetypes;
98 }
99}
100
101bool DropMenu::isMultipleMimetypes() const
102{
103 return m_multipleMimetypes;
104}
105
106#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...)
KGUIADDONS_EXPORT void setWindow(QObject *job, QWindow *window)
void aboutToHide()
void popup(const QPoint &p, QAction *atAction)
void deleteLater()
void destroyed(QObject *obj)
QObject * parent() const const
T qobject_cast(QObject *object)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void addActions(const QList< QAction * > &actions)
WId winId() const const
QWindow * windowHandle() const const
void setTransientParent(QWindow *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:09:37 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.