Krita Source Code Documentation
Loading...
Searching...
No Matches
KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP > Class Template Reference

#include <kis_parse_spin_box_p.h>

+ Inheritance diagram for KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >:

Public Types

using BaseSpinBoxType = BaseSpinBoxTypeTP
 
using SpinBoxType = SpinBoxTypeTP
 
using ValueType = decltype(std::declval<SpinBoxType>().value())
 

Public Member Functions

bool eventFilter (QObject *o, QEvent *e) override
 
void fixupCursorPosition (int oldPos, int newPos)
 
void fixupSelection ()
 
void hideWarning () const
 
bool isLastValid () const
 
 KisParseSpinBoxPrivate (SpinBoxType *q)
 
bool lineEditMouseDoubleClickEvent (QMouseEvent *e)
 
bool lineEditPaintEvent (QPaintEvent *)
 
template<typename U = SpinBoxTypeTP, typename = typename std::enable_if<std::is_same<ValueType, int>::value, U>::type>
int parseMathExpression (const QString &text, bool *ok) const
 
template<typename U = SpinBoxTypeTP, typename = typename std::enable_if<std::is_same<ValueType, double>::value, U>::type>
double parseMathExpression (const QString &text, bool *ok) const
 
bool qFocusOutEvent (QFocusEvent *)
 
bool qKeyPressEvent (QKeyEvent *e)
 
bool qResizeEvent (QResizeEvent *)
 
bool qStyleChangeEvent (QEvent *)
 
void setValue (ValueType value, bool overwriteExpression=false)
 
void showWarning () const
 
void showWarning (int delay) const
 
void stepBy (int steps)
 
QString textFromValue (ValueType value) const
 
QValidator::State validate (QString &, int &) const
 
ValueType valueFromText (const QString &text) const
 
QString veryCleanText () const
 

Private Attributes

bool m_isLastValid {true}
 
bool m_isWarningActive {false}
 
QString m_lastExpressionParsed
 
QLineEdit * m_lineEdit
 
SpinBoxTypem_q
 
bool m_showWarningIcon {false}
 
QTimer m_timerShowWarning
 
QVariantAnimation m_warningAnimation
 

Static Private Attributes

static QIcon m_warningIcon
 
static constexpr int showWarningInterval {2000}
 
static constexpr double warningAnimationDuration {250.0}
 
static constexpr double widthOfWarningIconArea {24.0}
 

Detailed Description

template<typename SpinBoxTypeTP, typename BaseSpinBoxTypeTP>
class KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >

Definition at line 35 of file kis_parse_spin_box_p.h.

Member Typedef Documentation

◆ BaseSpinBoxType

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
using KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::BaseSpinBoxType = BaseSpinBoxTypeTP

Definition at line 39 of file kis_parse_spin_box_p.h.

◆ SpinBoxType

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
using KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::SpinBoxType = SpinBoxTypeTP

Definition at line 38 of file kis_parse_spin_box_p.h.

◆ ValueType

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
using KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::ValueType = decltype(std::declval<SpinBoxType>().value())

Definition at line 40 of file kis_parse_spin_box_p.h.

Constructor & Destructor Documentation

◆ KisParseSpinBoxPrivate()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::KisParseSpinBoxPrivate ( SpinBoxType * q)
inline

Definition at line 42 of file kis_parse_spin_box_p.h.

43 : m_q(q)
44 , m_lineEdit(m_q->lineEdit())
45 {
46 m_q->installEventFilter(this);
47
48 m_lineEdit->setAutoFillBackground(false);
49 m_lineEdit->installEventFilter(this);
50 connect(m_lineEdit, &QLineEdit::selectionChanged, this, &KisParseSpinBoxPrivate::fixupSelection);
51 connect(m_lineEdit, &QLineEdit::cursorPositionChanged, this, &KisParseSpinBoxPrivate::fixupCursorPosition);
52
53 m_timerShowWarning.setSingleShot(true);
54 connect(&m_timerShowWarning, &QTimer::timeout, this, QOverload<>::of(&KisParseSpinBoxPrivate::showWarning));
55 if (m_warningIcon.isNull() && QFile(":/./16_light_warning.svg").exists()) {
56 m_warningIcon = QIcon(":/./16_light_warning.svg");
57 }
58 m_warningAnimation.setStartValue(0.0);
59 m_warningAnimation.setEndValue(1.0);
60 m_warningAnimation.setEasingCurve(QEasingCurve(QEasingCurve::InOutCubic));
61 connect(&m_warningAnimation, &QVariantAnimation::valueChanged, m_lineEdit, QOverload<>::of(&QLineEdit::update));
62 }
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void fixupCursorPosition(int oldPos, int newPos)
QVariantAnimation m_warningAnimation

References connect(), KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::fixupCursorPosition(), KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::fixupSelection(), and KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::showWarning().

Member Function Documentation

◆ eventFilter()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::eventFilter ( QObject * o,
QEvent * e )
inlineoverride

Definition at line 443 of file kis_parse_spin_box_p.h.

444 {
445 if (!o || !e) {
446 return false;
447 }
448 if (o == m_q) {
449 switch (e->type()) {
450 case QEvent::Resize: return qResizeEvent(static_cast<QResizeEvent*>(e));
451 case QEvent::StyleChange: return qStyleChangeEvent(e);
452 case QEvent::KeyPress: return qKeyPressEvent(static_cast<QKeyEvent*>(e));
453 case QEvent::FocusOut: return qFocusOutEvent(static_cast<QFocusEvent*>(e));
454 default: break;
455 }
456 } else if (o == m_lineEdit) {
457 switch (e->type()) {
458 case QEvent::Paint: return lineEditPaintEvent(static_cast<QPaintEvent*>(e));
459 case QEvent::MouseButtonDblClick: return lineEditMouseDoubleClickEvent(static_cast<QMouseEvent*>(e));
460 default: break;
461 }
462 }
463 return false;
464 }
bool qKeyPressEvent(QKeyEvent *e)
bool lineEditPaintEvent(QPaintEvent *)
bool qResizeEvent(QResizeEvent *)
bool lineEditMouseDoubleClickEvent(QMouseEvent *e)
bool qFocusOutEvent(QFocusEvent *)

◆ fixupCursorPosition()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
void KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::fixupCursorPosition ( int oldPos,
int newPos )
inline

Definition at line 199 of file kis_parse_spin_box_p.h.

200 {
201 Q_UNUSED(oldPos);
202 if (newPos < m_q->prefix().length()) {
203 m_lineEdit->setCursorPosition(m_q->prefix().length());
204 } else {
205 const int suffixStart = m_q->text().length() - m_q->suffix().length();
206 if (newPos > suffixStart) {
207 m_lineEdit->setCursorPosition(suffixStart);
208 }
209 }
210 }
qreal length(const QPointF &vec)
Definition Ellipse.cc:82

References length().

◆ fixupSelection()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
void KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::fixupSelection ( )
inline

Definition at line 181 of file kis_parse_spin_box_p.h.

182 {
183 // If there's no selection just do nothing
184 if (m_lineEdit->selectedText().isEmpty()) {
185 return;
186 }
187 const int suffixStart = m_q->text().length() - m_q->suffix().length();
188 const int newStart = qBound(m_q->prefix().length(), m_lineEdit->selectionStart(), suffixStart);
189 const int newEnd = qBound(m_q->prefix().length(), m_lineEdit->selectionStart() + m_lineEdit->selectedText().length(), suffixStart);
190 if (m_lineEdit->cursorPosition() == m_lineEdit->selectionStart()) {
191 m_lineEdit->setSelection(newEnd, -(newEnd - newStart));
192 } else {
193 m_lineEdit->setSelection(newStart, newEnd - newStart);
194 }
195 }

◆ hideWarning()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
void KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::hideWarning ( ) const
inline

Definition at line 263 of file kis_parse_spin_box_p.h.

264 {
265 m_timerShowWarning.stop();
266 m_warningAnimation.stop();
267 m_isWarningActive = false;
268 // scale the animation duration in case the animation is in the middle
269 const int animationDuration =
270 static_cast<int>(std::round(m_warningAnimation.currentValue().toReal() * warningAnimationDuration));
271 m_warningAnimation.setStartValue(m_warningAnimation.currentValue());
272 m_warningAnimation.setEndValue(0.0);
273 m_warningAnimation.setDuration(animationDuration);
274 m_warningAnimation.start();
275 }
static constexpr double warningAnimationDuration

◆ isLastValid()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::isLastValid ( ) const
inline

