Krita Source Code Documentation
Loading...
Searching...
No Matches
KisAnimCurvesValuesHeader.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016 Jouni Pentikäinen <joupent@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#ifndef _KIS_ANIMATION_CURVES_VALUE_RULER_H
8#define _KIS_ANIMATION_CURVES_VALUE_RULER_H
9
10#include <QHeaderView>
11#include "kis_debug.h"
12#include <QtMath>
13
14const int UNIT_SIZE_PIXELS = 32;
15
16class KisAnimCurvesValuesHeader : public QHeaderView
17{
18 Q_OBJECT
19
20public:
21 KisAnimCurvesValuesHeader(QWidget *parent);
23
24 void setScale(qreal scale);
25 qreal scale() const;
26
27 void setValueOffset(qreal valueOffset);
28 qreal valueOffset() const;
29
30 qreal step() const;
31
37 qreal valueToWidget(qreal value) const;
38 qreal widgetToValue(qreal position) const;
39
40 inline qreal visibleValueMax() const {
41 return widgetToValue(rect().top());
42 }
43
44 inline qreal visibleValueMin() const {
45 return widgetToValue(rect().bottom());
46 }
47
48 qreal visibleValueDifference() const;
49
50 void zoomToFitRange(qreal min, qreal max);
51
52 inline qreal firstVisibleStep() const {
53 const qreal valueStep = step();
54 return qCeil(valueOffset() / valueStep) * valueStep;
55 }
56
57 inline qreal pixelsToValueOffset(const int pixels) const {
58 return (qreal(pixels) * -1 / scaledUnit());
59 }
60
61 inline int valueToPixelOffset(const qreal value) const {
62 return (value * scaledUnit()) / -1;
63 }
64
65 QSize sizeHint() const override {return QSize(64, 0);}
66 void paintEvent(QPaintEvent *e) override;
67
68Q_SIGNALS:
69 void scaleChanged(qreal scale);
70 void valueOffsetChanged(qreal offset);
71
72protected:
73 virtual void mouseMoveEvent(QMouseEvent* mouseEvent) override;
74 virtual void mousePressEvent(QMouseEvent* mouseEvent) override;
75
76private:
77 inline qreal scaledUnit() const {
78 return UNIT_SIZE_PIXELS * scale();
79 }
80
81 inline qreal pixelsPerStep(const qreal step) const {
82 return step * scaledUnit();
83 }
84
85 inline qreal roundUpPower10(qreal value) const {
86 return qPow(10.0, (qreal)qCeil(log10(value))) / 10.0;
87 }
88
89 inline qreal roundDownPower10(qreal value) const {
90 return qPow(10.0, (qreal)qFloor(log10(value))) / 10.0;
91 }
92
93 struct Private;
94 const QScopedPointer<Private> m_d;
95};
96
97#endif
float value(const T *src, size_t ch)
const int UNIT_SIZE_PIXELS
virtual void mouseMoveEvent(QMouseEvent *mouseEvent) override
qreal roundUpPower10(qreal value) const
qreal roundDownPower10(qreal value) const
qreal widgetToValue(qreal position) const
virtual void mousePressEvent(QMouseEvent *mouseEvent) override
qreal valueToWidget(qreal value) const
valueToWidgetOffset
qreal pixelsPerStep(const qreal step) const
void paintEvent(QPaintEvent *e) override
qreal pixelsToValueOffset(const int pixels) const
int valueToPixelOffset(const qreal value) const
void valueOffsetChanged(qreal offset)
void scaleChanged(qreal scale)
const QScopedPointer< Private > m_d
void setValueOffset(qreal valueOffset)
void zoomToFitRange(qreal min, qreal max)