itom  3.0.0
basePopupWidget.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2016, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom and its software development toolkit (SDK).
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  In addition, as a special exception, the Institut fuer Technische
15  Optik (ITO) gives you certain additional rights.
16  These rights are described in the ITO LGPL Exception version 1.0,
17  which can be found in the file LGPL_EXCEPTION.txt in this package.
18 
19  itom is distributed in the hope that it will be useful, but
20  WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
22  General Public Licence for more details.
23 
24  You should have received a copy of the GNU Library General Public License
25  along with itom. If not, see <http://www.gnu.org/licenses/>.
26 
27  This file is a port and modified version of the
28  CTK Common Toolkit (http://www.commontk.org)
29 *********************************************************************** */
30 
31 #ifndef BASEPOPUPWIDGET_H
32 #define BASEPOPUPWIDGET_H
33 
34 // Qt includes
35 #include <QEasingCurve>
36 #include <QFrame>
37 #include <QMetaType>
38 
39 #include "commonWidgets.h"
40 
42 
45 class ITOMWIDGETS_EXPORT BasePopupWidget : public QFrame
46 {
47  Q_OBJECT
48 
49 #if QT_VERSION < 0x050500
50  //for >= Qt 5.5.0 see Q_ENUM definition below
51  Q_ENUMS(AnimationEffect)
52  Q_ENUMS(VerticalDirection)
53 #endif
54 
56  Q_PROPERTY( AnimationEffect animationEffect READ animationEffect WRITE setAnimationEffect)
57 
58 
59  Q_PROPERTY( int effectDuration READ effectDuration WRITE setEffectDuration);
61 
64  Q_PROPERTY( QEasingCurve::Type easingCurve READ easingCurve WRITE setEasingCurve);
65 
69  Q_PROPERTY( Qt::Alignment alignment READ alignment WRITE setAlignment);
70 
74  Q_PROPERTY( Qt::Orientations orientation READ orientation WRITE setOrientation);
75 
78  Q_PROPERTY( BasePopupWidget::VerticalDirection verticalDirection READ verticalDirection WRITE setVerticalDirection);
79 
82  Q_PROPERTY( Qt::LayoutDirection horizontalDirection READ horizontalDirection WRITE setHorizontalDirection);
83 
84 public:
85  typedef QFrame Superclass;
93  explicit BasePopupWidget(QWidget* parent = 0);
94  virtual ~BasePopupWidget();
95 
100  QWidget* baseWidget()const;
101 
102  enum AnimationEffect
103  {
104  WindowOpacityFadeEffect = 0,
105  ScrollEffect,
106  FadeEffect
107  };
108 
109  AnimationEffect animationEffect()const;
110  void setAnimationEffect(AnimationEffect effect);
111 
112  int effectDuration()const;
113  void setEffectDuration(int duration);
114 
115  QEasingCurve::Type easingCurve()const;
116  void setEasingCurve(QEasingCurve::Type easingCurve);
117 
118  Qt::Alignment alignment()const;
119  void setAlignment(Qt::Alignment alignment);
120 
121  Qt::Orientations orientation()const;
122  void setOrientation(Qt::Orientations orientation);
123 
124  enum VerticalDirection{
125  TopToBottom = 1,
126  BottomToTop = 2
127  };
128 
129 #if QT_VERSION >= 0x050500
130  //Q_ENUM exposes a meta object to the enumeration types, such that the key names for the enumeration
131  //values are always accessible.
132  Q_ENUM(AnimationEffect);
133  Q_ENUM(VerticalDirection);
134 #endif
135 
136  VerticalDirection verticalDirection()const;
137  void setVerticalDirection(VerticalDirection direction);
138 
139  Qt::LayoutDirection horizontalDirection()const;
140  void setHorizontalDirection(Qt::LayoutDirection direction);
141 
142 public Q_SLOTS:
145  virtual void hidePopup();
148  virtual void showPopup();
151  inline void showPopup(bool show);
152 
153 Q_SIGNALS:
154  void popupOpened(bool open);
155 
156 protected:
157  explicit BasePopupWidget(BasePopupWidgetPrivate* pimpl, QWidget* parent = 0);
158  QScopedPointer<BasePopupWidgetPrivate> d_ptr;
159  Q_PROPERTY(double effectAlpha READ effectAlpha WRITE setEffectAlpha DESIGNABLE false)
160  Q_PROPERTY(QRect effectGeometry READ effectGeometry WRITE setEffectGeometry DESIGNABLE false)
161 
162  double effectAlpha()const;
163  QRect effectGeometry()const;
164 
165  virtual void setBaseWidget(QWidget* baseWidget);
166 
167  virtual bool event(QEvent* event);
168  virtual void paintEvent(QPaintEvent*);
169 
170 protected Q_SLOTS:
171  virtual void onEffectFinished();
172  void setEffectAlpha(double alpha);
173  void setEffectGeometry(QRect geometry);
174  void onBaseWidgetDestroyed();
175 
176 private:
177  Q_DECLARE_PRIVATE(BasePopupWidget);
178  Q_DISABLE_COPY(BasePopupWidget);
179 };
180 
181 Q_DECLARE_METATYPE(BasePopupWidget::AnimationEffect)
182 Q_DECLARE_METATYPE(BasePopupWidget::VerticalDirection)
183 
184 // -------------------------------------------------------------------------
185 void BasePopupWidget::showPopup(bool show)
186 {
187  if (show)
188  {
189  this->showPopup();
190  }
191  else
192  {
193  this->hidePopup();
194  }
195 }
196 
197 #endif
Definition: basePopupWidget.h:45
Definition: basePopupWidget_p.h:44