35 #include <QApplication> 38 #include <QMouseEvent> 39 #include <QResizeEvent> 40 #include <QTimerEvent> 61 target_->removeEventFilter(
this);
69 target_->removeEventFilter(
this);
76 target_->installEventFilter(
this);
82 return rect_.toRect();
104 QApplication::restoreOverrideCursor();
124 switch (event->type())
126 case QEvent::MouseButtonPress:
128 case QEvent::MouseButtonRelease:
130 case QEvent::MouseMove:
146 if (!
rect_.contains(event->pos()))
160 if (event->button() == Qt::LeftButton)
165 qWarning(
"changing state to %d",
state_);
187 if (event->button() == Qt::LeftButton)
205 if (!
rect_.contains(event->localPos()))
209 QApplication::restoreOverrideCursor();
218 Qt::CursorShape shape;
223 shape = Qt::SizeFDiagCursor;
227 shape = Qt::SizeBDiagCursor;
230 shape = Qt::SizeAllCursor;
235 QApplication::changeOverrideCursor(QCursor(shape));
239 QApplication::setOverrideCursor(QCursor(shape));
287 qWarning(
"Unhandled state in PlaceableWindowProxy: %d",
state_);
296 const QPointF &p3)
const 298 QPointF v1 = p2 - p1;
299 QPointF v2 = p3 - p1;
301 double d = v1.x()*v2.y() - v1.y()*v2.x();
304 double new_width = std::abs(p3.x() - p1.x());
310 double new_height = rect.height() / rect.width() * new_width;
311 return QRectF(0, 0, new_width, new_height);
315 double new_height = std::abs(p3.y() - p1.y());
321 double new_width = rect.width() / rect.height() * new_height;
322 return QRectF(0, 0, new_width, new_height);
363 const QPointF &pt)
const 365 if (!
rect_.contains(pt))
370 const double threshold = 10.0;
371 double near_left = pt.x() -
rect_.left() < threshold;
372 double near_top = pt.y() -
rect_.top() < threshold;
373 double near_right =
rect_.right() - pt.x() < threshold;
374 double near_bottom =
rect_.bottom() - pt.y() < threshold;
376 if (near_top && near_left)
380 else if (near_top && near_right)
384 else if (near_bottom && near_left)
388 else if (near_bottom && near_right)
void setContainer(QWidget *)
void setRect(const QRect &)
void winResize(const QSize &)
bool handleMouseRelease(QMouseEvent *)
bool eventFilter(QObject *object, QEvent *event)
State getNextState(const QPointF &pt) const
bool handleMousePress(QMouseEvent *)
void rectResize(int dx, int dy)
bool handleResize(QResizeEvent *)
bool handleMouseMove(QMouseEvent *)
void timerEvent(QTimerEvent *)
void setVisible(bool visible)
QRectF resizeHelper(const QRectF &rect, const QPointF &p1, const QPointF &p2, const QPointF &p3) const