KOffice – TDE office suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

kis_wet_palette_widget.cc 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. * This file is part of Chalk
  3. *
  4. * Copyright (c) 1999 Matthias Elter (me@kde.org)
  5. * Copyright (c) 2001-2002 Igor Jansen (rm@kde.org)
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  20. */
  21. #include <tqpushbutton.h>
  22. #include <tqapplication.h>
  23. #include <tqclipboard.h>
  24. #include <tqcolor.h>
  25. #include <tqdrawutil.h>
  26. #include <tqhbox.h>
  27. #include <tqlabel.h>
  28. #include <tqlayout.h>
  29. #include <tqpainter.h>
  30. #include <tqspinbox.h>
  31. #include <tqstyle.h>
  32. #include <tqtooltip.h>
  33. #include <tdelocale.h>
  34. #include <knuminput.h>
  35. #include <koFrameButton.h>
  36. #include <kis_meta_registry.h>
  37. #include <kis_factory.h>
  38. #include <kis_canvas_subject.h>
  39. #include <kis_colorspace_factory_registry.h>
  40. #include <kis_color.h>
  41. #include <kis_color_cup.h>
  42. #include "kis_wet_colorspace.h"
  43. #include "kis_wet_palette_widget.h"
  44. KisWetPaletteWidget::KisWetPaletteWidget(TQWidget *parent, const char *name) : super(parent, name)
  45. {
  46. m_subject = 0;
  47. TQVBoxLayout * vl = new TQVBoxLayout(this, 0, -1, "main layout");
  48. TQGridLayout * l = new TQGridLayout(vl, 2, 8, 2, "color wells grid");
  49. KisColorCup * b;
  50. int WIDTH = 24;
  51. int HEIGHT = 24;
  52. b = new KisColorCup(this);
  53. b->setColor( TQColor(240, 32, 160) );
  54. l->addWidget(b, 0, 0);
  55. TQToolTip::add(b, i18n("Quinacridone Rose"));
  56. b->setFixedSize(WIDTH, HEIGHT);
  57. connect(b, TQT_SIGNAL(changed(const TQColor &)), TQT_SLOT(slotFGColorSelected(const TQColor &)));
  58. b = new KisColorCup(this);
  59. b->setColor(TQColor(159, 88, 43));
  60. l->addWidget(b, 0, 1);
  61. TQToolTip::add(b,i18n("Indian Red"));
  62. b->setFixedSize(WIDTH, HEIGHT);
  63. connect(b, TQT_SIGNAL(changed(const TQColor &)), TQT_SLOT(slotFGColorSelected(const TQColor &)));
  64. b = new KisColorCup(this);
  65. b->setColor( TQColor(254, 220, 64) );
  66. l->addWidget(b, 0, 2);
  67. TQToolTip::add(b,i18n("Cadmium Yellow"));
  68. b->setFixedSize(WIDTH, HEIGHT);
  69. connect(b, TQT_SIGNAL(changed(const TQColor &)), TQT_SLOT(slotFGColorSelected(const TQColor &)));
  70. b = new KisColorCup(this);
  71. b->setColor(TQColor(36, 180, 32));
  72. l->addWidget(b, 0, 3);
  73. TQToolTip::add(b,i18n("Hookers Green"));
  74. b->setFixedSize(WIDTH, HEIGHT);
  75. connect(b, TQT_SIGNAL(changed(const TQColor &)), TQT_SLOT(slotFGColorSelected(const TQColor &)));
  76. b = new KisColorCup(this);
  77. b->setColor(TQColor(16, 185, 215));
  78. l->addWidget(b, 0, 4);
  79. TQToolTip::add(b,i18n("Cerulean Blue"));
  80. b->setFixedSize(WIDTH, HEIGHT);
  81. connect(b, TQT_SIGNAL(changed(const TQColor &)), TQT_SLOT(slotFGColorSelected(const TQColor &)));
  82. b = new KisColorCup(this);
  83. b->setColor(TQColor(96, 32, 8));
  84. l->addWidget(b, 0, 5);
  85. TQToolTip::add(b,i18n("Burnt Umber"));
  86. b->setFixedSize(WIDTH, HEIGHT);
  87. connect(b, TQT_SIGNAL(changed(const TQColor &)), TQT_SLOT(slotFGColorSelected(const TQColor &)));
  88. b = new KisColorCup(this);
  89. b->setColor(TQColor(254, 96, 8));
  90. l->addWidget(b, 0, 6);
  91. TQToolTip::add(b,i18n("Cadmium Red"));
  92. b->setFixedSize(WIDTH, HEIGHT);
  93. connect(b, TQT_SIGNAL(changed(const TQColor &)), TQT_SLOT(slotFGColorSelected(const TQColor &)));
  94. b = new KisColorCup(this);
  95. b->setColor(TQColor(255, 136, 8));
  96. l->addWidget(b, 0, 7);
  97. TQToolTip::add(b,i18n("Brilliant Orange"));
  98. b->setFixedSize(WIDTH, HEIGHT);
  99. connect(b, TQT_SIGNAL(changed(const TQColor &)), TQT_SLOT(slotFGColorSelected(const TQColor &)));
  100. b = new KisColorCup(this);
  101. b->setColor(TQColor(240, 199, 8));
  102. l->addWidget(b, 1, 0);
  103. TQToolTip::add(b,i18n("Hansa Yellow"));
  104. b->setFixedSize(WIDTH, HEIGHT);
  105. connect(b, TQT_SIGNAL(changed(const TQColor &)), TQT_SLOT(slotFGColorSelected(const TQColor &)));
  106. b = new KisColorCup(this);
  107. b->setColor(TQColor(96, 170, 130));
  108. l->addWidget(b, 1, 1);
  109. TQToolTip::add(b,i18n("Phthalo Green"));
  110. b->setFixedSize(WIDTH, HEIGHT);
  111. connect(b, TQT_SIGNAL(changed(const TQColor &)), TQT_SLOT(slotFGColorSelected(const TQColor &)));
  112. b = new KisColorCup(this);
  113. b->setColor(TQColor(48, 32, 170));
  114. l->addWidget(b, 1, 2);
  115. TQToolTip::add(b,i18n("French Ultramarine"));
  116. b->setFixedSize(WIDTH, HEIGHT);
  117. connect(b, TQT_SIGNAL(changed(const TQColor &)), TQT_SLOT(slotFGColorSelected(const TQColor &)));
  118. b = new KisColorCup(this);
  119. b->setColor(TQColor(118, 16, 135));
  120. l->addWidget(b, 1, 3);
  121. TQToolTip::add(b,i18n("Interference Lilac"));
  122. b->setFixedSize(WIDTH, HEIGHT);
  123. connect(b, TQT_SIGNAL(changed(const TQColor &)), TQT_SLOT(slotFGColorSelected(const TQColor &)));
  124. b = new KisColorCup(this);
  125. b->setColor(TQColor(254, 254, 254));
  126. l->addWidget(b, 1, 4);
  127. TQToolTip::add(b,i18n("Titanium White"));
  128. b->setFixedSize(WIDTH, HEIGHT);
  129. connect(b, TQT_SIGNAL(changed(const TQColor &)), TQT_SLOT(slotFGColorSelected(const TQColor &)));
  130. b = new KisColorCup(this);
  131. b->setColor(TQColor(64, 64, 74));
  132. l->addWidget(b, 1, 5);
  133. TQToolTip::add(b,i18n("Ivory Black"));
  134. b->setFixedSize(WIDTH, HEIGHT);
  135. connect(b, TQT_SIGNAL(changed(const TQColor &)), TQT_SLOT(slotFGColorSelected(const TQColor &)));
  136. b = new KisColorCup(this);
  137. b->setColor(TQColor(255, 255, 255));
  138. l->addWidget(b, 1, 6);
  139. TQToolTip::add(b,i18n("Pure Water"));
  140. b->setFixedSize(WIDTH, HEIGHT);
  141. connect(b, TQT_SIGNAL(changed(const TQColor &)), TQT_SLOT(slotFGColorSelected(const TQColor &)));
  142. TQGridLayout * g2 = new TQGridLayout(vl, 2, 2);
  143. TQLabel * label = new TQLabel(i18n("Paint strength:"), this);
  144. g2->addWidget(label, 0, 0);
  145. m_strength = new KDoubleNumInput(0.0, 2.0, 1.0, 0.1, 1, this);
  146. m_strength->setRange(0.0, 2.0, 0.1, true);
  147. connect(m_strength, TQT_SIGNAL(valueChanged(double)), this, TQT_SLOT(slotStrengthChanged(double)));
  148. g2->addWidget(m_strength, 0, 1);
  149. label = new TQLabel(i18n("Wetness:"), this);
  150. g2->addWidget(label, 1, 0);
  151. m_wetness = new KIntNumInput(16, this);
  152. connect(m_wetness, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotWetnessChanged(int)));
  153. m_wetness->setRange(0, 16, true);
  154. g2->addWidget(m_wetness, 1, 1);
  155. g2->addItem(new TQSpacerItem(1, 1, TQSizePolicy::Expanding, TQSizePolicy::Minimum));
  156. }
  157. void KisWetPaletteWidget::update(KisCanvasSubject *subject)
  158. {
  159. m_subject = subject;
  160. }
  161. void KisWetPaletteWidget::slotFGColorSelected(const TQColor& c)
  162. {
  163. KisWetColorSpace* cs = dynamic_cast<KisWetColorSpace*>(KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("WET", ""), ""));
  164. Q_ASSERT(cs);
  165. WetPack pack;
  166. TQ_UINT8* data = reinterpret_cast< TQ_UINT8*>(&pack);
  167. cs->fromTQColor(c, data);
  168. pack.paint.w = 15 * m_wetness->value();
  169. // upscale from double to uint16:
  170. pack.paint.h = static_cast< TQ_UINT16>(m_strength->value() * (double)(0xffff/2));
  171. KisColor color(data, cs);
  172. if(m_subject)
  173. m_subject->setFGColor(color);
  174. }
  175. void KisWetPaletteWidget::slotWetnessChanged(int n)
  176. {
  177. if (!m_subject)
  178. return;
  179. KisWetColorSpace* cs = dynamic_cast<KisWetColorSpace*>(KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("WET", ""), ""));
  180. Q_ASSERT(cs);
  181. KisColor color = m_subject->fgColor();
  182. color.convertTo(cs);
  183. WetPack pack = *(reinterpret_cast<WetPack*>(color.data()));
  184. pack.paint.w = 15 * n;
  185. color.setColor(reinterpret_cast< TQ_UINT8*>(&pack), cs);
  186. m_subject->setFGColor(color);
  187. }
  188. void KisWetPaletteWidget::slotStrengthChanged(double n)
  189. {
  190. if (!m_subject)
  191. return;
  192. KisWetColorSpace* cs = dynamic_cast<KisWetColorSpace*>(
  193. KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("WET", ""), ""));
  194. Q_ASSERT(cs);
  195. KisColor color = m_subject->fgColor();
  196. color.convertTo(cs);
  197. WetPack pack = *(reinterpret_cast<WetPack*>(color.data()));
  198. pack.paint.h = static_cast< TQ_UINT16>(n * (double)(0xffff/2)); // upscale from double to uint16
  199. color.setColor(reinterpret_cast< TQ_UINT8*>(&pack), cs);
  200. m_subject->setFGColor(color);
  201. }
  202. #include "kis_wet_palette_widget.moc"