diff --git a/src/lib/navigation/completer/locationcompleterdelegate.cpp b/src/lib/navigation/completer/locationcompleterdelegate.cpp index 8a6ef626e..4701ecf6b 100644 --- a/src/lib/navigation/completer/locationcompleterdelegate.cpp +++ b/src/lib/navigation/completer/locationcompleterdelegate.cpp @@ -16,7 +16,6 @@ * along with this program. If not, see . * ============================================================ */ #include "locationcompleterdelegate.h" -#include "locationcompleterview.h" #include "locationcompletermodel.h" #include "locationbar.h" #include "iconprovider.h" @@ -44,12 +43,11 @@ static bool isUrlOrDomain(const QString &text) return false; } -LocationCompleterDelegate::LocationCompleterDelegate(LocationCompleterView* parent) +LocationCompleterDelegate::LocationCompleterDelegate(QObject *parent) : QStyledItemDelegate(parent) , m_rowHeight(0) , m_padding(0) , m_drawSwitchToTab(true) - , m_view(parent) { } @@ -73,13 +71,7 @@ void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewI int leftPosition = m_padding * 2; int rightPosition = opt.rect.right() - m_padding; - opt.state &= ~QStyle::State_MouseOver; - - if (m_view->hoveredIndex() == index) { - opt.state |= QStyle::State_Selected; - } else { - opt.state &= ~QStyle::State_Selected; - } + opt.state |= QStyle::State_Active; const QPalette::ColorRole colorRole = opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text; const QPalette::ColorRole colorLinkRole = opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Link; @@ -173,12 +165,12 @@ void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewI QRect textRect(linkRect); textRect.setX(textRect.x() + m_padding + 16 + m_padding); - viewItemDrawText(painter, &opt, textRect, LocationCompleterView::tr("Switch to tab"), textPalette.color(colorLinkRole)); + viewItemDrawText(painter, &opt, textRect, tr("Switch to tab"), textPalette.color(colorLinkRole)); } else if (isVisitSearchItem) { if (!isWebSearch) { - link = LocationCompleterView::tr("Visit"); + link = tr("Visit"); } else { - link = LocationCompleterView::tr("Search on %1").arg(LocationBar::searchEngineName()); + link = tr("Search on %1").arg(LocationBar::searchEngineName()); } viewItemDrawText(painter, &opt, linkRect, link, textPalette.color(colorLinkRole)); } else { diff --git a/src/lib/navigation/completer/locationcompleterdelegate.h b/src/lib/navigation/completer/locationcompleterdelegate.h index b8279ea37..bd42ddd16 100644 --- a/src/lib/navigation/completer/locationcompleterdelegate.h +++ b/src/lib/navigation/completer/locationcompleterdelegate.h @@ -22,12 +22,10 @@ #include "qzcommon.h" -class LocationCompleterView; - class QUPZILLA_EXPORT LocationCompleterDelegate : public QStyledItemDelegate { public: - explicit LocationCompleterDelegate(LocationCompleterView* parent = 0); + explicit LocationCompleterDelegate(QObject *parent = 0); void paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; @@ -46,8 +44,6 @@ private: mutable int m_padding; bool m_drawSwitchToTab; QString m_originalText; - - LocationCompleterView* m_view; }; #endif // LOCATIONCOMPLETERDELEGATE_H diff --git a/src/lib/navigation/completer/locationcompleterview.cpp b/src/lib/navigation/completer/locationcompleterview.cpp index 02e30837a..58e6e7c8b 100644 --- a/src/lib/navigation/completer/locationcompleterview.cpp +++ b/src/lib/navigation/completer/locationcompleterview.cpp @@ -50,11 +50,6 @@ LocationCompleterView::LocationCompleterView() setItemDelegate(m_delegate); } -QPersistentModelIndex LocationCompleterView::hoveredIndex() const -{ - return m_hoveredIndex; -} - void LocationCompleterView::setOriginalText(const QString &originalText) { m_delegate->setOriginalText(originalText); @@ -72,7 +67,7 @@ bool LocationCompleterView::eventFilter(QObject* object, QEvent* event) case QEvent::KeyPress: { QKeyEvent* keyEvent = static_cast(event); Qt::KeyboardModifiers modifiers = keyEvent->modifiers(); - const QModelIndex idx = m_hoveredIndex; + const QModelIndex idx = currentIndex(); const QModelIndex visitSearchIdx = model()->index(0, 0).data(LocationCompleterModel::VisitSearchItemRole).toBool() ? model()->index(0, 0) : QModelIndex(); if ((keyEvent->key() == Qt::Key_Up || keyEvent->key() == Qt::Key_Down) && currentIndex() != idx) { @@ -190,7 +185,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 (idx.isValid() || m_hoveredIndex.isValid()) { + if (idx != visitSearchIdx || m_hoveredIndex.isValid()) { m_delegate->setShowSwitchToTab(false); viewport()->update(); return true; @@ -262,15 +257,6 @@ void LocationCompleterView::close() emit closed(); } -void LocationCompleterView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) -{ - m_hoveredIndex = current; - - QListView::currentChanged(current, previous); - - viewport()->update(); -} - void LocationCompleterView::mouseMoveEvent(QMouseEvent* event) { if (m_ignoreNextMouseMove || !isVisible()) { diff --git a/src/lib/navigation/completer/locationcompleterview.h b/src/lib/navigation/completer/locationcompleterview.h index 34e80f654..c17691c36 100644 --- a/src/lib/navigation/completer/locationcompleterview.h +++ b/src/lib/navigation/completer/locationcompleterview.h @@ -47,9 +47,6 @@ signals: public slots: void close(); -private slots: - void currentChanged(const QModelIndex ¤t, const QModelIndex &previous); - protected: void mouseMoveEvent(QMouseEvent* event); void mouseReleaseEvent(QMouseEvent* event);