Definition at line 101 of file kis_parse_spin_box_p.h.

102 {
103 return m_isLastValid;
104 }

◆ lineEditMouseDoubleClickEvent()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::lineEditMouseDoubleClickEvent ( QMouseEvent * e)
inline

Definition at line 430 of file kis_parse_spin_box_p.h.

431 {
432 if (!m_q->isEnabled() || m_lineEdit->isReadOnly()) {
433 return false;
434 }
435 // If we double click anywhere with the left button then select all the value text
436 if (e->button() == Qt::LeftButton) {
437 m_q->selectAll();
438 return true;
439 }
440 return false;
441 }

◆ lineEditPaintEvent()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::lineEditPaintEvent ( QPaintEvent * )
inline

Definition at line 364 of file kis_parse_spin_box_p.h.

365 {
366 QPainter painter(m_lineEdit);
367 painter.setRenderHint(QPainter::Antialiasing, true);
368 QPalette pal = m_lineEdit->palette();
369 // the overlay color, a red warning color when there is an error
370 QColor color(255, 48, 0, 0);
371 constexpr int maxOpacity = 160;
372 QColor textColor;
373 const qreal warningAnimationPos = m_warningAnimation.currentValue().toReal();
374 // compute colors
375 if (m_warningAnimation.state() == QVariantAnimation::Running) {
376 color.setAlpha(static_cast<int>(std::round(KisAlgebra2D::lerp(0.0, static_cast<double>(maxOpacity), warningAnimationPos))));
377 textColor = KisPaintingTweaks::blendColors(m_q->palette().text().color(), Qt::white, 1.0 - warningAnimationPos);
378 } else {
379 if (m_isWarningActive) {
380 color.setAlpha(maxOpacity);
381 textColor = Qt::white;
382 } else {
383 textColor = m_q->palette().text().color();
384 }
385 }
386 // Paint the overlay
387 const QRect rect = m_lineEdit->rect();
388 painter.setBrush(color);
389 painter.setPen(Qt::NoPen);
390 QString style = qApp->property(currentUnderlyingStyleNameProperty).toString().toLower();
391 if (style == "fusion") {
392 painter.drawRoundedRect(rect, 1, 1);
393 } else {
394 painter.drawRoundedRect(rect, 0, 0);
395 }
396 // Paint the warning icon
397 if (m_showWarningIcon) {
398 constexpr qreal warningIconMargin = 4.0;
399 const qreal warningIconSize = widthOfWarningIconArea - 2.0 * warningIconMargin;
400 if (m_warningAnimation.state() == QVariantAnimation::Running) {
401 qreal warningIconPos =
403 m_lineEdit->alignment() & Qt::AlignRight ? -warningIconMargin : rect.width() - warningIconSize + warningIconMargin,
404 m_lineEdit->alignment() & Qt::AlignRight ? warningIconMargin : rect.width() - warningIconSize - warningIconMargin,
405 warningAnimationPos
406 );
407 painter.setOpacity(warningAnimationPos);
408 painter.drawPixmap(
409 warningIconPos, (static_cast<qreal>(rect.height()) - warningIconSize) / 2.0,
410 m_warningIcon.pixmap(warningIconSize, warningIconSize)
411 );
412 } else if (m_isWarningActive) {
413 painter.drawPixmap(
414 m_lineEdit->alignment() & Qt::AlignRight ? warningIconMargin : rect.width() - warningIconSize - warningIconMargin,
415 (static_cast<qreal>(rect.height()) - warningIconSize) / 2.0,
416 m_warningIcon.pixmap(warningIconSize, warningIconSize)
417 );
418 }
419 }
420 // Set the text color
421 pal.setBrush(QPalette::Text, textColor);
422 // Make sure the background of the line edit is transparent so that
423 // the base class paint event only draws the text
424 pal.setBrush(QPalette::Base, Qt::transparent);
425 pal.setBrush(QPalette::Button, Qt::transparent);
426 m_lineEdit->setPalette(pal);
427 return false;
428 }
static constexpr double widthOfWarningIconArea
constexpr const char * currentUnderlyingStyleNameProperty
Definition kis_global.h:116
Point lerp(const Point &pt1, const Point &pt2, qreal t)
QColor blendColors(const QColor &c1, const QColor &c2, qreal r1)

