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

Draw cursor in locationbar when completion popup is shown.

Closes #645
This commit is contained in:
nowrep 2013-01-28 19:38:03 +01:00
parent eb583d429b
commit 780106ddd0
3 changed files with 36 additions and 2 deletions

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -43,6 +43,11 @@ void LocationCompleter::setLocationBar(LocationBar* locationBar)
m_locationBar = locationBar;
}
bool LocationCompleter::isPopupVisible()
{
return s_view->isVisible();
}
void LocationCompleter::closePopup()
{
s_view->close();

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -35,6 +35,8 @@ public:
explicit LocationCompleter(QObject* parent = 0);
void setLocationBar(LocationBar* locationBar);
bool isPopupVisible();
void closePopup();
signals:

View File

@ -591,6 +591,33 @@ void LocationBar::hideProgress()
void LocationBar::paintEvent(QPaintEvent* event)
{
if (m_completer.isPopupVisible()) {
// We need to draw cursor
LineEdit::paintEvent(event);
QStyleOptionFrameV3 option;
initStyleOption(&option);
int lm, tm, rm, bm;
getTextMargins(&lm, &tm, &rm, &bm);
QRect contentsRect = style()->subElementRect(QStyle::SE_LineEditContents, &option, this);
contentsRect.adjust(lm, tm, -rm, -bm);
const QFontMetrics &fm = fontMetrics();
QString textPart = text().left(cursorPosition()) + " ";
int cursorXpos = lm + fontMetrics().width(textPart);
int cursorYpos = contentsRect.y() + (contentsRect.height() - fm.height() + 1) / 2;
int cursorWidth = style()->pixelMetric(QStyle::PM_TextCursorWidth, &option, this);
int cursorHeight = fontMetrics().height();
QPainter p(this);
QRect cursorRect(cursorXpos, cursorYpos, cursorWidth, cursorHeight);
p.fillRect(cursorRect, option.palette.text().color());
return;
}
if (hasFocus() || text().isEmpty() || m_forceLineEditPaintEvent) {
LineEdit::paintEvent(event);
if (m_forceLineEditPaintEvent) {