kdgantt1
KDGanttViewItemDrag.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <KDGanttView.h>
00031
00032 #include <KDGanttViewItemDrag.h>
00033 #include <KDGanttViewItem.h>
00034 #include <QPixmap>
00035
00055 #include <QBitmap>
00056 KDGanttViewItemDrag::KDGanttViewItemDrag( KDGanttViewItem* item , QWidget *source, const char * name ) : QStoredDrag("x-application/x-KDGanttViewItemDrag", source, name )
00057 {
00058 myItem = item;
00059
00060 QPixmap pix;
00061 if (item->pixmap() ) {
00062 pix = QPixmap(*(item->pixmap())) ;
00063 }
00064 else {
00065 KDGanttViewItem::Shape start, middle, end;
00066 item->shapes( start, middle, end );
00067 QColor st, mi, en;
00068 item->colors( st, mi, en );
00069 pix = QPixmap(item->myGanttView->getPixmap( start, st, item->myGanttView->lvBackgroundColor(), 10 ));
00070 }
00071 int off = -pix.width()/2 -2;
00072 #ifdef Q_WS_WIN
00073 if ( item->pixmap() )
00074 #endif
00075 setPixmap( pix , QPoint( off, off ) );
00076 QDomDocument doc( "GanttView" );
00077 QString docstart = "<GanttView/>";
00078 doc.setContent( docstart );
00079 QDomElement itemsElement = doc.createElement( "Items" );
00080 doc.documentElement().appendChild( itemsElement );
00081 item->createNode( doc, itemsElement );
00082 #if QT_VERSION < 0x040000
00083 QDataStream s( array, IO_WriteOnly );
00084 #else
00085 QDataStream s( &array, IO_WriteOnly );
00086 #endif
00087 s << doc.toString();
00088 }
00089
00090
00097 QByteArray KDGanttViewItemDrag::encodedData( const char * c) const
00098 {
00099 QString s ( c );
00100 if ( s == "x-application/x-KDGanttViewItemDrag" ) {
00101 return array;
00102 }
00103 return QByteArray();
00104 }
00105
00111 KDGanttViewItem* KDGanttViewItemDrag::getItem()
00112 {
00113 return myItem;
00114 }
00115
00116
00123 bool KDGanttViewItemDrag::canDecode ( const QMimeSource * e )
00124 {
00125 if ( QString( e->format() ) == "x-application/x-KDGanttViewItemDrag" )
00126 return true;
00127
00128 return false;
00129 }
00130
00131
00140 bool KDGanttViewItemDrag::decode ( const QMimeSource * e , QString & string)
00141 {
00142 QByteArray arr;
00143 arr = e->encodedData( "x-application/x-KDGanttViewItemDrag");
00144
00145 if ( arr.count() ) {
00146 #if QT_VERSION < 0x040000
00147 QDataStream s( arr, IO_ReadOnly );
00148 #else
00149 QDataStream s( &arr, IO_ReadOnly );
00150 #endif
00151 s >> string;
00152 }
00153 return true;
00154 }
00155