Beispiel #1
0
void DocumentBrowser::scrollToAnchor(const QString &text)
{
    const HistoryEntry &historyEntry = createHistoryEntry();

    m_url.setFragment(text);

    if (text.isEmpty()) {
        m_htmlWidget->setScrollBarValue(Qt::Horizontal,0);
        m_htmlWidget->setScrollBarValue(Qt::Vertical,0);
    } else {
        m_htmlWidget->scrollToAnchor(text);
    }

    m_urlComboBox->blockSignals(true);
    int index = m_urlComboBox->findText(m_url.toString());
    if (index == -1) {
        m_urlComboBox->addItem(m_url.toString());
        index = m_urlComboBox->count()-1;
    }
    m_urlComboBox->setCurrentIndex(index);
    m_urlComboBox->blockSignals(false);

    emit documentLoaded();

    if (!m_backwardStack.isEmpty() && m_url == m_backwardStack.top().url)
    {
        //restoreHistoryEntry(m_backwardStack.top());
        return;
    }

    if (!m_backwardStack.isEmpty()) {
        m_backwardStack.top() = historyEntry;
    }

    HistoryEntry entry;
    entry.url = m_url;
    m_backwardStack.push(entry);

    emit backwardAvailable(m_backwardStack.count() > 1);

    if (!m_forwardStack.isEmpty() && m_url == m_forwardStack.top().url) {
        m_forwardStack.pop();
        emit forwardAvailable(m_forwardStack.count() > 0);
    } else {
        m_forwardStack.clear();
        emit forwardAvailable(false);
    }
}
Beispiel #2
0
/*!
    Changes the document displayed to the next document in the list of
    documents built by navigating links. Does nothing if there is no
    next document.

    \sa backward(), forwardAvailable()
*/
void Q3TextBrowser::forward()
{
    if (d->forwardStack.isEmpty())
        return;
    setSource(d->forwardStack.pop());
    emit forwardAvailable(!d->forwardStack.isEmpty());
}
Beispiel #3
0
/*!
    Changes the document displayed to the previous document in the
    list of documents built by navigating links. Does nothing if there
    is no previous document.

    \sa forward(), backwardAvailable()
*/
void Q3TextBrowser::backward()
{
    if (d->stack.count() <= 1)
        return;
    d->forwardStack.push(d->stack.pop());
    setSource(d->stack.pop());
    emit forwardAvailable(true);
}
Beispiel #4
0
void HelpViewer::actionChanged()
{
    QAction *a = qobject_cast<QAction *>(sender());
    if (a == pageAction(QWebPage::Copy))
        emit copyAvailable(a->isEnabled());
    else if (a == pageAction(QWebPage::Back))
        emit backwardAvailable(a->isEnabled());
    else if (a == pageAction(QWebPage::Forward))
        emit forwardAvailable(a->isEnabled());
}
Beispiel #5
0
void AMPWebView::slotUrlChanged( const QUrl &url )
{
    qDebug( "AMPWebView::slotUrlChanged()" );
    // emited by frame as soon as the title of the html header was recieved
    emit statusBarMessage( tr( "Loading:" )+' '+url.toString(), 20000 );
    PHIAHistoryItem it( url, title(), icon(), QDateTime::currentDateTime() );
    _history->addHistoryItem( it );
    emit forwardAvailable( _history->canGoForward() );
    emit backAvailable( _history->canGoBack() );
    emit urlChanged( url );
}
Beispiel #6
0
void DocumentBrowser::backward()
{
    if (m_backwardStack.count() <= 1) {
        return;
    }
    m_forwardStack.push(createHistoryEntry());
    m_backwardStack.pop();
    emit requestUrl(m_backwardStack.top().url);
    emit backwardAvailable(m_backwardStack.count() > 1);
    emit forwardAvailable(true);
}
Beispiel #7
0
void DocumentBrowser::forward()
{
    if (m_forwardStack.isEmpty()) {
        return;
    }
    if (!m_backwardStack.isEmpty()) {
        m_backwardStack.top() = createHistoryEntry();
    }
    m_backwardStack.push(m_forwardStack.pop());
    emit requestUrl(m_backwardStack.top().url);
    emit backwardAvailable(true);
    emit forwardAvailable(m_forwardStack.count() > 0);
}
bool QTextBrowser::qt_emit( int _id, QUObject* _o )
{
    switch ( _id - staticMetaObject()->signalOffset() ) {
    case 0: backwardAvailable((bool)static_QUType_bool.get(_o+1)); break;
    case 1: forwardAvailable((bool)static_QUType_bool.get(_o+1)); break;
    case 2: sourceChanged((const QString&)static_QUType_QString.get(_o+1)); break;
    case 3: highlighted((const QString&)static_QUType_QString.get(_o+1)); break;
    case 4: linkClicked((const QString&)static_QUType_QString.get(_o+1)); break;
    case 5: anchorClicked((const QString&)static_QUType_QString.get(_o+1),(const QString&)static_QUType_QString.get(_o+2)); break;
    default:
	return QTextEdit::qt_emit(_id,_o);
    }
    return TRUE;
}
Beispiel #9
0
void AMPWebView::slotForward()
{
    if ( !canGoForward() ) return;
    _history->forward();
    emit forwardAvailable( canGoForward() );
    QWebHistoryItem wit=_webPage->history()->forwardItem();
    PHIAHistoryItem it=_history->currentItem();
    if ( wit.isValid() && it.url()==wit.url() ) {
        qDebug( "slotForward(): matches forward item" );
        _webPage->triggerAction( QWebPage::Forward );
    } else {
        qDebug( "%s<>%s", qPrintable( wit.url().toString() ), qPrintable( it.url().toString() ) );
        QNetworkRequest req;
        req.setUrl( it.url() );
        slotNetworkRequest( req );
    }
}
Beispiel #10
0
DocumentBrowser::DocumentBrowser(LiteApi::IApplication *app, QObject *parent) :
    LiteApi::IDocumentBrowser(parent),
    m_liteApp(app),
    m_extension(new Extension)
{
    m_widget = new QWidget;

    m_htmlWidget = app->htmlWidgetManager()->createByName(this,"QTextBrowser");

    m_toolBar = new QToolBar;
    m_toolBar->setIconSize(LiteApi::getToolBarIconSize());

    m_backwardAct = new QAction(QIcon("icon:images/backward.png"),tr("Back"),this);
    m_forwardAct = new QAction(QIcon("icon:images/forward.png"),tr("Forward"),this);
    m_reloadUrlAct = new QAction(QIcon("icon:images/reload.png"),tr("Reload"),this);
    m_toolBar->addAction(m_backwardAct);
    m_toolBar->addAction(m_forwardAct);

    LiteApi::IActionContext *actionContext = m_liteApp->actionManager()->getActionContext(this,"Document");

    m_increaseFontSize = new QAction(tr("Increase Font Size"),this);
    actionContext->regAction(m_increaseFontSize,"IncreaseFontSize","Ctrl++;Ctrl+=");

    m_decreaseFontSize = new QAction(tr("Decrease Font Size"),this);
    actionContext->regAction(m_decreaseFontSize,"DecreaseFontSize","Ctrl+-");

    m_resetFontSize = new QAction(tr("Reset Font Size"),this);
    actionContext->regAction(m_resetFontSize,"ResizeFontSize","Ctrl+0");

    m_urlComboBox = new QComboBox;
    m_urlComboBox->setEditable(true);
    m_urlComboBox->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);

    m_toolBar->addSeparator();
    m_toolBar->addWidget(m_urlComboBox);
    m_toolBar->addAction(m_reloadUrlAct);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->setMargin(0);
    mainLayout->setSpacing(0);

    mainLayout->addWidget(m_toolBar);
    mainLayout->addWidget(m_htmlWidget->widget());
    m_widget->setLayout(mainLayout);

    m_widget->addAction(m_increaseFontSize);
    m_widget->addAction(m_decreaseFontSize);
    m_widget->addAction(m_resetFontSize);

    connect(m_increaseFontSize,SIGNAL(triggered()),this,SLOT(increaseFontSize()));
    connect(m_decreaseFontSize,SIGNAL(triggered()),this,SLOT(decreaseFontSize()));
    connect(m_resetFontSize,SIGNAL(triggered()),this,SLOT(resetFontSize()));
    connect(m_htmlWidget,SIGNAL(linkHovered(QUrl)),this,SIGNAL(linkHovered(QUrl)));
    connect(m_htmlWidget,SIGNAL(linkClicked(QUrl)),this,SLOT(linkClicked(QUrl)));
    connect(m_htmlWidget,SIGNAL(loadFinished(bool)),this,SIGNAL(documentLoaded()));
    connect(m_backwardAct,SIGNAL(triggered()),this,SLOT(backward()));
    connect(m_forwardAct,SIGNAL(triggered()),this,SLOT(forward()));
    connect(m_reloadUrlAct,SIGNAL(triggered()),this,SLOT(reloadUrl()));
    connect(m_urlComboBox,SIGNAL(activated(QString)),this,SLOT(activatedUrl(QString)));
    connect(this,SIGNAL(backwardAvailable(bool)),m_backwardAct,SLOT(setEnabled(bool)));
    connect(this,SIGNAL(forwardAvailable(bool)),m_forwardAct,SLOT(setEnabled(bool)));

    m_extension->addObject("LiteApi.IDocumentBrowser",this);
    m_extension->addObject("LiteApi.IHtmlWidget",m_htmlWidget);
    m_extension->addObject("LiteApi.QTextBrowser",m_htmlWidget->widget());
    m_htmlWidget->installEventFilter(m_liteApp->editorManager());

    requestFontZoom(0);

    QPalette p = m_htmlWidget->widget()->palette();
    p.setBrush(QPalette::Highlight,Qt::yellow);
    p.setColor(QPalette::HighlightedText,Qt::black);
    m_htmlWidget->widget()->setPalette(p);

    emit backwardAvailable(false);
    emit forwardAvailable(false);
}
Beispiel #11
0
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);
}
Beispiel #12
0
/*!
  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 &lt;qt \c type=detail&gt;, 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
}