Krita Source Code Documentation
Loading...
Searching...
No Matches
KisSelectionPropertySlider.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2018 Jouni Pentikäinen <joupent@gmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#ifndef KISSELECTIONPROPERTYSLIDER_H
8#define KISSELECTIONPROPERTYSLIDER_H
9
10#include <QObject>
11
12#include <KoShape.h>
13#include <kritaui_export.h>
14#include <kis_signals_blocker.h>
15#include "kis_slider_spin_box.h"
16
18{
19 Q_OBJECT
20
21public:
22 explicit KisSelectionPropertySliderBase(QWidget* parent = 0);
24
36 void setTextTemplates(const QString &normalTemplate, const QString &mixedTemplate);
37
41 void setPrefix(const QString &) = delete;
42
46 void setSuffix(const QString &) = delete;
47
48protected:
49 void setInternalValue(qreal value, bool blockUpdateSignal) override;
50
51 void setSelectionValue(qreal commonValue, bool mixed);
52
53 virtual bool hasSelection() const = 0;
54 virtual qreal getCommonValue() const = 0;
55
56private Q_SLOTS:
57 void slotCompressedUpdate();
58
59private:
60 struct Private;
61 const QScopedPointer<Private> m_d;
62};
63
79template<class T>
81{
82public:
83 explicit KisSelectionPropertySlider(QWidget *parent = 0)
85 {}
86
87 void setValueGetter(qreal (*getter)(T))
88 {
89 m_valueGetter = getter;
90 }
91
92 void setSelection(QList<T> newSelection)
93 {
94 KisSignalsBlocker b(this);
95
96 m_selection = newSelection;
97
98 const qreal commonValue = getCommonValue();
99
100 setEnabled(!m_selection.isEmpty());
101 setSelectionValue(commonValue, commonValue < 0.0);
102 }
103
105 return m_selection;
106 }
107
108protected:
109 bool hasSelection() const override
110 {
111 return !m_selection.isEmpty();
112 }
113
114 qreal getCommonValue() const override
115 {
116 qreal commonValue = -1.0;
117
118 Q_FOREACH (T item, m_selection) {
119 const qreal itemValue = m_valueGetter(item);
120
121 if (commonValue < 0) {
122 commonValue = itemValue;
123 } else if (!qFuzzyCompare(commonValue, itemValue)) {
124 commonValue = -1.0;
125 break;
126 }
127 }
128
129 return commonValue;
130 }
131
132private:
133 qreal (*m_valueGetter)(T) {nullptr};
135};
136
137class KRITAUI_EXPORT KisShapePropertySlider : public KisSelectionPropertySlider<KoShape*>
138{
139public:
140 KisShapePropertySlider(QWidget* parent=nullptr);
141};
142
143#endif
float value(const T *src, size_t ch)
This class is a spinbox in which you can click and drag to set the value. A slider like bar is displa...
virtual void setInternalValue(qreal newValue, bool newBlockUpdateSignal)
void setSuffix(const QString &)=delete
const QScopedPointer< Private > m_d
void setPrefix(const QString &)=delete
virtual bool hasSelection() const =0
virtual qreal getCommonValue() const =0
void setValueGetter(qreal(*getter)(T))
void setSelection(QList< T > newSelection)
static bool qFuzzyCompare(half p1, half p2)