Commit 2974c9c8 authored by Jonathan Marten's avatar Jonathan Marten
Browse files

Search bar: Ignore a right mouse click over the search engine icon

So that the text edit context menu does not pop up over the top
of the search engine selection menu.
parent 111ebc5a
Pipeline #194839 passed with stage
in 8 minutes
......@@ -579,12 +579,29 @@ int SearchBarCombo::findHistoryItem(const QString &searchText)
return -1;
}
void SearchBarCombo::mousePressEvent(QMouseEvent *e)
bool SearchBarCombo::overIcon(int x)
{
QStyleOptionComplex opt;
int x0 = QStyle::visualRect(layoutDirection(), style()->subControlRect(QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxEditField, this), rect()).x();
const int x0 = QStyle::visualRect(layoutDirection(), style()->subControlRect(QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxEditField, this), rect()).x();
return (x > x0 + 2 && x < lineEdit()->x());
}
void SearchBarCombo::contextMenuEvent(QContextMenuEvent *e)
{
if (overIcon(e->x())) {
// Do not pass on the event, so that the combo box context menu
// does not pop up over the search engine selection menu. That
// menu will have been triggered by the iconClicked() signal emitted
// in mousePressEvent() below.
e->accept();
} else {
KHistoryComboBox::contextMenuEvent(e);
}
}
if (e->x() > x0 + 2 && e->x() < lineEdit()->x()) {
void SearchBarCombo::mousePressEvent(QMouseEvent *e)
{
if (overIcon(e->x())) {
emit iconClicked();
e->accept();
} else {
......
......@@ -94,6 +94,20 @@ protected:
*/
void mousePressEvent(QMouseEvent *e) override;
/**
* Captures context menu requests and ignores any over the icon.
*/
void contextMenuEvent(QContextMenuEvent *e) override;
private:
/**
* See whether a mouse click is over the search engine icon.
*
* @param x X coordinate of mouse event
* @return @c true if the click was over the icon
*/
bool overIcon(int x);
private Q_SLOTS:
void historyCleared();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment