diff --git a/libs/ui/KisReferenceImage.h b/libs/ui/KisReferenceImage.h index 99441b44d0..ad8758ece4 100644 --- a/libs/ui/KisReferenceImage.h +++ b/libs/ui/KisReferenceImage.h @@ -1,87 +1,87 @@ /* * Copyright (C) 2017 Boudewijn Rempt * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KISREFERENCEIMAGE_H #define KISREFERENCEIMAGE_H #include #include #include #include #include class QImage; class QPointF; class QPainter; class QRectF; class KoStore; class KisCoordinatesConverter; class KisCanvas2; /** * @brief The KisReferenceImage class represents a single reference image */ class KRITAUI_EXPORT KisReferenceImage : public KoTosContainer { public: - struct SetSaturationCommand : public KUndo2Command { + struct KRITAUI_EXPORT SetSaturationCommand : public KUndo2Command { QVector images; QVector oldSaturations; qreal newSaturation; explicit SetSaturationCommand(const QList &images, qreal newSaturation, KUndo2Command *parent = 0); void undo() override; void redo() override; }; KisReferenceImage(); KisReferenceImage(const KisReferenceImage &rhs); ~KisReferenceImage(); KoShape *cloneShape() const override; static KisReferenceImage * fromFile(const QString &filename); void setImage(QImage image); void setSource(const QString &location); void setPosition(QPointF pos); void setSaturation(qreal saturation); qreal saturation() const; void paint(QPainter &gc, const KoViewConverter &converter, KoShapePaintingContext &paintcontext) override; bool loadOdf(const KoXmlElement &element, KoShapeLoadingContext &context) override { return false; } void saveOdf(KoShapeSavingContext &context) const override {} QColor getPixel(QPointF position); void saveXml(QDomDocument &document, QDomElement &parentElement, int id); bool saveImage(KoStore *store) const; static KisReferenceImage * fromXml(const QDomElement &elem); bool loadImage(KoStore *store); private: struct Private; const QScopedPointer d; }; #endif // KISREFERENCEIMAGE_H diff --git a/libs/ui/widgets/KisSelectionPropertySlider.cpp b/libs/ui/widgets/KisSelectionPropertySlider.cpp index fd65f97794..59f737470d 100644 --- a/libs/ui/widgets/KisSelectionPropertySlider.cpp +++ b/libs/ui/widgets/KisSelectionPropertySlider.cpp @@ -1,85 +1,89 @@ /* * Copyright (C) 2018 Jouni Pentikäinen * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include #include "KisSelectionPropertySlider.h" struct KisSelectionPropertySliderBase::Private { KisSignalCompressor *signalCompressor; QString normalPrefix; QString mixedPrefix; explicit Private(KisSelectionPropertySliderBase *q) : signalCompressor(new KisSignalCompressor(100, KisSignalCompressor::FIRST_ACTIVE, q)) {} }; KisSelectionPropertySliderBase::KisSelectionPropertySliderBase(QWidget *parent) : KisDoubleSliderSpinBox(parent) , m_d(new Private(this)) { connect(m_d->signalCompressor, SIGNAL(timeout()), SLOT(slotCompressedUpdate())); } KisSelectionPropertySliderBase::~KisSelectionPropertySliderBase() {} void KisSelectionPropertySliderBase::setPrefixes(const QString &normalPrefix, const QString &mixedPrefix) { m_d->normalPrefix = normalPrefix; m_d->mixedPrefix = mixedPrefix; setPrefix(normalPrefix); } void KisSelectionPropertySliderBase::setInternalValue(int _value, bool blockUpdateSignal) { static const qreal eps = 1e-3; if (!hasSelection()) return; setPrivateValue(_value); const qreal newValue = value(); const qreal commonValue = getCommonValue(); if (qAbs(commonValue - newValue) < eps) { return; } if(!blockUpdateSignal) { m_d->signalCompressor->start(); } } void KisSelectionPropertySliderBase::slotCompressedUpdate() { emit(valueChanged(value())); } void KisSelectionPropertySliderBase::setSelectionValue(qreal commonValue, bool mixed) { if (mixed) { setValue(0.0); setPrefix(m_d->mixedPrefix); } else { setValue(commonValue); setPrefix(m_d->normalPrefix); } } + +KisShapePropertySlider::KisShapePropertySlider(QWidget *parent) + : KisSelectionPropertySlider::KisSelectionPropertySlider(parent) +{} diff --git a/libs/ui/widgets/KisSelectionPropertySlider.h b/libs/ui/widgets/KisSelectionPropertySlider.h index 962f822e11..608e6b0ca0 100644 --- a/libs/ui/widgets/KisSelectionPropertySlider.h +++ b/libs/ui/widgets/KisSelectionPropertySlider.h @@ -1,131 +1,135 @@ /* * Copyright (C) 2018 Jouni Pentikäinen * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KISSELECTIONPROPERTYSLIDER_H #define KISSELECTIONPROPERTYSLIDER_H #include #include #include #include #include "kis_slider_spin_box.h" class KRITAUI_EXPORT KisSelectionPropertySliderBase : public KisDoubleSliderSpinBox { Q_OBJECT public: explicit KisSelectionPropertySliderBase(QWidget* parent = 0); ~KisSelectionPropertySliderBase() override; void setPrefixes(const QString &normalPrefix, const QString &mixedPrefix); protected: void setInternalValue(int value, bool blockUpdateSignal) override; void setSelectionValue(qreal commonValue, bool mixed); virtual bool hasSelection() const = 0; virtual qreal getCommonValue() const = 0; private Q_SLOTS: void slotCompressedUpdate(); private: struct Private; const QScopedPointer m_d; }; /** * This is a generic slider for adjusting a property across a set of one or * more items such as a selection. * * When using this class, first call the setValueGetter method to allow the * slider to get values from the items. For example: * slider->setValueGetter( * [](KoShape *s) { return s->transparency(); } * ); * * To update the slider, call setSelection with the new set of objects. * * When the slider is dragged, valueChanged(qreal) signals are emitted after * signal compression. */ template class KRITAUI_EXPORT KisSelectionPropertySlider : public KisSelectionPropertySliderBase { public: explicit KisSelectionPropertySlider(QWidget *parent = 0) : KisSelectionPropertySliderBase(parent) {} void setValueGetter(qreal (*getter)(T)) { m_valueGetter = getter; } void setSelection(QList newSelection) { KisSignalsBlocker b(this); m_selection = newSelection; const qreal commonValue = getCommonValue(); setEnabled(!m_selection.isEmpty()); setSelectionValue(commonValue, commonValue < 0.0); } QList selection() const { return m_selection; } protected: bool hasSelection() const override { return !m_selection.isEmpty(); } qreal getCommonValue() const override { qreal commonValue = -1.0; Q_FOREACH (T item, m_selection) { const qreal itemValue = m_valueGetter(item); if (commonValue < 0) { commonValue = itemValue; } else if (!qFuzzyCompare(commonValue, itemValue)) { commonValue = -1.0; break; } } return commonValue; } private: qreal (*m_valueGetter)(T); QList m_selection; }; -using KisShapePropertySlider = KisSelectionPropertySlider; +class KRITAUI_EXPORT KisShapePropertySlider : public KisSelectionPropertySlider +{ +public: + KisShapePropertySlider(QWidget* parent=0); +}; #endif