20 #include <tqpainter.h>
21 #include "kcolordrag.h"
23 static const char *
const color_mime_string =
"application/x-color";
24 static const char *
const text_mime_string =
"text/plain";
28 : TQStoredDrag( color_mime_string, dragsource, name)
34 : TQStoredDrag( color_mime_string, dragsource, name)
42 TQColorDrag tmp(color, 0, 0);
43 setEncodedData(tmp.encodedData(color_mime_string));
45 TQPixmap colorpix( 25, 20);
46 colorpix.fill( color);
47 TQPainter p( &colorpix );
49 p.drawRect(0,0,25,20);
51 setPixmap(colorpix, TQPoint(-5,-7));
54 const char *KColorDrag::format(
int i)
const
57 return text_mime_string;
59 return TQStoredDrag::format(i);
62 TQByteArray KColorDrag::encodedData (
const char * m )
const
64 if (!qstrcmp(m, text_mime_string) )
67 TQColorDrag::decode(
const_cast<KColorDrag *
>(
this), color);
68 TQCString result = TQString(color.name()).latin1();
69 ((TQByteArray&)result).resize(result.length());
72 return TQStoredDrag::encodedData(m);
78 if (e->provides(color_mime_string))
80 if (e->provides(text_mime_string))
91 if (TQColorDrag::decode(e, color))
94 TQByteArray data = e->encodedData( text_mime_string);
95 TQString colorName = TQString::fromLatin1(data.data(), data.size());
96 if ((colorName.length() < 4) || (colorName[0] !=
'#'))
98 color.setNamedColor(colorName);
99 return color.isValid();
109 void KColorDrag::virtual_hook(
int,
void* )
112 #include "kcolordrag.moc"
A drag-and-drop object for colors.
static bool decode(TQMimeSource *e, TQColor &col)
Decodes the MIME source e and puts the resulting color into col.
static bool canDecode(TQMimeSource *e)
Returns true if the MIME source e contains a color object.
static KColorDrag * makeDrag(const TQColor &, TQWidget *dragsource) TDE_DEPRECATED
KColorDrag(TQWidget *dragsource=0, const char *name=0)
Constructs a color drag with a white color.
void setColor(const TQColor &col)
Sets the color of the drag to col.