Krita Source Code Documentation
Loading...
Searching...
No Matches
KoZoomMode Class Reference

#include <KoZoomMode.h>

Public Types

enum  Mode { ZOOM_CONSTANT = 0 , ZOOM_PAGE = 1 , ZOOM_WIDTH = 2 , ZOOM_HEIGHT = 16 }
 

Static Public Member Functions

static qreal findNextZoom (qreal currentZoom, const QVector< qreal > &zoomLevels)
 
static qreal findPrevZoom (qreal currentZoom, const QVector< qreal > &zoomLevels)
 
static QVector< qreal > generateStandardZoomLevels (qreal minZoom, qreal maxZoom)
 
static QString toString (Mode mode)
 

Static Private Attributes

static const char *const modes []
 

Detailed Description

The ZoomMode container

Definition at line 19 of file KoZoomMode.h.

Member Enumeration Documentation

◆ Mode

Enumerator
ZOOM_CONSTANT 

zoom x %

ZOOM_PAGE 

zoom page

ZOOM_WIDTH 

zoom pagewidth

ZOOM_HEIGHT 

zoom pageheight

Definition at line 22 of file KoZoomMode.h.

23 {
24 ZOOM_CONSTANT = 0,
25 ZOOM_PAGE = 1,
26 ZOOM_WIDTH = 2,
27 ZOOM_HEIGHT = 16,
28 };
@ ZOOM_CONSTANT
zoom x %
Definition KoZoomMode.h:24
@ ZOOM_PAGE
zoom page
Definition KoZoomMode.h:25
@ ZOOM_WIDTH
zoom pagewidth
Definition KoZoomMode.h:26
@ ZOOM_HEIGHT
zoom pageheight
Definition KoZoomMode.h:27

Member Function Documentation

◆ findNextZoom()

qreal KoZoomMode::findNextZoom ( qreal currentZoom,
const QVector< qreal > & zoomLevels )
static

Find the next zoom level to switch during the zoom-in operation

Definition at line 63 of file KoZoomMode.cpp.

64{
65 const qreal eps = 1e-5;
66 int i = 0;
67 while (i < zoomLevels.size() - 1 && currentZoom > zoomLevels[i] - eps) {
68 i++;
69 }
70
71 return qMax(currentZoom, zoomLevels[i]);
72}
const qreal eps

References eps.

◆ findPrevZoom()

qreal KoZoomMode::findPrevZoom ( qreal currentZoom,
const QVector< qreal > & zoomLevels )
static

Find the previous zoom level to switch during the zoom-out operation

Definition at line 74 of file KoZoomMode.cpp.

75{
76 const qreal eps = 1e-5;
77 int i = zoomLevels.size() - 1;
78 while (i > 0 && currentZoom < zoomLevels[i] + eps) i--;
79
80 return qMin(currentZoom, zoomLevels[i]);
81}

References eps.

◆ generateStandardZoomLevels()

QVector< qreal > KoZoomMode::generateStandardZoomLevels ( qreal minZoom,
qreal maxZoom )
static

Generates standard zoom levels for the allowed range of minZoom and maxZoom

Definition at line 34 of file KoZoomMode.cpp.

35{
36 KConfigGroup config = KSharedConfig::openConfig()->group("");
37 int steps = config.readEntry("zoomSteps", 2);
38 qreal k = steps / M_LN2;
39
40 int first = ceil(log(minZoom) * k);
41 int size = floor(log(maxZoom) * k) - first + 1;
42 QVector<qreal> zoomLevels(size);
43
44 // enforce zoom levels relating to thirds (33.33%, 66.67%, ...)
45 QVector<qreal> snap(steps);
46 if (steps > 1) {
47 qreal third = log(4./ 3.) * k;
48 int i = round(third);
49 snap[(i - first) % steps] = third - i;
50 }
51
52 k = 1./ k;
53 for (int i = 0; i < steps; i++) {
54 qreal f = exp((i + first + snap[i]) * k);
55 f = floor(f * 0x1p48 + 0.5) / 0x1p48; // round off inaccuracies
56 for (int j = i; j < size; j += steps, f *= 2.) {
57 zoomLevels[j] = f;
58 }
59 }
60 return zoomLevels;
61}
int size(const Forest< T > &forest)
Definition KisForest.h:1232

◆ toString()

QString KoZoomMode::toString ( Mode mode)
static
Returns
the to QString converted and translated Mode mode

Definition at line 19 of file KoZoomMode.cpp.

20{
21 switch (mode) {
23 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(0 && "constant zoom has no user-friendly representation", "XXX");
25 return i18n("Fit View");
27 return i18n("Fit Width");
29 return i18n("Fit Height");
30 }
31 return "";
32}
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129

References KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, ZOOM_CONSTANT, ZOOM_HEIGHT, ZOOM_PAGE, and ZOOM_WIDTH.

Member Data Documentation

◆ modes

const char* const KoZoomMode::modes[]
staticprivate

Definition at line 52 of file KoZoomMode.h.


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