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

KDEUI

  • sources
  • kde-4.14
  • kdelibs
  • 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 
28 void
29 KColorMimeData::populateMimeData(QMimeData *mimeData, const QColor &color)
30 {
31  mimeData->setColorData(color);
32  mimeData->setText(color.name());
33 }
34 
35 bool
36 KColorMimeData::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 
49 QColor
50 KColorMimeData::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 
60 QDrag*
61 KColorMimeData::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 }
QDrag::setHotSpot
void setHotSpot(const QPoint &hotspot)
QWidget
QPainter::end
bool end()
QPixmap::fill
void fill(const QColor &color)
QDrag::setMimeData
void setMimeData(QMimeData *data)
QColor::name
QString name() const
KColorMimeData::canDecode
bool canDecode(const QMimeData *mimeData)
Returns true if the MIME data mimeData contains a color object.
Definition: kcolormimedata.cpp:36
QMimeData::setColorData
void setColorData(const QVariant &color)
QDrag::setPixmap
void setPixmap(const QPixmap &pixmap)
QVariant::value
T value() const
QPoint
QMimeData::hasText
bool hasText() const
QMimeData
QPainter::drawRect
void drawRect(const QRectF &rectangle)
kcolormimedata.h
QMimeData::text
QString text() const
QPainter::setPen
void setPen(const QColor &color)
QPainter
QDrag
QMimeData::setText
void setText(const QString &text)
QString
QColor
QMimeData::colorData
QVariant colorData() const
QPixmap
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::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
QString::length
int length() const
QMimeData::hasColor
bool hasColor() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:23:59 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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