Krita Source Code Documentation
Loading...
Searching...
No Matches
DlgColorRange Class Reference

#include <dlg_colorrange.h>

+ Inheritance diagram for DlgColorRange:

Public Member Functions

 DlgColorRange (KisViewManager *viewManager, QWidget *parent=0)
 
 ~DlgColorRange () override
 
- Public Member Functions inherited from KoDialog
QPushButton * button (ButtonCode id) const
 
QIcon buttonIcon (ButtonCode id) const
 
QString buttonText (ButtonCode id) const
 
QString buttonToolTip (ButtonCode id) const
 
QString buttonWhatsThis (ButtonCode id) const
 
ButtonCode defaultButton () const
 
QString helpLinkText () const
 
void incrementInitialSize (const QSize &size)
 
bool isButtonEnabled (ButtonCode id) const
 
 KoDialog (QWidget *parent=0, Qt::WindowFlags f=Qt::WindowFlags())
 
QWidget * mainWidget ()
 
QSize minimumSizeHint () const override
 
void setButtonFocus (ButtonCode id)
 
void setButtonGuiItem (ButtonCode id, const KGuiItem &item)
 
void setButtonIcon (ButtonCode id, const QIcon &icon)
 
void setButtons (ButtonCodes buttonMask)
 
void setButtonsOrientation (Qt::Orientation orientation)
 
void setButtonText (ButtonCode id, const QString &text)
 
void setButtonToolTip (ButtonCode id, const QString &text)
 
void setButtonWhatsThis (ButtonCode id, const QString &text)
 
void setDefaultButton (ButtonCode id)
 
void setEscapeButton (ButtonCode id)
 
void setInitialSize (const QSize &size)
 
void setMainWidget (QWidget *widget)
 
void showButton (ButtonCode id, bool state)
 
void showButtonSeparator (bool state)
 
QSize sizeHint () const override
 
 ~KoDialog () override
 

Private Slots

void cancelClicked ()
 
void okClicked ()
 
void slotAdd (bool on)
 
void slotDeselectClicked ()
 
void slotInvertClicked ()
 
void slotSelectClicked ()
 
void slotSelectionTypeChanged (int index)
 
void slotSubtract (bool on)
 

Private Member Functions

QImage createMask (KisSelectionSP selection, KisPaintDeviceSP layer)
 

Private Attributes

enumAction m_currentAction
 
bool m_invert
 
SelectionAction m_mode
 
QCursor m_oldCursor
 
WdgColorRangem_page
 
int m_selectionCommandsAdded
 
KisViewManagerm_viewManager
 

Additional Inherited Members

- Public Types inherited from KoDialog
enum  ButtonCode {
  None = 0x00000000 , Help = 0x00000001 , Default = 0x00000002 , Ok = 0x00000004 ,
  Apply = 0x00000008 , Try = 0x00000010 , Cancel = 0x00000020 , Close = 0x00000040 ,
  No = 0x00000080 , Yes = 0x00000100 , Reset = 0x00000200 , Details = 0x00000400 ,
  User1 = 0x00001000 , User2 = 0x00002000 , User3 = 0x00004000 , NoDefault = 0x00008000
}
 
enum  ButtonPopupMode { InstantPopup = 0 , DelayedPopup = 1 }
 
enum  CaptionFlag { NoCaptionFlags = 0 , AppNameCaption = 1 , ModifiedCaption = 2 , HIGCompliantCaption = AppNameCaption }
 
- Public Slots inherited from KoDialog
void delayedDestruct ()
 
void enableButton (ButtonCode id, bool state)
 
void enableButtonApply (bool state)
 
void enableButtonCancel (bool state)
 
void enableButtonOk (bool state)
 
void enableLinkedHelp (bool state)
 
bool isDetailsWidgetVisible () const
 
virtual void setCaption (const QString &caption)
 
virtual void setCaption (const QString &caption, bool modified)
 
void setDetailsWidget (QWidget *detailsWidget)
 
void setDetailsWidgetVisible (bool visible)
 
void setHelp (const QString &anchor, const QString &appname=QString())
 
void setHelpLinkText (const QString &text)
 
virtual void setPlainCaption (const QString &caption)
 
- Signals inherited from KoDialog
void aboutToShowDetails ()
 
void applyClicked ()
 
void buttonClicked (KoDialog::ButtonCode button)
 
void cancelClicked ()
 
void closeClicked ()
 
void defaultClicked ()
 
void finished ()
 
void helpClicked ()
 
void hidden ()
 
void layoutHintChanged ()
 
void noClicked ()
 
void okClicked ()
 
void resetClicked ()
 
void tryClicked ()
 
void user1Clicked ()
 
void user2Clicked ()
 
void user3Clicked ()
 
void yesClicked ()
 
- Static Public Member Functions inherited from KoDialog
static int groupSpacingHint ()
 
