File indexing completed on 2026-06-07 05:41:26
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2008 Lubos Lunak <l.lunak@suse.cz> 0006 SPDX-FileCopyrightText: 2009 Lucas Murray <lmurray@undefinedfire.com> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #pragma once 0012 0013 #include "screenpreviewwidget.h" 0014 0015 #include <QActionGroup> 0016 #include <QGraphicsItem> 0017 #include <QList> 0018 #include <array> 0019 #include <memory> 0020 0021 class QAction; 0022 class QGraphicsView; 0023 class QGraphicsScene; 0024 class QMenu; 0025 0026 namespace KSvg 0027 { 0028 class FrameSvg; 0029 } 0030 0031 namespace KWin 0032 { 0033 0034 class Monitor : public ScreenPreviewWidget 0035 { 0036 Q_OBJECT 0037 public: 0038 explicit Monitor(QWidget *parent); 0039 ~Monitor(); 0040 0041 void setEdgeEnabled(int edge, bool enabled); 0042 void setEdgeHidden(int edge, bool set); 0043 bool edgeHidden(int edge) const; 0044 void clear(); 0045 void addEdgeItem(int edge, const QString &item); 0046 void setEdgeItemEnabled(int edge, int index, bool enabled); 0047 bool edgeItemEnabled(int edge, int index) const; 0048 void selectEdgeItem(int edge, int index); 0049 int selectedEdgeItem(int edge) const; 0050 0051 enum Edges { 0052 Left, 0053 Right, 0054 Top, 0055 Bottom, 0056 TopLeft, 0057 TopRight, 0058 BottomLeft, 0059 BottomRight, 0060 None 0061 }; 0062 Q_SIGNALS: 0063 void changed(); 0064 void edgeSelectionChanged(int edge, int index); 0065 0066 protected: 0067 void resizeEvent(QResizeEvent *e) override; 0068 bool event(QEvent *event) override; 0069 0070 private: 0071 class Corner; 0072 void popup(Corner *c, QPoint pos); 0073 void flip(Corner *c, QPoint pos); 0074 void checkSize(); 0075 std::unique_ptr<QGraphicsScene> m_scene; 0076 std::unique_ptr<QGraphicsView> m_view; 0077 std::array<std::unique_ptr<Corner>, 8> m_items; 0078 std::array<bool, 8> m_hidden; 0079 std::array<std::unique_ptr<QMenu>, 8> m_popups; 0080 std::array<QList<QAction *>, 8> m_popupActions; 0081 std::array<std::unique_ptr<QActionGroup>, 8> m_actionGroups; 0082 }; 0083 0084 class Monitor::Corner : public QGraphicsRectItem 0085 { 0086 public: 0087 Corner(Monitor *m); 0088 ~Corner() override; 0089 void setActive(bool active); 0090 bool active() const; 0091 0092 protected: 0093 void contextMenuEvent(QGraphicsSceneContextMenuEvent *e) override; 0094 void mousePressEvent(QGraphicsSceneMouseEvent *e) override; 0095 void hoverEnterEvent(QGraphicsSceneHoverEvent *e) override; 0096 void hoverLeaveEvent(QGraphicsSceneHoverEvent *e) override; 0097 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; 0098 0099 private: 0100 Monitor *const m_monitor; 0101 const std::unique_ptr<KSvg::FrameSvg> m_button; 0102 bool m_active = false; 0103 bool m_hover = false; 0104 }; 0105 0106 } // namespace