File indexing completed on 2024-09-29 09:33:14
0001 /* 0002 This file is part of the KDE project 0003 SPDX-FileCopyrightText: 2001 Ian Reinhart Geiser <geiseri@yahoo.com> 0004 SPDX-FileCopyrightText: 2006 Thiago Macieira <thiago@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #include "kmainwindowiface_p.h" 0010 0011 #include "kactioncollection.h" 0012 #include "kxmlguiwindow.h" 0013 0014 #include <QAction> 0015 #include <QApplication> 0016 #include <QClipboard> 0017 0018 KMainWindowInterface::KMainWindowInterface(KXmlGuiWindow *mainWindow) 0019 : QDBusAbstractAdaptor(mainWindow) 0020 , m_MainWindow(mainWindow) 0021 { 0022 } 0023 0024 KMainWindowInterface::~KMainWindowInterface() 0025 { 0026 } 0027 0028 QStringList KMainWindowInterface::actions() 0029 { 0030 QStringList tmp_actions; 0031 const QList<QAction *> lst = m_MainWindow->actionCollection()->actions(); 0032 for (QAction *it : lst) { 0033 if (!it->associatedWidgets().isEmpty()) { 0034 tmp_actions.append(it->objectName()); 0035 } 0036 } 0037 return tmp_actions; 0038 } 0039 0040 bool KMainWindowInterface::activateAction(const QString &action) 0041 { 0042 QAction *tmp_Action = m_MainWindow->actionCollection()->action(action); 0043 if (tmp_Action) { 0044 tmp_Action->trigger(); 0045 return true; 0046 } else { 0047 return false; 0048 } 0049 } 0050 0051 bool KMainWindowInterface::disableAction(const QString &action) 0052 { 0053 QAction *tmp_Action = m_MainWindow->actionCollection()->action(action); 0054 if (tmp_Action) { 0055 tmp_Action->setEnabled(false); 0056 return true; 0057 } else { 0058 return false; 0059 } 0060 } 0061 0062 bool KMainWindowInterface::enableAction(const QString &action) 0063 { 0064 QAction *tmp_Action = m_MainWindow->actionCollection()->action(action); 0065 if (tmp_Action) { 0066 tmp_Action->setEnabled(true); 0067 return true; 0068 } else { 0069 return false; 0070 } 0071 } 0072 0073 bool KMainWindowInterface::actionIsEnabled(const QString &action) 0074 { 0075 QAction *tmp_Action = m_MainWindow->actionCollection()->action(action); 0076 if (tmp_Action) { 0077 return tmp_Action->isEnabled(); 0078 } else { 0079 return false; 0080 } 0081 } 0082 0083 QString KMainWindowInterface::actionToolTip(const QString &action) 0084 { 0085 QAction *tmp_Action = m_MainWindow->actionCollection()->action(action); 0086 if (tmp_Action) { 0087 return tmp_Action->toolTip(); 0088 } else { 0089 return QStringLiteral("Error no such object!"); 0090 } 0091 } 0092 0093 qlonglong KMainWindowInterface::winId() 0094 { 0095 return qlonglong(m_MainWindow->winId()); 0096 } 0097 0098 void KMainWindowInterface::grabWindowToClipBoard() 0099 { 0100 QClipboard *clipboard = QApplication::clipboard(); 0101 clipboard->setPixmap(m_MainWindow->grab()); 0102 } 0103 0104 #include "moc_kmainwindowiface_p.cpp"