File indexing completed on 2024-04-28 16:44:32

0001 /*
0002  * SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005  */
0006 #include "decoratedclient.h"
0007 #include "private/decoratedclientprivate.h"
0008 #include "private/decorationbridge.h"
0009 
0010 #include <QColor>
0011 
0012 namespace KDecoration2
0013 {
0014 DecoratedClient::DecoratedClient(Decoration *parent, DecorationBridge *bridge)
0015     : QObject()
0016     , d(bridge->createClient(this, parent))
0017 {
0018 }
0019 
0020 DecoratedClient::~DecoratedClient() = default;
0021 
0022 #define DELEGATE(type, method)                                                                                                                                 \
0023     type DecoratedClient::method() const                                                                                                                       \
0024     {                                                                                                                                                          \
0025         return d->method();                                                                                                                                    \
0026     }
0027 
0028 DELEGATE(bool, isActive)
0029 DELEGATE(QString, caption)
0030 DELEGATE(int, desktop)
0031 DELEGATE(bool, isOnAllDesktops)
0032 DELEGATE(bool, isShaded)
0033 DELEGATE(QIcon, icon)
0034 DELEGATE(bool, isMaximized)
0035 DELEGATE(bool, isMaximizedHorizontally)
0036 DELEGATE(bool, isMaximizedVertically)
0037 DELEGATE(bool, isKeepAbove)
0038 DELEGATE(bool, isKeepBelow)
0039 DELEGATE(bool, isCloseable)
0040 DELEGATE(bool, isMaximizeable)
0041 DELEGATE(bool, isMinimizeable)
0042 DELEGATE(bool, providesContextHelp)
0043 DELEGATE(bool, isModal)
0044 DELEGATE(bool, isShadeable)
0045 DELEGATE(bool, isMoveable)
0046 DELEGATE(bool, isResizeable)
0047 DELEGATE(WId, windowId)
0048 DELEGATE(WId, decorationId)
0049 DELEGATE(int, width)
0050 DELEGATE(int, height)
0051 DELEGATE(QSize, size)
0052 DELEGATE(QPalette, palette)
0053 DELEGATE(Qt::Edges, adjacentScreenEdges)
0054 DELEGATE(QString, windowClass)
0055 
0056 #undef DELEGATE
0057 
0058 bool DecoratedClient::hasApplicationMenu() const
0059 {
0060     if (const auto *appMenuEnabledPrivate = dynamic_cast<ApplicationMenuEnabledDecoratedClientPrivate *>(d.get())) {
0061         return appMenuEnabledPrivate->hasApplicationMenu();
0062     }
0063     return false;
0064 }
0065 
0066 bool DecoratedClient::isApplicationMenuActive() const
0067 {
0068     if (const auto *appMenuEnabledPrivate = dynamic_cast<ApplicationMenuEnabledDecoratedClientPrivate *>(d.get())) {
0069         return appMenuEnabledPrivate->isApplicationMenuActive();
0070     }
0071     return false;
0072 }
0073 
0074 QPointer<Decoration> DecoratedClient::decoration() const
0075 {
0076     return QPointer<Decoration>(d->decoration());
0077 }
0078 
0079 QColor DecoratedClient::color(QPalette::ColorGroup group, QPalette::ColorRole role) const
0080 {
0081     return d->palette().color(group, role);
0082 }
0083 
0084 QColor DecoratedClient::color(ColorGroup group, ColorRole role) const
0085 {
0086     return d->color(group, role);
0087 }
0088 
0089 void DecoratedClient::showApplicationMenu(int actionId)
0090 {
0091     if (auto *appMenuEnabledPrivate = dynamic_cast<ApplicationMenuEnabledDecoratedClientPrivate *>(d.get())) {
0092         appMenuEnabledPrivate->showApplicationMenu(actionId);
0093     }
0094 }
0095 
0096 } // namespace