Qt 4.8
Public Types | Signals | Public Functions | Protected Functions | Private Types | Private Functions | Properties | List of all members
QWidgetResizeHandler Class Reference

#include <qwidgetresizehandler_p.h>

Inheritance diagram for QWidgetResizeHandler:
QObject

Public Types

enum  Action { Move = 0x01, Resize = 0x02, Any = Move|Resize }
 

Signals

void activate ()
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

void doMove ()
 
void doResize ()
 
bool isActive () const
 
bool isActive (Action ac) const
 
bool isButtonDown () const
 
bool isMovingEnabled () const
 
 QWidgetResizeHandler (QWidget *parent, QWidget *cw=0)
 
void setActive (bool b)
 
void setActive (Action ac, bool b)
 
void setExtraHeight (int h)
 
void setFrameWidth (int w)
 
void setMovingEnabled (bool b)
 
void setSizeProtection (bool b)
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Functions

bool eventFilter (QObject *o, QEvent *e)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
void keyPressEvent (QKeyEvent *e)
 
void mouseMoveEvent (QMouseEvent *e)
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Private Types

enum  MousePosition {
  Nowhere, TopLeft, BottomRight, BottomLeft,
  TopRight, Top, Bottom, Left,
  Right, Center
}
 

Private Functions

bool isMove () const
 
bool isResize () const
 
void setMouseCursor (MousePosition m)
 

Properties

uint activeForMove:1
 
uint activeForResize:1
 
uint buttonDown:1
 
QWidgetchildWidget
 
int extrahei
 
int fw
 
QPoint invertedMoveOffset
 
MousePosition mode
 
QPoint moveOffset
 
uint moveResizeMode:1
 
uint movingEnabled:1
 
int range
 
uint sizeprotect:1
 
QWidgetwidget
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 66 of file qwidgetresizehandler_p.h.

Enumerations

◆ Action

Enumerator
Move 
Resize 
Any 

Definition at line 71 of file qwidgetresizehandler_p.h.

◆ MousePosition

Constructors and Destructors

◆ QWidgetResizeHandler()

QWidgetResizeHandler::QWidgetResizeHandler ( QWidget parent,
QWidget cw = 0 
)
explicit

Definition at line 64 of file qwidgetresizehandler.cpp.

65  : QObject(parent), widget(parent), childWidget(cw ? cw : parent),
66  fw(0), extrahei(0), buttonDown(false), moveResizeMode(false), sizeprotect(true), movingEnabled(true)
67 {
68  mode = Nowhere;
69  widget->setMouseTracking(true);
70  QFrame *frame = qobject_cast<QFrame*>(widget);
71  range = frame ? frame->frameWidth() : RANGE;
72  range = qMax(RANGE, range);
75 }
T * qobject_cast(QObject *object)
Definition: qobject.h:375
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void setMouseTracking(bool enable)
Definition: qwidget.h:990
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
void installEventFilter(QObject *)
Installs an event filter filterObj on this object.
Definition: qobject.cpp:2070
#define RANGE
int frameWidth
the width of the frame that is drawn.
Definition: qframe.h:64
The QFrame class is the base class of widgets that can have a frame.
Definition: qframe.h:55

Functions

◆ activate

void QWidgetResizeHandler::activate ( )
signal

Referenced by eventFilter().

◆ doMove()

void QWidgetResizeHandler::doMove ( )

Definition at line 528 of file qwidgetresizehandler.cpp.

Referenced by QWorkspaceChild::doMove().

529 {
530  if (!activeForMove)
531  return;
532 
533  mode = Center;
534  moveResizeMode = true;
537 #ifndef QT_NO_CURSOR
539 #else
540  widget->grabMouse();
541 #endif
542  widget->grabKeyboard();
543 }
void grabMouse()
Grabs the mouse input.
QPoint bottomRight() const
Returns the position of the rectangle&#39;s bottom-right corner.
Definition: qrect.h:291
void grabKeyboard()
Grabs the keyboard input.
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310

