mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
LocationCompleter: Don't change selected index with mouseover
Also render proper item state (selected / under mouse) in delegate.
This commit is contained in:
parent
9e8614447e
commit
6bceef43e2
@ -16,7 +16,6 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#include "locationcompleterdelegate.h"
|
#include "locationcompleterdelegate.h"
|
||||||
#include "locationcompleterview.h"
|
|
||||||
#include "locationcompletermodel.h"
|
#include "locationcompletermodel.h"
|
||||||
#include "locationbar.h"
|
#include "locationbar.h"
|
||||||
#include "iconprovider.h"
|
#include "iconprovider.h"
|
||||||
@ -44,12 +43,11 @@ static bool isUrlOrDomain(const QString &text)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LocationCompleterDelegate::LocationCompleterDelegate(LocationCompleterView* parent)
|
LocationCompleterDelegate::LocationCompleterDelegate(QObject *parent)
|
||||||
: QStyledItemDelegate(parent)
|
: QStyledItemDelegate(parent)
|
||||||
, m_rowHeight(0)
|
, m_rowHeight(0)
|
||||||
, m_padding(0)
|
, m_padding(0)
|
||||||
, m_drawSwitchToTab(true)
|
, m_drawSwitchToTab(true)
|
||||||
, m_view(parent)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,13 +71,7 @@ void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewI
|
|||||||
int leftPosition = m_padding * 2;
|
int leftPosition = m_padding * 2;
|
||||||
int rightPosition = opt.rect.right() - m_padding;
|
int rightPosition = opt.rect.right() - m_padding;
|
||||||
|
|
||||||
opt.state &= ~QStyle::State_MouseOver;
|
opt.state |= QStyle::State_Active;
|
||||||
|
|
||||||
if (m_view->hoveredIndex() == index) {
|
|
||||||
opt.state |= QStyle::State_Selected;
|
|
||||||
} else {
|
|
||||||
opt.state &= ~QStyle::State_Selected;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QPalette::ColorRole colorRole = opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text;
|
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;
|
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);
|
QRect textRect(linkRect);
|
||||||
textRect.setX(textRect.x() + m_padding + 16 + m_padding);
|
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) {
|
} else if (isVisitSearchItem) {
|
||||||
if (!isWebSearch) {
|
if (!isWebSearch) {
|
||||||
link = LocationCompleterView::tr("Visit");
|
link = tr("Visit");
|
||||||
} else {
|
} 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));
|
viewItemDrawText(painter, &opt, linkRect, link, textPalette.color(colorLinkRole));
|
||||||
} else {
|
} else {
|
||||||
|
@ -22,12 +22,10 @@
|
|||||||
|
|
||||||
#include "qzcommon.h"
|
#include "qzcommon.h"
|
||||||
|
|
||||||
class LocationCompleterView;
|
|
||||||
|
|
||||||
class QUPZILLA_EXPORT LocationCompleterDelegate : public QStyledItemDelegate
|
class QUPZILLA_EXPORT LocationCompleterDelegate : public QStyledItemDelegate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit LocationCompleterDelegate(LocationCompleterView* parent = 0);
|
explicit LocationCompleterDelegate(QObject *parent = 0);
|
||||||
|
|
||||||
void paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
void paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
QSize sizeHint(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;
|
mutable int m_padding;
|
||||||
bool m_drawSwitchToTab;
|
bool m_drawSwitchToTab;
|
||||||
QString m_originalText;
|
QString m_originalText;
|
||||||
|
|
||||||
LocationCompleterView* m_view;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LOCATIONCOMPLETERDELEGATE_H
|
#endif // LOCATIONCOMPLETERDELEGATE_H
|
||||||
|
@ -50,11 +50,6 @@ LocationCompleterView::LocationCompleterView()
|
|||||||
setItemDelegate(m_delegate);
|
setItemDelegate(m_delegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPersistentModelIndex LocationCompleterView::hoveredIndex() const
|
|
||||||
{
|
|
||||||
return m_hoveredIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LocationCompleterView::setOriginalText(const QString &originalText)
|
void LocationCompleterView::setOriginalText(const QString &originalText)
|
||||||
{
|
{
|
||||||
m_delegate->setOriginalText(originalText);
|
m_delegate->setOriginalText(originalText);
|
||||||
@ -72,7 +67,7 @@ bool LocationCompleterView::eventFilter(QObject* object, QEvent* event)
|
|||||||
case QEvent::KeyPress: {
|
case QEvent::KeyPress: {
|
||||||
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
|
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
|
||||||
Qt::KeyboardModifiers modifiers = keyEvent->modifiers();
|
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();
|
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) {
|
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:
|
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 (idx.isValid() || m_hoveredIndex.isValid()) {
|
if (idx != visitSearchIdx || m_hoveredIndex.isValid()) {
|
||||||
m_delegate->setShowSwitchToTab(false);
|
m_delegate->setShowSwitchToTab(false);
|
||||||
viewport()->update();
|
viewport()->update();
|
||||||
return true;
|
return true;
|
||||||
@ -262,15 +257,6 @@ void LocationCompleterView::close()
|
|||||||
emit closed();
|
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)
|
void LocationCompleterView::mouseMoveEvent(QMouseEvent* event)
|
||||||
{
|
{
|
||||||
if (m_ignoreNextMouseMove || !isVisible()) {
|
if (m_ignoreNextMouseMove || !isVisible()) {
|
||||||
|
@ -47,9 +47,6 @@ signals:
|
|||||||
public slots:
|
public slots:
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
private slots:
|
|
||||||
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mouseMoveEvent(QMouseEvent* event);
|
void mouseMoveEvent(QMouseEvent* event);
|
||||||
void mouseReleaseEvent(QMouseEvent* event);
|
void mouseReleaseEvent(QMouseEvent* event);
|
||||||
|
Loading…
Reference in New Issue
Block a user