File indexing completed on 2024-05-12 09:31:34

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(bool, isOnAllDesktops)
0031 DELEGATE(bool, isShaded)
0032 DELEGATE(QIcon, icon)
0033 DELEGATE(bool, isMaximized)
0034 DELEGATE(bool, isMaximizedHorizontally)
0035 DELEGATE(bool, isMaximizedVertically)
0036 DELEGATE(bool, isKeepAbove)
0037 DELEGATE(bool, isKeepBelow)
0038 DELEGATE(bool, isCloseable)
0039 DELEGATE(bool, isMaximizeable)
0040 DELEGATE(bool, isMinimizeable)
0041 DELEGATE(bool, providesContextHelp)
0042 DELEGATE(bool, isModal)
0043 DELEGATE(bool, isShadeable)
0044 DELEGATE(bool, isMoveable)
0045 DELEGATE(bool, isResizeable)
0046 DELEGATE(WId, windowId)
0047 DELEGATE(WId, decorationId)
0048 DELEGATE(int, width)
0049 DELEGATE(int, height)
0050 DELEGATE(QSize, size)
0051 DELEGATE(QPalette, palette)
0052 DELEGATE(Qt::Edges, adjacentScreenEdges)
0053 DELEGATE(QString, windowClass)
0054 
0055 #undef DELEGATE
0056 
0057 bool DecoratedClient::hasApplicationMenu() const
0058 {
0059     if (const auto *appMenuEnabledPrivate = dynamic_cast<ApplicationMenuEnabledDecoratedClientPrivate *>(d.get())) {
0060         return appMenuEnabledPrivate->hasApplicationMenu();
0061     }
0062     return false;
0063 }
0064 
0065 bool DecoratedClient::isApplicationMenuActive() const
0066 {
0067     if (const auto *appMenuEnabledPrivate = dynamic_cast<ApplicationMenuEnabledDecoratedClientPrivate *>(d.get())) {
0068         return appMenuEnabledPrivate->isApplicationMenuActive();
0069     }
0070     return false;
0071 }
0072 
0073 Decoration *DecoratedClient::decoration() const
0074 {
0075     return d->decoration();
0076 }
0077 
0078 QColor DecoratedClient::color(QPalette::ColorGroup group, QPalette::ColorRole role) const
0079 {
0080     return d->palette().color(group, role);
0081 }
0082 
0083 QColor DecoratedClient::color(ColorGroup group, ColorRole role) const
0084 {
0085     return d->color(group, role);
0086 }
0087 
0088 void DecoratedClient::showApplicationMenu(int actionId)
0089 {
0090     if (auto *appMenuEnabledPrivate = dynamic_cast<ApplicationMenuEnabledDecoratedClientPrivate *>(d.get())) {
0091         appMenuEnabledPrivate->showApplicationMenu(actionId);
0092     }
0093 }
0094 
0095 } // namespace
0096 
0097 #include "moc_decoratedclient.cpp"