File indexing completed on 2025-01-05 03:51:07

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 1997-04-21
0007  * Description : Frame with popup menu behavior.
0008  *
0009  * SPDX-FileCopyrightText: 2011-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 1997      by Tim D. Gilman <tdgilman at best dot org>
0011  * SPDX-FileCopyrightText: 1998-2001 by Mirko Boehm <mirko at kde dot org>
0012  * SPDX-FileCopyrightText: 2007      by John Layt <john at layt dot net>
0013  *
0014  * SPDX-License-Identifier: GPL-2.0-or-later
0015  *
0016  * ============================================================ */
0017 
0018 #ifndef DIGIKAM_DPOP_UP_FRAME_H
0019 #define DIGIKAM_DPOP_UP_FRAME_H
0020 
0021 // Qt includes
0022 
0023 #include <QFrame>
0024 
0025 namespace Digikam
0026 {
0027 
0028 class DPopupFrame : public QFrame
0029 {
0030     Q_OBJECT
0031 
0032 public:
0033 
0034     /**
0035      * The constructor. Creates a dialog without buttons.
0036      */
0037     explicit DPopupFrame(QWidget* const parent = nullptr);
0038 
0039     /**
0040      * The destructor
0041      */
0042     ~DPopupFrame() override;
0043 
0044     /**
0045      * Set the main widget. You cannot set the main widget from the constructor,
0046      * since it must be a child of the frame itselfes.
0047      * Be careful: the size is set to the main widgets size. It is up to you to
0048      * set the main widgets correct size before setting it as the main
0049      * widget.
0050      */
0051     void setMainWidget(QWidget* const m);
0052 
0053     /**
0054      * The resize event. Simply resizes the main widget to the whole
0055      * widgets client size.
0056      */
0057     void resizeEvent(QResizeEvent* e) override;
0058 
0059     /**
0060      * Open the popup window at position pos.
0061      */
0062     void popup(const QPoint& p);
0063 
0064     /**
0065      * Execute the popup window.
0066      */
0067     int exec(const QPoint& p);
0068 
0069     /**
0070      * Execute the popup window.
0071      */
0072     int exec(int x, int y);
0073 
0074 Q_SIGNALS:
0075 
0076     void leaveModality();
0077 
0078 protected:
0079 
0080     /**
0081      * Catch key press events.
0082      */
0083     void keyPressEvent(QKeyEvent* e) override;
0084 
0085     /**
0086      * Catch hide events.
0087      */
0088     void hideEvent(QHideEvent* e)    override;
0089 
0090 public Q_SLOTS:
0091 
0092     /**
0093      * Close the popup window. This is called from the main widget, usually.
0094      * @p r is the result returned from exec().
0095      */
0096     void close(int r);
0097 
0098 private:
0099 
0100     class Private;
0101     Private* const d;
0102 
0103     friend class Private;
0104 
0105     Q_DISABLE_COPY(DPopupFrame)
0106 };
0107 
0108 } // namespace Digikam
0109 
0110 #endif // DIGIKAM_DPOP_UP_FRAME_H