File indexing completed on 2024-12-01 13:37:34

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2011 Arthur Arlt <a.arlt@stud.uni-heidelberg.de>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #pragma once
0011 #include <QObject>
0012 #include <QRect>
0013 #include <kwinglobals.h>
0014 #include <memory>
0015 
0016 #include <kwin_export.h>
0017 #include <memory>
0018 
0019 class QQmlContext;
0020 class QQmlComponent;
0021 
0022 namespace KWin
0023 {
0024 class OutlineVisual;
0025 
0026 /**
0027  * @short This class is used to show the outline of a given geometry.
0028  *
0029  * The class renders an outline by using four windows. One for each border of
0030  * the geometry. It is possible to replace the outline with an effect. If an
0031  * effect is available the effect will be used, otherwise the outline will be
0032  * rendered by using the X implementation.
0033  *
0034  * @author Arthur Arlt
0035  * @since 4.7
0036  */
0037 class KWIN_EXPORT Outline : public QObject
0038 {
0039     Q_OBJECT
0040     Q_PROPERTY(QRect geometry READ geometry NOTIFY geometryChanged)
0041     Q_PROPERTY(QRect visualParentGeometry READ visualParentGeometry NOTIFY visualParentGeometryChanged)
0042     Q_PROPERTY(QRect unifiedGeometry READ unifiedGeometry NOTIFY unifiedGeometryChanged)
0043     Q_PROPERTY(bool active READ isActive NOTIFY activeChanged)
0044 public:
0045     explicit Outline();
0046     ~Outline() override;
0047 
0048     /**
0049      * Set the outline geometry.
0050      * To show the outline use showOutline.
0051      * @param outlineGeometry The geometry of the outline to be shown
0052      * @see showOutline
0053      */
0054     void setGeometry(const QRect &outlineGeometry);
0055 
0056     /**
0057      * Set the visual parent geometry.
0058      * This is the geometry from which the will emerge.
0059      * @param visualParentGeometry The visual geometry of the visual parent
0060      * @see showOutline
0061      */
0062     void setVisualParentGeometry(const QRect &visualParentGeometry);
0063 
0064     /**
0065      * Shows the outline of a window using either an effect or the X implementation.
0066      * To stop the outline process use hideOutline.
0067      * @see hideOutline
0068      */
0069     void show();
0070 
0071     /**
0072      * Shows the outline for the given @p outlineGeometry.
0073      * This is the same as setOutlineGeometry followed by showOutline directly.
0074      * To stop the outline process use hideOutline.
0075      * @param outlineGeometry The geometry of the outline to be shown
0076      * @see hideOutline
0077      */
0078     void show(const QRect &outlineGeometry);
0079 
0080     /**
0081      * Shows the outline for the given @p outlineGeometry animated from @p visualParentGeometry.
0082      * This is the same as setOutlineGeometry followed by setVisualParentGeometry
0083      * and then showOutline.
0084      * To stop the outline process use hideOutline.
0085      * @param outlineGeometry The geometry of the outline to be shown
0086      * @param visualParentGeometry The geometry from where the outline should emerge
0087      * @see hideOutline
0088      * @since 5.10
0089      */
0090     void show(const QRect &outlineGeometry, const QRect &visualParentGeometry);
0091 
0092     /**
0093      * Hides shown outline.
0094      * @see showOutline
0095      */
0096     void hide();
0097 
0098     const QRect &geometry() const;
0099     const QRect &visualParentGeometry() const;
0100     QRect unifiedGeometry() const;
0101 
0102     bool isActive() const;
0103 
0104 private Q_SLOTS:
0105     void compositingChanged();
0106 
0107 Q_SIGNALS:
0108     void activeChanged();
0109     void geometryChanged();
0110     void unifiedGeometryChanged();
0111     void visualParentGeometryChanged();
0112 
0113 private:
0114     void createHelper();
0115     std::unique_ptr<OutlineVisual> m_visual;
0116     QRect m_outlineGeometry;
0117     QRect m_visualParentGeometry;
0118     bool m_active;
0119 };
0120 
0121 class KWIN_EXPORT OutlineVisual
0122 {
0123 public:
0124     OutlineVisual(Outline *outline);
0125     virtual ~OutlineVisual();
0126     virtual void show() = 0;
0127     virtual void hide() = 0;
0128 
0129 protected:
0130     Outline *const m_outline;
0131 };
0132 
0133 class CompositedOutlineVisual : public OutlineVisual
0134 {
0135 public:
0136     CompositedOutlineVisual(Outline *outline);
0137     ~CompositedOutlineVisual() override;
0138     void show() override;
0139     void hide() override;
0140 
0141 private:
0142     std::unique_ptr<QQmlContext> m_qmlContext;
0143     std::unique_ptr<QQmlComponent> m_qmlComponent;
0144     std::unique_ptr<QObject> m_mainItem;
0145 };
0146 }