1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

LocationBar: Proper fix for determing when to draw cursor.

Cursor will be properly drawn by Qt when starting writing
into empty lineedit (eg. select all and start typing).
After the completion popup is hidden for the first time, Qt will stop
drawing cursor and will only paint it again after losing and gaining
focus.
This commit is contained in:
nowrep 2013-02-22 15:20:28 +01:00
parent 1cbc8c6d2d
commit b4b1ce03d6
4 changed files with 35 additions and 15 deletions

View File

@ -88,12 +88,14 @@ void LocationCompleter::currentChanged(const QModelIndex &index)
emit showCompletion(completion);
}
void LocationCompleter::popupClosed()
void LocationCompleter::slotPopupClosed()
{
disconnect(s_view->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(currentChanged(QModelIndex)));
disconnect(s_view, SIGNAL(clicked(QModelIndex)), this, SIGNAL(completionActivated()));
disconnect(s_view, SIGNAL(closed()), this, SLOT(popupClosed()));
disconnect(s_view, SIGNAL(closed()), this, SLOT(slotPopupClosed()));
disconnect(s_view, SIGNAL(aboutToActivateTab(TabPosition)), m_locationBar, SLOT(clear()));
emit popupClosed();
}
void LocationCompleter::showPopup()
@ -118,7 +120,7 @@ void LocationCompleter::showPopup()
connect(s_view->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(currentChanged(QModelIndex)));
connect(s_view, SIGNAL(clicked(QModelIndex)), this, SIGNAL(completionActivated()));
connect(s_view, SIGNAL(closed()), this, SLOT(popupClosed()));
connect(s_view, SIGNAL(closed()), this, SLOT(slotPopupClosed()));
connect(s_view, SIGNAL(aboutToActivateTab(TabPosition)), m_locationBar, SLOT(clear()));
adjustPopupSize();

View File

@ -43,6 +43,7 @@ public:
signals:
void showCompletion(const QString &);
void completionActivated();
void popupClosed();
public slots:
void complete(const QString &string);
@ -50,7 +51,7 @@ public slots:
private slots:
void currentChanged(const QModelIndex &index);
void popupClosed();
void slotPopupClosed();
private:
void showPopup();

View File

@ -54,7 +54,9 @@ LocationBar::LocationBar(QupZilla* mainClass)
, m_holdingAlt(false)
, m_loadProgress(0)
, m_progressVisible(false)
, m_forceLineEditPaintEvent(false)
, m_forcePaintEvent(false)
, m_drawCursor(true)
, m_popupClosed(false)
{
setObjectName("locationbar");
setDragEnabled(true);
@ -82,6 +84,7 @@ LocationBar::LocationBar(QupZilla* mainClass)
m_completer.setLocationBar(this);
connect(&m_completer, SIGNAL(showCompletion(QString)), this, SLOT(showCompletion(QString)));
connect(&m_completer, SIGNAL(completionActivated()), this, SLOT(urlEnter()));
connect(&m_completer, SIGNAL(popupClosed()), this, SLOT(completionPopupClosed()));
connect(this, SIGNAL(textEdited(QString)), this, SLOT(textEdit()));
connect(m_goIcon, SIGNAL(clicked(QPoint)), this, SLOT(urlEnter()));
@ -118,7 +121,7 @@ void LocationBar::setWebView(TabbedWebView* view)
void LocationBar::setText(const QString &text)
{
LineEdit::setText(text);
m_forceLineEditPaintEvent = true;
m_forcePaintEvent = true;
setCursorPosition(0);
}
@ -138,6 +141,12 @@ void LocationBar::showCompletion(const QString &newText)
end(false);
}
void LocationBar::completionPopupClosed()
{
m_popupClosed = true;
m_drawCursor = true;
}
QUrl LocationBar::createUrl()
{
QUrl urlToLoad;
@ -172,7 +181,7 @@ QString LocationBar::convertUrlToText(const QUrl &url) const
QString stringUrl = QzTools::urlEncodeQueryString(url);
if (stringUrl == QLatin1String("qupzilla:speeddial") || stringUrl == QLatin1String("about:blank")) {
stringUrl = "";
stringUrl.clear();
}
return stringUrl;
@ -195,6 +204,11 @@ void LocationBar::textEdit()
m_completer.closePopup();
}
// Decide whether to draw cursor
if (text().length() <= 1 && m_drawCursor && !m_popupClosed) {
m_drawCursor = false;
}
showGoButton();
}
@ -401,7 +415,8 @@ void LocationBar::focusOutEvent(QFocusEvent* event)
return;
}
m_forceLineEditPaintEvent = true;
m_popupClosed = false;
m_forcePaintEvent = true;
setCursorPosition(0);
hideGoButton();
@ -552,11 +567,10 @@ void LocationBar::hideProgress()
void LocationBar::paintEvent(QPaintEvent* event)
{
if (m_completer.isPopupVisible() && !m_completer.showingMostVisited()) {
if (m_drawCursor && m_completer.isPopupVisible() && !m_completer.showingMostVisited()) {
// We need to draw cursor when popup is visible
// But don't paint it if we are just showing most visited sites
LineEdit::paintEvent(event);
QStyleOptionFrameV3 option;
initStyleOption(&option);
@ -569,7 +583,7 @@ void LocationBar::paintEvent(QPaintEvent* event)
const QFontMetrics &fm = fontMetrics();
QString textPart = text().left(cursorPosition());
int cursorXpos = lm + fontMetrics().width(textPart) + 3;
int cursorXpos = contentsRect.x() + 3 + 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();
@ -583,10 +597,10 @@ void LocationBar::paintEvent(QPaintEvent* event)
return;
}
if (hasFocus() || text().isEmpty() || m_forceLineEditPaintEvent) {
if (hasFocus() || text().isEmpty() || m_forcePaintEvent) {
LineEdit::paintEvent(event);
if (m_forceLineEditPaintEvent) {
m_forceLineEditPaintEvent = false;
if (m_forcePaintEvent) {
m_forcePaintEvent = false;
update();
}
return;

View File

@ -71,6 +71,7 @@ private slots:
void updatePlaceHolderText();
void showCompletion(const QString &newText);
void completionPopupClosed();
void onLoadStarted();
void onLoadProgress(int progress);
@ -123,7 +124,9 @@ private:
ProgressStyle m_progressStyle;
QColor m_progressColor;
bool m_forceLineEditPaintEvent;
bool m_forcePaintEvent;
bool m_drawCursor;
bool m_popupClosed;
};
#endif // LOCATIONBAR_H