mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-14 02:52:12 +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:
parent
1cbc8c6d2d
commit
b4b1ce03d6
|
@ -88,12 +88,14 @@ void LocationCompleter::currentChanged(const QModelIndex &index)
|
||||||
emit showCompletion(completion);
|
emit showCompletion(completion);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocationCompleter::popupClosed()
|
void LocationCompleter::slotPopupClosed()
|
||||||
{
|
{
|
||||||
disconnect(s_view->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(currentChanged(QModelIndex)));
|
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(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()));
|
disconnect(s_view, SIGNAL(aboutToActivateTab(TabPosition)), m_locationBar, SLOT(clear()));
|
||||||
|
|
||||||
|
emit popupClosed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocationCompleter::showPopup()
|
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->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(currentChanged(QModelIndex)));
|
||||||
connect(s_view, SIGNAL(clicked(QModelIndex)), this, SIGNAL(completionActivated()));
|
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()));
|
connect(s_view, SIGNAL(aboutToActivateTab(TabPosition)), m_locationBar, SLOT(clear()));
|
||||||
|
|
||||||
adjustPopupSize();
|
adjustPopupSize();
|
||||||
|
|
|
@ -43,6 +43,7 @@ public:
|
||||||
signals:
|
signals:
|
||||||
void showCompletion(const QString &);
|
void showCompletion(const QString &);
|
||||||
void completionActivated();
|
void completionActivated();
|
||||||
|
void popupClosed();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void complete(const QString &string);
|
void complete(const QString &string);
|
||||||
|
@ -50,7 +51,7 @@ public slots:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void currentChanged(const QModelIndex &index);
|
void currentChanged(const QModelIndex &index);
|
||||||
void popupClosed();
|
void slotPopupClosed();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void showPopup();
|
void showPopup();
|
||||||
|
|
|
@ -54,7 +54,9 @@ LocationBar::LocationBar(QupZilla* mainClass)
|
||||||
, m_holdingAlt(false)
|
, m_holdingAlt(false)
|
||||||
, m_loadProgress(0)
|
, m_loadProgress(0)
|
||||||
, m_progressVisible(false)
|
, m_progressVisible(false)
|
||||||
, m_forceLineEditPaintEvent(false)
|
, m_forcePaintEvent(false)
|
||||||
|
, m_drawCursor(true)
|
||||||
|
, m_popupClosed(false)
|
||||||
{
|
{
|
||||||
setObjectName("locationbar");
|
setObjectName("locationbar");
|
||||||
setDragEnabled(true);
|
setDragEnabled(true);
|
||||||
|
@ -82,6 +84,7 @@ LocationBar::LocationBar(QupZilla* mainClass)
|
||||||
m_completer.setLocationBar(this);
|
m_completer.setLocationBar(this);
|
||||||
connect(&m_completer, SIGNAL(showCompletion(QString)), this, SLOT(showCompletion(QString)));
|
connect(&m_completer, SIGNAL(showCompletion(QString)), this, SLOT(showCompletion(QString)));
|
||||||
connect(&m_completer, SIGNAL(completionActivated()), this, SLOT(urlEnter()));
|
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(this, SIGNAL(textEdited(QString)), this, SLOT(textEdit()));
|
||||||
connect(m_goIcon, SIGNAL(clicked(QPoint)), this, SLOT(urlEnter()));
|
connect(m_goIcon, SIGNAL(clicked(QPoint)), this, SLOT(urlEnter()));
|
||||||
|
@ -118,7 +121,7 @@ void LocationBar::setWebView(TabbedWebView* view)
|
||||||
void LocationBar::setText(const QString &text)
|
void LocationBar::setText(const QString &text)
|
||||||
{
|
{
|
||||||
LineEdit::setText(text);
|
LineEdit::setText(text);
|
||||||
m_forceLineEditPaintEvent = true;
|
m_forcePaintEvent = true;
|
||||||
setCursorPosition(0);
|
setCursorPosition(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,6 +141,12 @@ void LocationBar::showCompletion(const QString &newText)
|
||||||
end(false);
|
end(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LocationBar::completionPopupClosed()
|
||||||
|
{
|
||||||
|
m_popupClosed = true;
|
||||||
|
m_drawCursor = true;
|
||||||
|
}
|
||||||
|
|
||||||
QUrl LocationBar::createUrl()
|
QUrl LocationBar::createUrl()
|
||||||
{
|
{
|
||||||
QUrl urlToLoad;
|
QUrl urlToLoad;
|
||||||
|
@ -172,7 +181,7 @@ QString LocationBar::convertUrlToText(const QUrl &url) const
|
||||||
QString stringUrl = QzTools::urlEncodeQueryString(url);
|
QString stringUrl = QzTools::urlEncodeQueryString(url);
|
||||||
|
|
||||||
if (stringUrl == QLatin1String("qupzilla:speeddial") || stringUrl == QLatin1String("about:blank")) {
|
if (stringUrl == QLatin1String("qupzilla:speeddial") || stringUrl == QLatin1String("about:blank")) {
|
||||||
stringUrl = "";
|
stringUrl.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
return stringUrl;
|
return stringUrl;
|
||||||
|
@ -195,6 +204,11 @@ void LocationBar::textEdit()
|
||||||
m_completer.closePopup();
|
m_completer.closePopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Decide whether to draw cursor
|
||||||
|
if (text().length() <= 1 && m_drawCursor && !m_popupClosed) {
|
||||||
|
m_drawCursor = false;
|
||||||
|
}
|
||||||
|
|
||||||
showGoButton();
|
showGoButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,7 +415,8 @@ void LocationBar::focusOutEvent(QFocusEvent* event)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_forceLineEditPaintEvent = true;
|
m_popupClosed = false;
|
||||||
|
m_forcePaintEvent = true;
|
||||||
setCursorPosition(0);
|
setCursorPosition(0);
|
||||||
hideGoButton();
|
hideGoButton();
|
||||||
|
|
||||||
|
@ -552,11 +567,10 @@ void LocationBar::hideProgress()
|
||||||
|
|
||||||
void LocationBar::paintEvent(QPaintEvent* event)
|
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
|
// We need to draw cursor when popup is visible
|
||||||
// But don't paint it if we are just showing most visited sites
|
// But don't paint it if we are just showing most visited sites
|
||||||
LineEdit::paintEvent(event);
|
LineEdit::paintEvent(event);
|
||||||
|
|
||||||
QStyleOptionFrameV3 option;
|
QStyleOptionFrameV3 option;
|
||||||
initStyleOption(&option);
|
initStyleOption(&option);
|
||||||
|
|
||||||
|
@ -569,7 +583,7 @@ void LocationBar::paintEvent(QPaintEvent* event)
|
||||||
const QFontMetrics &fm = fontMetrics();
|
const QFontMetrics &fm = fontMetrics();
|
||||||
|
|
||||||
QString textPart = text().left(cursorPosition());
|
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 cursorYpos = contentsRect.y() + (contentsRect.height() - fm.height() + 1) / 2;
|
||||||
int cursorWidth = style()->pixelMetric(QStyle::PM_TextCursorWidth, &option, this);
|
int cursorWidth = style()->pixelMetric(QStyle::PM_TextCursorWidth, &option, this);
|
||||||
int cursorHeight = fontMetrics().height();
|
int cursorHeight = fontMetrics().height();
|
||||||
|
@ -583,10 +597,10 @@ void LocationBar::paintEvent(QPaintEvent* event)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasFocus() || text().isEmpty() || m_forceLineEditPaintEvent) {
|
if (hasFocus() || text().isEmpty() || m_forcePaintEvent) {
|
||||||
LineEdit::paintEvent(event);
|
LineEdit::paintEvent(event);
|
||||||
if (m_forceLineEditPaintEvent) {
|
if (m_forcePaintEvent) {
|
||||||
m_forceLineEditPaintEvent = false;
|
m_forcePaintEvent = false;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -71,6 +71,7 @@ private slots:
|
||||||
|
|
||||||
void updatePlaceHolderText();
|
void updatePlaceHolderText();
|
||||||
void showCompletion(const QString &newText);
|
void showCompletion(const QString &newText);
|
||||||
|
void completionPopupClosed();
|
||||||
|
|
||||||
void onLoadStarted();
|
void onLoadStarted();
|
||||||
void onLoadProgress(int progress);
|
void onLoadProgress(int progress);
|
||||||
|
@ -123,7 +124,9 @@ private:
|
||||||
ProgressStyle m_progressStyle;
|
ProgressStyle m_progressStyle;
|
||||||
QColor m_progressColor;
|
QColor m_progressColor;
|
||||||
|
|
||||||
bool m_forceLineEditPaintEvent;
|
bool m_forcePaintEvent;
|
||||||
|
bool m_drawCursor;
|
||||||
|
bool m_popupClosed;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LOCATIONBAR_H
|
#endif // LOCATIONBAR_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user