◆ doResize()

void QWidgetResizeHandler::doResize ( )

Definition at line 498 of file qwidgetresizehandler.cpp.

Referenced by QWorkspaceChild::doResize().

499 {
500  if (!activeForResize)
501  return;
502 
503  moveResizeMode = true;
505  if (moveOffset.x() < widget->width()/2) {
506  if (moveOffset.y() < widget->height()/2)
507  mode = TopLeft;
508  else
509  mode = BottomLeft;
510  } else {
511  if (moveOffset.y() < widget->height()/2)
512  mode = TopRight;
513  else
514  mode = BottomRight;
515  }
517 #ifndef QT_NO_CURSOR
520 #else
521  widget->grabMouse();
522 #endif
523  widget->grabKeyboard();
526 }
void grabMouse()
Grabs the mouse input.
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
void setMouseCursor(MousePosition m)
QPoint bottomRight() const
Returns the position of the rectangle&#39;s bottom-right corner.
Definition: qrect.h:291
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
static bool resizeHorizontalDirectionFixed
QCursor cursor
the cursor shape for this widget
Definition: qwidget.h:183
void grabKeyboard()
Grabs the keyboard input.
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
static bool resizeVerticalDirectionFixed
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310

◆ eventFilter()

bool QWidgetResizeHandler::eventFilter ( QObject ,
QEvent  
)
protectedvirtual

Filters events if this object has been installed as an event filter for the watched object.

In your reimplementation of this function, if you want to filter the event out, i.e. stop it being handled further, return true; otherwise return false.

Example:

class MainWindow : public QMainWindow
{
public:
MainWindow();
protected:
bool eventFilter(QObject *obj, QEvent *ev);
private:
QTextEdit *textEdit;
};
MainWindow::MainWindow()
{
textEdit = new QTextEdit;
setCentralWidget(textEdit);
textEdit->installEventFilter(this);
}
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if (obj == textEdit) {
if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
qDebug() << "Ate key press" << keyEvent->key();
return true;
} else {
return false;
}
} else {
// pass the event on to the parent class
return QMainWindow::eventFilter(obj, event);
}
}

Notice in the example above that unhandled events are passed to the base class's eventFilter() function, since the base class might have reimplemented eventFilter() for its own internal purposes.

Warning
If you delete the receiver object in this function, be sure to return true. Otherwise, Qt will forward the event to the deleted object and the program might crash.
See also
installEventFilter()

Reimplemented from QObject.

Definition at line 97 of file qwidgetresizehandler.cpp.

