57
60
, initialized_( false )
59
62
// Insert a KHTMLPart in the placeholder
60
chatMessageView_ = new ChatMessageView( this );
63
chatMessageView_ = new ChatMessageView( this, this );
61
64
connect( chatMessageView_, SIGNAL( popupMenu(const QString&,const QPoint&) ),
62
65
this, SLOT ( slotShowContextMenu(const QString&,const QPoint&) ) );
63
66
connect( chatMessageView_, SIGNAL( openUrlRequest(const KUrl&) ),
68
71
// Create a layout to maximize the KHTMLPart
69
72
QVBoxLayout *layout = new QVBoxLayout( this );
70
73
layout->setContentsMargins( 0, 6, 0, 0 );
71
layout->addWidget( chatMessageView_->widget() );
74
layout->addWidget( chatMessageView_->view() );
73
76
// And to the messages view
74
77
chatMessageView_->view()->setAcceptDrops( true );
75
78
chatMessageView_->view()->installEventFilter( this );
77
80
// Create the containers for this chat's current text and drawing
78
inkEditContents_ = new InkImage();
79
81
messageEditContents_ = new QTextDocument();
82
inkDrawing_ = new Isf::Drawing();
81
84
// Adapt the new document for RTL is necessary
82
85
if( QApplication::isRightToLeft() )
125
128
switch( event->type() )
127
130
case QEvent::DragEnter:
131
case QEvent::DragMove:
129
133
QDragEnterEvent *dragEvent = static_cast<QDragEnterEvent*>( event );
131
if( dragEvent->mimeData()->hasUrls() )
133
dragEvent->acceptProposedAction();
136
else if( dragEvent->mimeData()->hasFormat( "application/kmess.list.item" ) )
138
dragEvent->acceptProposedAction();
137
#ifdef KMESSDEBUG_CHATVIEW
138
kDebug() << "Ignoring invalid drag event!";
143
const QMimeData *mimeData = dragEvent->mimeData();
144
if( mimeData->hasUrls()
145
|| mimeData->hasImage()
146
|| mimeData->hasFormat( "application/kmess.list.item" ) )
148
#ifdef KMESSDEBUG_CHATVIEW
149
kDebug() << "Accepting drag event of mimetypes:" << dragEvent->mimeData()->formats();
151
dragEvent->acceptProposedAction();
155
#ifdef KMESSDEBUG_CHATVIEW
156
kDebug() << "Ignoring invalid drop having mimetypes:" << dragEvent->mimeData()->formats();
147
163
QDropEvent *dropEvent = static_cast<QDropEvent*>( event );
148
164
const QMimeData *data = dropEvent->mimeData();
150
// Process a file transfer drop only if it contains file URLs
151
// and comes from out of our application.
152
if( data->hasUrls() && dropEvent->source() == 0 )
154
#ifdef KMESSDEBUG_CHATVIEW
155
kDebug() << "Drag'n'dropped files:" << dropEvent->mimeData()->urls();
166
// Process the drop only if it comes from out of our application.
167
if( ! dropEvent || dropEvent->source() != 0 )
169
#ifdef KMESSDEBUG_CHATVIEW
170
kDebug() << "Ignoring invalid drop!";
175
const QMimeData *mimeData = dropEvent->mimeData();
176
if( mimeData->hasUrls() )
178
#ifdef KMESSDEBUG_CHATVIEW
179
kDebug() << "Drag'n'dropped files:" << mimeData->urls();
158
182
// Send the files to the contact
159
startFileTransfer( dropEvent->mimeData()->urls() );
161
dropEvent->acceptProposedAction();
183
startFileTransfer( mimeData->urls() );
185
dropEvent->acceptProposedAction();
189
if( mimeData->hasImage() )
191
QImage image( qvariant_cast<QImage>( mimeData->imageData() ) );
195
#ifdef KMESSDEBUG_CHATVIEW
196
kDebug() << "Drag'n'dropped an invalid image!";
201
#ifdef KMESSDEBUG_CHATVIEW
202
kDebug() << "Drag'n'dropped a" << image.size() << "image";
205
// Create a temporary file where the image will be stored.
206
// TODO: The file is not destroyed, as it needs to be kept
207
// available until the transfer is completed. Find a way
208
// to remove it when KMess quits or as soon as the transfer
211
file.setAutoRemove( false );
212
file.setFileTemplate( QDir::tempPath() + "/kmess.XXXXXX.jpg" );
216
#ifdef KMESSDEBUG_CHATVIEW
217
kDebug() << "Cannot create temporary image file!";
222
dropEvent->acceptProposedAction();
224
// Save the image and get its local URL
225
image.save( &file, "JPG" );
227
QUrl imageUrl( "file://" + file.fileName() );
229
// Send the image to the contact
231
urlList.append( imageUrl );
232
startFileTransfer( urlList );