Skip to content

Commit

Permalink
Merge branch 'kazakov/lager-mypaint-engine-port' into kazakov/lager-b…
Browse files Browse the repository at this point in the history
…ased-brush-editor

# Conflicts:
#	libs/ui/CMakeLists.txt
#	plugins/paintops/libpaintop/KisCurveOptionWidget2.cpp
#	plugins/paintops/libpaintop/KisCurveOptionWidget2.h
  • Loading branch information
dimula73 committed Dec 23, 2022
2 parents b4e34dd + c4a009f commit 9ccb656
Show file tree
Hide file tree
Showing 137 changed files with 4,568 additions and 2,876 deletions.
1 change: 0 additions & 1 deletion libs/brush/KisBrushModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ void BRUSH_EXPORT setEffectiveSizeForBrush(const BrushType type,
qreal BRUSH_EXPORT lightnessModeActivated(BrushType type,
const PredefinedBrushData &predefinedBrush);


}

#endif // KISBRUSHMODEL_H
38 changes: 38 additions & 0 deletions libs/global/KisMpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <tuple>
#include <utility>
#include <optional>

/**
* 'kismpl' stands for kis-meta-program-library
Expand Down Expand Up @@ -137,7 +138,44 @@ struct first_type
template <typename... T>
using first_type_t = typename first_type<T...>::type;

namespace detail {
template <typename Fun, typename T>
struct fold_optional_impl {
std::optional<T> fold(const std::optional<T> &first) {
return first;
}

std::optional<T> fold(const std::optional<T> &first, const std::optional<T> &second) {
if (first && second) {
return m_fun(*first, *second);
} else if (first) {
return first;
} else {
return second;
}
}

template <typename... Rest>
std::optional<T> fold(const std::optional<T> &first, std::optional<T> const &second, const std::optional<Rest> &...rest) {
return fold(fold(first, second), rest...);
}

const Fun m_fun;
};

} // namespace detail

/**
* Folds all the valid optional values using the binary function \p fun into one
* optional value. When none optional values are present, an empty optional of the
* specified type is returned.
*/
template <typename Fun, typename... Args,
typename T = typename first_type_t<std::remove_reference_t<Args>...>::value_type>
std::optional<T> fold_optional(Fun &&fun, Args &&...args) {
return detail::fold_optional_impl<Fun, T>{std::forward<Fun>(fun)}.fold(args...);
}

} // namespace kismpl

#endif // KISMPL_H
26 changes: 26 additions & 0 deletions libs/global/KisZug.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <zug/transducer/map.hpp>
#include <zug/reducing/last.hpp>
#include <lager/lenses.hpp>
#include <lager/reader.hpp>

/**
* kiszug is a namespace extending the functionality of
Expand Down Expand Up @@ -83,6 +84,31 @@ constexpr auto foreach_arg =
});
};

/**
* Fold all valid optional cursors from a set into one by using \p func
*
* Example:
*
* std::optional<lager::reader<int>> brushSize1 = ...;
* std::optional<lager::reader<int>> brushSize2 = ...;
*
* std::optional<lager::reader<int>> maxSize =
* fold_optional_cursors(&std::max, brushSize1, brushSize2);
*
* The resulting reader 'maxSize' will hold the maximum value of the two
* brushes, or nothing if the source readers do not exist.
*/
template <typename Func, typename... Cursors,
typename FirstCursor = typename kismpl::first_type_t<std::remove_reference_t<Cursors>...>::value_type,
typename T = typename FirstCursor::value_type>
std::optional<lager::reader<T>> fold_optional_cursors(const Func &func, Cursors&& ...cursors) {
auto fold_func = [func] (const auto &lhs, const auto &rhs) {
return lager::with(lhs, rhs).map(func);
};

return kismpl::fold_optional(fold_func, cursors...);
}

