LeechCraft  0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
LC::Util::AutoResizeMixin Class Reference

Automatically moves a widget to fit a rectangle on resize. More...

#include "autoresizemixin.h"

+ Inheritance diagram for LC::Util::AutoResizeMixin:
+ Collaboration diagram for LC::Util::AutoResizeMixin:

Public Types

using RectGetter_f = std::function< QRect()>
 A function type used to get the rect to fit widget in. More...
 

Public Member Functions

UTIL_GUI_API AutoResizeMixin (const QPoint &point, RectGetter_f rect, QWidget *widget)
 Constructs the resize mixin. More...
 
UTIL_GUI_API AutoResizeMixin (const QPoint &point, RectGetter_f rect, QWindow *window)
 Constructs the resize mixin. More...
 
bool eventFilter (QObject *, QEvent *) override
 Listens for resize events and refits the widget. More...
 

Detailed Description

Automatically moves a widget to fit a rectangle on resize.

An instance of this class manages a single widget and moves it automatically after the widget has been resized, so that it stays inside the given rectangle. The autoresize mixin never tries to resize the widget itself (despite the name perhaps).

This class also tries to keep a corner of the managed widget near a given point passed to the constructor. This is useful when the widget pops up in response to some mouse-initiated action so that it appears near the mouse cursor.

Most commonly this function is used to keep various popup widgets on screen, but it can also be used to prefer showing some popup inside the LeechCraft window, for example.

The rectangle into which the widget should be embedded is obtained via a functor returning the rectangle. The functor is invoked each time the widget is to be refit.

This class also supports Qt5's QWindow objects.

Definition at line 46 of file autoresizemixin.h.

Member Typedef Documentation

◆ RectGetter_f

using LC::Util::AutoResizeMixin::RectGetter_f = std::function<QRect ()>

A function type used to get the rect to fit widget in.

Definition at line 54 of file autoresizemixin.h.

Constructor & Destructor Documentation

◆ AutoResizeMixin() [1/2]

LC::Util::AutoResizeMixin::AutoResizeMixin ( const QPoint &  point,
RectGetter_f  rect,
QWidget *  widget 
)

Constructs the resize mixin.

This function constructs the resize mixin managing the given widget, trying to fit it inside the rect, preferably with a corner of the widget sticking near the point.

Parameters
[in]pointThe point near which the widget should be shown.
[in]rectThe functor returning the rectangle into which the widget should be fitted.
[in]widgetThe widget to fit.

Definition at line 23 of file autoresizemixin.cpp.

◆ AutoResizeMixin() [2/2]

LC::Util::AutoResizeMixin::AutoResizeMixin ( const QPoint &  point,
RectGetter_f  rect,
QWindow *  window 
)

Constructs the resize mixin.

This function constructs the resize mixin managing the given window, trying to fit it inside the rect, preferably with a corner of the window sticking near the point.

Parameters
[in]pointThe point near which the window should be shown.
[in]rectThe functor returning the rectangle into which the window should be fitted.
[in]windowThe widget to fit.

Definition at line 33 of file autoresizemixin.cpp.

Member Function Documentation

◆ eventFilter()

bool LC::Util::AutoResizeMixin::eventFilter ( QObject *  ,
QEvent *  event 
)
override

Listens for resize events and refits the widget.

Definition at line 43 of file autoresizemixin.cpp.


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