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 #include <rcp/GuiRCPExports.h>
69 
70 class QMouseEvent;
71 class QKeyEvent;
72 
73 namespace mira {
74 
76 
78 {
79  Q_OBJECT
80 
81 public:
82  enum Action {
83  Move = 0x01,
84  Resize = 0x02,
85  Any = Move|Resize
86  };
87 
88  explicit WidgetResizeHandler(QWidget *parent, QWidget *cw = 0);
89  void setActive(bool b) { setActive(Any, b); }
90  void setActive(Action ac, bool b);
91  bool isActive() const { return isActive(Any); }
92  bool isActive(Action ac) const;
93  void setMovingEnabled(bool b) { movingEnabled = b; }
94  bool isMovingEnabled() const { return movingEnabled; }
95 
96  bool isButtonDown() const { return buttonDown; }
97 
98  void setExtraHeight(int h) { extrahei = h; }
99  void setSizeProtection(bool b) { sizeprotect = b; }
100 
101  void setFrameWidth(int w) { fw = w; }
102 
103  void doResize();
104  void doMove();
105 
106 Q_SIGNALS:
107  void activate();
108 
109 protected:
110  bool eventFilter(QObject *o, QEvent *e);
111  void mouseMoveEvent(QMouseEvent *e);
112  void keyPressEvent(QKeyEvent *e);
113 
114 private:
115  Q_DISABLE_COPY(WidgetResizeHandler)
116 
117  enum MousePosition {
118  Nowhere,
119  TopLeft, BottomRight, BottomLeft, TopRight,
120  Top, Bottom, Left, Right,
121  Center
122  };
123 
124  QWidget *widget;
125  QWidget *childWidget;
126  QPoint moveOffset;
127  QPoint invertedMoveOffset;
128  MousePosition mode;
129  int fw;
130  int extrahei;
131  int range;
132  uint buttonDown :1;
133  uint moveResizeMode :1;
134  uint activeForResize :1;
135  uint sizeprotect :1;
136  uint movingEnabled :1;
137  uint activeForMove :1;
138 
139  void setMouseCursor(MousePosition m);
140  bool isMove() const {
141  return moveResizeMode && mode == Center;
142  }
143  bool isResize() const {
144  return moveResizeMode && !isMove();
145  }
146 };
147 
149 
150 }
151 
152 #endif
Action
Definition: WidgetResizeHandler.h:82
bool isMovingEnabled() const
Definition: WidgetResizeHandler.h:94
bool isButtonDown() const
Definition: WidgetResizeHandler.h:96
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
void setSizeProtection(bool b)
Definition: WidgetResizeHandler.h:99
void setActive(bool b)
Definition: WidgetResizeHandler.h:89
void setExtraHeight(int h)
Definition: WidgetResizeHandler.h:98
Definition: WidgetResizeHandler.h:77
bool isActive() const
Definition: WidgetResizeHandler.h:91
void setMovingEnabled(bool b)
Definition: WidgetResizeHandler.h:93
Gui export macro declaration.
#define MIRA_GUI_RCP_EXPORT
Definition: GuiRCPExports.h:61
void setFrameWidth(int w)
Definition: WidgetResizeHandler.h:101