Skip to content

Commit

Permalink
Draw cursor in locationbar when completion popup is shown.
Browse files Browse the repository at this point in the history
  • Loading branch information
nowrep committed Jan 28, 2013
1 parent eb583d4 commit 780106d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/lib/navigation/completer/locationcompleter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 David Rosca <[email protected]>
* Copyright (C) 2010-2013 David Rosca <[email protected]>
*
* 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
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion src/lib/navigation/completer/locationcompleter.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 David Rosca <[email protected]>
* Copyright (C) 2010-2013 David Rosca <[email protected]>
*
* 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
Expand Down Expand Up @@ -35,6 +35,8 @@ class QT_QUPZILLA_EXPORT LocationCompleter : public QObject
explicit LocationCompleter(QObject* parent = 0);

void setLocationBar(LocationBar* locationBar);

bool isPopupVisible();
void closePopup();

signals:
Expand Down
27 changes: 27 additions & 0 deletions src/lib/navigation/locationbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 780106d

Please sign in to comment.