1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

Move switchToTab to QzSettings.

This commit is contained in:
Franz Fellner 2012-12-04 16:16:45 +01:00
parent 4c33d3563d
commit e9a8b8d7d8
8 changed files with 13 additions and 61 deletions

View File

@ -325,7 +325,6 @@ HEADERS += \
tools/focusselectlineedit.h \ tools/focusselectlineedit.h \
navigation/completer/locationcompleterdelegate.h \ navigation/completer/locationcompleterdelegate.h \
navigation/completer/locationcompleter.h \ navigation/completer/locationcompleter.h \
navigation/completer/locationcompletermodel.h \
navigation/completer/locationcompleterview.h \ navigation/completer/locationcompleterview.h \
history/history.h \ history/history.h \
history/historymodel.h \ history/historymodel.h \

View File

@ -33,6 +33,7 @@ LocationCompleter::LocationCompleter(QObject* parent)
s_view = new LocationCompleterView; s_view = new LocationCompleterView;
s_view->setModel(s_model); s_view->setModel(s_model);
s_view->setItemDelegate(new LocationCompleterDelegate(s_view));
} }
} }

View File

@ -28,8 +28,6 @@ LocationCompleterModel::LocationCompleterModel(QObject* parent)
: QStandardItemModel(parent) : QStandardItemModel(parent)
, m_lastCompletion(QChar(QChar::Nbsp)) , 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) 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(query.value(3), CountRole);
item->setData(QVariant(true), BookmarkRole); item->setData(QVariant(true), BookmarkRole);
item->setData(string, SearchStringRole); item->setData(string, SearchStringRole);
if(m_switchTabs) { if(qzSettings->showSwitchTab) {
item->setData(QVariant::fromValue<TabPosition>(tabPositionForUrl(url)), TabPositionRole); item->setData(QVariant::fromValue<TabPosition>(tabPositionForUrl(url)), TabPositionRole);
} }
@ -100,7 +98,7 @@ void LocationCompleterModel::refreshCompletions(const QString &string)
item->setData(query.value(3), CountRole); item->setData(query.value(3), CountRole);
item->setData(QVariant(false), BookmarkRole); item->setData(QVariant(false), BookmarkRole);
item->setData(string, SearchStringRole); item->setData(string, SearchStringRole);
if(m_switchTabs) { if(qzSettings->showSwitchTab) {
item->setData(QVariant::fromValue<TabPosition>(tabPositionForUrl(url)), TabPositionRole); item->setData(QVariant::fromValue<TabPosition>(tabPositionForUrl(url)), TabPositionRole);
} }
@ -130,7 +128,7 @@ void LocationCompleterModel::showMostVisited()
item->setData(query.value(0), IdRole); item->setData(query.value(0), IdRole);
item->setData(query.value(2), TitleRole); item->setData(query.value(2), TitleRole);
item->setData(QVariant(false), BookmarkRole); item->setData(QVariant(false), BookmarkRole);
if(m_switchTabs) { if(qzSettings->showSwitchTab) {
item->setData(QVariant::fromValue<TabPosition>(tabPositionForUrl(url)), TabPositionRole); item->setData(QVariant::fromValue<TabPosition>(tabPositionForUrl(url)), TabPositionRole);
} }
@ -216,17 +214,3 @@ TabPosition LocationCompleterModel::tabPositionForUrl(const QUrl& url) const
} }
return TabPosition(); 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();
}

View File

