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

#include <KoZoomActionState.h>

Public Types

using ZoomItem = std::tuple<KoZoomMode::Mode, qreal, QString>
 

Public Member Functions

int calcNearestStandardLevel () const
 
int calcNearestStandardLevel (qreal zoom) const
 
 KoZoomActionState (const KoZoomState &state)
 
void setZoomState (const KoZoomState &state)
 

Public Attributes

int currentRealLevelIndex = 0
 
QString currentRealLevelText
 
QVector< ZoomItemguiLevels
 
QVector< ZoomItemrealGuiLevels
 
QVector< qreal > standardLevels
 
KoZoomState zoomState
 

Detailed Description

Definition at line 17 of file KoZoomActionState.h.

Member Typedef Documentation

◆ ZoomItem

using KoZoomActionState::ZoomItem = std::tuple<KoZoomMode::Mode, qreal, QString>

Definition at line 20 of file KoZoomActionState.h.

Constructor & Destructor Documentation

◆ KoZoomActionState()

KoZoomActionState::KoZoomActionState ( const KoZoomState & state)

Definition at line 48 of file KoZoomActionState.cpp.

49{
50 setZoomState(state);
51}
void setZoomState(const KoZoomState &state)

References setZoomState().

Member Function Documentation

◆ calcNearestStandardLevel() [1/2]

int KoZoomActionState::calcNearestStandardLevel ( ) const

Definition at line 141 of file KoZoomActionState.cpp.

142{
144}
int calcNearestStandardLevel() const

References calcNearestStandardLevel(), KoZoomState::zoom, and zoomState.

◆ calcNearestStandardLevel() [2/2]

int KoZoomActionState::calcNearestStandardLevel ( qreal zoom) const

Definition at line 128 of file KoZoomActionState.cpp.

129{
130 const qreal eps = 1e-5;
131 auto fuzzyCompareLess = [eps](qreal lhs, qreal rhs) {
132 return lhs + eps < rhs;
133 };
134
135 auto it = std::lower_bound(standardLevels.begin(), standardLevels.end(),
136 zoom, fuzzyCompareLess);
137
138 return qMin(standardLevels.size() - 1, std::distance(standardLevels.begin(), it));
139}
QVector< qreal > standardLevels
const qreal eps

References eps, and standardLevels.

◆ setZoomState()

void KoZoomActionState::setZoomState ( const KoZoomState & state)

1) If all elements are smaller than the new zoom, then add into the end 2) If the found element is too similar to the new zoom, then just keep the existing element instead

Definition at line 53 of file KoZoomActionState.cpp.

54{
55 const bool forceInitialization = realGuiLevels.isEmpty();
56 bool needsUpdateRealLevels = forceInitialization;
57
58 if (forceInitialization ||
59 !qFuzzyCompare(newState.minZoom, zoomState.minZoom) ||
60 !qFuzzyCompare(newState.maxZoom, zoomState.maxZoom)) {
61
62 auto newStandardLevels = KoZoomMode::generateStandardZoomLevels(newState.minZoom, newState.maxZoom);
63 if (newStandardLevels != standardLevels) {
64 standardLevels = newStandardLevels;
65 auto newGuiLevels = generateZoomGuiItems(newStandardLevels);
66 if (newGuiLevels != guiLevels) {
67 guiLevels = newGuiLevels;
68 needsUpdateRealLevels = true;
69 }
70 }
71 }
72
73 int proposedCurrentIndex = currentRealLevelIndex;
74
75 if (needsUpdateRealLevels || !qFuzzyCompare(newState.zoom, zoomState.zoom) || newState.mode != zoomState.mode) {
77
78 const qreal eps = 1e-5;
79 auto fuzzyCompareLess = [eps] (const ZoomItem &lhs, qreal rhs) {
80 return std::get<qreal>(lhs) + eps < rhs;
81 };
82
83 auto it = std::lower_bound(realGuiLevels.begin(), realGuiLevels.end(),
84 newState.zoom, fuzzyCompareLess);
85
91 if (it == realGuiLevels.end() || !(qAbs(std::get<qreal>(*it) - newState.zoom) < eps)) {
92 it = realGuiLevels.insert(it, {KoZoomMode::ZOOM_CONSTANT, newState.zoom, zoomToString(newState.zoom)});
93 }
94
95 proposedCurrentIndex = std::distance(realGuiLevels.begin(), it);
96 }
97
98 auto textForFixedMode = [&] (const int index) {
99 ZoomItem zoomItem = realGuiLevels[index];
100 return i18nc("concatenate mode name (e.g. \"Fit Page\") and real zoom percent string", "%1 (%2)",
101 std::get<QString>(zoomItem),
102 zoomToString(newState.zoom));
103 };
104
105 switch (newState.mode) {
109 break;
113 break;
117 break;
119 default:
120 currentRealLevelIndex = proposedCurrentIndex;
122 break;
123 }
124
125 zoomState = newState;
126}
QVector< ZoomItem > realGuiLevels
QVector< ZoomItem > guiLevels
std::tuple< KoZoomMode::Mode, qreal, QString > ZoomItem
@ 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
static QVector< qreal > generateStandardZoomLevels(qreal minZoom, qreal maxZoom)
KoZoomMode::Mode mode
Definition KoZoomState.h:24
qreal maxZoom
Definition KoZoomState.h:27
qreal minZoom
Definition KoZoomState.h:26
static bool qFuzzyCompare(half p1, half p2)

References currentRealLevelIndex, currentRealLevelText, eps, KoZoomMode::generateStandardZoomLevels(), guiLevels, KoZoomState::maxZoom, KoZoomState::minZoom, KoZoomState::mode, qFuzzyCompare(), realGuiLevels, standardLevels, KoZoomState::zoom, KoZoomMode::ZOOM_CONSTANT, KoZoomMode::ZOOM_HEIGHT, KoZoomMode::ZOOM_PAGE, KoZoomMode::ZOOM_WIDTH, and zoomState.

Member Data Documentation

◆ currentRealLevelIndex

int KoZoomActionState::currentRealLevelIndex = 0

Definition at line 26 of file KoZoomActionState.h.

◆ currentRealLevelText

QString KoZoomActionState::currentRealLevelText

Definition at line 27 of file KoZoomActionState.h.

◆ guiLevels

QVector<ZoomItem> KoZoomActionState::guiLevels

Definition at line 24 of file KoZoomActionState.h.

◆ realGuiLevels

QVector<ZoomItem> KoZoomActionState::realGuiLevels

Definition at line 25 of file KoZoomActionState.h.

◆ standardLevels

QVector<qreal> KoZoomActionState::standardLevels

Definition at line 23 of file KoZoomActionState.h.

◆ zoomState

KoZoomState KoZoomActionState::zoomState

Definition at line 22 of file KoZoomActionState.h.


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