Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

...
 
Commits (17)
......@@ -91,6 +91,9 @@ void KisStopGradientEditor::setCompactMode(bool value)
lblName->setVisible(!value);
buttonReverse->setVisible(!value);
nameedit->setVisible(!value);
foregroundRadioButton->setVisible(!value);
backgroundRadioButton->setVisible(!value);
colorRadioButton->setVisible(!value);
buttonReverseSecond->setVisible(value);
}
......
......@@ -5,3 +5,4 @@ add_subdirectory(screentone)
if(SeExpr2_FOUND)
add_subdirectory(seexpr)
endif()
add_subdirectory(multigridpattern)
set(kritamultigridpatterngenerator_SOURCES
multigridpatterngenerator.cpp
kis_wdg_multigrid_pattern.cpp
)
ki18n_wrap_ui(kritamultigridpatterngenerator_SOURCES
wdgmultigridpatternoptions.ui
)
add_library(kritamultigridpatterngenerator MODULE ${kritamultigridpatterngenerator_SOURCES})
target_link_libraries(kritamultigridpatterngenerator kritaui)
install(TARGETS kritamultigridpatterngenerator DESTINATION ${KRITA_PLUGIN_INSTALL_DIR})
/*
* This file is part of Krita
*
* Copyright (c) 2020 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kis_wdg_multigrid_pattern.h"
#include <QLayout>
#include <QDomDocument>
#include <QDomElement>
#include <KoColor.h>
#include <filter/kis_filter_configuration.h>
#include "ui_wdgmultigridpatternoptions.h"
KisWdgMultigridPattern::KisWdgMultigridPattern(QWidget* parent, const KoColorSpace *cs)
: KisConfigWidget(parent)
{
m_widget = new Ui_WdgMultigridPatternOptions();
m_widget->setupUi(this);
m_cs = cs;
QLinearGradient grad;
grad.setColorAt(0, Qt::green);
grad.setColorAt(1.0, Qt::blue);
m_gradient = KoStopGradient::fromQGradient(&grad);
widget()->wdgGradient->setGradient(m_gradient);
widget()->wdgGradient->setCompactMode(true);
widget()->sldDivisions->setRange(0, 100);
widget()->sldDivisions->setPrefix(i18n("Divisions:"));
widget()->sldDimensions->setRange(3, 36);
widget()->sldDimensions->setPrefix(i18nc("The Dimensions of Multigrid pattern generator", "Dimensions:"));
widget()->sldOffset->setRange(0.01, 0.49, 2);
widget()->sldOffset->setPrefix(i18n("Offset:"));
widget()->sldColorRatio->setRange(-2.0, 2.0, 2);
widget()->sldColorRatio->setPrefix(i18n("Ratio:"));
widget()->sldColorIndex->setRange(-2.0, 2.0, 2);
widget()->sldColorIndex->setPrefix(i18n("Index:"));
widget()->sldColorIntersect->setRange(-2.0, 2.0, 2);
widget()->sldColorIntersect->setPrefix(i18n("Intersect:"));
widget()->cmbConnectorType->addItem(i18n("No Connectors"));
widget()->cmbConnectorType->addItem(i18n("Acute Angles"));
widget()->cmbConnectorType->addItem(i18n("Obtuse Angles"));
widget()->cmbConnectorType->addItem(i18n("Cross Shape"));
widget()->cmbConnectorType->addItem(i18n("Center Dot"));
widget()->cmbConnectorType->addItem(i18n("Corner Dot"));
connect(m_widget->sldDivisions, SIGNAL(valueChanged(int)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->sldDimensions, SIGNAL(valueChanged(int)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->sldOffset, SIGNAL(valueChanged(qreal)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->sldColorIndex, SIGNAL(valueChanged(qreal)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->sldColorRatio, SIGNAL(valueChanged(qreal)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->sldColorIntersect, SIGNAL(valueChanged(qreal)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->wdgGradient, SIGNAL(sigGradientChanged()), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->spnLineWidth, SIGNAL(valueChanged(int)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->bnLineColor, SIGNAL(changed(const KoColor&)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->spnConnectorWidth, SIGNAL(valueChanged(int)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->bnConnectorColor, SIGNAL(changed(const KoColor&)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->cmbConnectorType, SIGNAL(currentIndexChanged(int)), this, SIGNAL(sigConfigurationUpdated()));
}
KisWdgMultigridPattern::~KisWdgMultigridPattern()
{
delete m_widget;
}
void KisWdgMultigridPattern::setConfiguration(const KisPropertiesConfigurationSP config)
{
if (config->hasProperty("gradientXML")) {
QDomDocument doc;
doc.setContent(config->getString("gradientXML", ""));
KoStopGradient gradient = KoStopGradient::fromXML(doc.firstChildElement());
if (gradient.stops().size() > 0) {
m_gradient->setStops(gradient.stops());
}
widget()->wdgGradient->setGradient(m_gradient);
}
KoColor c = config->getColor("lineColor");
c.convertTo(m_cs);
widget()->bnLineColor->setColor(c);
widget()->spnLineWidth->setValue(config->getInt("lineWidth", 1));
widget()->sldDivisions->setValue(config->getInt("divisions", 1));
widget()->sldDimensions->setValue(config->getInt("dimensions", 5));
widget()->sldOffset->setValue(config->getFloat("offset", 0.2));
widget()->sldColorIndex->setValue(config->getFloat("colorIndex", 1.0));
widget()->sldColorRatio->setValue(config->getFloat("colorRatio", 0.0));
widget()->sldColorIntersect->setValue(config->getFloat("colorIntersect", 0.0));
c = config->getColor("connectorColor");
c.convertTo(m_cs);
widget()->bnConnectorColor->setColor(c);
widget()->cmbConnectorType->setCurrentIndex(config->getInt("connectorType", 1));
widget()->spnConnectorWidth->setValue(config->getInt("connectorWidth", 1));
}
KisPropertiesConfigurationSP KisWdgMultigridPattern::configuration() const
{
KisFilterConfigurationSP config = new KisFilterConfiguration("multigrid", 1);
if (m_gradient) {
QDomDocument doc;
QDomElement elt = doc.createElement("gradient");
m_gradient->toXML(doc, elt);
doc.appendChild(elt);
config->setProperty("gradientXML", doc.toString());
}
QVariant v;
KoColor c;
c.fromKoColor(widget()->bnLineColor->color());
v.setValue(c);
config->setProperty("lineColor", v);
config->setProperty("lineWidth", widget()->spnLineWidth->value());
config->setProperty("divisions", widget()->sldDivisions->value());
config->setProperty("dimensions", widget()->sldDimensions->value());
config->setProperty("offset", widget()->sldOffset->value());
config->setProperty("colorRatio", widget()->sldColorRatio->value());
config->setProperty("colorIndex", widget()->sldColorIndex->value());
config->setProperty("colorIntersect", widget()->sldColorIntersect->value());
c.fromKoColor(widget()->bnConnectorColor->color());
v.setValue(c);
config->setProperty("connectorColor", v);
config->setProperty("connectorType", widget()->cmbConnectorType->currentIndex());
config->setProperty("connectorWidth", widget()->spnConnectorWidth->value());
return config;
}
/*
* This file is part of Krita
*
* Copyright (c) 2020 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KIS_WDG_MULTIGRID_PATTERN_H
#define KIS_WDG_MULTIGRID_PATTERN_H
#include <kis_config_widget.h>
#include <KoColorSpace.h>
#include <KoColorSpaceRegistry.h>
#include <KoStopGradient.h>
class Ui_WdgMultigridPatternOptions;
class KisWdgMultigridPattern : public KisConfigWidget
{
Q_OBJECT
public:
KisWdgMultigridPattern(QWidget* parent = 0, const KoColorSpace *cs = KoColorSpaceRegistry::instance()->rgb8());
~KisWdgMultigridPattern() override;
public:
inline const Ui_WdgMultigridPatternOptions* widget() const {
return m_widget;
}
void setConfiguration(const KisPropertiesConfigurationSP) override;
KisPropertiesConfigurationSP configuration() const override;
private:
Ui_WdgMultigridPatternOptions* m_widget;
const KoColorSpace *m_cs;
KoStopGradient *m_gradient;
};
#endif
{
"Id": "Multigrid Pattern Generator",
"Type": "Service",
"X-KDE-Library": "kritamultigridpatterngenerator",
"X-KDE-ServiceTypes": [
"Krita/Generator"
],
"X-Krita-Version": "28"
}
/*
* This file is part of Krita
*
* Copyright (c) 2020 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef MULTIGRID_PATTERN_GENERATOR_H
#define MULTIGRID_PATTERN_GENERATOR_H
#include <QObject>
#include <QVariant>
#include "generator/kis_generator.h"
class KisConfigWidget;
/*
* This is de Bruijn's 1981 multigrid approach for generating aperiodic tilings
* of the plane with rhombs. At dimensions 5, offset .2 and .4 this generator
* makes penrose tilings.
* Other configurations show up in nature as quasicrystals.
*
* Based off the explaination of the algorithm here:
* http://www.physics.emory.edu/faculty/weeks//software/exquasi.html
* With extra explaination here: https://www.schoengeometry.com/c-infintil.html
*/
class KritaMultigridPatternGenerator : public QObject
{
Q_OBJECT
public:
KritaMultigridPatternGenerator(QObject *parent, const QVariantList &);
~KritaMultigridPatternGenerator() override;
};
struct KisMultiGridRhomb {
QPolygonF shape;
int parallel1;
int parallel2;
int line1;
int line2;
};
class KisMultigridPatternGenerator : public KisGenerator
{
public:
enum Connector{
None,
Acute,
Obtuse,
Cross,
CenterDot,
CornerDot
};
KisMultigridPatternGenerator();
using KisGenerator::generate;
void generate(KisProcessingInformation dst,
const QSize& size,
const KisFilterConfigurationSP config,
KoUpdater* progressUpdater
) const override;
static inline KoID id() {
return KoID("multigrid", i18n("Multigrid"));
}
KisFilterConfigurationSP defaultConfiguration() const override;
KisConfigWidget * createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP dev, bool useForMasks) const override;
// XXX: Fix the generation to work with tiles
virtual bool allowsSplittingIntoPatches() const override { return false; }
private:
QList<KisMultiGridRhomb> generateRhombs(int lines, int divisions, qreal offset) const;
QList<int> getIndicesFromPoint(QPointF point, QList<qreal> angles, qreal offset) const;
/**
* Projects the 5d vertice to a point.
*/
QPointF getVertice(QList<int> indices, QList<qreal> angles) const;
};
#endif
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>WdgMultigridPatternOptions</class>
<widget class="QWidget" name="WdgMultigridPatternOptions">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>243</width>
<height>407</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tabShapes">
<attribute name="title">
<string>Shapes</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="KisSliderSpinBox" name="sldDimensions" native="true"/>
</item>
<item>
<widget class="KisSliderSpinBox" name="sldDivisions" native="true"/>
</item>
<item>
<widget class="KisDoubleSliderSpinBox" name="sldOffset" native="true"/>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabLines">
<attribute name="title">
<string>Lines</string>
</attribute>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Line Width:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spnLineWidth"/>
</item>
<item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="gbConnector">
<property name="title">
<string>Connector Lines</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Type:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="cmbConnectorType"/>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spnConnectorWidth"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Width:</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabColor">
<attribute name="title">
<string>Colors</string>
</attribute>
<layout class="QFormLayout" name="formLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Lines: </string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="KisColorButton" name="bnLineColor"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Connector:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="KisColorButton" name="bnConnectorColor">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="KisStopGradientEditor" name="wdgGradient" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QGroupBox" name="gbColors">
<property name="title">
<string>Color Factors</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="1" column="0" colspan="2">
<widget class="KisDoubleSliderSpinBox" name="sldColorRatio" native="true"/>
</item>
<item row="2" column="0" colspan="2">
<widget class="KisDoubleSliderSpinBox" name="sldColorIntersect" native="true"/>
</item>
<item row="3" column="0" colspan="2">
<widget class="KisDoubleSliderSpinBox" name="sldColorIndex" native="true"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KisStopGradientEditor</class>
<extends>QWidget</extends>
<header>kis_stopgradient_editor.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>KisDoubleSliderSpinBox</class>
<extends>QWidget</extends>
<header>kis_slider_spin_box.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>KisColorButton</class>
<extends>QPushButton</extends>
<header>kis_color_button.h</header>
</customwidget>
<customwidget>
<class>KisSliderSpinBox</class>
<extends>QWidget</extends>
<header location="global">kis_slider_spin_box.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>