static QString makeStandardCaption (const QString &userCaption, QWidget *window=0, CaptionFlags flags=HIGCompliantCaption)
 
static int marginHint ()
 
static void resizeLayout (QLayout *lay, int margin, int spacing)
 
static void resizeLayout (QWidget *widget, int margin, int spacing)
 
static int spacingHint ()
 
- Protected Slots inherited from KoDialog
virtual void slotButtonClicked (int button)
 
- Protected Member Functions inherited from KoDialog
void closeEvent (QCloseEvent *e) override
 
void hideEvent (QHideEvent *) override
 
void keyPressEvent (QKeyEvent *) override
 
void showEvent (QShowEvent *e) override
 

Detailed Description

This dialog allows the user to create a selection mask based on a (range of) colors.

Definition at line 51 of file dlg_colorrange.h.

Constructor & Destructor Documentation

◆ DlgColorRange()

DlgColorRange::DlgColorRange ( KisViewManager * viewManager,
QWidget * parent = 0 )

Definition at line 43 of file dlg_colorrange.cc.

44 : KoDialog(parent)
46 , m_viewManager(viewManager)
47{
48 setCaption(i18n("Color Range"));
51
52 m_page = new WdgColorRange(this);
53 Q_CHECK_PTR(m_page);
54 m_page->setObjectName("color_range");
55
56 setCaption(i18n("Color Range"));
58 resize(m_page->sizeHint());
59
60 m_page->intFuzziness->setObjectName("fuzziness");
61 m_page->intFuzziness->setRange(0, 200);
62 m_page->intFuzziness->setSingleStep(10);
63 m_page->intFuzziness->setValue(100);
64
65 m_invert = false;
68
69 connect(this, SIGNAL(okClicked()),
70 this, SLOT(okClicked()));
71
72 connect(this, SIGNAL(cancelClicked()),
73 this, SLOT(cancelClicked()));
74
75 connect(m_page->chkInvert, SIGNAL(clicked()),
76 this, SLOT(slotInvertClicked()));
77
78 connect(m_page->cmbSelect, SIGNAL(activated(int)),
79 this, SLOT(slotSelectionTypeChanged(int)));
80
81 connect(m_page->radioAdd, SIGNAL(toggled(bool)),
82 this, SLOT(slotAdd(bool)));
83
84 connect(m_page->radioSubtract, SIGNAL(toggled(bool)),
85 this, SLOT(slotSubtract(bool)));
86
87 connect(m_page->bnSelect, SIGNAL(clicked()),
88 this, SLOT(slotSelectClicked()));
89
90 connect(m_page->bnDeselect, SIGNAL(clicked()),
91 this, SLOT(slotDeselectClicked()));
92
93 m_page->bnDeselect->setEnabled(false);
94
95}
@ SELECTION_ADD
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void slotAdd(bool on)
int m_selectionCommandsAdded
void slotSelectionTypeChanged(int index)
void slotSubtract(bool on)
WdgColorRange * m_page
KisViewManager * m_viewManager
void slotDeselectClicked()
enumAction m_currentAction
SelectionAction m_mode
void setMainWidget(QWidget *widget)
Definition KoDialog.cpp:354
virtual void setCaption(const QString &caption)
Definition KoDialog.cpp:498
void setButtons(ButtonCodes buttonMask)
Definition KoDialog.cpp:195
void setDefaultButton(ButtonCode id)
Definition KoDialog.cpp:302
@ Ok
Show Ok button. (this button accept()s the dialog; result set to QDialog::Accepted)
Definition KoDialog.h:127
@ Cancel
Show Cancel-button. (this button reject()s the dialog; result set to QDialog::Rejected)
Definition KoDialog.h:130
KoDialog(QWidget *parent=0, Qt::WindowFlags f=Qt::WindowFlags())
Definition KoDialog.cpp:176
@ REDS

References KoDialog::Cancel, cancelClicked(), connect(), m_currentAction, m_invert, m_mode, m_page, KoDialog::Ok, okClicked(), REDS, SELECTION_ADD, KoDialog::setButtons(), KoDialog::setCaption(), KoDialog::setDefaultButton(), KoDialog::setMainWidget(), slotAdd(), slotDeselectClicked(), slotInvertClicked(), slotSelectClicked(), slotSelectionTypeChanged(), and slotSubtract().

◆ ~DlgColorRange()

DlgColorRange::~DlgColorRange ( )
override

Definition at line 97 of file dlg_colorrange.cc.

98{
99 delete m_page;
100}

References m_page.

Member Function Documentation

◆ cancelClicked

void DlgColorRange::cancelClicked ( )
privateslot

Definition at line 107 of file dlg_colorrange.cc.

