File indexing completed on 2025-02-16 13:11:49
0001 /* -*- C++ -*- 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 1997 Tim D. Gilman <tdgilman@best.org> 0004 SPDX-FileCopyrightText: 1998-2001 Mirko Boehm <mirko@kde.org> 0005 SPDX-FileCopyrightText: 2007 John Layt <john@layt.net> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #ifndef KPOPUPFRAME_H 0011 #define KPOPUPFRAME_H 0012 0013 #include <kwidgetsaddons_export.h> 0014 0015 #include <QFrame> 0016 #include <memory> 0017 0018 /** 0019 * @class KPopupFrame kpopupframe.h KPopupFrame 0020 * 0021 * Frame with popup menu behavior. 0022 * @author Tim Gilman, Mirko Boehm 0023 */ 0024 class KWIDGETSADDONS_EXPORT KPopupFrame : public QFrame 0025 { 0026 Q_OBJECT 0027 protected: 0028 /** 0029 * Catch key press events. 0030 */ 0031 void keyPressEvent(QKeyEvent *e) override; 0032 0033 /** 0034 * Catch hide events. 0035 */ 0036 void hideEvent(QHideEvent *e) override; 0037 0038 public Q_SLOTS: 0039 /** 0040 * Close the popup window. This is called from the main widget, usually. 0041 * 0042 * @param r is the result returned from exec() 0043 */ 0044 void close(int r); 0045 0046 public: 0047 /** 0048 * The constructor. Creates a dialog without buttons. 0049 */ 0050 KPopupFrame(QWidget *parent = nullptr); 0051 0052 /** 0053 * The destructor 0054 */ 0055 ~KPopupFrame() override; 0056 0057 /** 0058 * Set the main widget. You cannot set the main widget from the constructor, 0059 * since it must be a child of the frame itself. 0060 * Be careful: the size is set to the main widgets size. It is up to you to 0061 * set the main widgets correct size before setting it as the main 0062 * widget. 0063 */ 0064 void setMainWidget(QWidget *m); 0065 0066 /** 0067 * The resize event. Simply resizes the main widget to the whole 0068 * widgets client size. 0069 */ 0070 void resizeEvent(QResizeEvent *resize) override; 0071 0072 /** 0073 * Open the popup window at position pos. 0074 */ 0075 void popup(const QPoint &pos); 0076 0077 /** 0078 * Execute the popup window. 0079 */ 0080 int exec(const QPoint &p); 0081 0082 /** 0083 * Execute the popup window. 0084 */ 0085 int exec(int x, int y); 0086 0087 Q_SIGNALS: 0088 void leaveModality(); 0089 0090 private: 0091 friend class KPopupFramePrivate; 0092 std::unique_ptr<class KPopupFramePrivate> const d; 0093 0094 Q_DISABLE_COPY(KPopupFrame) 0095 }; 0096 0097 #endif // KPOPUPFRAME_H