namespace lenses {
template <typename T>
auto scale = [] (T multiplier) {
Expand Down
20 changes: 20 additions & 0 deletions libs/global/kis_algebra_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,26 @@ T inwardUnitNormal(const T &a, int polygonDirection)
return polygonDirection * leftUnitNormal(a);
}

/**
* Helper function to convert a qreal to int lazily. If the
* passed type is an integer, then the value is rounded.
* Otherwise it is just passed forward.
*/
template<typename R>
R lazyRound(qreal value);

template<>
inline int lazyRound<int>(qreal value)
{
return qRound(value);
}

template<>
inline qreal lazyRound<qreal>(qreal value)
{
return value;
}

/**
* \return 1 if the polygon is counterclockwise
* -1 if the polygon is clockwise
Expand Down
2 changes: 1 addition & 1 deletion libs/image/brushengine/kis_paintop_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class KRITAIMAGE_EXPORT KisPaintOpSettings : public KisPropertiesConfiguration
* Removes all the settings from the object while keeping the paintop id,
* which is loaded to the object by the factory
*/
void resetSettings(const QStringList &preserveProperties = QStringList());
virtual void resetSettings(const QStringList &preserveProperties = QStringList());

/**
* @return the node the paintop is working on.
Expand Down
5 changes: 5 additions & 0 deletions libs/image/kis_cubic_curve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ KisCubicCurve::KisCubicCurve(const QList<QPointF>& points) : d(new Private)
d->data->keepSorted();
}

KisCubicCurve::KisCubicCurve(const QVector<QPointF> &points)
: KisCubicCurve(points.toList())
{
}

KisCubicCurve::KisCubicCurve(const KisCubicCurve& curve)
: d(new Private(*curve.d))
{
Expand Down
1 change: 1 addition & 0 deletions libs/image/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ kis_add_tests(
kis_mesh_transform_worker_test.cpp
KisKeyframeAnimationInterfaceSignalTest.cpp
KisOverlayPaintDeviceWrapperTest.cpp
KisMplTest.cpp
LINK_LIBRARIES kritaimage Qt5::Test
NAME_PREFIX "libs-image-"
)
Expand Down
37 changes: 37 additions & 0 deletions libs/image/tests/KisMplTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* SPDX-FileCopyrightText: 2022 Dmitry Kazakov <[email protected]>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "KisMplTest.h"

#include <simpletest.h>

#include <optional>
#include <QDebug>

#include <KisMpl.h>


void KisMplTest::test()
{
std::optional<int> a(0x1);
std::optional<int> b(0x2);
std::optional<int> c(0x4);
std::optional<int> d;
std::optional<int> e;

QCOMPARE(kismpl::fold_optional(std::plus{}, a, b, c, d, e), std::optional<int>(7));
QCOMPARE(kismpl::fold_optional(std::plus{}, e, a, b, c, d), std::optional<int>(7));
QCOMPARE(kismpl::fold_optional(std::plus{}, d, e, a, b, c), std::optional<int>(7));
QCOMPARE(kismpl::fold_optional(std::plus{}, c, d, e, a, b), std::optional<int>(7));
QCOMPARE(kismpl::fold_optional(std::plus{}, b, c, d, e, a), std::optional<int>(7));

QCOMPARE(kismpl::fold_optional(std::plus{}, b, c, d, e), std::optional<int>(6));
QCOMPARE(kismpl::fold_optional(std::plus{}, c, d, e), std::optional<int>(4));
QCOMPARE(kismpl::fold_optional(std::plus{}, d, e), std::optional<int>());
QCOMPARE(kismpl::fold_optional(std::plus{}, e), std::optional<int>());

}

SIMPLE_TEST_MAIN(KisMplTest)
18 changes: 18 additions & 0 deletions libs/image/tests/KisMplTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* SPDX-FileCopyrightText: 2022 Dmitry Kazakov <[email protected]>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef KISMPLTEST_H
#define KISMPLTEST_H

#include <QtTest/QtTest>

class KisMplTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void test();
};

#endif // KISMPLTEST_H
1 change: 1 addition & 0 deletions libs/ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ set(kritaui_LIB_SRCS
widgets/kis_utility_title_bar.cpp
widgets/kis_curve_widget.cpp
widgets/KisCurveWidgetConnectionHelper.cpp
widgets/KisCurveWidgetControlsManager.cpp
widgets/kis_custom_image_widget.cc
widgets/kis_image_from_clipboard_widget.cpp
widgets/kis_double_widget.cc
Expand Down
20 changes: 13 additions & 7 deletions libs/ui/kis_paintop_option.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,24 @@ void KisPaintOpOption::lodLimitations(KisPaintopLodLimitations *l) const
Q_UNUSED(l);
}

lager::reader<KisPaintopLodLimitations> KisPaintOpOption::effectiveLodLimitations() const
KisPaintOpOption::OptionalLodLimitationsReader KisPaintOpOption::effectiveLodLimitations() const
{
return lager::with(m_d->pageEnabledReader, lodLimitationsReader())
.map([](bool enabled, const KisPaintopLodLimitations &l) {
return enabled ? l : KisPaintopLodLimitations();
});
OptionalLodLimitationsReader reader = lodLimitationsReader();

if (reader) {
reader = lager::with(m_d->pageEnabledReader, *reader)
.map([](bool enabled, const KisPaintopLodLimitations &l) {
return enabled ? l : KisPaintopLodLimitations();
});
}

return reader;
}

lager::reader<KisPaintopLodLimitations> KisPaintOpOption::lodLimitationsReader() const
KisPaintOpOption::OptionalLodLimitationsReader KisPaintOpOption::lodLimitationsReader() const
{
// no limitations by default
return lager::make_constant(KisPaintopLodLimitations());
return std::nullopt;
}

KisPaintOpOption::PaintopCategory KisPaintOpOption::category() const
Expand Down
6 changes: 4 additions & 2 deletions libs/ui/kis_paintop_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class KRITAUI_EXPORT KisPaintOpOption : public QObject
Q_OBJECT
public:

using OptionalLodLimitationsReader = std::optional<lager::reader<KisPaintopLodLimitations>>;

enum PaintopCategory {
GENERAL,
COLOR,
Expand Down Expand Up @@ -82,10 +84,10 @@ class KRITAUI_EXPORT KisPaintOpOption : public QObject
QWidget *configurationPage() const;

virtual void lodLimitations(KisPaintopLodLimitations *l) const;
lager::reader<KisPaintopLodLimitations> effectiveLodLimitations() const;
OptionalLodLimitationsReader effectiveLodLimitations() const;

protected:
virtual lager::reader<KisPaintopLodLimitations> lodLimitationsReader() const;
virtual OptionalLodLimitationsReader lodLimitationsReader() const;
void setConfigurationPage(QWidget *page);

KisResourcesInterfaceSP resourcesInterface() const;
Expand Down
12 changes: 6 additions & 6 deletions libs/ui/kis_paintop_settings_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@
#include <brushengine/kis_paintop_lod_limitations.h>

#include <lager/constant.hpp>
#include <KisZug.h>


struct KisPaintOpSettingsWidget::Private
{
Private()
: lodLimitations(lager::make_constant(KisPaintopLodLimitations()))
{
}

QList<KisPaintOpOption*> paintOpOptions;
KisCategorizedListView* optionsList;
KisPaintOpOptionListModel* model;
QStackedWidget* optionsStack;
lager::reader<KisPaintopLodLimitations> lodLimitations;
std::optional<lager::reader<KisPaintopLodLimitations>> lodLimitations;
};

KisPaintOpSettingsWidget::KisPaintOpSettingsWidget(QWidget * parent)
Expand Down Expand Up @@ -110,10 +110,10 @@ void KisPaintOpSettingsWidget::addPaintOpOption(KisPaintOpOption *option, QStrin
connect(option, SIGNAL(sigSettingChanged()), SIGNAL(sigConfigurationItemChanged()));
m_d->optionsStack->addWidget(option->configurationPage());
m_d->paintOpOptions << option;

m_d->lodLimitations =
lager::with(m_d->lodLimitations,
option->effectiveLodLimitations())
.map(std::bit_or{});
kiszug::fold_optional_cursors(std::bit_or{}, m_d->lodLimitations,
option->effectiveLodLimitations());
}

void KisPaintOpSettingsWidget::setConfiguration(const KisPropertiesConfigurationSP config)
Expand Down Expand Up @@ -164,7 +164,7 @@ KisPaintopLodLimitations KisPaintOpSettingsWidget::lodLimitations() const

lager::reader<KisPaintopLodLimitations> KisPaintOpSettingsWidget::lodLimitationsReader() const
{
return m_d->lodLimitations;
return m_d->lodLimitations.value_or(lager::make_constant(KisPaintopLodLimitations()));
}

lager::reader<qreal> KisPaintOpSettingsWidget::effectiveBrushSize() const
Expand Down
26 changes: 26 additions & 0 deletions libs/ui/kritaui_export_instance.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* SPDX-FileCopyrightText: 2022 L. E. Segovia <[email protected]>
* SPDX-FileCopyrightText: 2022 Dmitry Kazakov <[email protected]>
*
* SPDX-License-Ref: GPL-2.0-or-later
*/

#ifndef KRITAUI_EXPORT_INSTANCE_H
#define KRITAUI_EXPORT_INSTANCE_H

#include "kritaui_export.h"

/* See https://reviews.llvm.org/D61118 */

#if defined(__MINGW64__) || defined(__MINGW32__)
#define KRITAUI_EXPORT_TEMPLATE KRITAUI_EXPORT
#define KRITAUI_EXPORT_INSTANCE
#elif defined(_MSC_VER)
#define KRITAUI_EXPORT_TEMPLATE
#define KRITAUI_EXPORT_INSTANCE KRITAUI_EXPORT
#else
#define KRITAUI_EXPORT_TEMPLATE KRITAUI_EXPORT
#define KRITAUI_EXPORT_INSTANCE KRITAUI_EXPORT
#endif

#endif // KRITAUI_EXPORT_INSTANCE_H
Loading

0 comments on commit 9ccb656

Please sign in to comment.