void Q3TextBrowser::setSource(const QString& name) { #ifndef QT_NO_CURSOR if (isVisible()) qApp->setOverrideCursor(Qt::WaitCursor); #endif d->textOrSourceChanged = true; QString source = name; QString mark; int hash = name.indexOf(QLatin1Char('#')); if (hash != -1) { source = name.left(hash); mark = name.mid(hash+1); } if (source.left(5) == QLatin1String("file:")) source = source.mid(6); QString url = mimeSourceFactory()->makeAbsolute(source, context()); QString txt; bool dosettext = false; if (!source.isEmpty() && url != d->curmain) { const QMimeSource* m = mimeSourceFactory()->data(source, context()); if (!m){ qWarning("Q3TextBrowser: no mimesource for %s", source.latin1()); } else { if (!Q3TextDrag::decode(m, txt)) { qWarning("Q3TextBrowser: cannot decode %s", source.latin1()); } } if (isVisible()) { QString firstTag = txt.left(txt.indexOf(QLatin1Char('>')) + 1); if (firstTag.left(3) == QLatin1String("<qt") && firstTag.contains(QLatin1String("type")) && firstTag.contains(QLatin1String("detail"))) { popupDetail(txt, QCursor::pos()); #ifndef QT_NO_CURSOR qApp->restoreOverrideCursor(); #endif return; } } d->curmain = url; dosettext = true; } d->curmark = mark; if (!mark.isEmpty()) { url += QLatin1Char('#'); url += mark; } if (d->home.count() == 0) d->home = url; if (d->stack.isEmpty() || d->stack.top() != url) d->stack.push(url); int stackCount = (int)d->stack.count(); if (d->stack.top() == url) stackCount--; emit backwardAvailable(stackCount > 0); stackCount = (int)d->forwardStack.count(); if (d->forwardStack.isEmpty() || d->forwardStack.top() == url) stackCount--; emit forwardAvailable(stackCount > 0); if (dosettext) Q3TextEdit::setText(txt, url); if (!mark.isEmpty()) scrollToAnchor(mark); else setContentsPos(0, 0); #ifndef QT_NO_CURSOR if (isVisible()) qApp->restoreOverrideCursor(); #endif emit sourceChanged(url); }
/*! Sets the text document with the given \a name to be displayed. The name is looked up in the mimeSourceFactory() of the browser. In addition to the factory lookup, this functions also checks for optional anchors and scrolls the document accordingly. If the first tag in the document is \c <qt \c type=detail>, it is displayed as a popup rather than as new document in the browser window itself. Otherwise, the document is set normally via setText(), with \a name as new context. If you are using the filesystem access capabilities of the mime source factory, you have to ensure that the factory knows about the encoding of specified text files, otherwise no data will be available. The default factory handles a couple of common file extensions such as \c *.html and \c *.txt with reasonable defaults. See QMimeSourceFactory::data() for details. */ void QTextBrowser::setSource(const QString& name) { #ifndef QT_NO_CURSOR if ( isVisible() ) qApp->setOverrideCursor( waitCursor ); #endif QString source = name; QString mark; int hash = name.find('#'); if ( hash != -1) { source = name.left( hash ); mark = name.mid( hash+1 ); } if ( source.left(5) == "file:" ) source = source.mid(6); QString url = mimeSourceFactory()->makeAbsolute( source, context() ); QString txt; bool dosettext = FALSE; if ( !source.isEmpty() && url != d->curmain ) { const QMimeSource* m = mimeSourceFactory()->data( source, context() ); if ( !m ){ qWarning("QTextBrowser: no mimesource for %s", source.latin1() ); } else { if ( !QTextDrag::decode( m, txt ) ) { qWarning("QTextBrowser: cannot decode %s", source.latin1() ); } } if ( isVisible() ) { QString firstTag = txt.left( txt.find('>' )+1 ); QRichText* tmp = new QRichText( firstTag, QApplication::font() ); static QString s_type = QString::fromLatin1("type"); static QString s_detail = QString::fromLatin1("detail"); bool doReturn = FALSE; if ( tmp->attributes().contains(s_type) && tmp->attributes()[s_type] == s_detail ) doReturn = TRUE; QTextFormatCollection* formats = tmp->formats; delete tmp; delete formats; //#### fix inheritance structure in rich text if ( doReturn ) { popupDetail( txt, d->lastClick ); #ifndef QT_NO_CURSOR qApp->restoreOverrideCursor(); #endif return; } } d->curmain = url; dosettext = TRUE; } d->curmark = mark; if ( !mark.isEmpty() ) { url += "#"; url += mark; } if ( !d->home ) d->home = url; if ( d->stack.isEmpty() || d->stack.top() != url) { d->stack.push( url ); } int stackCount = d->stack.count(); if ( d->stack.top() == url ) stackCount--; emit backwardAvailable( stackCount > 0 ); stackCount = d->forwardStack.count(); if ( d->forwardStack.top() == url ) stackCount--; emit forwardAvailable( stackCount > 0 ); if ( dosettext ) setText( txt, url ); if ( isVisible() && !mark.isEmpty() ) scrollToAnchor( mark ); else setContentsPos( 0, 0 ); #ifndef QT_NO_CURSOR if ( isVisible() ) qApp->restoreOverrideCursor(); #endif }