KXmlGui

kmainwindowiface.cpp
1/*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2001 Ian Reinhart Geiser <geiseri@yahoo.com>
4 SPDX-FileCopyrightText: 2006 Thiago Macieira <thiago@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "kmainwindowiface_p.h"
10
11#include "kactioncollection.h"
12#include "kxmlguiwindow.h"
13
14#include <QAction>
15#include <QApplication>
16#include <QClipboard>
17
18#include <algorithm>
19
20KMainWindowInterface::KMainWindowInterface(KXmlGuiWindow *mainWindow)
21 : QDBusAbstractAdaptor(mainWindow)
22 , m_MainWindow(mainWindow)
23{
24}
25
26KMainWindowInterface::~KMainWindowInterface()
27{
28}
29
30QStringList KMainWindowInterface::actions()
31{
32 QStringList tmp_actions;
33 const QList<QAction *> lst = m_MainWindow->actionCollection()->actions();
34 for (QAction *it : lst) {
35 const QList<QObject *> associatedObjects = it->associatedObjects();
36 const bool hasAssociatedWidgets = std::any_of(associatedObjects.cbegin(), associatedObjects.cend(), [](QObject *object) {
37 return (qobject_cast<QWidget *>(object) != nullptr);
38 });
39 if (hasAssociatedWidgets) {
40 tmp_actions.append(it->objectName());
41 }
42 }
43 return tmp_actions;
44}
45
46bool KMainWindowInterface::activateAction(const QString &action)
47{
48 QAction *tmp_Action = m_MainWindow->actionCollection()->action(action);
49 if (tmp_Action) {
50 tmp_Action->trigger();
51 return true;
52 } else {
53 return false;
54 }
55}
56
57bool KMainWindowInterface::disableAction(const QString &action)
58{
59 QAction *tmp_Action = m_MainWindow->actionCollection()->action(action);
60 if (tmp_Action) {
61 tmp_Action->setEnabled(false);
62 return true;
63 } else {
64 return false;
65 }
66}
67
68bool KMainWindowInterface::enableAction(const QString &action)
69{
70 QAction *tmp_Action = m_MainWindow->actionCollection()->action(action);
71 if (tmp_Action) {
72 tmp_Action->setEnabled(true);
73 return true;
74 } else {
75 return false;
76 }
77}
78
79bool KMainWindowInterface::actionIsEnabled(const QString &action)
80{
81 QAction *tmp_Action = m_MainWindow->actionCollection()->action(action);
82 if (tmp_Action) {
83 return tmp_Action->isEnabled();
84 } else {
85 return false;
86 }
87}
88
89QString KMainWindowInterface::actionToolTip(const QString &action)
90{
91 QAction *tmp_Action = m_MainWindow->actionCollection()->action(action);
92 if (tmp_Action) {
93 return tmp_Action->toolTip();
94 } else {
95 return QStringLiteral("Error no such object!");
96 }
97}
98
99qlonglong KMainWindowInterface::winId()
100{
101 return qlonglong(m_MainWindow->winId());
102}
103
104void KMainWindowInterface::grabWindowToClipBoard()
105{
106 QClipboard *clipboard = QApplication::clipboard();
107 clipboard->setPixmap(m_MainWindow->grab());
108}
109
110#include "moc_kmainwindowiface_p.cpp"
KMainWindow with convenience functions and integration with XmlGui files.
void setEnabled(bool)
void trigger()
void setPixmap(const QPixmap &pixmap, Mode mode)
QClipboard * clipboard()
void append(QList< T > &&value)
const_iterator cbegin() const const
const_iterator cend() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:19:32 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.