108{
109 if (!m_viewManager) return;
110 if (!m_viewManager->image()) return;
111
112 for (int i = 0; i < m_selectionCommandsAdded; i++) {
114 }
115 m_viewManager->canvas()->update();
116 reject();
117}
virtual void undoLastCommand()=0
KisUndoAdapter * undoAdapter()
The undo adapter is used to add commands to the undo stack.
QWidget * canvas() const
Return the actual widget that is displaying the current image.
KisImageWSP image() const
Return the image this view is displaying.

References KisViewManager::canvas(), KisViewManager::image(), m_selectionCommandsAdded, m_viewManager, KisViewManager::undoAdapter(), and KisUndoAdapter::undoLastCommand().

◆ createMask()

QImage DlgColorRange::createMask ( KisSelectionSP selection,
KisPaintDeviceSP layer )
private

◆ okClicked

void DlgColorRange::okClicked ( )
privateslot

Definition at line 102 of file dlg_colorrange.cc.

103{
104 accept();
105}

◆ slotAdd

void DlgColorRange::slotAdd ( bool on)
privateslot

Definition at line 135 of file dlg_colorrange.cc.

136{
137 if (on)
139}

References m_mode, and SELECTION_ADD.

◆ slotDeselectClicked

void DlgColorRange::slotDeselectClicked ( )
privateslot

Definition at line 250 of file dlg_colorrange.cc.

251{
252 if (!m_viewManager) return;
253
254
258 m_page->bnDeselect->setEnabled(false);
259 }
260}

References m_page, m_selectionCommandsAdded, m_viewManager, KisViewManager::undoAdapter(), and KisUndoAdapter::undoLastCommand().

◆ slotInvertClicked

void DlgColorRange::slotInvertClicked ( )
privateslot

Definition at line 119 of file dlg_colorrange.cc.

120{
121 m_invert = m_page->chkInvert->isChecked();
122}

References m_invert, and m_page.

◆ slotSelectClicked

void DlgColorRange::slotSelectClicked ( )
privateslot

Definition at line 141 of file dlg_colorrange.cc.

142{
145
146 QRect rc = m_viewManager->image()->bounds();
147
148 if (rc.isEmpty()) return;
149
150 KisCursorOverrideLock cursorLock(KisCursor::waitCursor());
151
152 qint32 x, y, w, h;
153 rc.getRect(&x, &y, &w, &h);
154
157
158 KoColor match;
159 switch (m_currentAction) {
160 case REDS:
161 match = KoColor(QColor(Qt::red), cs);
162 break;
163 case YELLOWS:
164 match = KoColor(QColor(Qt::yellow), cs);
165 break;
166 case GREENS:
167 match = KoColor(QColor(Qt::green), cs);
168 break;
169 case CYANS:
170 match = KoColor(QColor(Qt::cyan), cs);
171 break;
172 case BLUES:
173 match = KoColor(QColor(Qt::blue), cs);
174 break;
175 case MAGENTAS:
176 match = KoColor(QColor(Qt::magenta), cs);
177 break;
178 default:
179 ;
180 };
181
182 int fuzziness = m_page->intFuzziness->value();
183
186
188 KisHLineIteratorSP selIter = selection->pixelSelection()->createHLineIteratorNG(x, y, w);
189
190 for (int row = y; row < h - y; ++row) {
191 do {
192 // Don't try to select transparent pixels.
193 if (cs->opacityU8(hiter->oldRawData()) > OPACITY_TRANSPARENT_U8) {
194
195 bool selected = false;
196
197 KoColor c(hiter->oldRawData(), cs);
199 c.convertTo(lab);
200 quint8 L = lab->scaleToU8(c.data(), 0);
201
202 switch (m_currentAction) {
203 case HIGHLIGHTS:
204 selected = (L > MAX_SELECTED - fuzziness);
205 break;
206 case MIDTONES:
207 selected = (L > MAX_SELECTED / 2 - fuzziness && L < MAX_SELECTED / 2 + fuzziness);
208 break;
209 case SHADOWS:
210 selected = (L < MIN_SELECTED + fuzziness);
211 break;
212 default:
213 ;
214 }
215 }
216 else {
217 quint8 difference = cs->difference(match.data(), c.data());
218 selected = (difference <= fuzziness);
219 }
220
221 if (selected) {
222 if (!m_invert) {
223 if (m_mode == SELECTION_ADD) {
224 *(selIter->rawData()) = MAX_SELECTED;
225 } else if (m_mode == SELECTION_SUBTRACT) {
226 *(selIter->rawData()) = MIN_SELECTED;
227 }
228 } else {
229 if (m_mode == SELECTION_ADD) {
230 *(selIter->rawData()) = MIN_SELECTED;
231 } else if (m_mode == SELECTION_SUBTRACT) {
232 *(selIter->rawData()) = MAX_SELECTED;
233 }
234 }
235 }
236 }
237 } while (hiter->nextPixel() && selIter->nextPixel());
238 hiter->nextRow();
239 selIter->nextRow();
240 }
241
243 KisSelectionToolHelper helper(m_viewManager->canvasBase(), kundo2_i18n("Color Range Selection"));
244 helper.selectPixelSelection(selection->pixelSelection(), m_mode);
245
246 m_page->bnDeselect->setEnabled(true);
248}
@ SELECTION_SUBTRACT
const quint8 OPACITY_TRANSPARENT_U8
virtual const quint8 * oldRawData() const =0
virtual bool nextPixel()=0
static QCursor waitCursor()
Definition kis_cursor.cc:54
virtual void nextRow()=0
QRect bounds() const override
KisHLineIteratorSP createHLineIteratorNG(qint32 x, qint32 y, qint32 w)
const KoColorSpace * colorSpace() const
KisHLineConstIteratorSP createHLineConstIteratorNG(qint32 x, qint32 y, qint32 w) const
KisCanvas2 * canvasBase() const
Return the canvas base class.
KisPaintDeviceSP activeDevice()
Convenience method to get at the active paint device.
virtual quint8 difference(const quint8 *src1, const quint8 *src2) const =0
virtual quint8 scaleToU8(const quint8 *srcPixel, qint32 channelPos) const =0
virtual quint8 opacityU8(const quint8 *pixel) const =0
quint8 * data()
Definition KoColor.h:144
@ CYANS
@ BLUES
@ SHADOWS
@ MAGENTAS
@ MIDTONES
@ YELLOWS
@ GREENS
@ HIGHLIGHTS
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75
const quint8 MAX_SELECTED
Definition kis_global.h:32
const quint8 MIN_SELECTED
Definition kis_global.h:33
QSharedPointer< T > toQShared(T *ptr)
KUndo2MagicString kundo2_i18n(const char *text)
KisPixelSelectionSP pixelSelection
const KoColorSpace * lab16(const QString &profileName=QString())
static KoColorSpaceRegistry * instance()

