From 8362bf63dea22bbf6736609b0f49c152f975eb63 Mon Sep 17 00:00:00 2001 From: tpearson Date: Wed, 20 Jan 2010 01:29:50 +0000 Subject: Added old abandoned KDE3 version of koffice git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- krita/plugins/tools/tool_selectsimilar/Makefile.am | 31 + .../tool_selectsimilar/kis_tool_selectsimilar.cc | 271 +++ .../tool_selectsimilar/kis_tool_selectsimilar.h | 101 + .../kritatoolselectsimilar.desktop | 43 + .../tools/tool_selectsimilar/selectsimilar.cc | 61 + .../tools/tool_selectsimilar/selectsimilar.h | 34 + .../tool_selectsimilar/tool_similar_selection.png | Bin 0 -> 723 bytes .../tool_selectsimilar/tool_similar_selection.svg | 2118 ++++++++++++++++++++ .../tool_similar_selection_minus_cursor.png | Bin 0 -> 612 bytes .../tool_similar_selection_plus_cursor.png | Bin 0 -> 629 bytes 10 files changed, 2659 insertions(+) create mode 100644 krita/plugins/tools/tool_selectsimilar/Makefile.am create mode 100644 krita/plugins/tools/tool_selectsimilar/kis_tool_selectsimilar.cc create mode 100644 krita/plugins/tools/tool_selectsimilar/kis_tool_selectsimilar.h create mode 100644 krita/plugins/tools/tool_selectsimilar/kritatoolselectsimilar.desktop create mode 100644 krita/plugins/tools/tool_selectsimilar/selectsimilar.cc create mode 100644 krita/plugins/tools/tool_selectsimilar/selectsimilar.h create mode 100644 krita/plugins/tools/tool_selectsimilar/tool_similar_selection.png create mode 100644 krita/plugins/tools/tool_selectsimilar/tool_similar_selection.svg create mode 100644 krita/plugins/tools/tool_selectsimilar/tool_similar_selection_minus_cursor.png create mode 100644 krita/plugins/tools/tool_selectsimilar/tool_similar_selection_plus_cursor.png (limited to 'krita/plugins/tools/tool_selectsimilar') diff --git a/krita/plugins/tools/tool_selectsimilar/Makefile.am b/krita/plugins/tools/tool_selectsimilar/Makefile.am new file mode 100644 index 00000000..d92642c1 --- /dev/null +++ b/krita/plugins/tools/tool_selectsimilar/Makefile.am @@ -0,0 +1,31 @@ +kde_services_DATA = kritatoolselectsimilar.desktop + +INCLUDES = -I$(srcdir)/../../../sdk \ + -I$(srcdir)/../../../core \ + -I$(srcdir)/../../../kritacolor/ \ + -I$(srcdir)/../../../ui \ + -I$/../../../ui \ + $(KOFFICE_INCLUDES) \ + $(all_includes) + + +kritatoolselectsimilar_la_SOURCES = selectsimilar.cc kis_tool_selectsimilar.cc +noinst_HEADERS = selectsimilar.h kis_tool_selectsimilar.h + +kde_module_LTLIBRARIES = kritatoolselectsimilar.la + +kritatoolselectsimilar_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +kritatoolselectsimilar_la_LIBADD = ../../../libkritacommon.la + +kritatoolselectsimilar_la_METASOURCES = AUTO + +KDE_OPTIONS = nofinal + +# directory for pixmaps +kritapics_DATA = \ + tool_similar_selection.png \ + tool_similar_selection_plus_cursor.png \ + tool_similar_selection_minus_cursor.png + +kritapicsdir = $(kde_datadir)/krita/pics + diff --git a/krita/plugins/tools/tool_selectsimilar/kis_tool_selectsimilar.cc b/krita/plugins/tools/tool_selectsimilar/kis_tool_selectsimilar.cc new file mode 100644 index 00000000..cdb38cb3 --- /dev/null +++ b/krita/plugins/tools/tool_selectsimilar/kis_tool_selectsimilar.cc @@ -0,0 +1,271 @@ +/* + * Copyright (c) 1999 Matthias Elter + * Copyright (c) 2002 Patrick Julien + * Copyright (c) 2005 Boudewijn Rempt + * + * 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 +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kis_tool_selectsimilar.h" + +void selectByColor(KisPaintDeviceSP dev, KisSelectionSP selection, const Q_UINT8 * c, int fuzziness, enumSelectionMode mode) +{ + // XXX: Multithread this! + Q_INT32 x, y, w, h; + + dev->exactBounds(x, y, w, h); + + KisColorSpace * cs = dev->colorSpace(); + + for (int y2 = y; y2 < y + h; ++y2) { + KisHLineIterator hiter = dev->createHLineIterator(x, y2, w, false); + KisHLineIterator selIter = selection->createHLineIterator(x, y2, w, true); + while (!hiter.isDone()) { + //if (dev->colorSpace()->hasAlpha()) + // opacity = dev->colorSpace()->getAlpha(hiter.rawData()); + + Q_UINT8 match = cs->difference(c, hiter.rawData()); + + if (mode == SELECTION_ADD) { + if (match <= fuzziness) { + *(selIter.rawData()) = MAX_SELECTED; + } + } + else if (mode == SELECTION_SUBTRACT) { + if (match <= fuzziness) { + *(selIter.rawData()) = MIN_SELECTED; + } + } + ++hiter; + ++selIter; + } + } + +} + + + +KisToolSelectSimilar::KisToolSelectSimilar() + : super(i18n("Select Similar Colors")) +{ + setName("tool_select_similar"); + m_addCursor = KisCursor::load("tool_similar_selection_plus_cursor.png", 1, 21); + m_subtractCursor = KisCursor::load("tool_similar_selection_minus_cursor.png", 1, 21); + setCursor(m_addCursor); + m_subject = 0; + m_optWidget = 0; + m_selectionOptionsWidget = 0; + m_fuzziness = 20; + m_currentSelectAction = m_defaultSelectAction = SELECTION_ADD; + m_timer = new QTimer(this); + connect(m_timer, SIGNAL(timeout()), SLOT(slotTimer()) ); +} + +KisToolSelectSimilar::~KisToolSelectSimilar() +{ +} + +void KisToolSelectSimilar::activate() +{ + KisToolNonPaint::activate(); + m_timer->start(50); + setPickerCursor(m_currentSelectAction); + + if (m_selectionOptionsWidget) { + m_selectionOptionsWidget->slotActivated(); + } +} + +void KisToolSelectSimilar::deactivate() +{ + m_timer->stop(); +} + +void KisToolSelectSimilar::buttonPress(KisButtonPressEvent *e) +{ + + if (m_subject) { + QApplication::setOverrideCursor(KisCursor::waitCursor()); + KisImageSP img; + KisPaintDeviceSP dev; + QPoint pos; + Q_UINT8 opacity = OPACITY_OPAQUE; + + if (e->button() != QMouseEvent::LeftButton && e->button() != QMouseEvent::RightButton) + return; + + if (!(img = m_subject->currentImg())) + return; + + dev = img->activeDevice(); + + if (!dev || !img->activeLayer()->visible()) + return; + + pos = QPoint(e->pos().floorX(), e->pos().floorY()); + KisSelectedTransaction *t = 0; + if (img->undo()) t = new KisSelectedTransaction(i18n("Similar Selection"),dev); + + KisColor c = dev->colorAt(pos.x(), pos.y()); + opacity = dev->colorSpace()->getAlpha(c.data()); + + // XXX we should make this configurable: "allow to select transparent" + // if (opacity > OPACITY_TRANSPARENT) + selectByColor(dev, dev->selection(), c.data(), m_fuzziness, m_currentSelectAction); + + dev->setDirty(); + dev->emitSelectionChanged(); + + if(img->undo()) + img->undoAdapter()->addCommand(t); + m_subject->canvasController()->updateCanvas(); + + QApplication::restoreOverrideCursor(); + } +} + +void KisToolSelectSimilar::slotTimer() +{ +#if KDE_IS_VERSION(3,4,0) + int state = kapp->keyboardMouseState() & (Qt::ShiftButton|Qt::ControlButton|Qt::AltButton); +#else + int state = kapp->keyboardModifiers() & (KApplication::ShiftModifier + |KApplication::ControlModifier|KApplication::Modifier1); +#endif + enumSelectionMode action; + + if (state == Qt::ShiftButton) + action = SELECTION_ADD; + else if (state == Qt::ControlButton) + action = SELECTION_SUBTRACT; + else + action = m_defaultSelectAction; + + if (action != m_currentSelectAction) { + m_currentSelectAction = action; + setPickerCursor(action); + } +} + +void KisToolSelectSimilar::setPickerCursor(enumSelectionMode action) +{ + switch (action) { + case SELECTION_ADD: + m_subject->canvasController()->setCanvasCursor(m_addCursor); + break; + case SELECTION_SUBTRACT: + m_subject->canvasController()->setCanvasCursor(m_subtractCursor); + } +} + +void KisToolSelectSimilar::setup(KActionCollection *collection) +{ + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + m_action = new KRadioAction(i18n("&Similar Selection"), "tool_similar_selection", "Ctrl+E", this, SLOT(activate()), collection, name()); + Q_CHECK_PTR(m_action); + m_action->setToolTip(i18n("Select similar colors")); + m_action->setExclusiveGroup("tools"); + m_ownAction = true; + } +} + +void KisToolSelectSimilar::update(KisCanvasSubject *subject) +{ + super::update(subject); + m_subject = subject; +} + +void KisToolSelectSimilar::slotSetFuzziness(int fuzziness) +{ + m_fuzziness = fuzziness; +} + +void KisToolSelectSimilar::slotSetAction(int action) +{ + m_defaultSelectAction = (enumSelectionMode)action; +} + +QWidget* KisToolSelectSimilar::createOptionWidget(QWidget* parent) +{ + m_optWidget = new QWidget(parent); + Q_CHECK_PTR(m_optWidget); + + m_optWidget->setCaption(i18n("Similar Selection")); + + QVBoxLayout * l = new QVBoxLayout(m_optWidget, 0, 6); + Q_CHECK_PTR(l); + + m_selectionOptionsWidget = new KisSelectionOptions(m_optWidget, m_subject); + Q_CHECK_PTR(m_selectionOptionsWidget); + + l->addWidget(m_selectionOptionsWidget); + connect (m_selectionOptionsWidget, SIGNAL(actionChanged(int)), this, SLOT(slotSetAction(int))); + + QHBoxLayout * hbox = new QHBoxLayout(l); + Q_CHECK_PTR(hbox); + + QLabel * lbl = new QLabel(i18n("Fuzziness: "), m_optWidget); + Q_CHECK_PTR(lbl); + + hbox->addWidget(lbl); + + KIntNumInput * input = new KIntNumInput(m_optWidget, "fuzziness"); + Q_CHECK_PTR(input); + + input->setRange(0, 200, 10, true); + input->setValue(20); + hbox->addWidget(input); + connect(input, SIGNAL(valueChanged(int)), this, SLOT(slotSetFuzziness(int))); + + l->addItem(new QSpacerItem(1, 1, QSizePolicy::Fixed, QSizePolicy::Expanding)); + + return m_optWidget; +} + +QWidget* KisToolSelectSimilar::optionWidget() +{ + return m_optWidget; +} + +#include "kis_tool_selectsimilar.moc" diff --git a/krita/plugins/tools/tool_selectsimilar/kis_tool_selectsimilar.h b/krita/plugins/tools/tool_selectsimilar/kis_tool_selectsimilar.h new file mode 100644 index 00000000..10a57dd3 --- /dev/null +++ b/krita/plugins/tools/tool_selectsimilar/kis_tool_selectsimilar.h @@ -0,0 +1,101 @@ +/* + * Copyright (c) 1999 Matthias Elter + * Copyright (c) 2002 Patrick Julien + * 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_TOOL_SELECT_PICKER_H_ +#define KIS_TOOL_SELECT_PICKER_H_ + +#include +#include +#include + +class KisCanvasSubject; +class QWidget; +class QVBoxLayout; +class QCheckBox; +class KisIntSpinbox; + +/** + * Tool to select colours by pointing at a color on the image. + * TODO: + * Implement shift/shift-ctrl keyboard shortcuts for + * temporary add/subtract selection mode. + */ + +class KisSelectionOptions; + +class KisToolSelectSimilar : public KisToolNonPaint { + + Q_OBJECT + typedef KisToolNonPaint super; + +public: + KisToolSelectSimilar(); + virtual ~KisToolSelectSimilar(); + + virtual void update(KisCanvasSubject *subject); + virtual void setup(KActionCollection *collection); + virtual Q_UINT32 priority() { return 8; } + virtual enumToolType toolType() { return TOOL_SELECT; } + +public slots: + + void activate(); + void deactivate(); + + virtual void slotSetFuzziness(int); + virtual void slotSetAction(int); + +private: + virtual QWidget* createOptionWidget(QWidget* parent); + virtual QWidget* optionWidget(); + + virtual void buttonPress(KisButtonPressEvent *e); + void setPickerCursor(enumSelectionMode); + + KisCanvasSubject *m_subject; + QWidget *m_optWidget; + KisSelectionOptions *m_selectionOptionsWidget; + + int m_fuzziness; + enumSelectionMode m_defaultSelectAction; + enumSelectionMode m_currentSelectAction; + QTimer *m_timer; + QCursor m_addCursor; + QCursor m_subtractCursor; + +private slots: + void slotTimer(); +}; + +class KisToolSelectSimilarFactory : public KisToolFactory { + typedef KisToolFactory super; +public: + KisToolSelectSimilarFactory() : super() {}; + virtual ~KisToolSelectSimilarFactory(){}; + + virtual KisTool * createTool(KActionCollection * ac) { + KisTool * t = new KisToolSelectSimilar(); + Q_CHECK_PTR(t); + t->setup(ac); + return t; + } + virtual KisID id() { return KisID("selectsimilar", i18n("Select Similar")); } +}; + + +#endif // KIS_TOOL_SELECT_PICKER_H_ + diff --git a/krita/plugins/tools/tool_selectsimilar/kritatoolselectsimilar.desktop b/krita/plugins/tools/tool_selectsimilar/kritatoolselectsimilar.desktop new file mode 100644 index 00000000..a4c48d51 --- /dev/null +++ b/krita/plugins/tools/tool_selectsimilar/kritatoolselectsimilar.desktop @@ -0,0 +1,43 @@ +[Desktop Entry] +Name=Select Similar Colors Tool +Name[bg]=Инструмент за маркиране на подобни цветове +Name[ca]=Selecciona eines de colors similars +Name[cy]=Offer Detholi Lliwiau Tebyg +Name[da]=Vælg lignende farve-værktøjer +Name[de]="Auswahl nach ähnlichen Farben"-Werkzeug +Name[el]=Εργαλείο επιλογής παρόμοιων χρωμάτων +Name[en_GB]=Select Similar Colours Tool +Name[eo]=Similkolorelekto-ilo +Name[es]=Herramienta de selección de colores similares +Name[et]=Sarnase värvi valimise tööriist +Name[fa]=برگزیدن ابزار رنگهای مشابه +Name[fr]=Outils de sélection des couleurs similaires +Name[fy]=Lykense kleur seleksje ark +Name[gl]=Ferramenta de Selección de Cores Semellantes +Name[he]=בחירת כלי צבעים דומים +Name[hu]=Hasonló színeket kiválasztó eszköz +Name[is]=Velja svipaða liti tól +Name[it]=Strumento per la selezione dei colori simili +Name[ja]=類似色選択ツール +Name[km]=ឧបករណ៍​ជ្រើស​ពណ៌​ស្រដៀង​គ្នា +Name[nb]=Verktøy som velger liknende farger +Name[nds]=Warktüüch för de Utwahl vun lieke Klören +Name[ne]=समान रङ उपकरणहरू चयन गर्नुहोस् +Name[nl]=Gereedschap voor soortgelijke kleuren +Name[pl]=Narzędzie wyboru podobnych kolorów +Name[pt]=Ferramenta de Selecção de Cores Semelhantes +Name[pt_BR]=Ferramenta de Seleção de Cores Semelhantes +Name[ru]=Выделение по цвету +Name[se]=Reaidu mii vállje sullosaš ivnniid +Name[sk]=Výber podobných farieb +Name[sl]=Orodje za izbiro podobnih barv +Name[sr]=Алат за избор сличних боја +Name[sr@Latn]=Alat za izbor sličnih boja +Name[sv]=Välj liknande färg-verktyg +Name[uk]=Засіб вибору подібних кольорів +Name[zh_CN]=选择相似颜色工具 +Name[zh_TW]=選取近似色彩工具 +ServiceTypes=Krita/Tool +Type=Service +X-KDE-Library=kritatoolselectsimilar +X-Krita-Version=2 diff --git a/krita/plugins/tools/tool_selectsimilar/selectsimilar.cc b/krita/plugins/tools/tool_selectsimilar/selectsimilar.cc new file mode 100644 index 00000000..fc6b0c41 --- /dev/null +++ b/krita/plugins/tools/tool_selectsimilar/selectsimilar.cc @@ -0,0 +1,61 @@ +/* + * selectsimilar.h -- Part of Krita + * + * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) + * + * 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 + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "selectsimilar.h" +#include "kis_tool_selectsimilar.h" + +typedef KGenericFactory SelectSimilarFactory; +K_EXPORT_COMPONENT_FACTORY( kritatoolselectsimilar, SelectSimilarFactory( "krita" ) ) + +SelectSimilar::SelectSimilar(QObject *parent, const char *name, const QStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(SelectSimilarFactory::instance()); + + if ( parent->inherits("KisToolRegistry") ) + { + KisToolRegistry * r = dynamic_cast(parent); + r->add(new KisToolSelectSimilarFactory()); + } +} + +SelectSimilar::~SelectSimilar() +{ +} + +#include "selectsimilar.moc" + diff --git a/krita/plugins/tools/tool_selectsimilar/selectsimilar.h b/krita/plugins/tools/tool_selectsimilar/selectsimilar.h new file mode 100644 index 00000000..ca181bcc --- /dev/null +++ b/krita/plugins/tools/tool_selectsimilar/selectsimilar.h @@ -0,0 +1,34 @@ +/* + * selectsimilar.h -- Part of Krita + * + * 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 SELECTSIMILAR_H +#define SELECTSIMILAR_H + +#include + +class SelectSimilar : public KParts::Plugin +{ + Q_OBJECT + public: + SelectSimilar(QObject *parent, const char *name, const QStringList &); + virtual ~SelectSimilar(); + + +}; + +#endif // SELECTSIMILAR_H diff --git a/krita/plugins/tools/tool_selectsimilar/tool_similar_selection.png b/krita/plugins/tools/tool_selectsimilar/tool_similar_selection.png new file mode 100644 index 00000000..fd3ae241 Binary files /dev/null and b/krita/plugins/tools/tool_selectsimilar/tool_similar_selection.png differ diff --git a/krita/plugins/tools/tool_selectsimilar/tool_similar_selection.svg b/krita/plugins/tools/tool_selectsimilar/tool_similar_selection.svg new file mode 100644 index 00000000..371f3860 --- /dev/null +++ b/krita/plugins/tools/tool_selectsimilar/tool_similar_selection.svg @@ -0,0 +1,2118 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/krita/plugins/tools/tool_selectsimilar/tool_similar_selection_minus_cursor.png b/krita/plugins/tools/tool_selectsimilar/tool_similar_selection_minus_cursor.png new file mode 100644 index 00000000..b8bbc131 Binary files /dev/null and b/krita/plugins/tools/tool_selectsimilar/tool_similar_selection_minus_cursor.png differ diff --git a/krita/plugins/tools/tool_selectsimilar/tool_similar_selection_plus_cursor.png b/krita/plugins/tools/tool_selectsimilar/tool_similar_selection_plus_cursor.png new file mode 100644 index 00000000..aed6796f Binary files /dev/null and b/krita/plugins/tools/tool_selectsimilar/tool_similar_selection_plus_cursor.png differ -- cgit v1.2.1