LeechCraft 0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
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
15namespace LC::Util
16{
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
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
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}
std::function< QRect()> RectGetter_f
A function type used to get the rect to fit widget in.
UTIL_GUI_API AutoResizeMixin(const QPoint &point, RectGetter_f rect, QWidget *widget)
Constructs the resize mixin.
bool eventFilter(QObject *, QEvent *) override
Listens for resize events and refits the widget.
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:23
@ NoOverlap
Definition geometry.h:37
Container< T > Filter(const Container< T > &c, F f)
Definition prelude.h:118