• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
kcolordrag.cpp
1/* This file is part of the KDE libraries
2 Copyright (C) 1999 Steffen Hansen (hansen@kde.org)
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include <tqpainter.h>
21#include "kcolordrag.h"
22
23static const char * const color_mime_string = "application/x-color";
24static const char * const text_mime_string = "text/plain";
25
26KColorDrag::KColorDrag( const TQColor &color, TQWidget *dragsource,
27 const char *name)
28 : TQStoredDrag( color_mime_string, dragsource, name)
29{
30 setColor( color);
31}
32
33KColorDrag::KColorDrag( TQWidget *dragsource, const char *name)
34 : TQStoredDrag( color_mime_string, dragsource, name)
35{
36 setColor( white );
37}
38
39void
40KColorDrag::setColor( const TQColor &color)
41{
42 TQColorDrag tmp(color, 0, 0);
43 setEncodedData(tmp.encodedData(color_mime_string));
44
45 TQPixmap colorpix( 25, 20);
46 colorpix.fill( color);
47 TQPainter p( &colorpix );
48 p.setPen( black );
49 p.drawRect(0,0,25,20);
50 p.end();
51 setPixmap(colorpix, TQPoint(-5,-7));
52}
53
54const char *KColorDrag::format(int i) const
55{
56 if (i==1)
57 return text_mime_string;
58 else
59 return TQStoredDrag::format(i);
60}
61
62TQByteArray KColorDrag::encodedData ( const char * m ) const
63{
64 if (!qstrcmp(m, text_mime_string) )
65 {
66 TQColor color;
67 TQColorDrag::decode(const_cast<KColorDrag *>(this), color);
68 TQCString result = TQString(color.name()).latin1();
69 ((TQByteArray&)result).resize(result.length());
70 return result;
71 }
72 return TQStoredDrag::encodedData(m);
73}
74
75bool
76KColorDrag::canDecode( TQMimeSource *e)
77{
78 if (e->provides(color_mime_string))
79 return true;
80 if (e->provides(text_mime_string))
81 {
82 TQColor dummy;
83 return decode(e, dummy);
84 }
85 return false;
86}
87
88bool
89KColorDrag::decode( TQMimeSource *e, TQColor &color)
90{
91 if (TQColorDrag::decode(e, color))
92 return true;
93
94 TQByteArray data = e->encodedData( text_mime_string);
95 TQString colorName = TQString::fromLatin1(data.data(), data.size());
96 if ((colorName.length() < 4) || (colorName[0] != '#'))
97 return false;
98 color.setNamedColor(colorName);
99 return color.isValid();
100}
101
102
103KColorDrag*
104KColorDrag::makeDrag( const TQColor &color,TQWidget *dragsource)
105{
106 return new KColorDrag( color, dragsource);
107}
108
109void KColorDrag::virtual_hook( int, void* )
110{ /*BASE::virtual_hook( id, data );*/ }
111
112#include "kcolordrag.moc"
KColorDrag
A drag-and-drop object for colors.
Definition: kcolordrag.h:36
KColorDrag::decode
static bool decode(TQMimeSource *e, TQColor &col)
Decodes the MIME source e and puts the resulting color into col.
Definition: kcolordrag.cpp:89
KColorDrag::canDecode
static bool canDecode(TQMimeSource *e)
Returns true if the MIME source e contains a color object.
Definition: kcolordrag.cpp:76
KColorDrag::makeDrag
static KColorDrag * makeDrag(const TQColor &, TQWidget *dragsource) TDE_DEPRECATED
Definition: kcolordrag.cpp:104
KColorDrag::KColorDrag
KColorDrag(TQWidget *dragsource=0, const char *name=0)
Constructs a color drag with a white color.
Definition: kcolordrag.cpp:33
KColorDrag::setColor
void setColor(const TQColor &col)
Sets the color of the drag to col.
Definition: kcolordrag.cpp:40

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.9.4
This website is maintained by Timothy Pearson.