Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ColorWidget] Add CMYK support #57361

Merged
merged 12 commits into from
May 23, 2024
40 changes: 40 additions & 0 deletions src/gui/qgscompoundcolorwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ QgsCompoundColorWidget::QgsCompoundColorWidget( QWidget *parent, const QColor &c
connect( mRedRadio, &QRadioButton::toggled, this, &QgsCompoundColorWidget::mRedRadio_toggled );
connect( mGreenRadio, &QRadioButton::toggled, this, &QgsCompoundColorWidget::mGreenRadio_toggled );
connect( mBlueRadio, &QRadioButton::toggled, this, &QgsCompoundColorWidget::mBlueRadio_toggled );
connect( mCyanRadio, &QRadioButton::toggled, this, &QgsCompoundColorWidget::mCyanRadio_toggled );
connect( mMagentaRadio, &QRadioButton::toggled, this, &QgsCompoundColorWidget::mMagentaRadio_toggled );
connect( mYellowRadio, &QRadioButton::toggled, this, &QgsCompoundColorWidget::mYellowRadio_toggled );
connect( mBlackRadio, &QRadioButton::toggled, this, &QgsCompoundColorWidget::mBlackRadio_toggled );
connect( mAddColorToSchemeButton, &QPushButton::clicked, this, &QgsCompoundColorWidget::mAddColorToSchemeButton_clicked );
connect( mAddCustomColorButton, &QPushButton::clicked, this, &QgsCompoundColorWidget::mAddCustomColorButton_clicked );
connect( mSampleButton, &QPushButton::clicked, this, &QgsCompoundColorWidget::mSampleButton_clicked );
Expand Down Expand Up @@ -936,6 +940,42 @@ void QgsCompoundColorWidget::mBlueRadio_toggled( bool checked )
}
}

void QgsCompoundColorWidget::mCyanRadio_toggled( bool checked )
{
if ( checked )
{
mColorBox->setComponent( QgsColorWidget::Cyan );
mVerticalRamp->setComponent( QgsColorWidget::Cyan );
}
}

void QgsCompoundColorWidget::mMagentaRadio_toggled( bool checked )
{
if ( checked )
{
mColorBox->setComponent( QgsColorWidget::Magenta );
mVerticalRamp->setComponent( QgsColorWidget::Magenta );
}
}

void QgsCompoundColorWidget::mYellowRadio_toggled( bool checked )
{
if ( checked )
{
mColorBox->setComponent( QgsColorWidget::Yellow );
mVerticalRamp->setComponent( QgsColorWidget::Yellow );
}
}

void QgsCompoundColorWidget::mBlackRadio_toggled( bool checked )
{
if ( checked )
{
mColorBox->setComponent( QgsColorWidget::Black );
mVerticalRamp->setComponent( QgsColorWidget::Black );
}
}

void QgsCompoundColorWidget::mAddColorToSchemeButton_clicked()
{
mSchemeList->addColor( mColorPreview->color(), QgsSymbolLayerUtils::colorToName( mColorPreview->color() ) );
Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgscompoundcolorwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ class GUI_EXPORT QgsCompoundColorWidget : public QgsPanelWidget, private Ui::Qgs
void mRedRadio_toggled( bool checked );
void mGreenRadio_toggled( bool checked );
void mBlueRadio_toggled( bool checked );
void mCyanRadio_toggled( bool checked );
void mMagentaRadio_toggled( bool checked );
void mYellowRadio_toggled( bool checked );
void mBlackRadio_toggled( bool checked );

void mAddColorToSchemeButton_clicked();

Expand Down
33 changes: 11 additions & 22 deletions src/ui/qgscompoundcolorwidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@
<item row="0" column="0">
<widget class="QTabWidget" name="mTabWidget">
<property name="currentIndex">
<number>2</number>
<number>0</number>
</property>
<property name="iconSize">
<size>
Expand Down Expand Up @@ -701,18 +701,7 @@
</widget>
</item>
<item>
<widget class="QComboBox" name="mColorModel">
<item>
<property name="text">
<string>RGB</string>
</property>
</item>
<item>
<property name="text">
<string>CMYK</string>
</property>
</item>
</widget>
<widget class="QComboBox" name="mColorModel"/>
</item>
<item>
<spacer name="horizontalSpacer_2">
Expand Down Expand Up @@ -894,7 +883,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_14" stretch="0,0,1">
<item>
<widget class="QRadioButton" name="mCyan">
<widget class="QRadioButton" name="mCyanRadio">
<property name="text">
<string/>
</property>
Expand All @@ -915,7 +904,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_16" stretch="0,0,1">
<item>
<widget class="QRadioButton" name="mMagenta">
<widget class="QRadioButton" name="mMagentaRadio">
<property name="text">
<string/>
</property>
Expand All @@ -936,7 +925,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_26" stretch="0,0,1">
<item>
<widget class="QRadioButton" name="mYellow">
<widget class="QRadioButton" name="mYellowRadio">
<property name="text">
<string/>
</property>
Expand All @@ -957,7 +946,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_27" stretch="0,0,1">
<item>
<widget class="QRadioButton" name="mBlack">
<widget class="QRadioButton" name="mBlackRadio">
<property name="text">
<string/>
</property>
Expand Down Expand Up @@ -1091,17 +1080,17 @@
</action>
</widget>
<customwidgets>
<customwidget>
<class>QgsSpinBox</class>
<extends>QSpinBox</extends>
<header>qgsspinbox.h</header>
</customwidget>
<customwidget>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsSpinBox</class>
<extends>QSpinBox</extends>
<header>qgsspinbox.h</header>
</customwidget>
<customwidget>
<class>QgsColorBox</class>
<extends>QWidget</extends>
Expand Down
35 changes: 35 additions & 0 deletions tests/src/gui/testqgscompoundcolorwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "qgstest.h"

#include "qgscompoundcolorwidget.h"
#include "qgssettings.h"

class TestQgsCompoundColorWidget : public QgsTest
{
Expand All @@ -31,6 +32,7 @@ class TestQgsCompoundColorWidget : public QgsTest
void init();// will be called before each testfunction is executed.
void cleanup();// will be called after every testfunction.
void testCmykConversion();
void testComponentChange();
};

void TestQgsCompoundColorWidget::initTestCase()
Expand Down Expand Up @@ -88,5 +90,38 @@ void TestQgsCompoundColorWidget::testCmykConversion()
QCOMPARE( w.color(), QColor::fromCmyk( 170, 85, 0, 225, 50 ) );
}

void TestQgsCompoundColorWidget::testComponentChange()
{
QgsSettings().setValue( QStringLiteral( "Windows/ColorDialog/activeComponent" ), 3 );

QgsCompoundColorWidget w( nullptr, QColor( 10, 20, 30, 50 ) );
w.setVisible( true );

QCOMPARE( w.mColorBox->component(), QgsColorWidget::Red );
QCOMPARE( w.mVerticalRamp->component(), QgsColorWidget::Red );

const QList<QPair<QRadioButton *, QgsColorWidget::ColorComponent>> colors =
{
{ w.mHueRadio, QgsColorWidget::Hue },
{ w.mSaturationRadio, QgsColorWidget::Saturation },
{ w.mValueRadio, QgsColorWidget::Value },
{ w.mRedRadio, QgsColorWidget::Red },
{ w.mGreenRadio, QgsColorWidget::Green },
{ w.mBlueRadio, QgsColorWidget::Blue },
{ w.mCyanRadio, QgsColorWidget::Cyan },
{ w.mMagentaRadio, QgsColorWidget::Magenta },
{ w.mYellowRadio, QgsColorWidget::Yellow },
{ w.mBlackRadio, QgsColorWidget::Black }
};

for ( QPair<QRadioButton *, QgsColorWidget::ColorComponent> color : colors )
{
color.first->setChecked( true );
QCOMPARE( w.mColorBox->component(), color.second );
QCOMPARE( w.mVerticalRamp->component(), color.second );
}

}

QGSTEST_MAIN( TestQgsCompoundColorWidget )
#include "testqgscompoundcolorwidget.moc"