98 {
99  if (!isActive()
100  || (ee->type() != QEvent::MouseButtonPress
101  && ee->type() != QEvent::MouseButtonRelease
102  && ee->type() != QEvent::MouseMove
103  && ee->type() != QEvent::KeyPress
104  && ee->type() != QEvent::ShortcutOverride)
105  )
106  return false;
107 
108  Q_ASSERT(o == widget);
109  QWidget *w = widget;
111  if (buttonDown && ee->type() == QEvent::MouseButtonRelease)
112  buttonDown = false;
113  return false;
114  }
115 
116  QMouseEvent *e = (QMouseEvent*)ee;
117  switch (e->type()) {
119  if (w->isMaximized())
120  break;
122  return false;
123  if (e->button() == Qt::LeftButton) {
124 #if defined(Q_WS_X11)
125  /*
126  Implicit grabs do not stop the X server from changing
127  the cursor in children, which looks *really* bad when
128  doing resizingk, so we grab the cursor. Note that we do
129  not do this on Windows since double clicks are lost due
130  to the grab (see change 198463).
131  */
132  if (e->spontaneous())
133 # if !defined(QT_NO_CURSOR)
135 # else
136  widget->grabMouse();
137 # endif // QT_NO_CURSOR
138 #endif // Q_WS_X11
139  buttonDown = false;
140  emit activate();
141  bool me = movingEnabled;
142  movingEnabled = (me && o == widget);
143  mouseMoveEvent(e);
144  movingEnabled = me;
145  buttonDown = true;
148  if (mode == Center) {
149  if (movingEnabled)
150  return true;
151  } else {
152  return true;
153  }
154  }
155  } break;
157  if (w->isMaximized())
158  break;
159  if (e->button() == Qt::LeftButton) {
160  moveResizeMode = false;
161  buttonDown = false;
162  widget->releaseMouse();
164  if (mode == Center) {
165  if (movingEnabled)
166  return true;
167  } else {
168  return true;
169  }
170  }
171  break;
172  case QEvent::MouseMove: {
173  if (w->isMaximized())
174  break;
175  buttonDown = buttonDown && (e->buttons() & Qt::LeftButton); // safety, state machine broken!
176  bool me = movingEnabled;
177  movingEnabled = (me && o == widget && (buttonDown || moveResizeMode));
178  mouseMoveEvent(e);
179  movingEnabled = me;
180  if (mode == Center) {
181  if (movingEnabled)
182  return true;
183  } else {
184  return true;
185  }
186  } break;
187  case QEvent::KeyPress:
189  break;
191  if (buttonDown) {
192  ((QKeyEvent*)ee)->accept();
193  return true;
194  }
195  break;
196  default:
197  break;
198  }
199 
200  return false;
201 }
The QKeyEvent class describes a key event.
Definition: qevent.h:224
void grabMouse()
Grabs the mouse input.
void keyPressEvent(QKeyEvent *e)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void mouseMoveEvent(QMouseEvent *e)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QPoint bottomRight() const
Returns the position of the rectangle&#39;s bottom-right corner.
Definition: qrect.h:291
void releaseMouse()
Releases the mouse grab.
#define emit
Definition: qobjectdefs.h:76
bool spontaneous() const
Returns true if the event originated outside the application (a system event); otherwise returns fals...
Definition: qcoreevent.h:304
#define QT_NO_CURSOR
QCursor cursor
the cursor shape for this widget
Definition: qwidget.h:183
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
bool isMaximized() const
Definition: qwidget.cpp:3074
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
static QWidget * activePopupWidget()
Returns the active popup widget.
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition: qevent.h:102
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
void releaseKeyboard()
Releases the keyboard grab.
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
const QPoint & globalPos() const
Returns the global position of the mouse cursor at the time of the event.
Definition: qevent.h:96

◆ isActive() [1/2]

bool QWidgetResizeHandler::isActive ( ) const
inline

◆ isActive() [2/2]

bool QWidgetResizeHandler::isActive ( Action  ac) const

Definition at line 88 of file qwidgetresizehandler.cpp.

89 {
90  bool b = false;
91  if (ac & Move) b = activeForMove;
92  if (ac & Resize) b |= activeForResize;
93 
94  return b;
95 }

◆ isButtonDown()

bool QWidgetResizeHandler::isButtonDown ( ) const
inline

Definition at line 85 of file qwidgetresizehandler_p.h.

Referenced by QWorkspaceChild::leaveEvent().

◆ isMove()

bool QWidgetResizeHandler::isMove ( ) const
inlineprivate

Definition at line 129 of file qwidgetresizehandler_p.h.

Referenced by keyPressEvent().

◆ isMovingEnabled()

bool QWidgetResizeHandler::isMovingEnabled ( ) const
inline

Definition at line 83 of file qwidgetresizehandler_p.h.

◆ isResize()

bool QWidgetResizeHandler::isResize ( ) const
inlineprivate

Definition at line 132 of file qwidgetresizehandler_p.h.

Referenced by keyPressEvent().

132  {
133  return moveResizeMode && !isMove();
134  }

◆ keyPressEvent()

void QWidgetResizeHandler::keyPressEvent ( QKeyEvent e)
protected

Definition at line 374 of file qwidgetresizehandler.cpp.

Referenced by eventFilter().

375 {
376  if (!isMove() && !isResize())
377  return;
378  bool is_control = e->modifiers() & Qt::ControlModifier;
379  int delta = is_control?1:8;
380  QPoint pos = QCursor::pos();
381  switch (e->key()) {
382  case Qt::Key_Left:
383  pos.rx() -= delta;
384  if (pos.x() <= QApplication::desktop()->geometry().left()) {
385  if (mode == TopLeft || mode == BottomLeft) {
386  moveOffset.rx() += delta;
387  invertedMoveOffset.rx() += delta;
388  } else {
389  moveOffset.rx() -= delta;
390  invertedMoveOffset.rx() -= delta;
391  }
392  }
395  if (mode == BottomRight)
396  mode = BottomLeft;
397  else if (mode == TopRight)
398  mode = TopLeft;
399 #ifndef QT_NO_CURSOR
402 #else
403  widget->grabMouse();
404 #endif
405  }
406  break;
407  case Qt::Key_Right:
408  pos.rx() += delta;
409  if (pos.x() >= QApplication::desktop()->geometry().right()) {
410  if (mode == TopRight || mode == BottomRight) {
411  moveOffset.rx() += delta;
412  invertedMoveOffset.rx() += delta;
413  } else {
414  moveOffset.rx() -= delta;
415  invertedMoveOffset.rx() -= delta;
416  }
417  }
420  if (mode == BottomLeft)
421  mode = BottomRight;
422  else if (mode == TopLeft)
423  mode = TopRight;
424 #ifndef QT_NO_CURSOR
427 #else
428  widget->grabMouse();
429 #endif
430  }
431  break;
432  case Qt::Key_Up:
433  pos.ry() -= delta;
434  if (pos.y() <= QApplication::desktop()->geometry().top()) {
435  if (mode == TopLeft || mode == TopRight) {
436  moveOffset.ry() += delta;
437  invertedMoveOffset.ry() += delta;
438  } else {
439  moveOffset.ry() -= delta;
440  invertedMoveOffset.ry() -= delta;
441  }
442  }
445  if (mode == BottomLeft)
446  mode = TopLeft;
447  else if (mode == BottomRight)
448  mode = TopRight;
449 #ifndef QT_NO_CURSOR
452 #else
453  widget->grabMouse();
454 #endif
455  }
456  break;
457  case Qt::Key_Down:
458  pos.ry() += delta;
459  if (pos.y() >= QApplication::desktop()->geometry().bottom()) {
460  if (mode == BottomLeft || mode == BottomRight) {
461  moveOffset.ry() += delta;
462  invertedMoveOffset.ry() += delta;
463  } else {
464  moveOffset.ry() -= delta;
465  invertedMoveOffset.ry() -= delta;
466  }
467  }
470  if (mode == TopLeft)
471  mode = BottomLeft;
472  else if (mode == TopRight)
473  mode = BottomRight;
474 #ifndef QT_NO_CURSOR
477 #else
478  widget->grabMouse();
479 #endif
480  }
481  break;
482  case Qt::Key_Space:
483  case Qt::Key_Return:
484  case Qt::Key_Enter:
485  case Qt::Key_Escape:
486  moveResizeMode = false;
487  widget->releaseMouse();
489  buttonDown = false;
490  break;
491  default:
492  return;
493  }
494  QCursor::setPos(pos);
495 }
void grabMouse()
Grabs the mouse input.
void setMouseCursor(MousePosition m)
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int & ry()
Returns a reference to the y coordinate of this point.
Definition: qpoint.h:143
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
static void setPos(int x, int y)
Moves the cursor (hot spot) to the global screen position (x, y).
Definition: qcursor_mac.mm:315
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition: qevent.cpp:999
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
void releaseMouse()
Releases the mouse grab.
static bool resizeHorizontalDirectionFixed
int & rx()
Returns a reference to the x coordinate of this point.
Definition: qpoint.h:140
QCursor cursor
the cursor shape for this widget
Definition: qwidget.h:183
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
static bool resizeVerticalDirectionFixed
void releaseKeyboard()
Releases the keyboard grab.
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
const QRect & geometry() const
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310

◆ mouseMoveEvent()

void QWidgetResizeHandler::mouseMoveEvent ( QMouseEvent e)
protected

Definition at line 203 of file qwidgetresizehandler.cpp.

Referenced by eventFilter().

204 {
205  QPoint pos = widget->mapFromGlobal(e->globalPos());
206  if (!moveResizeMode && !buttonDown) {
207  if (pos.y() <= range && pos.x() <= range)
208  mode = TopLeft;
209  else if (pos.y() >= widget->height()-range && pos.x() >= widget->width()-range)
210  mode = BottomRight;
211  else if (pos.y() >= widget->height()-range && pos.x() <= range)
212  mode = BottomLeft;
213  else if (pos.y() <= range && pos.x() >= widget->width()-range)
214  mode = TopRight;
215  else if (pos.y() <= range)
216  mode = Top;
217  else if (pos.y() >= widget->height()-range)
218  mode = Bottom;
219  else if (pos.x() <= range)
220  mode = Left;
221  else if ( pos.x() >= widget->width()-range)
222  mode = Right;
223  else if (widget->rect().contains(pos))
224  mode = Center;
225  else
226  mode = Nowhere;
227 
228  if (widget->isMinimized() || !isActive(Resize))
229  mode = Center;
230 #ifndef QT_NO_CURSOR
232 #endif
233  return;
234  }
235 
236  if (mode == Center && !movingEnabled)
237  return;
238 
240  return;
241 
242 
243  QPoint globalPos = (!widget->isWindow() && widget->parentWidget()) ?
245  if (!widget->isWindow() && !widget->parentWidget()->rect().contains(globalPos)) {
246  if (globalPos.x() < 0)
247  globalPos.rx() = 0;
248  if (globalPos.y() < 0)
249  globalPos.ry() = 0;
250  if (sizeprotect && globalPos.x() > widget->parentWidget()->width())
251  globalPos.rx() = widget->parentWidget()->width();
252  if (sizeprotect && globalPos.y() > widget->parentWidget()->height())
253  globalPos.ry() = widget->parentWidget()->height();
254  }
255 
256  QPoint p = globalPos + invertedMoveOffset;
257  QPoint pp = globalPos - moveOffset;
258 
259 #ifdef Q_WS_X11
260  // Workaround for window managers which refuse to move a tool window partially offscreen.
262  pp.rx() = qMax(pp.x(), desktop.left());
263  pp.ry() = qMax(pp.y(), desktop.top());
264  p.rx() = qMin(p.x(), desktop.right());
265  p.ry() = qMin(p.y(), desktop.bottom());
266 #endif
267 
269  int mw = ms.width();
270  int mh = ms.height();
271  if (childWidget != widget) {
272  mw += 2 * fw;
273  mh += 2 * fw + extrahei;
274  }
275 
276  QSize maxsize(childWidget->maximumSize());
277  if (childWidget != widget)
278  maxsize += QSize(2 * fw, 2 * fw + extrahei);
279  QSize mpsize(widget->geometry().right() - pp.x() + 1,
280  widget->geometry().bottom() - pp.y() + 1);
281  mpsize = mpsize.expandedTo(widget->minimumSize()).expandedTo(QSize(mw, mh))
282  .boundedTo(maxsize);
283  QPoint mp(widget->geometry().right() - mpsize.width() + 1,
284  widget->geometry().bottom() - mpsize.height() + 1);
285 
286  QRect geom = widget->geometry();
287 
288  switch (mode) {
289  case TopLeft:
290  geom = QRect(mp, widget->geometry().bottomRight()) ;
291  break;
292  case BottomRight:
293  geom = QRect(widget->geometry().topLeft(), p) ;
294  break;
295  case BottomLeft:
296  geom = QRect(QPoint(mp.x(), widget->geometry().y()), QPoint(widget->geometry().right(), p.y())) ;
297  break;
298  case TopRight:
299  geom = QRect(QPoint(widget->geometry().x(), mp.y()), QPoint(p.x(), widget->geometry().bottom())) ;
300  break;
301  case Top:
302  geom = QRect(QPoint(widget->geometry().left(), mp.y()), widget->geometry().bottomRight()) ;
303  break;
304  case Bottom:
305  geom = QRect(widget->geometry().topLeft(), QPoint(widget->geometry().right(), p.y())) ;
306  break;
307  case Left:
308  geom = QRect(QPoint(mp.x(), widget->geometry().top()), widget->geometry().bottomRight()) ;
309  break;
310  case Right:
311  geom = QRect(widget->geometry().topLeft(), QPoint(p.x(), widget->geometry().bottom())) ;
312  break;
313  case Center:
314  geom.moveTopLeft(pp);
315  break;
316  default:
317  break;
318  }
319 
320  geom = QRect(geom.topLeft(),
321  geom.size().expandedTo(widget->minimumSize())
322  .expandedTo(QSize(mw, mh))
323  .boundedTo(maxsize));
324 
325  if (geom != widget->geometry() &&
326  (widget->isWindow() || widget->parentWidget()->rect().intersects(geom))) {
327  if (mode == Center)
328  widget->move(geom.topLeft());
329  else
330  widget->setGeometry(geom);
331  }
332 
334 }
QSize maximumSize
the widget&#39;s maximum size in pixels
Definition: qwidget.h:173
QSize minimumSize
the widget&#39;s minimum size
Definition: qwidget.h:172
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
Q_GUI_EXPORT QSize qSmartMinSize(const QSize &sizeHint, const QSize &minSizeHint, const QSize &minSize, const QSize &maxSize, const QSizePolicy &sizePolicy)
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
void setMouseCursor(MousePosition m)
QSize expandedTo(const QSize &) const
Returns a size holding the maximum width and height of this size and the given otherSize.
Definition: qsize.h:187
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int & ry()
Returns a reference to the y coordinate of this point.
Definition: qpoint.h:143
void setGeometry(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qwidget.h:1017
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QPoint bottomRight() const
Returns the position of the rectangle&#39;s bottom-right corner.
Definition: qrect.h:291
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
int & rx()
Returns a reference to the x coordinate of this point.
Definition: qpoint.h:140
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
static void syncX()
Synchronizes with the X server in the X11 implementation.
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
bool isMinimized() const
Definition: qwidget.cpp:3027
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
bool intersects(const QRect &r) const
Returns true if this rectangle intersects with the given rectangle (i.
Definition: qrect.cpp:1429
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
const QRect availableGeometry(int screen=-1) const
const QPoint & globalPos() const
Returns the global position of the mouse cursor at the time of the event.
Definition: qevent.h:96
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition: qwidget.h:158
void move(int x, int y)
This corresponds to move(QPoint(x, y)).
Definition: qwidget.h:1011
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288

◆ setActive() [1/2]

void QWidgetResizeHandler::setActive ( bool  b)
inline

◆ setActive() [2/2]

void QWidgetResizeHandler::setActive ( Action  ac,
bool  b 
)

◆ setExtraHeight()

void QWidgetResizeHandler::setExtraHeight ( int  h)
inline

Definition at line 87 of file qwidgetresizehandler_p.h.

Referenced by QWorkspaceChild::QWorkspaceChild().

◆ setFrameWidth()

void QWidgetResizeHandler::setFrameWidth ( int  w)
inline

Definition at line 90 of file qwidgetresizehandler_p.h.

Referenced by QWorkspaceChild::QWorkspaceChild().

◆ setMouseCursor()

void QWidgetResizeHandler::setMouseCursor ( MousePosition  m)
private

Definition at line 336 of file qwidgetresizehandler.cpp.

Referenced by doResize(), keyPressEvent(), mouseMoveEvent(), and setActive().

337 {
338 #ifdef QT_NO_CURSOR
339  Q_UNUSED(m);
340 #else
342  for (int i = 0; i < children.size(); ++i) {
343  if (QWidget *w = qobject_cast<QWidget*>(children.at(i))) {
344  if (!w->testAttribute(Qt::WA_SetCursor) && !w->inherits("QWorkspaceTitleBar")) {
345  w->setCursor(Qt::ArrowCursor);
346  }
347  }
348  }
349 
350  switch (m) {
351  case TopLeft:
352  case BottomRight:
354  break;
355  case BottomLeft:
356  case TopRight:
358  break;
359  case Top:
360  case Bottom:
362  break;
363  case Left:
364  case Right:
366  break;
367  default:
369  break;
370  }
371 #endif // QT_NO_CURSOR
372 }
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void setCursor(const QCursor &)
Definition: qwidget.cpp:5290
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
const QObjectList & children() const
Returns a list of child objects.
Definition: qobject.h:197
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ setMovingEnabled()

void QWidgetResizeHandler::setMovingEnabled ( bool  b)
inline

Definition at line 82 of file qwidgetresizehandler_p.h.

◆ setSizeProtection()

void QWidgetResizeHandler::setSizeProtection ( bool  b)
inline

Properties

◆ activeForMove

uint QWidgetResizeHandler::activeForMove
private

Definition at line 126 of file qwidgetresizehandler_p.h.

Referenced by doMove(), isActive(), QWidgetResizeHandler(), and setActive().

◆ activeForResize

uint QWidgetResizeHandler::activeForResize
private

Definition at line 123 of file qwidgetresizehandler_p.h.

Referenced by doResize(), isActive(), QWidgetResizeHandler(), and setActive().

◆ buttonDown

uint QWidgetResizeHandler::buttonDown
private

Definition at line 121 of file qwidgetresizehandler_p.h.

Referenced by eventFilter(), keyPressEvent(), and mouseMoveEvent().

◆ childWidget

QWidget* QWidgetResizeHandler::childWidget
private

Definition at line 114 of file qwidgetresizehandler_p.h.

Referenced by mouseMoveEvent().

◆ extrahei

int QWidgetResizeHandler::extrahei
private

Definition at line 119 of file qwidgetresizehandler_p.h.

Referenced by mouseMoveEvent().

◆ fw

int QWidgetResizeHandler::fw
private

Definition at line 118 of file qwidgetresizehandler_p.h.

Referenced by mouseMoveEvent().

◆ invertedMoveOffset

QPoint QWidgetResizeHandler::invertedMoveOffset
private

◆ mode

MousePosition QWidgetResizeHandler::mode
private

◆ moveOffset

QPoint QWidgetResizeHandler::moveOffset
private

◆ moveResizeMode

uint QWidgetResizeHandler::moveResizeMode
private

◆ movingEnabled

uint QWidgetResizeHandler::movingEnabled
private

Definition at line 125 of file qwidgetresizehandler_p.h.

Referenced by eventFilter(), and mouseMoveEvent().

◆ range

int QWidgetResizeHandler::range
private

Definition at line 120 of file qwidgetresizehandler_p.h.

Referenced by mouseMoveEvent(), and QWidgetResizeHandler().

◆ sizeprotect

uint QWidgetResizeHandler::sizeprotect
private

Definition at line 124 of file qwidgetresizehandler_p.h.

Referenced by mouseMoveEvent().

◆ widget

QWidget* QWidgetResizeHandler::widget
private

The documentation for this class was generated from the following files: