mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +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/>.
|
||||
* ============================================================ */
|
||||
#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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<QKeyEvent*>(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()) {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user