References KisViewManager::activeDevice(), BLUES, KisImage::bounds(), KisViewManager::canvasBase(), KisPaintDevice::colorSpace(), KoColor::convertTo(), KisPaintDevice::createHLineConstIteratorNG(), KisPaintDevice::createHLineIteratorNG(), CYANS, KoColor::data(), KoColorSpace::difference(), GREENS, HIGHLIGHTS, KisViewManager::image(), KoColorSpaceRegistry::instance(), KisPixelSelection::invalidateOutlineCache(), KIS_ASSERT_RECOVER_RETURN, kundo2_i18n(), KoColorSpaceRegistry::lab16(), m_currentAction, m_invert, m_mode, m_page, m_selectionCommandsAdded, m_viewManager, MAGENTAS, MAX_SELECTED, MIDTONES, MIN_SELECTED, KisBaseConstIteratorNG::nextPixel(), KisHLineConstIteratorNG::nextRow(), KisBaseConstAccessor::oldRawData(), OPACITY_TRANSPARENT_U8, KoColorSpace::opacityU8(), KisSelection::pixelSelection, REDS, KoColorSpace::scaleToU8(), SELECTION_ADD, SELECTION_SUBTRACT, KisSelectionToolHelper::selectPixelSelection(), SHADOWS, toQShared(), KisCursor::waitCursor(), and YELLOWS.

◆ slotSelectionTypeChanged

void DlgColorRange::slotSelectionTypeChanged ( int index)
privateslot

Definition at line 124 of file dlg_colorrange.cc.

125{
127}
enumAction

References m_currentAction.

◆ slotSubtract

void DlgColorRange::slotSubtract ( bool on)
privateslot

Definition at line 129 of file dlg_colorrange.cc.

130{
131 if (on)
133}

References m_mode, and SELECTION_SUBTRACT.

Member Data Documentation

◆ m_currentAction

enumAction DlgColorRange::m_currentAction
private

Definition at line 83 of file dlg_colorrange.h.

◆ m_invert

bool DlgColorRange::m_invert
private

Definition at line 84 of file dlg_colorrange.h.

◆ m_mode

SelectionAction DlgColorRange::m_mode
private

Definition at line 81 of file dlg_colorrange.h.

◆ m_oldCursor

QCursor DlgColorRange::m_oldCursor
private

Definition at line 82 of file dlg_colorrange.h.

◆ m_page

WdgColorRange* DlgColorRange::m_page
private

Definition at line 78 of file dlg_colorrange.h.

◆ m_selectionCommandsAdded

int DlgColorRange::m_selectionCommandsAdded
private

Definition at line 79 of file dlg_colorrange.h.

◆ m_viewManager

KisViewManager* DlgColorRange::m_viewManager
private

Definition at line 80 of file dlg_colorrange.h.


The documentation for this class was generated from the following files: