Commit 37d8dec3 authored by Jouni Pentikäinen's avatar Jouni Pentikäinen

Set defaults for cross-channel adjustment curves

Lightness is used as the default driver for all channels. The
configuration UI defaults to showing the first channel with a
curve set, or if no curves are set, saturation.
parent b94dee6c
......@@ -56,11 +56,19 @@
// KisCrossChannelFilterConfiguration
KisCrossChannelFilterConfiguration::KisCrossChannelFilterConfiguration(int channelCount)
: KisMultiChannelFilterConfiguration(channelCount, "crosschannel", 1)
KisCrossChannelFilterConfiguration::KisCrossChannelFilterConfiguration(int channelCount, const KoColorSpace *cs)
: KisMultiChannelFilterConfiguration(channelCount, "crosschannel", 1)
{
init();
m_driverChannels.resize(channelCount);
int defaultDriver = 0;
if (cs) {
QVector<VirtualChannelInfo> virtualChannels = KisMultiChannelFilter::getVirtualChannels(cs);
defaultDriver = qMax(0, KisMultiChannelFilter::findChannel(virtualChannels, VirtualChannelInfo::LIGHTNESS));
}
m_driverChannels.fill(defaultDriver, channelCount);
}
KisCrossChannelFilterConfiguration::~KisCrossChannelFilterConfiguration()
......@@ -119,7 +127,6 @@ KisCubicCurve KisCrossChannelFilterConfiguration::getDefaultCurve()
return KisCubicCurve(points);
}
KisCrossChannelConfigWidget::KisCrossChannelConfigWidget(QWidget * parent, KisPaintDeviceSP dev, Qt::WindowFlags f)
: KisMultiChannelConfigWidget(parent, dev, f)
{
......@@ -152,11 +159,27 @@ void KisCrossChannelConfigWidget::setConfiguration(const KisPropertiesConfigurat
m_driverChannels = cfg->driverChannels();
KisMultiChannelConfigWidget::setConfiguration(config);
// Show the first channel with a curve, or saturation by default
int initialChannel = -1;
for (int i = 0; i < m_virtualChannels.size(); i++) {
if (!m_curves[i].isConstant(0.5)) {
initialChannel = i;
break;
}
}
if (initialChannel < 0) {
initialChannel = qMax(0, KisMultiChannelFilter::findChannel(m_virtualChannels, VirtualChannelInfo::SATURATION));
}
setActiveChannel(initialChannel);
}
KisPropertiesConfigurationSP KisCrossChannelConfigWidget::configuration() const
{
auto *cfg = new KisCrossChannelFilterConfiguration(m_virtualChannels.count());
auto *cfg = new KisCrossChannelFilterConfiguration(m_virtualChannels.count(), m_dev->colorSpace());
KisPropertiesConfigurationSP cfgSP = cfg;
m_curves[m_activeVChannel] = m_page->curveWidget->curve();
......@@ -177,7 +200,7 @@ void KisCrossChannelConfigWidget::updateChannelControls()
KisPropertiesConfigurationSP KisCrossChannelConfigWidget::getDefaultConfiguration()
{
return new KisCrossChannelFilterConfiguration(m_virtualChannels.size());
return new KisCrossChannelFilterConfiguration(m_virtualChannels.size(), m_dev->colorSpace());
}
void KisCrossChannelConfigWidget::slotDriverChannelSelected(int index)
......@@ -205,7 +228,7 @@ KisConfigWidget * KisCrossChannelFilter::createConfigurationWidget(QWidget *pare
KisFilterConfigurationSP KisCrossChannelFilter::factoryConfiguration() const
{
return new KisCrossChannelFilterConfiguration(0);
return new KisCrossChannelFilterConfiguration(0, nullptr);
}
int mapChannel(const VirtualChannelInfo &channel) {
......
......@@ -57,7 +57,8 @@ public:
class KisCrossChannelFilterConfiguration : public KisMultiChannelFilterConfiguration
{
public:
KisCrossChannelFilterConfiguration(int n);
KisCrossChannelFilterConfiguration(int channelCount, const KoColorSpace *cs);
~KisCrossChannelFilterConfiguration() override;
const QVector<int> driverChannels() const;
......
......@@ -104,6 +104,17 @@ QVector<VirtualChannelInfo> KisMultiChannelFilter::getVirtualChannels(const KoCo
return vchannels;
}
int KisMultiChannelFilter::findChannel(const QVector<VirtualChannelInfo> &virtualChannels,
const VirtualChannelInfo::Type &channelType)
{
for (int i = 0; i < virtualChannels.size(); i++) {
if (virtualChannels[i].type() == channelType) {
return i;
}
}
return -1;
}
KisMultiChannelFilterConfiguration::KisMultiChannelFilterConfiguration(int channelCount, const QString & name, qint32 version)
: KisColorTransformationConfiguration(name, version)
......
......@@ -41,6 +41,7 @@ public:
bool needsTransparentPixels(const KisFilterConfigurationSP config, const KoColorSpace *cs) const override;
static QVector<VirtualChannelInfo> getVirtualChannels(const KoColorSpace *cs);
static int findChannel(const QVector<VirtualChannelInfo> &virtualChannels, const VirtualChannelInfo::Type &channelType);
protected:
KisMultiChannelFilter(const KoID &id, const QString &entry);
......@@ -112,6 +113,7 @@ protected Q_SLOTS:
protected:
void init();
void resetCurves();
void setActiveChannel(int ch);
virtual void updateChannelControls() = 0;
virtual KisPropertiesConfigurationSP getDefaultConfiguration() = 0;
......@@ -123,12 +125,9 @@ protected:
int m_activeVChannel = 0;
mutable QList<KisCubicCurve> m_curves;
WdgPerChannel * m_page;
KisPaintDeviceSP m_dev;
WdgPerChannel * m_page;
KisHistogram *m_histogram;
private:
void setActiveChannel(int ch);
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment