LeechCraft
0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
Toggle main menu visibility
Loading...
Searching...
No Matches
fontsizescrollchanger.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 "
fontsizescrollchanger.h
"
10
#include <QWidget>
11
#include <QWheelEvent>
12
#include <
util/sll/lambdaeventfilter.h
>
13
#include <
util/sll/visitor.h
>
14
15
namespace
LC::Util
16
{
17
namespace
18
{
19
auto
AddSteps (
int
size,
int
steps)
20
{
21
constexpr
auto
minFontSize = 6;
22
return
std::max (minFontSize, size + steps);
23
}
24
25
auto
AddSteps (QFont font,
int
steps)
26
{
27
if
(
const
auto
pts = font.pointSize (); pts > 0)
28
font.setPointSize (AddSteps (pts, steps));
29
else
if
(
const
auto
pxs = font.pixelSize (); pxs > 0)
30
font.setPixelSize (AddSteps (pxs, steps));
31
return
font;
32
}
33
}
34
35
void
InstallFontSizeChanger
(QWidget& widget,
const
FontSizeChangerParams
& params)
36
{
37
widget.installEventFilter (
Util::MakeLambdaEventFilter<QEvent::Wheel>
([params] (QWheelEvent *e)
38
{
39
if
(!(e->modifiers () & Qt::ControlModifier))
40
return
false
;
41
42
constexpr
qreal degreesPerDelta = 1 / 8.;
43
constexpr
qreal degreesPerStep = 15.;
44
45
auto
degrees = e->angleDelta ().y () * degreesPerDelta;
46
int
steps =
static_cast<
int
>
(degrees / degreesPerStep);
47
48
Visit
(params,
49
[=] (
const
auto
& methods)
50
{
51
const
auto
newFont = AddSteps (methods.GetView_ (), steps);
52
methods.SetView_ (newFont);
53
if
(e->modifiers () & Qt::ShiftModifier)
54
methods.SetDefault_ (newFont);
55
});
56
57
return
true
;
58
},
59
widget));
60
}
61
}
fontsizescrollchanger.h
lambdaeventfilter.h
LC::Util
Definition
icoreproxy.h:34
LC::Util::InstallFontSizeChanger
void InstallFontSizeChanger(QWidget &widget, const FontSizeChangerParams ¶ms)
Definition
fontsizescrollchanger.cpp:35
LC::Util::Visit
auto Visit(const Either< Left, Right > &either, Args &&... args)
Definition
either.h:180
LC::Util::FontSizeChangerParams
std::variant< PixelBasedParams, FontBasedParams > FontSizeChangerParams
Definition
fontsizescrollchanger.h:31
LC::Util::MakeLambdaEventFilter
auto MakeLambdaEventFilter(F &&f, QObject &parent)
Definition
lambdaeventfilter.h:51
visitor.h
src
util
gui
fontsizescrollchanger.cpp
Generated by
1.17.0