subclass QTextEdit insertFromMimedata or so ...
here a sample ....
http://www.qt-apps.org/content/show....?content=80234
void TextWriter
::insertFromMime( const QMimeData * source
) {
if ( source->formats().contains("application/x-picslists") ) {
/* multiple image list */
QByteArray dd
= source
->data
("application/x-picslists");
QList<SPics> li
= OpenImageGroup
(QString(dd
));
for (int i=0; i<li.size(); i++) {
SPics conni = li[i];
RegisterImage(conni,true);
}
return;
}
if ( source->hasImage() ) {
const QString TimestampsMs
= QString("%1-%2-image").
arg(timer1.
toTime_t()).
arg(timer1.
toString("zzz"));
QPixmap aspixmape
= qvariant_cast<QPixmap>
(source
->imageData
());
if (!aspixmape.isNull()) {
insertPixmap(aspixmape);
}
return;
}
/* external html */
if ( source->formats().contains("text/html") ) {
textCursor().insertFragment(fragment);
return;
}
/* external plain text incomming */
if ( source->hasText() ) {
textCursor().insertText(source->text());
return;
}
if ( source->hasUrls() ) {
QList<QUrl> urls = source->urls();
for ( int i = 0; i < urls.size(); ++i ) {
QUrl gettyurl
(urls.
at(i
));
//////////// qDebug() << "### gettyurl " << gettyurl.toString();
if (gettyurl.scheme() == "file") {
ImageonCursor(gettyurl.toLocalFile());
} else if (gettyurl.scheme() == "http") {
Gloader *grephttp = new Gloader();
grephttp->Setting(this,i,gettyurl);
grephttp
->start
(QThread::LowPriority);
/* grep class Gloader on
http://fop-miniscribus.googlecode.com/svn/trunk/GraphicsViewEdit/include/mimedataeditor.h
*/
}
}
return;
}
}
void TextWriter::insertFromMime( const QMimeData * source )
{
if ( source->formats().contains("application/x-picslists") ) {
/* multiple image list */
QByteArray dd = source->data("application/x-picslists");
QList<SPics> li = OpenImageGroup(QString(dd));
for (int i=0; i<li.size(); i++) {
SPics conni = li[i];
RegisterImage(conni,true);
}
return;
}
if ( source->hasImage() ) {
QDateTime timer1( QDateTime::currentDateTime() );
const QString TimestampsMs = QString("%1-%2-image").arg(timer1.toTime_t()).arg(timer1.toString("zzz"));
QPixmap aspixmape = qvariant_cast<QPixmap>(source->imageData());
if (!aspixmape.isNull()) {
insertPixmap(aspixmape);
}
return;
}
/* external html */
if ( source->formats().contains("text/html") ) {
QString draghtml = source->html();
QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(draghtml);
textCursor().insertFragment(fragment);
return;
}
/* external plain text incomming */
if ( source->hasText() ) {
textCursor().insertText(source->text());
return;
}
if ( source->hasUrls() ) {
QList<QUrl> urls = source->urls();
for ( int i = 0; i < urls.size(); ++i ) {
QUrl gettyurl(urls.at(i));
//////////// qDebug() << "### gettyurl " << gettyurl.toString();
if (gettyurl.scheme() == "file") {
ImageonCursor(gettyurl.toLocalFile());
} else if (gettyurl.scheme() == "http") {
Gloader *grephttp = new Gloader();
grephttp->Setting(this,i,gettyurl);
grephttp->start(QThread::LowPriority);
/* grep class Gloader on
http://fop-miniscribus.googlecode.com/svn/trunk/GraphicsViewEdit/include/mimedataeditor.h
*/
}
}
return;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks