LeechCraft  0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
autoresizemixin.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Distributed under the Boost Software License, Version 1.0.
6  * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7  **********************************************************************/
8 
9 #include "autoresizemixin.h"
10 #include <QWidget>
11 #include <QWindow>
12 #include <QResizeEvent>
13 #include <util/gui/geometry.h>
14 
15 namespace LC::Util
16 {
17  AutoResizeMixin::AutoResizeMixin (const QPoint& point, RectGetter_f size, QWidget *view)
18  : QObject (view)
19  , OrigPoint_ (point)
20  , Mover_ ([view] (const QPoint& pos) { view->move (pos); })
21  , Rect_ (std::move (size))
22  {
23  view->installEventFilter (this);
24  Refit (view->size ());
25  }
26 
27  AutoResizeMixin::AutoResizeMixin (const QPoint& point, RectGetter_f size, QWindow *window)
28  : QObject (window)
29  , OrigPoint_ (point)
30  , Mover_ ([window] (const QPoint& pos) { window->setPosition (pos); })
31  , Rect_ (std::move (size))
32  {
33  window->installEventFilter (this);
34  Refit (window->size ());
35  }
36 
37  bool AutoResizeMixin::eventFilter (QObject*, QEvent *event)
38  {
39  if (event->type () != QEvent::Resize)
40  return false;
41 
42  auto re = static_cast<QResizeEvent*> (event);
43  Refit (re->size ());
44  return false;
45  }
46 
47  void AutoResizeMixin::Refit (const QSize& size)
48  {
49  Mover_ (FitRect (OrigPoint_, size, Rect_ (), Util::FitFlag::NoOverlap));
50  }
51 }
geometry.h
LC::Util
Definition: icoreproxy.h:33
LC::Util::NoOverlap
@ NoOverlap
Definition: geometry.h:37
LC::Util::AutoResizeMixin::AutoResizeMixin
UTIL_GUI_API AutoResizeMixin(const QPoint &point, RectGetter_f rect, QWidget *widget)
Constructs the resize mixin.
Definition: autoresizemixin.cpp:23
autoresizemixin.h
LC::Util::AutoResizeMixin::eventFilter
bool eventFilter(QObject *, QEvent *) override
Listens for resize events and refits the widget.
Definition: autoresizemixin.cpp:43
LC::Util::Resize
@ Resize
Definition: winflags.h:44
LC::Util::FitRect
QPoint FitRect(QPoint pos, const QSize &size, const QRect &geometry, FitFlags flags, const QPoint &shiftAdd)
Tries to fit a rectangle (like a dialog or popup) into geometry.
Definition: geometry.cpp:29