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

KDE3Support

k3colordrag.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 1999 Steffen Hansen (hansen@kde.org)
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "k3colordrag.h"
00021 
00022 #include <QtGui/QPainter>
00023 
00024 static const char * const color_mime_string = "application/x-color";
00025 static const char * const text_mime_string = "text/plain";
00026 
00027 K3ColorDrag::K3ColorDrag( const QColor &color, QWidget *dragsource,
00028             const char *name)
00029      : Q3StoredDrag( color_mime_string, dragsource, name)
00030 {
00031      setColor( color);
00032 }
00033 
00034 K3ColorDrag::K3ColorDrag( QWidget *dragsource, const char *name)
00035      : Q3StoredDrag( color_mime_string, dragsource, name)
00036 {
00037      setColor( Qt::white );
00038 }
00039 
00040 void
00041 K3ColorDrag::setColor( const QColor &color)
00042 {
00043      Q3ColorDrag tmp(color, 0, 0);
00044      setEncodedData(tmp.encodedData(color_mime_string));
00045 
00046      QPixmap colorpix( 25, 20);
00047      colorpix.fill( color);
00048      QPainter p( &colorpix );
00049      p.setPen( Qt::black );
00050      p.drawRect(0,0,25,20);
00051      p.end();
00052      setPixmap(colorpix, QPoint(-5,-7));
00053 }
00054 
00055 const char *K3ColorDrag::format(int i) const
00056 {
00057      if (i==1)
00058         return text_mime_string;
00059      else
00060         return Q3StoredDrag::format(i);
00061 }
00062 
00063 QByteArray K3ColorDrag::encodedData ( const char * m ) const
00064 {
00065      if (!qstrcmp(m, text_mime_string) )
00066      {
00067         QColor color;
00068         Q3ColorDrag::decode(const_cast<K3ColorDrag *>(this), color);
00069         QByteArray result = color.name().toLatin1();
00070         result.resize(result.length());
00071         return result;
00072      }
00073      return Q3StoredDrag::encodedData(m);
00074 }
00075 
00076 bool
00077 K3ColorDrag::canDecode( QMimeSource *e)
00078 {
00079      if (e->provides(color_mime_string))
00080         return true;
00081      if (e->provides(text_mime_string))
00082      {
00083         QColor dummy;
00084         return decode(e, dummy);
00085      }
00086      return false;
00087 }
00088 
00089 bool
00090 K3ColorDrag::decode( QMimeSource *e, QColor &color)
00091 {
00092      if (Q3ColorDrag::decode(e, color))
00093         return true;
00094 
00095      QByteArray data = e->encodedData( text_mime_string);
00096      QString colorName = QString::fromLatin1(data.data(), data.size());
00097      if ((colorName.length() < 4) || (colorName[0] != '#'))
00098         return false;
00099      color.setNamedColor(colorName);
00100      return color.isValid();
00101 }
00102 
00103 
00104 K3ColorDrag*
00105 K3ColorDrag::makeDrag( const QColor &color,QWidget *dragsource)
00106 {
00107      return new K3ColorDrag( color, dragsource);
00108 }
00109 
00110 void K3ColorDrag::virtual_hook( int, void* )
00111 { /*BASE::virtual_hook( id, data );*/ }
00112 
00113 #include "k3colordrag.moc"

KDE3Support

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal