File indexing completed on 2024-04-28 09:43:35
0001 /** 0002 * SPDX-FileCopyrightText: (C) 2003 by Sébastien Laoût <slaout@linux62.org> 0003 * SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef FOCUSEDWIDGETS_H 0007 #define FOCUSEDWIDGETS_H 0008 0009 #include <KTextEdit> 0010 #include <QClipboard> 0011 0012 class QEvent; 0013 class QKeyEvent; 0014 class QWheelEvent; 0015 0016 class QMenu; 0017 0018 class FocusedTextEdit : public KTextEdit 0019 { 0020 Q_OBJECT 0021 public: 0022 explicit FocusedTextEdit(bool disableUpdatesOnKeyPress, QWidget *parent = nullptr); 0023 ~FocusedTextEdit() override; 0024 void paste(QClipboard::Mode mode); 0025 public Q_SLOTS: 0026 void onSelectionChanged(); //!< Put selected text into the global mouse selection 0027 protected: 0028 void keyPressEvent(QKeyEvent *event) override; 0029 void wheelEvent(QWheelEvent *event) override; 0030 void enterEvent(QEvent *event) override; 0031 void insertFromMimeData(const QMimeData *source) override; 0032 Q_SIGNALS: 0033 void escapePressed(); 0034 void mouseEntered(); 0035 0036 private: 0037 bool m_disableUpdatesOnKeyPress; 0038 }; 0039 0040 /** class FocusWidgetFilter 0041 * @author Kelvie Wong 0042 * 0043 * A very simple event filter that returns when escape and return are pressed, 0044 * and as well, to emit a signal for the mouse event. 0045 * 0046 * This allows us to create our own focus model with widgets inside baskets 0047 * (although I'm not sure how useful this will all be after we port Basket to be 0048 * use QGraphicsView). 0049 * 0050 * Keypresses are filtered (i.e. the widget will not get the key press events), 0051 * but the enterEvent is not (for backwards compatibility). 0052 */ 0053 class FocusWidgetFilter : public QObject 0054 { 0055 Q_OBJECT 0056 public: 0057 /** Constructor 0058 * @param watched The widget to install the event filter on; also becomes 0059 * the parent of this object. */ 0060 explicit FocusWidgetFilter(QWidget *watched = nullptr); 0061 ~FocusWidgetFilter() override 0062 { 0063 } 0064 0065 protected: 0066 bool eventFilter(QObject *object, QEvent *event) override; 0067 0068 Q_SIGNALS: 0069 void escapePressed(); 0070 void returnPressed(); 0071 void mouseEntered(); 0072 }; 0073 0074 #endif // FOCUSEDWIDGETS_H