MIRA
WidgetResizeHandler.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtGui module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** Commercial Usage
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
15 **
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
28 ** GNU General Public License Usage
29 ** Alternatively, this file may be used under the terms of the GNU
30 ** General Public License version 3.0 as published by the Free Software
31 ** Foundation and appearing in the file LICENSE.GPL included in the
32 ** packaging of this file. Please review the following information to
33 ** ensure the GNU General Public License version 3.0 requirements will be
34 ** met: http://www.gnu.org/copyleft/gpl.html.
35 **
36 ** If you have questions regarding the use of this file, please contact
37 ** Nokia at qt-info@nokia.com.
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
62 #ifndef _MIRA_WIDGETRESIZEHANDLER_H_
63 #define _MIRA_WIDGETRESIZEHANDLER_H_
64 
65 #include <QObject>
66 #include <QPoint>
67 
68 class QMouseEvent;
69 class QKeyEvent;
70 
71 namespace mira {
72 
74 
75 class WidgetResizeHandler : public QObject
76 {
77  Q_OBJECT
78 
79 public:
80  enum Action {
81  Move = 0x01,
82  Resize = 0x02,
84  };
85 
86  explicit WidgetResizeHandler(QWidget *parent, QWidget *cw = 0);
87  void setActive(bool b) { setActive(Any, b); }
88  void setActive(Action ac, bool b);
89  bool isActive() const { return isActive(Any); }
90  bool isActive(Action ac) const;
91  void setMovingEnabled(bool b) { movingEnabled = b; }
92  bool isMovingEnabled() const { return movingEnabled; }
93 
94  bool isButtonDown() const { return buttonDown; }
95 
96  void setExtraHeight(int h) { extrahei = h; }
97  void setSizeProtection(bool b) { sizeprotect = b; }
98 
99  void setFrameWidth(int w) { fw = w; }
100 
101  void doResize();
102  void doMove();
103 
104 Q_SIGNALS:
105  void activate();
106 
107 protected:
108  bool eventFilter(QObject *o, QEvent *e);
109  void mouseMoveEvent(QMouseEvent *e);
110  void keyPressEvent(QKeyEvent *e);
111 
112 private:
113  Q_DISABLE_COPY(WidgetResizeHandler)
114 
115  enum MousePosition {
116  Nowhere,
117  TopLeft, BottomRight, BottomLeft, TopRight,
118  Top, Bottom, Left, Right,
119  Center
120  };
121 
122  QWidget *widget;
123  QWidget *childWidget;
124  QPoint moveOffset;
125  QPoint invertedMoveOffset;
126  MousePosition mode;
127  int fw;
128  int extrahei;
129  int range;
130  uint buttonDown :1;
131  uint moveResizeMode :1;
132  uint activeForResize :1;
133  uint sizeprotect :1;
134  uint movingEnabled :1;
135  uint activeForMove :1;
136 
137  void setMouseCursor(MousePosition m);
138  bool isMove() const {
139  return moveResizeMode && mode == Center;
140  }
141  bool isResize() const {
142  return moveResizeMode && !isMove();
143  }
144 };
145 
147 
148 }
149 
150 #endif
Action
Definition: WidgetResizeHandler.h:80
bool isMovingEnabled() const
Definition: WidgetResizeHandler.h:92
bool isButtonDown() const
Definition: WidgetResizeHandler.h:94
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
void setSizeProtection(bool b)
Definition: WidgetResizeHandler.h:97
void setActive(bool b)
Definition: WidgetResizeHandler.h:87
void setExtraHeight(int h)
Definition: WidgetResizeHandler.h:96
Definition: WidgetResizeHandler.h:83
WidgetResizeHandler(QWidget *parent, QWidget *cw=0)
Definition: WidgetResizeHandler.h:75
bool isActive() const
Definition: WidgetResizeHandler.h:89
Definition: WidgetResizeHandler.h:81
void setMovingEnabled(bool b)
Definition: WidgetResizeHandler.h:91
Definition: WidgetResizeHandler.h:82
void setFrameWidth(int w)
Definition: WidgetResizeHandler.h:99
void keyPressEvent(QKeyEvent *e)
void mouseMoveEvent(QMouseEvent *e)
bool eventFilter(QObject *o, QEvent *e)