References KisPaintingTweaks::blendColors(), currentUnderlyingStyleNameProperty, and KisAlgebra2D::lerp().

◆ parseMathExpression() [1/2]

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
template<typename U = SpinBoxTypeTP, typename = typename std::enable_if<std::is_same<ValueType, int>::value, U>::type>
int KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::parseMathExpression ( const QString & text,
bool * ok ) const
inline

Definition at line 120 of file kis_parse_spin_box_p.h.

121 {
123 }
int parseIntegerMathExpr(QString const &expr, bool *noProblem)
parse an expression to an int.

References KisNumericParser::parseIntegerMathExpr().

◆ parseMathExpression() [2/2]

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
template<typename U = SpinBoxTypeTP, typename = typename std::enable_if<std::is_same<ValueType, double>::value, U>::type>
double KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::parseMathExpression ( const QString & text,
bool * ok ) const
inline

Definition at line 127 of file kis_parse_spin_box_p.h.

128 {
130 if(qIsNaN(value) || qIsInf(value)){
131 *ok = false;
132 }
133 return value;
134 }
float value(const T *src, size_t ch)
double parseSimpleMathExpr(const QString &expr, bool *noProblem)
parse an expression to a double.

References KisNumericParser::parseSimpleMathExpr(), and value().

◆ qFocusOutEvent()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::qFocusOutEvent ( QFocusEvent * )
inline

Definition at line 350 of file kis_parse_spin_box_p.h.

351 {
352 if (!isLastValid()) {
353 // Immediately show the warning if the expression is not valid
354 showWarning();
355 } else {
356 // Set the value forcing the expression to be overwritten.
357 // This will make an expression like "2*4" automatically be changed
358 // to "8" when the spinbox looses focus
359 setValue(m_q->value(), true);
360 }
361 return false;
362 }
void setValue(ValueType value, bool overwriteExpression=false)

◆ qKeyPressEvent()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::qKeyPressEvent ( QKeyEvent * e)
inline

Definition at line 310 of file kis_parse_spin_box_p.h.

311 {
312 switch (e->key()) {
313 case Qt::Key_Enter:
314 case Qt::Key_Return:
315 if (!isLastValid()) {
316 // Immediately show the warning if the expression is not valid
317 showWarning();
318 return true;
319 } else {
320 // Set the value forcing the expression to be overwritten.
321 // This will make an expression like "2*4" automatically be changed
322 // to "8" when enter/return key is pressed
323 setValue(m_q->value(), true);
324 }
325 break;
326 // Prevent deleting the last character of the prefix and the first
327 // one of the suffix. This solves some issue that appears when the
328 // prefix ends with a space or the suffix starts with a space. For
329 // example, if the prefix is "size: " and the value 50, deleting
330 // the space will join the string "size:" with "50" to form
331 // "size:50", and since that string does not start with the prefix,
332 // it will be treated as the new entered value. Then, prepending
333 // the prefix will display the text "size: size:50".
334 case Qt::Key_Backspace:
335 if (m_lineEdit->selectedText().length() == 0 && m_lineEdit->cursorPosition() == m_q->prefix().length()) {
336 return true;
337 }
338 break;
339 case Qt::Key_Delete:
340 if (m_lineEdit->selectedText().length() == 0 && m_lineEdit->cursorPosition() == m_q->text().length() - m_q->suffix().length()) {
341 return true;
342 }
343 break;
344 default:
345 break;
346 }
347 return false;
348 }

◆ qResizeEvent()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::qResizeEvent ( QResizeEvent * )
inline

Definition at line 277 of file kis_parse_spin_box_p.h.

278 {
279 // When resizing the spinbox, perform style specific positioning
280 // of the lineedit
281
282 // Get the default rect for the lineedit widget
283 QStyleOptionSpinBox spinBoxOptions;
284 m_q->initStyleOption(&spinBoxOptions);
285 QRect rect = m_q->style()->subControlRect(QStyle::CC_SpinBox, &spinBoxOptions, QStyle::SC_SpinBoxEditField);
286 // Offset the rect to make it take all the available space inside the
287 // spinbox, without overlapping the buttons
288 QString style = qApp->property(currentUnderlyingStyleNameProperty).toString().toLower();
289 if (style == "breeze") {
290 rect.adjust(-4, -4, 0, 4);
291 } else if (style == "fusion") {
292 rect.adjust(-2, -1, 2, 1);
293 }
294 // Set the rect
295 m_lineEdit->setGeometry(rect);
296
297 return true;
298 }

References currentUnderlyingStyleNameProperty.

◆ qStyleChangeEvent()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::qStyleChangeEvent ( QEvent * )
inline

Definition at line 300 of file kis_parse_spin_box_p.h.

301 {
302 // Fire a resize event so that the line edit geometry is updated.
303 // For some reason (stylesheet set in the app) setting the geometry
304 // using qstyle to get a rect has no effect here, as if the style is
305 // not updated yet...
306 qApp->postEvent(m_q, new QResizeEvent(m_q->size(), m_q->size()));
307 return false;
308 }

◆ setValue()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
void KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::setValue ( ValueType value,
bool overwriteExpression = false )
inline

Definition at line 75 of file kis_parse_spin_box_p.h.

76 {
77 // The expression should be always cleared if the user is not
78 // actively editing the text
79 if (!m_q->hasFocus() || m_lineEdit->isReadOnly()) {
80 overwriteExpression = true;
81 }
82 // Clear the expression so that the line edit shows just the
83 // current value with prefix and suffix
84 if (overwriteExpression) {
85 m_lastExpressionParsed = QString();
86 }
87 // Prevent setting the new value if it is equal to the current one.
88 // That will maintain the current expression and warning status.
89 // If the value is different or the expression should overwritten then
90 // the value is set and the warning status is cleared
91 if (value != m_q->value() || overwriteExpression) {
92 m_q->BaseSpinBoxType::setValue(value);
93 if (!m_isLastValid) {
94 m_isLastValid = true;
96 Q_EMIT m_q->noMoreParsingError();
97 }
98 }
99 }

References value().

◆ showWarning() [1/2]

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
void KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::showWarning ( ) const
inline

Definition at line 213 of file kis_parse_spin_box_p.h.

214 {
215 if (m_isWarningActive && m_warningAnimation.state() == QVariantAnimation::Running) {
216 return;
217 }
218 m_timerShowWarning.stop();
219 m_warningAnimation.stop();
220 m_isWarningActive = true;
221 if (!m_warningIcon.isNull()) {
222 QFontMetricsF fm(m_lineEdit->font());
223#if QT_VERSION >= QT_VERSION_CHECK(5,11,0)
224 const qreal textWidth = fm.horizontalAdvance(m_lineEdit->text());
225#else
226 const qreal textWidth = fm.width(m_lineEdit->text());
227#endif
228 const int minimumWidth =
229 static_cast<int>(
230 std::ceil(
231 textWidth + (m_q->alignment() == Qt::AlignCenter ? 2.0 : 1.0) * widthOfWarningIconArea + 4
232 )
233 );
234 if (m_lineEdit->width() >= minimumWidth) {
235 m_showWarningIcon = true;
236 } else {
237 m_showWarningIcon = false;
238 }
239 }
240 // scale the animation duration in case the animation is in the middle
241 const int animationDuration =
242 static_cast<int>(std::round((1.0 - m_warningAnimation.currentValue().toReal()) * warningAnimationDuration));
243 m_warningAnimation.setStartValue(m_warningAnimation.currentValue());
244 m_warningAnimation.setEndValue(1.0);
245 m_warningAnimation.setDuration(animationDuration);
246 m_warningAnimation.start();
247 }

◆ showWarning() [2/2]

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
void KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::showWarning ( int delay) const
inline

Definition at line 250 of file kis_parse_spin_box_p.h.

251 {
252 if (delay > 0) {
253 if (!m_isWarningActive || m_warningAnimation.state() != QVariantAnimation::Running) {
254 m_timerShowWarning.start(delay);
255 }
256 return;
257 }
258 // If "delay" is not greater that 0 then the warning will be
259 // immediately shown
260 showWarning();
261 }

◆ stepBy()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
void KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::stepBy ( int steps)
inline

Definition at line 64 of file kis_parse_spin_box_p.h.

65 {
66 if (steps == 0) {
67 return;
68 }
69 // Use the reimplementation os setValue in this function so that we can
70 // clear the expression
71 setValue(m_q->value() + static_cast<ValueType>(steps) * m_q->singleStep(), true);
72 m_q->selectAll();
73 }
decltype(std::declval< SpinBoxType >().value()) ValueType

