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

#include <kis_aspect_ratio_locker.h>

+ Inheritance diagram for KisAspectRatioLocker:

Classes

struct  Private
 

Signals

void aspectButtonChanged ()
 
void aspectButtonToggled (bool value)
 
void sliderValueChanged ()
 

Public Member Functions

template<class AngleBoxType >
void connectAngleBoxes (AngleBoxType *spinOne, AngleBoxType *spinTwo, KoAspectButton *aspectButton)
 
template<class SpinBoxType >
void connectSpinBoxes (SpinBoxType *spinOne, SpinBoxType *spinTwo, KoAspectButton *aspectButton)
 
 KisAspectRatioLocker (QObject *parent=0)
 
void setBlockUpdateSignalOnDrag (bool block)
 
void updateAspect ()
 
 ~KisAspectRatioLocker () override
 

Private Slots

void slotAspectButtonChanged ()
 
void slotSpinDraggingFinished ()
 
void slotSpinOneChanged ()
 
void slotSpinTwoChanged ()
 

Private Attributes

const QScopedPointer< Privatem_d
 

Detailed Description

KisAspectRatioLocker is a class for locking the ratio between two sliders, i.e. to keep width and height of the image proportional.

When the locker takes responsibility of two sliders and a button, you should not use the valueChanged() and toggled() signals of the sliders and the button themselves. Instead you need to connect to the corresponding signals of the locker.

Usage:

   \code{.cpp}

   KisIntParseSpinBox *intRoundCornersX = ...;
   KisIntParseSpinBox *intRoundCornersY = ...;
   KoAspectButton *cornersAspectButton = ...;

   auto *cornersAspectLocker = new KisAspectRatioLocker(this);
   cornersAspectLocker->connectSpinBoxes(intRoundCornersX, intRoundCornersY, cornersAspectButton);

   connect(cornersAspectLocker, SIGNAL(sliderValueChanged()), SLOT(slotRoundCornersChanged()));
   connect(cornersAspectLocker, SIGNAL(aspectButtonChanged()), SLOT(slotRoundCornersAspectLockChanged()));

   \endcode

Definition at line 46 of file kis_aspect_ratio_locker.h.

Constructor & Destructor Documentation

◆ KisAspectRatioLocker()

KisAspectRatioLocker::KisAspectRatioLocker ( QObject * parent = 0)

Definition at line 140 of file kis_aspect_ratio_locker.cpp.

141 : QObject(parent),
142 m_d(new Private)
143{
144}
const QScopedPointer< Private > m_d

◆ ~KisAspectRatioLocker()

KisAspectRatioLocker::~KisAspectRatioLocker ( )
override

Definition at line 146 of file kis_aspect_ratio_locker.cpp.

147{
148}

Member Function Documentation

◆ aspectButtonChanged

void KisAspectRatioLocker::aspectButtonChanged ( )
signal

Emitted when the aspec locking button state is changed.

◆ aspectButtonToggled

void KisAspectRatioLocker::aspectButtonToggled ( bool value)
signal

Emitted when the aspec locking button state is changed, but also passing its new state.

◆ connectAngleBoxes()

template<class AngleBoxType >
template KRITAUI_EXPORT void KisAspectRatioLocker::connectAngleBoxes ( AngleBoxType * spinOne,
AngleBoxType * spinTwo,
KoAspectButton * aspectButton )

Link two angular spin boxes and an aspect button together

Definition at line 173 of file kis_aspect_ratio_locker.cpp.

174{
175 m_d->spinOne.reset(new SliderWrapper(spinOne));
176 m_d->spinTwo.reset(new SliderWrapper(spinTwo));
177 m_d->aspectButton = aspectButton;
178
179 connect(spinOne, SIGNAL(angleChanged(qreal)), SLOT(slotSpinOneChanged()));
180 connect(spinTwo, SIGNAL(angleChanged(qreal)), SLOT(slotSpinTwoChanged()));
181
182 connect(m_d->aspectButton, SIGNAL(keepAspectRatioChanged(bool)), SLOT(slotAspectButtonChanged()));
184}

References m_d, slotAspectButtonChanged(), slotSpinOneChanged(), and slotSpinTwoChanged().

◆ connectSpinBoxes()

template<class SpinBoxType >
template KRITAUI_EXPORT void KisAspectRatioLocker::connectSpinBoxes ( SpinBoxType * spinOne,
SpinBoxType * spinTwo,
KoAspectButton * aspectButton )

Link two spin boxes and an aspect button together

Definition at line 151 of file kis_aspect_ratio_locker.cpp.

152{
153 m_d->spinOne.reset(new SliderWrapper(spinOne));
154 m_d->spinTwo.reset(new SliderWrapper(spinTwo));
155 m_d->aspectButton = aspectButton;
156
157 if (QVariant::fromValue(spinOne->value()).type() == QVariant::Double) {
158 connect(spinOne, SIGNAL(valueChanged(qreal)), SLOT(slotSpinOneChanged()));
159 connect(spinTwo, SIGNAL(valueChanged(qreal)), SLOT(slotSpinTwoChanged()));
160 } else {
161 connect(spinOne, SIGNAL(valueChanged(int)), SLOT(slotSpinOneChanged()));
162 connect(spinTwo, SIGNAL(valueChanged(int)), SLOT(slotSpinTwoChanged()));
163 }
164
165 m_d->spinOne->connectDraggingFinished(this, SLOT(slotSpinDraggingFinished()));
166 m_d->spinTwo->connectDraggingFinished(this, SLOT(slotSpinDraggingFinished()));
167
168 connect(m_d->aspectButton, SIGNAL(keepAspectRatioChanged(bool)), SLOT(slotAspectButtonChanged()));
170}

