You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
3.1 KiB
113 lines
3.1 KiB
15 years ago
|
/* This file is part of the KDE libraries
|
||
|
Copyright (C) 1999 Steffen Hansen (hansen@kde.org)
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
15 years ago
|
#include <tqpainter.h>
|
||
15 years ago
|
#include "kcolordrag.h"
|
||
|
|
||
|
static const char * const color_mime_string = "application/x-color";
|
||
|
static const char * const text_mime_string = "text/plain";
|
||
|
|
||
15 years ago
|
KColorDrag::KColorDrag( const TQColor &color, TQWidget *dragsource,
|
||
15 years ago
|
const char *name)
|
||
15 years ago
|
: TQStoredDrag( color_mime_string, dragsource, name)
|
||
15 years ago
|
{
|
||
|
setColor( color);
|
||
|
}
|
||
|
|
||
15 years ago
|
KColorDrag::KColorDrag( TQWidget *dragsource, const char *name)
|
||
|
: TQStoredDrag( color_mime_string, dragsource, name)
|
||
15 years ago
|
{
|
||
|
setColor( white );
|
||
|
}
|
||
|
|
||
|
void
|
||
15 years ago
|
KColorDrag::setColor( const TQColor &color)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQColorDrag tmp(color, 0, 0);
|
||
14 years ago
|
setEncodedData(tmp.tqencodedData(color_mime_string));
|
||
15 years ago
|
|
||
15 years ago
|
TQPixmap colorpix( 25, 20);
|
||
15 years ago
|
colorpix.fill( color);
|
||
15 years ago
|
TQPainter p( &colorpix );
|
||
15 years ago
|
p.setPen( black );
|
||
|
p.drawRect(0,0,25,20);
|
||
|
p.end();
|
||
15 years ago
|
setPixmap(colorpix, TQPoint(-5,-7));
|
||
15 years ago
|
}
|
||
|
|
||
|
const char *KColorDrag::format(int i) const
|
||
|
{
|
||
|
if (i==1)
|
||
|
return text_mime_string;
|
||
|
else
|
||
15 years ago
|
return TQStoredDrag::format(i);
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
TQByteArray KColorDrag::tqencodedData ( const char * m ) const
|
||
15 years ago
|
{
|
||
|
if (!qstrcmp(m, text_mime_string) )
|
||
|
{
|
||
15 years ago
|
TQColor color;
|
||
|
TQColorDrag::decode(const_cast<KColorDrag *>(this), color);
|
||
14 years ago
|
TQCString result = TQString(color.name()).latin1();
|
||
15 years ago
|
((TQByteArray&)result).resize(result.length());
|
||
15 years ago
|
return result;
|
||
|
}
|
||
14 years ago
|
return TQStoredDrag::tqencodedData(m);
|
||
15 years ago
|
}
|
||
|
|
||
|
bool
|
||
15 years ago
|
KColorDrag::canDecode( TQMimeSource *e)
|
||
15 years ago
|
{
|
||
|
if (e->provides(color_mime_string))
|
||
|
return true;
|
||
|
if (e->provides(text_mime_string))
|
||
|
{
|
||
15 years ago
|
TQColor dummy;
|
||
15 years ago
|
return decode(e, dummy);
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
bool
|
||
15 years ago
|
KColorDrag::decode( TQMimeSource *e, TQColor &color)
|
||
15 years ago
|
{
|
||
15 years ago
|
if (TQColorDrag::decode(e, color))
|
||
15 years ago
|
return true;
|
||
|
|
||
14 years ago
|
TQByteArray data = e->tqencodedData( text_mime_string);
|
||
|
TQString colorName = TQString::tqfromLatin1(data.data(), data.size());
|
||
15 years ago
|
if ((colorName.length() < 4) || (colorName[0] != '#'))
|
||
|
return false;
|
||
|
color.setNamedColor(colorName);
|
||
|
return color.isValid();
|
||
|
}
|
||
|
|
||
|
|
||
|
KColorDrag*
|
||
15 years ago
|
KColorDrag::makeDrag( const TQColor &color,TQWidget *dragsource)
|
||
15 years ago
|
{
|
||
|
return new KColorDrag( color, dragsource);
|
||
|
}
|
||
|
|
||
|
void KColorDrag::virtual_hook( int, void* )
|
||
|
{ /*BASE::virtual_hook( id, data );*/ }
|
||
|
|
||
|
#include "kcolordrag.moc"
|