• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDE3Support

  • kde3support
  • kdeui
k3colordrag.cpp
Go to the documentation of this file.
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 "k3colordrag.h"
21
22#include <QtGui/QPainter>
23
24static const char * const color_mime_string = "application/x-color";
25static const char * const text_mime_string = "text/plain";
26
27K3ColorDrag::K3ColorDrag( const QColor &color, QWidget *dragsource,
28 const char *name)
29 : Q3StoredDrag( color_mime_string, dragsource, name)
30{
31 setColor( color);
32}
33
34K3ColorDrag::K3ColorDrag( QWidget *dragsource, const char *name)
35 : Q3StoredDrag( color_mime_string, dragsource, name)
36{
37 setColor( Qt::white );
38}
39
40void
41K3ColorDrag::setColor( const QColor &color)
42{
43 Q3ColorDrag tmp(color, 0, 0);
44 setEncodedData(tmp.encodedData(color_mime_string));
45
46 QPixmap colorpix( 25, 20);
47 colorpix.fill( color);
48 QPainter p( &colorpix );
49 p.setPen( Qt::black );
50 p.drawRect(0,0,25,20);
51 p.end();
52 setPixmap(colorpix, QPoint(-5,-7));
53}
54
55const char *K3ColorDrag::format(int i) const
56{
57 if (i==1)
58 return text_mime_string;
59 else
60 return Q3StoredDrag::format(i);
61}
62
63QByteArray K3ColorDrag::encodedData ( const char * m ) const
64{
65 if (!qstrcmp(m, text_mime_string) )
66 {
67 QColor color;
68 Q3ColorDrag::decode(const_cast<K3ColorDrag *>(this), color);
69 QByteArray result = color.name().toLatin1();
70 result.resize(result.length());
71 return result;
72 }
73 return Q3StoredDrag::encodedData(m);
74}
75
76bool
77K3ColorDrag::canDecode( QMimeSource *e)
78{
79 if (e->provides(color_mime_string))
80 return true;
81 if (e->provides(text_mime_string))
82 {
83 QColor dummy;
84 return decode(e, dummy);
85 }
86 return false;
87}
88
89bool
90K3ColorDrag::decode( QMimeSource *e, QColor &color)
91{
92 if (Q3ColorDrag::decode(e, color))
93 return true;
94
95 QByteArray data = e->encodedData( text_mime_string);
96 QString colorName = QString::fromLatin1(data.data(), data.size());
97 if ((colorName.length() < 4) || (colorName[0] != '#'))
98 return false;
99 color.setNamedColor(colorName);
100 return color.isValid();
101}
102
103
104K3ColorDrag*
105K3ColorDrag::makeDrag( const QColor &color,QWidget *dragsource)
106{
107 return new K3ColorDrag( color, dragsource);
108}
109
110void K3ColorDrag::virtual_hook( int, void* )
111{ /*BASE::virtual_hook( id, data );*/ }
112
113#include "k3colordrag.moc"
K3ColorDrag
A drag-and-drop object for colors.
Definition: k3colordrag.h:35
K3ColorDrag::canDecode
static bool canDecode(QMimeSource *e)
Returns true if the MIME source e contains a color object.
Definition: k3colordrag.cpp:77
K3ColorDrag::virtual_hook
virtual void virtual_hook(int id, void *data)
Definition: k3colordrag.cpp:110
K3ColorDrag::encodedData
virtual QByteArray encodedData(const char *m) const
Definition: k3colordrag.cpp:63
K3ColorDrag::K3ColorDrag
K3ColorDrag(QWidget *dragsource=0, const char *name=0)
Constructs a color drag with a white color.
Definition: k3colordrag.cpp:34
K3ColorDrag::decode
static bool decode(QMimeSource *e, QColor &col)
Decodes the MIME source e and puts the resulting color into col.
Definition: k3colordrag.cpp:90
K3ColorDrag::format
virtual const char * format(int i) const
Definition: k3colordrag.cpp:55
K3ColorDrag::makeDrag
static K3ColorDrag * makeDrag(const QColor &, QWidget *dragsource)
Definition: k3colordrag.cpp:105
K3ColorDrag::setColor
void setColor(const QColor &col)
Sets the color of the drag to col.
Definition: k3colordrag.cpp:41
Q3StoredDrag
QWidget
text_mime_string
static const char *const text_mime_string
Definition: k3colordrag.cpp:25
color_mime_string
static const char *const color_mime_string
Definition: k3colordrag.cpp:24
k3colordrag.h
dummy
static int dummy
Definition: k3syntaxhighlighter.cpp:41
name
const char * name(StandardAction id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDE3Support

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

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal