Seamly2D
Code documentation
vwidgetpopup.h
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * Copyright (C) 2017 Seamly, LLC *
4  * *
5  * https://github.com/fashionfreedom/seamly2d *
6  * *
7  ***************************************************************************
8  **
9  ** Seamly2D is free software: you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation, either version 3 of the License, or
12  ** (at your option) any later version.
13  **
14  ** Seamly2D is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** You should have received a copy of the GNU General Public License
20  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
21  **
22  **************************************************************************
23 
24  ************************************************************************
25  **
26  ** @file vwidgetpopup.h
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 16 2, 2015
29  **
30  ** @brief
31  ** @copyright
32  ** This source code is part of the Valentine project, a pattern making
33  ** program, whose allow create and modeling patterns of clothing.
34  ** Copyright (C) 2013-2015 Seamly2D project
35  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
36  **
37  ** Seamly2D is free software: you can redistribute it and/or modify
38  ** it under the terms of the GNU General Public License as published by
39  ** the Free Software Foundation, either version 3 of the License, or
40  ** (at your option) any later version.
41  **
42  ** Seamly2D is distributed in the hope that it will be useful,
43  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
44  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  ** GNU General Public License for more details.
46  **
47  ** You should have received a copy of the GNU General Public License
48  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
49  **
50  *************************************************************************/
51 
52 #ifndef VWIDGETPOPUP_H
53 #define VWIDGETPOPUP_H
54 
55 #include <QFrame>
56 #include <QMetaObject>
57 #include <QObject>
58 #include <QString>
59 #include <QtGlobal>
60 
61 /**
62  \brief Class showing a widget as popup window.
63 
64  setWidget() function allows you to specify the widget to be popped up.
65  After widget is set, you normally should call show() slot in order to pop the
66  widget up at the specified global position.
67 
68  VWidgetPopup takes care about positioning of your widget on the screen so it will
69  be always visible even if popped beside.
70 */
71 class VWidgetPopup : public QFrame
72 {
73  Q_OBJECT
74 
75 public:
76  /** Constructor.
77 
78  If \a parent not specified (default), then popup widget gets
79  attribute Qt::WA_DeleteOnClose and will be deleted after close.
80  */
81  explicit VWidgetPopup(QWidget *parent = nullptr);
82 
83  /** Sets widget to be popped up to \a widget.
84  If \a own is true then the widget will be reparented to the popup widget.
85  */
86  void SetWidget(QWidget *widget, bool own = true);
87 
88  /** Returns widget to be popped up. */
89  QWidget* Widget() const;
90 
91  /** Returns true if widget is owned by this popup widget, false otherwise. */
92  bool isOwned() const;
93 
94  int GetLifeTime() const;
95  void SetLifeTime(int value);
96 
97  static void PopupMessage(QWidget *w, const QString &msg);
98 
99 public slots:
100  /** Pops up the widget at global coordinates \a coord. */
101  void Show(QPoint coord);
102 
103 protected:
104  Q_DISABLE_COPY(VWidgetPopup)
105  QWidget *mWidget;
106  bool mOwn;
107  QWidget *mOldParent;
108  int lifeTime;
109 };
110 
111 //---------------------------------------------------------------------------------------------------------------------
112 inline QWidget *VWidgetPopup::Widget() const
113 {
114  return mWidget;
115 }
116 
117 //---------------------------------------------------------------------------------------------------------------------
118 inline bool VWidgetPopup::isOwned() const
119 {
120  return mOwn;
121 }
122 
123 //---------------------------------------------------------------------------------------------------------------------
124 inline int VWidgetPopup::GetLifeTime() const
125 {
126  return lifeTime;
127 }
128 
129 //---------------------------------------------------------------------------------------------------------------------
130 inline void VWidgetPopup::SetLifeTime(int value)
131 {
132  lifeTime = value;
133 }
134 
135 #endif // VWIDGETPOPUP_H
Class showing a widget as popup window.
Definition: vwidgetpopup.h:72
int GetLifeTime() const
Definition: vwidgetpopup.h:124
static void PopupMessage(QWidget *w, const QString &msg)
QWidget * mOldParent
Definition: vwidgetpopup.h:107
void SetWidget(QWidget *widget, bool own=true)
QWidget * Widget() const
Definition: vwidgetpopup.h:112
void Show(QPoint coord)
bool isOwned() const
Definition: vwidgetpopup.h:118
VWidgetPopup(QWidget *parent=nullptr)
void SetLifeTime(int value)
Definition: vwidgetpopup.h:130
QWidget * mWidget
Definition: vwidgetpopup.h:105