◆ textFromValue()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
QString KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::textFromValue ( ValueType value) const
inline

Definition at line 166 of file kis_parse_spin_box_p.h.

167 {
168 // If the last expression parsed is not null then the user actively
169 // changed the text, so that expression is returned regardless of the
170 // actual value
171 if (!m_lastExpressionParsed.isNull()) {
173 }
174 // Otherwise we transform the passed value to a string using the
175 // method from the base class and return that
176 return m_q->BaseSpinBoxType::textFromValue(value);
177 }

References value().

◆ validate()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
QValidator::State KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::validate ( QString & ,
int &  ) const
inline

Definition at line 111 of file kis_parse_spin_box_p.h.

112 {
113 // We want the user to be able to write any kind of expression.
114 // If it produces a valid value or not is decided in "valueFromText"
115 return QValidator::Acceptable;
116 }

◆ valueFromText()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
ValueType KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::valueFromText ( const QString & text) const
inline

Definition at line 136 of file kis_parse_spin_box_p.h.

137 {
138 // Always hide the warning when the text changes
139 hideWarning();
140 // Get the expression, removing the prefix and suffix
142 if (m_lastExpressionParsed.endsWith(m_q->suffix())) {
143 m_lastExpressionParsed.remove(m_lastExpressionParsed.size() - m_q->suffix().size(), m_q->suffix().size());
144 }
145 if(m_lastExpressionParsed.startsWith(m_q->prefix())){
146 m_lastExpressionParsed.remove(0, m_q->prefix().size());
147 }
148 // Parse
149 bool ok;
151 // Validate
152 if (!ok) {
153 m_isLastValid = false;
154 value = m_q->value();
156 Q_EMIT m_q->errorWhileParsing(text);
157 } else {
158 if (!m_isLastValid) {
159 m_isLastValid = true;
160 Q_EMIT m_q->noMoreParsingError();
161 }
162 }
163 return value;
164 }
static constexpr int showWarningInterval
int parseMathExpression(const QString &text, bool *ok) const

References value().

◆ veryCleanText()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
QString KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::veryCleanText ( ) const
inline

Definition at line 106 of file kis_parse_spin_box_p.h.

107 {
108 return m_q->cleanText();
109 }

Member Data Documentation

◆ m_isLastValid

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_isLastValid {true}
mutableprivate

Definition at line 478 of file kis_parse_spin_box_p.h.

478{true};

◆ m_isWarningActive

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_isWarningActive {false}
mutableprivate

Definition at line 479 of file kis_parse_spin_box_p.h.

479{false};

◆ m_lastExpressionParsed

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
QString KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_lastExpressionParsed
mutableprivate

Definition at line 477 of file kis_parse_spin_box_p.h.

◆ m_lineEdit

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
QLineEdit* KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_lineEdit
private

Definition at line 476 of file kis_parse_spin_box_p.h.

◆ m_q

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
SpinBoxType* KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_q
private

Definition at line 475 of file kis_parse_spin_box_p.h.

◆ m_showWarningIcon

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_showWarningIcon {false}
mutableprivate

Definition at line 481 of file kis_parse_spin_box_p.h.

481{false};

◆ m_timerShowWarning

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
QTimer KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_timerShowWarning
mutableprivate

Definition at line 480 of file kis_parse_spin_box_p.h.

◆ m_warningAnimation

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
QVariantAnimation KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_warningAnimation
mutableprivate

Definition at line 482 of file kis_parse_spin_box_p.h.

◆ m_warningIcon

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
QIcon KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_warningIcon
staticprivate

Definition at line 483 of file kis_parse_spin_box_p.h.

◆ showWarningInterval

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
constexpr int KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::showWarningInterval {2000}
staticconstexprprivate

Definition at line 469 of file kis_parse_spin_box_p.h.

469{2000};

◆ warningAnimationDuration

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
constexpr double KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::warningAnimationDuration {250.0}
staticconstexprprivate

Definition at line 473 of file kis_parse_spin_box_p.h.

473{250.0};

◆ widthOfWarningIconArea

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
constexpr double KisParseSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::widthOfWarningIconArea {24.0}
staticconstexprprivate

Definition at line 471 of file kis_parse_spin_box_p.h.

471{24.0};

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