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

KDEUI

  • kdeui
  • colors
kcolormimedata.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 Copyright (C) 2005 Joseph Wenninger (jowenn@kde.org)
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include "kcolormimedata.h"
22
23#include <QColor>
24#include <QDrag>
25#include <QMimeData>
26#include <QPainter>
27
28void
29KColorMimeData::populateMimeData(QMimeData *mimeData, const QColor &color)
30{
31 mimeData->setColorData(color);
32 mimeData->setText(color.name());
33}
34
35bool
36KColorMimeData::canDecode(const QMimeData *mimeData)
37{
38 if (mimeData->hasColor())
39 return true;
40 if (mimeData->hasText())
41 {
42 const QString colorName=mimeData->text();
43 if ((colorName.length() >= 4) && (colorName[0] == '#'))
44 return true;
45 }
46 return false;
47}
48
49QColor
50KColorMimeData::fromMimeData(const QMimeData *mimeData)
51{
52 if (mimeData->hasColor())
53 return mimeData->colorData().value<QColor>();
54 if (canDecode(mimeData))
55 return QColor(mimeData->text());
56 return QColor();
57}
58
59
60QDrag*
61KColorMimeData::createDrag(const QColor &color, QWidget *dragsource)
62{
63 QDrag *drag=new QDrag(dragsource);
64 QMimeData *mime=new QMimeData;
65 populateMimeData(mime,color);
66 drag->setMimeData(mime);
67 QPixmap colorpix( 25, 20 );
68 colorpix.fill( color );
69 QPainter p( &colorpix );
70 p.setPen( Qt::black );
71 p.drawRect(0,0,24,19);
72 p.end();
73 drag->setPixmap(colorpix);
74 drag->setHotSpot(QPoint(-5,-7));
75 return drag;
76}
QWidget
kcolormimedata.h
KColorMimeData::createDrag
QDrag * createDrag(const QColor &color, QWidget *dragsource)
Creates a color drag object.
Definition: kcolormimedata.cpp:61
KColorMimeData::fromMimeData
QColor fromMimeData(const QMimeData *mimeData)
Decodes the MIME data mimeData and returns the resulting color.
Definition: kcolormimedata.cpp:50
KColorMimeData::canDecode
bool canDecode(const QMimeData *mimeData)
Returns true if the MIME data mimeData contains a color object.
Definition: kcolormimedata.cpp:36
KColorMimeData::populateMimeData
void populateMimeData(QMimeData *mimeData, const QColor &color)
Sets the color and text representation fields for the specified color in the mimedata object: applica...
Definition: kcolormimedata.cpp:29
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.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • 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