Ejemplo n.º 1
0
WebView *TabWidget::newTab(bool makeCurrent)
{
    // line edit
    UrlLineEdit *urlLineEdit = new UrlLineEdit;
    QLineEdit *lineEdit = urlLineEdit->lineEdit();
    if (!m_lineEditCompleter && count() > 0) {
        HistoryCompletionModel *completionModel = new HistoryCompletionModel(this);
        completionModel->setSourceModel(BrowserApplication::historyManager()->historyFilterModel());
        m_lineEditCompleter = new QCompleter(completionModel, this);
        // Should this be in Qt by default?
        QAbstractItemView *popup = m_lineEditCompleter->popup();
        QListView *listView = qobject_cast<QListView*>(popup);
        if (listView)
            listView->setUniformItemSizes(true);
    }
    lineEdit->setCompleter(m_lineEditCompleter);
    connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(lineEditReturnPressed()));
    m_lineEdits->addWidget(urlLineEdit);
    m_lineEdits->setSizePolicy(lineEdit->sizePolicy());

    // optimization to delay creating the more expensive WebView, history, etc
    if (count() == 0) {
        QWidget *emptyWidget = new QWidget;
        QPalette p = emptyWidget->palette();
        p.setColor(QPalette::Window, palette().color(QPalette::Base));
        emptyWidget->setPalette(p);
        emptyWidget->setAutoFillBackground(true);
        disconnect(this, SIGNAL(currentChanged(int)),
            this, SLOT(currentChanged(int)));
        addTab(emptyWidget, tr("(Untitled)"));
        connect(this, SIGNAL(currentChanged(int)),
            this, SLOT(currentChanged(int)));
        return 0;
    }
Ejemplo n.º 2
0
QStringList HistoryCompleter::splitPath(const QString &path) const
{
    if (path == m_searchString)
        return QStringList() << QLatin1String("a");

    // queue an update to our search string
    // We will wait a bit so that if the user is quickly typing,
    // we don't try to complete until they pause.
    if (m_filterTimer.isActive())
        m_filterTimer.stop();
    m_filterTimer.start(150);

    // if the previous search results are not a superset of
    // the current search results, tell the model that it is not valid yet
    if (!path.startsWith(m_searchString)) {
        HistoryCompletionModel *completionModel = qobject_cast<HistoryCompletionModel*>(model());
        Q_ASSERT(completionModel);
        completionModel->setValid(false);
    }

    m_searchString = path;

    // the actual filtering is done by the HistoryCompletionModel; we just
    // return a short dummy here so that QCompleter thinks we match everything
    return QStringList() << QLatin1String("a");
}
Ejemplo n.º 3
0
WebView *TabWidget::makeNewTab(bool makeCurrent)
{
    // line edit
    LocationBar *locationBar = new LocationBar;
    if (!m_lineEditCompleter) {
        HistoryCompletionModel *completionModel = new HistoryCompletionModel(this);
        completionModel->setSourceModel(BrowserApplication::historyManager()->historyFilterModel());
        m_lineEditCompleter = new HistoryCompleter(completionModel, this);
        connect(m_lineEditCompleter, SIGNAL(activated(const QString &)),
                this, SLOT(loadString(const QString &)));
        // Should this be in Qt by default?
        QAbstractItemView *popup = m_lineEditCompleter->popup();
        QListView *listView = qobject_cast<QListView*>(popup);
        if (listView) {
            // Urls are always LeftToRight
            listView->setLayoutDirection(Qt::LeftToRight);
            listView->setUniformItemSizes(true);
        }
    }
Ejemplo n.º 4
0
void HistoryCompleter::updateFilter()
{
    HistoryCompletionModel *completionModel = qobject_cast<HistoryCompletionModel*>(model());
    Q_ASSERT(completionModel);

    // tell the HistoryCompletionModel about the new search string
    completionModel->setSearchString(m_searchString);

    // sort the model
    completionModel->sort(0);

    // mark it valid
    completionModel->setValid(true);

    // and now update the QCompleter widget, but only if the user is still
    // typing a url
    if (widget() && widget()->hasFocus())
        complete();
}