From 4c33d3563dc321f79bd636b54943eb7ea7cd3e17 Mon Sep 17 00:00:00 2001 From: Franz Fellner Date: Tue, 4 Dec 2012 14:29:27 +0100 Subject: [PATCH 1/4] Add "Switch to Tab" mode for completion plopup, to just seitch to the tab that displays the url currently completed. Also add an option to disable the "switch tab" offer. If enabled the user can press "Shift" to load the url in the current tab instead of switching tab. I tried to copy behaviour of firefox. I hope I did not miss a bit... --- .../completer/locationcompleter.cpp | 3 +- .../completer/locationcompleterdelegate.cpp | 17 +++- .../completer/locationcompleterdelegate.h | 3 + .../completer/locationcompletermodel.cpp | 44 +++++++++ .../completer/locationcompletermodel.h | 21 ++++- .../completer/locationcompleterview.cpp | 91 +++++++++++++++++++ .../completer/locationcompleterview.h | 8 ++ src/lib/preferences/preferences.cpp | 2 + src/lib/preferences/preferences.ui | 40 +++++--- 9 files changed, 210 insertions(+), 19 deletions(-) diff --git a/src/lib/navigation/completer/locationcompleter.cpp b/src/lib/navigation/completer/locationcompleter.cpp index d758c5aa4..7a71eaa4d 100644 --- a/src/lib/navigation/completer/locationcompleter.cpp +++ b/src/lib/navigation/completer/locationcompleter.cpp @@ -33,7 +33,6 @@ LocationCompleter::LocationCompleter(QObject* parent) s_view = new LocationCompleterView; s_view->setModel(s_model); - s_view->setItemDelegate(new LocationCompleterDelegate(s_view)); } } @@ -77,6 +76,7 @@ void LocationCompleter::popupClosed() disconnect(s_view->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(currentChanged(QModelIndex))); disconnect(s_view, SIGNAL(clicked(QModelIndex)), this, SIGNAL(completionActivated())); disconnect(s_view, SIGNAL(closed()), this, SLOT(popupClosed())); + disconnect(s_view, SIGNAL(aboutToActivateTab(TabPosition)), m_locationBar, SLOT(clear())); } void LocationCompleter::showPopup() @@ -102,6 +102,7 @@ void LocationCompleter::showPopup() connect(s_view->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(currentChanged(QModelIndex))); connect(s_view, SIGNAL(clicked(QModelIndex)), this, SIGNAL(completionActivated())); connect(s_view, SIGNAL(closed()), this, SLOT(popupClosed())); + connect(s_view, SIGNAL(aboutToActivateTab(TabPosition)), m_locationBar, SLOT(clear())); adjustPopupSize(); } diff --git a/src/lib/navigation/completer/locationcompleterdelegate.cpp b/src/lib/navigation/completer/locationcompleterdelegate.cpp index 09e0f9d20..a92b2109d 100644 --- a/src/lib/navigation/completer/locationcompleterdelegate.cpp +++ b/src/lib/navigation/completer/locationcompleterdelegate.cpp @@ -28,6 +28,7 @@ LocationCompleterDelegate::LocationCompleterDelegate(LocationCompleterView* pare : QStyledItemDelegate(parent) , m_rowHeight(0) , m_padding(0) + , m_drawSwitchToTab(true) , m_view(parent) { } @@ -109,8 +110,14 @@ void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewI QRect linkRect(titleRect.x(), infoYPos, titleRect.width(), opt.fontMetrics.height()); QString link(opt.fontMetrics.elidedText(index.data(Qt::DisplayRole).toString(), Qt::ElideRight, linkRect.width())); painter->setFont(opt.font); - - drawHighlightedTextLine(linkRect, link, searchText, painter, style, opt, colorLinkRole); + TabPosition pos = index.data(LocationCompleterModel::TabPositionRole).value(); + if(m_drawSwitchToTab && pos.windowIndex != -1) { + // TODO: select and paint a nice icon to give better feedback to the user. + drawTextLine(linkRect, tr("Switch to tab"), painter, style, opt, colorLinkRole); + } + else { + drawHighlightedTextLine(linkRect, link, searchText, painter, style, opt, colorLinkRole); + } // Draw line at the very bottom of item if the item is not highlighted if (!(opt.state & QStyle::State_Selected)) { @@ -288,3 +295,9 @@ QSize LocationCompleterDelegate::sizeHint(const QStyleOptionViewItem &option, co return QSize(200, m_rowHeight); } + +void LocationCompleterDelegate::drawSwitchToTab(bool enable) +{ + m_drawSwitchToTab = enable; +} + diff --git a/src/lib/navigation/completer/locationcompleterdelegate.h b/src/lib/navigation/completer/locationcompleterdelegate.h index f1585557e..bd448c676 100644 --- a/src/lib/navigation/completer/locationcompleterdelegate.h +++ b/src/lib/navigation/completer/locationcompleterdelegate.h @@ -32,6 +32,8 @@ public: void paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; + void drawSwitchToTab(bool enable); + private: void drawHighlightedTextLine(const QRect &rect, QString text, const QString &searchText, QPainter* painter, const QStyle* style, const QStyleOptionViewItemV4 &option, @@ -45,6 +47,7 @@ private: mutable int m_rowHeight; mutable int m_padding; + bool m_drawSwitchToTab; LocationCompleterView* m_view; }; diff --git a/src/lib/navigation/completer/locationcompletermodel.cpp b/src/lib/navigation/completer/locationcompletermodel.cpp index 8629f50a6..1464ce3fe 100644 --- a/src/lib/navigation/completer/locationcompletermodel.cpp +++ b/src/lib/navigation/completer/locationcompletermodel.cpp @@ -19,6 +19,8 @@ #include "iconprovider.h" #include "qzsettings.h" #include "mainapplication.h" +#include "qupzilla.h" +#include "tabwidget.h" #include @@ -26,6 +28,8 @@ LocationCompleterModel::LocationCompleterModel(QObject* parent) : QStandardItemModel(parent) , m_lastCompletion(QChar(QChar::Nbsp)) { + connect(mApp, SIGNAL(message(Qz::AppMessageType,bool)), this, SLOT(receiveMessage(Qz::AppMessageType,bool))); + loadSettings(); } bool countBiggerThan(const QStandardItem* i1, const QStandardItem* i2) @@ -70,6 +74,9 @@ void LocationCompleterModel::refreshCompletions(const QString &string) item->setData(query.value(3), CountRole); item->setData(QVariant(true), BookmarkRole); item->setData(string, SearchStringRole); + if(m_switchTabs) { + item->setData(QVariant::fromValue(tabPositionForUrl(url)), TabPositionRole); + } urlList.append(url); itemList.append(item); @@ -93,6 +100,9 @@ void LocationCompleterModel::refreshCompletions(const QString &string) item->setData(query.value(3), CountRole); item->setData(QVariant(false), BookmarkRole); item->setData(string, SearchStringRole); + if(m_switchTabs) { + item->setData(QVariant::fromValue(tabPositionForUrl(url)), TabPositionRole); + } itemList.append(item); } @@ -120,6 +130,9 @@ void LocationCompleterModel::showMostVisited() item->setData(query.value(0), IdRole); item->setData(query.value(2), TitleRole); item->setData(QVariant(false), BookmarkRole); + if(m_switchTabs) { + item->setData(QVariant::fromValue(tabPositionForUrl(url)), TabPositionRole); + } appendRow(item); } @@ -186,3 +199,34 @@ QSqlQuery LocationCompleterModel::createQuery(const QString &searchString, const return sqlQuery; } + +TabPosition LocationCompleterModel::tabPositionForUrl(const QUrl& url) const +{ + for(int win=0; win < mApp->windowCount(); ++win) { + QupZilla* mainWin = mApp->mainWindows().at(win); + QList tabs = mainWin->tabWidget()->allTabs(); + for(int tab=0; tab < tabs.count(); ++tab) { + if(tabs[tab]->url() == url) { + TabPosition pos; + pos.windowIndex = win; + pos.tabIndex = tab; + return pos; + } + } + } + return TabPosition(); +} + +void LocationCompleterModel::receiveMessage(Qz::AppMessageType mes, bool state) +{ + Q_UNUSED(state) + if(mes == Qz::AM_ReloadSettings) { + loadSettings(); + } +} + +void LocationCompleterModel::loadSettings() +{ + Settings settings; + m_switchTabs = settings.value("AddressBar/showSwitchTab", true).toBool(); +} diff --git a/src/lib/navigation/completer/locationcompletermodel.h b/src/lib/navigation/completer/locationcompletermodel.h index a91b05797..1a5556332 100644 --- a/src/lib/navigation/completer/locationcompletermodel.h +++ b/src/lib/navigation/completer/locationcompletermodel.h @@ -20,18 +20,32 @@ #include +#include "qz_namespace.h" + class QSqlQuery; class QUrl; +struct TabPosition { + int windowIndex; + int tabIndex; + TabPosition() + : windowIndex(-1) + , tabIndex(-1) + {} +}; +Q_DECLARE_METATYPE(TabPosition) + class LocationCompleterModel : public QStandardItemModel { + Q_OBJECT public: enum Role { TitleRole = Qt::UserRole + 1, BookmarkRole = Qt::UserRole + 2, IdRole = Qt::UserRole + 3, SearchStringRole = Qt::UserRole + 4, - CountRole = Qt::UserRole + 5 + CountRole = Qt::UserRole + 5, + TabPositionRole = Qt::UserRole + 6 }; explicit LocationCompleterModel(QObject* parent = 0); @@ -52,9 +66,14 @@ private: QSqlQuery createQuery(const QString &searchString, const QString &orderBy, const QList &alreadyFound, int limit, bool bookmarks = false, bool exactMatch = false); + TabPosition tabPositionForUrl(const QUrl& url) const; + void loadSettings(); QString m_lastCompletion; + bool m_switchTabs; +private slots: + void receiveMessage(Qz::AppMessageType mes, bool state); }; #endif // LOCATIONCOMPLETERMODEL_H diff --git a/src/lib/navigation/completer/locationcompleterview.cpp b/src/lib/navigation/completer/locationcompleterview.cpp index 173e64d60..3a243cfc5 100644 --- a/src/lib/navigation/completer/locationcompleterview.cpp +++ b/src/lib/navigation/completer/locationcompleterview.cpp @@ -17,8 +17,12 @@ * ============================================================ */ #include "locationcompleterview.h" #include "locationcompletermodel.h" +#include "locationcompleterdelegate.h" #include "mainapplication.h" +#include "qupzilla.h" #include "history.h" +#include "tabwidget.h" +#include "settings.h" #include #include @@ -40,6 +44,11 @@ LocationCompleterView::LocationCompleterView() setMouseTracking(true); installEventFilter(this); + + connect(mApp, SIGNAL(message(Qz::AppMessageType,bool)), this, SLOT(receiveMessage(Qz::AppMessageType,bool))); + + setItemDelegate(new LocationCompleterDelegate(this)); + loadSettings(); } QPersistentModelIndex LocationCompleterView::hoveredIndex() const @@ -63,6 +72,21 @@ bool LocationCompleterView::eventFilter(QObject* object, QEvent* event) } switch (keyEvent->key()) { + case Qt::Key_Return: + case Qt::Key_Enter: + if(m_switchTabs && !(keyEvent->modifiers() & Qt::ShiftModifier)) { + QModelIndex idx = selectionModel()->currentIndex(); + if(idx.isValid()) { + TabPosition pos = idx.data(LocationCompleterModel::TabPositionRole).value(); + if(pos.windowIndex!= -1) { + activateTab(pos); + close(); + return true; + } + } + } + break; + case Qt::Key_End: case Qt::Key_Home: if (keyEvent->modifiers() & Qt::ControlModifier) { @@ -134,12 +158,35 @@ bool LocationCompleterView::eventFilter(QObject* object, QEvent* event) case Qt::Key_PageUp: case Qt::Key_PageDown: return false; + + case Qt::Key_Shift: + // don't switch if there is no hovered or selected index to not disturb typing + if(m_switchTabs && (selectionModel()->currentIndex().isValid() || m_hoveredIndex.isValid())) { + static_cast(itemDelegate())->drawSwitchToTab(false); + viewport()->update(); + return true; + } + break; } // switch (keyEvent->key()) (static_cast(focusProxy()))->event(keyEvent); return true; } + case QEvent::KeyRelease: { + QKeyEvent* keyEvent = static_cast(event); + + switch(keyEvent->key()) { + case Qt::Key_Shift: + if(m_switchTabs) { + static_cast(itemDelegate())->drawSwitchToTab(true); + viewport()->update(); + return true; + } + } + } + + case QEvent::Show: m_ignoreNextMouseMove = true; break; @@ -170,6 +217,9 @@ void LocationCompleterView::close() QListView::hide(); verticalScrollBar()->setValue(0); + if(m_switchTabs) { + static_cast(itemDelegate())->drawSwitchToTab(true); + } } void LocationCompleterView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) @@ -203,3 +253,44 @@ void LocationCompleterView::mouseMoveEvent(QMouseEvent* event) QListView::mouseMoveEvent(event); } + +void LocationCompleterView::mouseReleaseEvent(QMouseEvent* event) +{ + if(m_switchTabs && !(event->modifiers() & Qt::ShiftModifier) && m_hoveredIndex.isValid()) { + TabPosition pos = m_hoveredIndex.data(LocationCompleterModel::TabPositionRole).value(); + if(pos.windowIndex != -1) { + event->accept(); + activateTab(pos); + close(); + } + else { + QListView::mouseReleaseEvent(event); + } + } + else { + QListView::mouseReleaseEvent(event); + } +} + +void LocationCompleterView::activateTab(TabPosition pos) +{ + emit aboutToActivateTab(pos); + QupZilla* win = mApp->mainWindows().at(pos.windowIndex); + win->activateWindow(); + win->tabWidget()->setCurrentIndex(pos.tabIndex); +} + +void LocationCompleterView::receiveMessage(Qz::AppMessageType mes, bool state) +{ + Q_UNUSED(state) + if(mes == Qz::AM_ReloadSettings) { + loadSettings(); + } +} + +void LocationCompleterView::loadSettings() +{ + Settings settings; + m_switchTabs = settings.value("AddressBar/showSwitchTab", true).toBool(); + static_cast(itemDelegate())->drawSwitchToTab(m_switchTabs); +} diff --git a/src/lib/navigation/completer/locationcompleterview.h b/src/lib/navigation/completer/locationcompleterview.h index b6a8545fd..357c158fc 100644 --- a/src/lib/navigation/completer/locationcompleterview.h +++ b/src/lib/navigation/completer/locationcompleterview.h @@ -21,6 +21,7 @@ #include #include "qz_namespace.h" +#include "locationcompletermodel.h" class QT_QUPZILLA_EXPORT LocationCompleterView : public QListView { @@ -34,20 +35,27 @@ public: signals: void closed(); + void aboutToActivateTab(TabPosition pos); public slots: void close(); private slots: void currentChanged(const QModelIndex ¤t, const QModelIndex &previous); + void activateTab(TabPosition pos);private slots: + void receiveMessage(Qz::AppMessageType mes, bool state); protected: void mouseMoveEvent(QMouseEvent* event); + void mouseReleaseEvent(QMouseEvent* event); private: + void loadSettings(); + bool m_ignoreNextMouseMove; QPersistentModelIndex m_hoveredIndex; + bool m_switchTabs; }; #endif // LOCATIONCOMPLETERVIEW_H diff --git a/src/lib/preferences/preferences.cpp b/src/lib/preferences/preferences.cpp index 015342467..67d3a413a 100644 --- a/src/lib/preferences/preferences.cpp +++ b/src/lib/preferences/preferences.cpp @@ -214,6 +214,7 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent) //AddressBar settings.beginGroup("AddressBar"); ui->addressbarCompletion->setCurrentIndex(settings.value("showSuggestions", 0).toInt()); + ui->completionShowSwitchTab->setChecked(settings.value("showSwitchTab", true).toBool()); ui->selectAllOnFocus->setChecked(settings.value("SelectAllTextOnDoubleClick", true).toBool()); ui->selectAllOnClick->setChecked(settings.value("SelectAllTextOnClick", false).toBool()); ui->addCountryWithAlt->setChecked(settings.value("AddCountryDomainWithAltKey", true).toBool()); @@ -937,6 +938,7 @@ void Preferences::saveSettings() //AddressBar settings.beginGroup("AddressBar"); settings.setValue("showSuggestions", ui->addressbarCompletion->currentIndex()); + settings.setValue("showSwitchTab", ui->completionShowSwitchTab->isChecked()); settings.setValue("SelectAllTextOnDoubleClick", ui->selectAllOnFocus->isChecked()); settings.setValue("SelectAllTextOnClick", ui->selectAllOnClick->isChecked()); settings.setValue("AddCountryDomainWithAltKey", ui->addCountryWithAlt->isChecked()); diff --git a/src/lib/preferences/preferences.ui b/src/lib/preferences/preferences.ui index 9ba0631b6..3d37a15ba 100644 --- a/src/lib/preferences/preferences.ui +++ b/src/lib/preferences/preferences.ui @@ -160,9 +160,9 @@ Qt::NoFocus - 5 + 0 - + @@ -486,7 +486,7 @@ - + @@ -647,14 +647,14 @@ - + 0 - + Tabs behavior @@ -770,7 +770,7 @@ - + Address Bar behavior @@ -832,6 +832,16 @@ + + + + Press "Shift" to not switch the tab but load the url in the current tab. + + + Propose to switch tab if completed url is already loaded. + + + @@ -963,7 +973,7 @@ - + @@ -1552,7 +1562,7 @@ - + @@ -1744,7 +1754,7 @@ - + @@ -1782,7 +1792,7 @@ - + @@ -1941,7 +1951,7 @@ - + @@ -2003,7 +2013,7 @@ - + @@ -2188,7 +2198,7 @@ - + @@ -2315,7 +2325,7 @@ - + @@ -2334,7 +2344,7 @@ - + From e9a8b8d7d87d14e976006f17475c6e59b89dddc8 Mon Sep 17 00:00:00 2001 From: Franz Fellner Date: Tue, 4 Dec 2012 16:16:45 +0100 Subject: [PATCH 2/4] Move switchToTab to QzSettings. --- src/lib/lib.pro | 1 - .../completer/locationcompleter.cpp | 1 + .../completer/locationcompletermodel.cpp | 22 ++----------- .../completer/locationcompletermodel.h | 10 ------ .../completer/locationcompleterview.cpp | 32 ++++--------------- .../completer/locationcompleterview.h | 6 +--- src/lib/other/qzsettings.cpp | 1 + src/lib/other/qzsettings.h | 1 + 8 files changed, 13 insertions(+), 61 deletions(-) diff --git a/src/lib/lib.pro b/src/lib/lib.pro index 4fcfc4ec1..6ac168f8e 100644 --- a/src/lib/lib.pro +++ b/src/lib/lib.pro @@ -325,7 +325,6 @@ HEADERS += \ tools/focusselectlineedit.h \ navigation/completer/locationcompleterdelegate.h \ navigation/completer/locationcompleter.h \ - navigation/completer/locationcompletermodel.h \ navigation/completer/locationcompleterview.h \ history/history.h \ history/historymodel.h \ diff --git a/src/lib/navigation/completer/locationcompleter.cpp b/src/lib/navigation/completer/locationcompleter.cpp index 7a71eaa4d..5a9f81fd9 100644 --- a/src/lib/navigation/completer/locationcompleter.cpp +++ b/src/lib/navigation/completer/locationcompleter.cpp @@ -33,6 +33,7 @@ LocationCompleter::LocationCompleter(QObject* parent) s_view = new LocationCompleterView; s_view->setModel(s_model); + s_view->setItemDelegate(new LocationCompleterDelegate(s_view)); } } diff --git a/src/lib/navigation/completer/locationcompletermodel.cpp b/src/lib/navigation/completer/locationcompletermodel.cpp index 1464ce3fe..88ab9a6fe 100644 --- a/src/lib/navigation/completer/locationcompletermodel.cpp +++ b/src/lib/navigation/completer/locationcompletermodel.cpp @@ -28,8 +28,6 @@ LocationCompleterModel::LocationCompleterModel(QObject* parent) : QStandardItemModel(parent) , m_lastCompletion(QChar(QChar::Nbsp)) { - connect(mApp, SIGNAL(message(Qz::AppMessageType,bool)), this, SLOT(receiveMessage(Qz::AppMessageType,bool))); - loadSettings(); } bool countBiggerThan(const QStandardItem* i1, const QStandardItem* i2) @@ -74,7 +72,7 @@ void LocationCompleterModel::refreshCompletions(const QString &string) item->setData(query.value(3), CountRole); item->setData(QVariant(true), BookmarkRole); item->setData(string, SearchStringRole); - if(m_switchTabs) { + if(qzSettings->showSwitchTab) { item->setData(QVariant::fromValue(tabPositionForUrl(url)), TabPositionRole); } @@ -100,7 +98,7 @@ void LocationCompleterModel::refreshCompletions(const QString &string) item->setData(query.value(3), CountRole); item->setData(QVariant(false), BookmarkRole); item->setData(string, SearchStringRole); - if(m_switchTabs) { + if(qzSettings->showSwitchTab) { item->setData(QVariant::fromValue(tabPositionForUrl(url)), TabPositionRole); } @@ -130,7 +128,7 @@ void LocationCompleterModel::showMostVisited() item->setData(query.value(0), IdRole); item->setData(query.value(2), TitleRole); item->setData(QVariant(false), BookmarkRole); - if(m_switchTabs) { + if(qzSettings->showSwitchTab) { item->setData(QVariant::fromValue(tabPositionForUrl(url)), TabPositionRole); } @@ -216,17 +214,3 @@ TabPosition LocationCompleterModel::tabPositionForUrl(const QUrl& url) const } return TabPosition(); } - -void LocationCompleterModel::receiveMessage(Qz::AppMessageType mes, bool state) -{ - Q_UNUSED(state) - if(mes == Qz::AM_ReloadSettings) { - loadSettings(); - } -} - -void LocationCompleterModel::loadSettings() -{ - Settings settings; - m_switchTabs = settings.value("AddressBar/showSwitchTab", true).toBool(); -} diff --git a/src/lib/navigation/completer/locationcompletermodel.h b/src/lib/navigation/completer/locationcompletermodel.h index 1a5556332..d3f046eab 100644 --- a/src/lib/navigation/completer/locationcompletermodel.h +++ b/src/lib/navigation/completer/locationcompletermodel.h @@ -37,7 +37,6 @@ Q_DECLARE_METATYPE(TabPosition) class LocationCompleterModel : public QStandardItemModel { - Q_OBJECT public: enum Role { TitleRole = Qt::UserRole + 1, @@ -52,10 +51,6 @@ public: void refreshCompletions(const QString &string); void showMostVisited(); -signals: - -public slots: - private: enum Type { HistoryAndBookmarks = 0, @@ -67,13 +62,8 @@ private: QSqlQuery createQuery(const QString &searchString, const QString &orderBy, const QList &alreadyFound, int limit, bool bookmarks = false, bool exactMatch = false); TabPosition tabPositionForUrl(const QUrl& url) const; - void loadSettings(); QString m_lastCompletion; - bool m_switchTabs; - -private slots: - void receiveMessage(Qz::AppMessageType mes, bool state); }; #endif // LOCATIONCOMPLETERMODEL_H diff --git a/src/lib/navigation/completer/locationcompleterview.cpp b/src/lib/navigation/completer/locationcompleterview.cpp index 3a243cfc5..d178d20eb 100644 --- a/src/lib/navigation/completer/locationcompleterview.cpp +++ b/src/lib/navigation/completer/locationcompleterview.cpp @@ -22,7 +22,7 @@ #include "qupzilla.h" #include "history.h" #include "tabwidget.h" -#include "settings.h" +#include "qzsettings.h" #include #include @@ -44,11 +44,6 @@ LocationCompleterView::LocationCompleterView() setMouseTracking(true); installEventFilter(this); - - connect(mApp, SIGNAL(message(Qz::AppMessageType,bool)), this, SLOT(receiveMessage(Qz::AppMessageType,bool))); - - setItemDelegate(new LocationCompleterDelegate(this)); - loadSettings(); } QPersistentModelIndex LocationCompleterView::hoveredIndex() const @@ -74,7 +69,7 @@ bool LocationCompleterView::eventFilter(QObject* object, QEvent* event) switch (keyEvent->key()) { case Qt::Key_Return: case Qt::Key_Enter: - if(m_switchTabs && !(keyEvent->modifiers() & Qt::ShiftModifier)) { + if(qzSettings->showSwitchTab && !(keyEvent->modifiers() & Qt::ShiftModifier)) { QModelIndex idx = selectionModel()->currentIndex(); if(idx.isValid()) { TabPosition pos = idx.data(LocationCompleterModel::TabPositionRole).value(); @@ -161,7 +156,7 @@ bool LocationCompleterView::eventFilter(QObject* object, QEvent* event) case Qt::Key_Shift: // don't switch if there is no hovered or selected index to not disturb typing - if(m_switchTabs && (selectionModel()->currentIndex().isValid() || m_hoveredIndex.isValid())) { + if(qzSettings->showSwitchTab && (selectionModel()->currentIndex().isValid() || m_hoveredIndex.isValid())) { static_cast(itemDelegate())->drawSwitchToTab(false); viewport()->update(); return true; @@ -178,7 +173,7 @@ bool LocationCompleterView::eventFilter(QObject* object, QEvent* event) switch(keyEvent->key()) { case Qt::Key_Shift: - if(m_switchTabs) { + if(qzSettings->showSwitchTab) { static_cast(itemDelegate())->drawSwitchToTab(true); viewport()->update(); return true; @@ -217,7 +212,7 @@ void LocationCompleterView::close() QListView::hide(); verticalScrollBar()->setValue(0); - if(m_switchTabs) { + if(qzSettings->showSwitchTab) { static_cast(itemDelegate())->drawSwitchToTab(true); } } @@ -256,7 +251,7 @@ void LocationCompleterView::mouseMoveEvent(QMouseEvent* event) void LocationCompleterView::mouseReleaseEvent(QMouseEvent* event) { - if(m_switchTabs && !(event->modifiers() & Qt::ShiftModifier) && m_hoveredIndex.isValid()) { + if(qzSettings->showSwitchTab && !(event->modifiers() & Qt::ShiftModifier) && m_hoveredIndex.isValid()) { TabPosition pos = m_hoveredIndex.data(LocationCompleterModel::TabPositionRole).value(); if(pos.windowIndex != -1) { event->accept(); @@ -279,18 +274,3 @@ void LocationCompleterView::activateTab(TabPosition pos) win->activateWindow(); win->tabWidget()->setCurrentIndex(pos.tabIndex); } - -void LocationCompleterView::receiveMessage(Qz::AppMessageType mes, bool state) -{ - Q_UNUSED(state) - if(mes == Qz::AM_ReloadSettings) { - loadSettings(); - } -} - -void LocationCompleterView::loadSettings() -{ - Settings settings; - m_switchTabs = settings.value("AddressBar/showSwitchTab", true).toBool(); - static_cast(itemDelegate())->drawSwitchToTab(m_switchTabs); -} diff --git a/src/lib/navigation/completer/locationcompleterview.h b/src/lib/navigation/completer/locationcompleterview.h index 357c158fc..f1ab04088 100644 --- a/src/lib/navigation/completer/locationcompleterview.h +++ b/src/lib/navigation/completer/locationcompleterview.h @@ -42,20 +42,16 @@ public slots: private slots: void currentChanged(const QModelIndex ¤t, const QModelIndex &previous); - void activateTab(TabPosition pos);private slots: - void receiveMessage(Qz::AppMessageType mes, bool state); + void activateTab(TabPosition pos); protected: void mouseMoveEvent(QMouseEvent* event); void mouseReleaseEvent(QMouseEvent* event); private: - void loadSettings(); - bool m_ignoreNextMouseMove; QPersistentModelIndex m_hoveredIndex; - bool m_switchTabs; }; #endif // LOCATIONCOMPLETERVIEW_H diff --git a/src/lib/other/qzsettings.cpp b/src/lib/other/qzsettings.cpp index d0aae3d10..6fce57f39 100644 --- a/src/lib/other/qzsettings.cpp +++ b/src/lib/other/qzsettings.cpp @@ -32,6 +32,7 @@ void QzSettings::loadSettings() addCountryWithAlt = settings.value("AddCountryDomainWithAltKey", true).toBool(); showLoadingProgress = settings.value("ShowLoadingProgress", false).toBool(); showLocationSuggestions = settings.value("showSuggestions", 0).toInt(); + showSwitchTab = settings.value("showSwitchTab", true).toBool(); settings.endGroup(); settings.beginGroup("SearchEngines"); diff --git a/src/lib/other/qzsettings.h b/src/lib/other/qzsettings.h index f341e6ba2..b5a452606 100644 --- a/src/lib/other/qzsettings.h +++ b/src/lib/other/qzsettings.h @@ -37,6 +37,7 @@ public: bool addCountryWithAlt; bool showLoadingProgress; int showLocationSuggestions; + bool showSwitchTab; // SearchEngines bool showSearchSuggestions; From 4e7fae41551bcc49648aebf368d49e05e6010ecc Mon Sep 17 00:00:00 2001 From: Franz Fellner Date: Tue, 4 Dec 2012 21:53:24 +0100 Subject: [PATCH 3/4] gitignore kdevelop4-files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d70a4e91e..cebe534ab 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ Thumbs.db tests/modeltest *.pdb *.ilk +*.kdev4 From 9ec85ad49d8455281252035143aa9330cb6b61dc Mon Sep 17 00:00:00 2001 From: Franz Fellner Date: Wed, 5 Dec 2012 11:53:56 +0100 Subject: [PATCH 4/4] WebSearchBar: Select alls text + set focus after search engine changed. This avoids another (double)click to select the text. --- src/lib/navigation/websearchbar.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/navigation/websearchbar.cpp b/src/lib/navigation/websearchbar.cpp index 1361f9472..42a759ac3 100644 --- a/src/lib/navigation/websearchbar.cpp +++ b/src/lib/navigation/websearchbar.cpp @@ -174,6 +174,8 @@ void WebSearchBar::setupEngines() void WebSearchBar::searchChanged(const ButtonWithMenu::Item &item) { + selectAll(); + setFocus(); setPlaceholderText(item.text); m_completerModel->setStringList(QStringList());