References m_d, slotAspectButtonChanged(), slotSpinDraggingFinished(), slotSpinOneChanged(), and slotSpinTwoChanged().

◆ setBlockUpdateSignalOnDrag()

void KisAspectRatioLocker::setBlockUpdateSignalOnDrag ( bool block)

Selects whether sliderValueChanged() signal should be emitted continuously while the user drags one of the slider or only once when the drag operation is completed

Definition at line 244 of file kis_aspect_ratio_locker.cpp.

245{
246 m_d->blockUpdatesOnDrag = value;
247}
float value(const T *src, size_t ch)

References m_d, and value().

◆ sliderValueChanged

void KisAspectRatioLocker::sliderValueChanged ( )
signal

Emitted when a value of any of the sliders has changed and all aspect corrections have been completed.

You should use this signal instead of the own signals of the sliders, because these signals might be either blocked or come in undefined order.

◆ slotAspectButtonChanged

void KisAspectRatioLocker::slotAspectButtonChanged ( )
privateslot

Definition at line 221 of file kis_aspect_ratio_locker.cpp.

222{
223 if (m_d->aspectButton->keepAspectRatio() &&
224 m_d->spinTwo->value() > 0 &&
225 m_d->spinOne->value() > 0) {
226 m_d->aspectRatio = qreal(m_d->spinTwo->value()) / m_d->spinOne->value();
227 } else {
228 m_d->aspectRatio = 1.0;
229 }
230
231 if (!m_d->spinTwo->isDragging()) {
232 Q_EMIT aspectButtonChanged();
233 Q_EMIT aspectButtonToggled(m_d->aspectButton->keepAspectRatio());
234 }
235}
void aspectButtonToggled(bool value)

References aspectButtonChanged(), aspectButtonToggled(), and m_d.

◆ slotSpinDraggingFinished

void KisAspectRatioLocker::slotSpinDraggingFinished ( )
privateslot

Definition at line 237 of file kis_aspect_ratio_locker.cpp.

238{
239 if (m_d->blockUpdatesOnDrag) {
240 Q_EMIT sliderValueChanged();
241 }
242}

References m_d, and sliderValueChanged().

◆ slotSpinOneChanged

void KisAspectRatioLocker::slotSpinOneChanged ( )
privateslot

Definition at line 197 of file kis_aspect_ratio_locker.cpp.

198{
199 if (m_d->aspectButton->keepAspectRatio()) {
200 KisSignalsBlocker b(m_d->spinTwo->object());
201 m_d->spinTwo->setValue(m_d->aspectRatio * m_d->spinOne->value());
202 }
203
204 if (!m_d->blockUpdatesOnDrag || !m_d->spinOne->isDragging()) {
205 Q_EMIT sliderValueChanged();
206 }
207}

References m_d, and sliderValueChanged().

◆ slotSpinTwoChanged

void KisAspectRatioLocker::slotSpinTwoChanged ( )
privateslot

Definition at line 209 of file kis_aspect_ratio_locker.cpp.

210{
211 if (m_d->aspectButton->keepAspectRatio()) {
212 KisSignalsBlocker b(m_d->spinOne->object());
213 m_d->spinOne->setValue(m_d->spinTwo->value() / m_d->aspectRatio);
214 }
215
216 if (!m_d->blockUpdatesOnDrag || !m_d->spinTwo->isDragging()) {
217 Q_EMIT sliderValueChanged();
218 }
219}

References m_d, and sliderValueChanged().

◆ updateAspect()

void KisAspectRatioLocker::updateAspect ( )

Recalculate and lock the new aspect ratio of the sliders. The function takes the current values of the sliders and calculates the new ratio based on them.

This function is expected to be used when a saved value is restored into the sliders. Make sure that you block signals of the controls while loading values.

Usage:

\code{.cpp}

// load values in a locked state
KisSignalsBlocker b(intRoundCornersX, intRoundCornersY, cornersAspectButton);
intRoundCornersX->setValue(cfg.readEntry("roundCornersX", 0));
intRoundCornersY->setValue(cfg.readEntry("roundCornersY", 0));
cornersAspectButton->setKeepAspectRatio(cfg.readEntry("roundCornersAspectLocked", true));

// update new aspect ratio
cornersAspectLocker->updateAspect();
\endcode

Definition at line 249 of file kis_aspect_ratio_locker.cpp.

250{
251 KisSignalsBlocker b(this);
253}

References slotAspectButtonChanged().

Member Data Documentation

◆ m_d

const QScopedPointer<Private> KisAspectRatioLocker::m_d
private

Definition at line 127 of file kis_aspect_ratio_locker.h.


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