@ -37,7 +37,6 @@ Q_DECLARE_METATYPE(TabPosition)
class LocationCompleterModel : public QStandardItemModel class LocationCompleterModel : public QStandardItemModel
{ {
Q_OBJECT
public: public:
enum Role { enum Role {
TitleRole = Qt::UserRole + 1, TitleRole = Qt::UserRole + 1,
@ -52,10 +51,6 @@ public:
void refreshCompletions(const QString &string); void refreshCompletions(const QString &string);
void showMostVisited(); void showMostVisited();
signals:
public slots:
private: private:
enum Type { enum Type {
HistoryAndBookmarks = 0, HistoryAndBookmarks = 0,
@ -67,13 +62,8 @@ private:
QSqlQuery createQuery(const QString &searchString, const QString &orderBy, const QList<QUrl> &alreadyFound, QSqlQuery createQuery(const QString &searchString, const QString &orderBy, const QList<QUrl> &alreadyFound,
int limit, bool bookmarks = false, bool exactMatch = false); int limit, bool bookmarks = false, bool exactMatch = false);
TabPosition tabPositionForUrl(const QUrl& url) const; TabPosition tabPositionForUrl(const QUrl& url) const;
void loadSettings();
QString m_lastCompletion; QString m_lastCompletion;
bool m_switchTabs;
private slots:
void receiveMessage(Qz::AppMessageType mes, bool state);
}; };
#endif // LOCATIONCOMPLETERMODEL_H #endif // LOCATIONCOMPLETERMODEL_H

View File

@ -22,7 +22,7 @@
#include "qupzilla.h" #include "qupzilla.h"
#include "history.h" #include "history.h"
#include "tabwidget.h" #include "tabwidget.h"
#include "settings.h" #include "qzsettings.h"
#include <QKeyEvent> #include <QKeyEvent>
#include <QApplication> #include <QApplication>
@ -44,11 +44,6 @@ LocationCompleterView::LocationCompleterView()
setMouseTracking(true); setMouseTracking(true);
installEventFilter(this); installEventFilter(this);
connect(mApp, SIGNAL(message(Qz::AppMessageType,bool)), this, SLOT(receiveMessage(Qz::AppMessageType,bool)));
setItemDelegate(new LocationCompleterDelegate(this));
loadSettings();
} }
QPersistentModelIndex LocationCompleterView::hoveredIndex() const QPersistentModelIndex LocationCompleterView::hoveredIndex() const
@ -74,7 +69,7 @@ bool LocationCompleterView::eventFilter(QObject* object, QEvent* event)
switch (keyEvent->key()) { switch (keyEvent->key()) {
case Qt::Key_Return: case Qt::Key_Return:
case Qt::Key_Enter: case Qt::Key_Enter:
if(m_switchTabs && !(keyEvent->modifiers() & Qt::ShiftModifier)) { if(qzSettings->showSwitchTab && !(keyEvent->modifiers() & Qt::ShiftModifier)) {
QModelIndex idx = selectionModel()->currentIndex(); QModelIndex idx = selectionModel()->currentIndex();
if(idx.isValid()) { if(idx.isValid()) {
TabPosition pos = idx.data(LocationCompleterModel::TabPositionRole).value<TabPosition>(); TabPosition pos = idx.data(LocationCompleterModel::TabPositionRole).value<TabPosition>();
@ -161,7 +156,7 @@ bool LocationCompleterView::eventFilter(QObject* object, QEvent* event)
case Qt::Key_Shift: case Qt::Key_Shift:
// don't switch if there is no hovered or selected index to not disturb typing // 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<LocationCompleterDelegate*>(itemDelegate())->drawSwitchToTab(false); static_cast<LocationCompleterDelegate*>(itemDelegate())->drawSwitchToTab(false);
viewport()->update(); viewport()->update();
return true; return true;
@ -178,7 +173,7 @@ bool LocationCompleterView::eventFilter(QObject* object, QEvent* event)
switch(keyEvent->key()) { switch(keyEvent->key()) {
case Qt::Key_Shift: case Qt::Key_Shift:
if(m_switchTabs) { if(qzSettings->showSwitchTab) {
static_cast<LocationCompleterDelegate*>(itemDelegate())->drawSwitchToTab(true); static_cast<LocationCompleterDelegate*>(itemDelegate())->drawSwitchToTab(true);
viewport()->update(); viewport()->update();
return true; return true;
@ -217,7 +212,7 @@ void LocationCompleterView::close()
QListView::hide(); QListView::hide();
verticalScrollBar()->setValue(0); verticalScrollBar()->setValue(0);
if(m_switchTabs) { if(qzSettings->showSwitchTab) {
static_cast<LocationCompleterDelegate*>(itemDelegate())->drawSwitchToTab(true); static_cast<LocationCompleterDelegate*>(itemDelegate())->drawSwitchToTab(true);
} }
} }
@ -256,7 +251,7 @@ void LocationCompleterView::mouseMoveEvent(QMouseEvent* event)
void LocationCompleterView::mouseReleaseEvent(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<TabPosition>(); TabPosition pos = m_hoveredIndex.data(LocationCompleterModel::TabPositionRole).value<TabPosition>();
if(pos.windowIndex != -1) { if(pos.windowIndex != -1) {
event->accept(); event->accept();
@ -279,18 +274,3 @@ void LocationCompleterView::activateTab(TabPosition pos)
win->activateWindow(); win->activateWindow();
win->tabWidget()->setCurrentIndex(pos.tabIndex); 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<LocationCompleterDelegate*>(itemDelegate())->drawSwitchToTab(m_switchTabs);
}

View File

@ -42,20 +42,16 @@ public slots:
private slots: private slots:
void currentChanged(const QModelIndex &current, const QModelIndex &previous); void currentChanged(const QModelIndex &current, const QModelIndex &previous);
void activateTab(TabPosition pos);private slots: void activateTab(TabPosition pos);
void receiveMessage(Qz::AppMessageType mes, bool state);
protected: protected:
void mouseMoveEvent(QMouseEvent* event); void mouseMoveEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event); void mouseReleaseEvent(QMouseEvent* event);
private: private:
void loadSettings();
bool m_ignoreNextMouseMove; bool m_ignoreNextMouseMove;
QPersistentModelIndex m_hoveredIndex; QPersistentModelIndex m_hoveredIndex;
bool m_switchTabs;
}; };
#endif // LOCATIONCOMPLETERVIEW_H #endif // LOCATIONCOMPLETERVIEW_H

View File

@ -32,6 +32,7 @@ void QzSettings::loadSettings()
addCountryWithAlt = settings.value("AddCountryDomainWithAltKey", true).toBool(); addCountryWithAlt = settings.value("AddCountryDomainWithAltKey", true).toBool();
showLoadingProgress = settings.value("ShowLoadingProgress", false).toBool(); showLoadingProgress = settings.value("ShowLoadingProgress", false).toBool();
showLocationSuggestions = settings.value("showSuggestions", 0).toInt(); showLocationSuggestions = settings.value("showSuggestions", 0).toInt();
showSwitchTab = settings.value("showSwitchTab", true).toBool();
settings.endGroup(); settings.endGroup();
settings.beginGroup("SearchEngines"); settings.beginGroup("SearchEngines");

View File

@ -37,6 +37,7 @@ public:
bool addCountryWithAlt; bool addCountryWithAlt;
bool showLoadingProgress; bool showLoadingProgress;
int showLocationSuggestions; int showLocationSuggestions;
bool showSwitchTab;
// SearchEngines // SearchEngines
bool showSearchSuggestions; bool showSearchSuggestions;