Skip to content

Commit

Permalink
Fix issues with PopupHelpWidget on Linux and macOS
Browse files Browse the repository at this point in the history
* Clean up parent alignment code
* Don't hide widget if it currently has focus
* Use Qt::Tool window type on macOS as well. This prevents the popup help from hiding to the background if the main window has focus.
* Fixes #2814
  • Loading branch information
droidmonkey committed Mar 6, 2020
1 parent e26063a commit 50e52df
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 84 deletions.
68 changes: 4 additions & 64 deletions src/gui/SearchHelpWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>487</width>
<height>326</height>
<width>397</width>
<height>264</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -20,28 +20,10 @@
<enum>QFrame::StyledPanel</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
Expand All @@ -63,7 +45,7 @@
<item>
<widget class="QLabel" name="label_24">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
Expand Down Expand Up @@ -96,24 +78,6 @@
<string>Modifiers</string>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="horizontalSpacing">
<number>8</number>
</property>
<property name="verticalSpacing">
<number>8</number>
</property>
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>10</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="minimumSize">
Expand Down Expand Up @@ -222,21 +186,6 @@
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>15</number>
</property>
<property name="topMargin">
<number>10</number>
</property>
<property name="rightMargin">
<number>15</number>
</property>
<property name="horizontalSpacing">
<number>8</number>
</property>
<property name="verticalSpacing">
<number>5</number>
</property>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
Expand Down Expand Up @@ -299,12 +248,6 @@
<string>Term Wildcards</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<property name="horizontalSpacing">
<number>8</number>
</property>
<property name="verticalSpacing">
<number>8</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_18">
<property name="minimumSize">
Expand Down Expand Up @@ -404,9 +347,6 @@
<string>Examples</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>8</number>
</property>
<item>
<widget class="QLabel" name="label_9">
<property name="sizePolicy">
Expand Down
1 change: 0 additions & 1 deletion src/gui/SearchWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ SearchWidget::SearchWidget(QWidget* parent)
setFocusProxy(m_ui->searchEdit);

m_helpWidget = new PopupHelpWidget(m_ui->searchEdit);
m_helpWidget->setOffset(QPoint(0, 1));
Ui::SearchHelpWidget helpUi;
helpUi.setupUi(m_helpWidget);

Expand Down
32 changes: 14 additions & 18 deletions src/gui/widgets/PopupHelpWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,22 @@

PopupHelpWidget::PopupHelpWidget(QWidget* parent)
: QFrame(parent)
, m_parentWindow(parent->window())
, m_appWindow(getMainWindow())
, m_offset({0, 0})
, m_corner(Qt::BottomLeftCorner)
{
Q_ASSERT(parent);

#ifdef Q_OS_MACOS
setWindowFlags(Qt::FramelessWindowHint | Qt::Drawer);
#else
setWindowFlags(Qt::FramelessWindowHint | Qt::Tool);
#endif
hide();

m_appWindow->installEventFilter(this);
parent->installEventFilter(this);
parentWidget()->installEventFilter(this);
}

PopupHelpWidget::~PopupHelpWidget()
{
m_parentWindow->removeEventFilter(this);
m_appWindow->removeEventFilter(this);
parentWidget()->removeEventFilter(this);
}

Expand All @@ -65,10 +60,10 @@ void PopupHelpWidget::setPosition(Qt::Corner corner)

bool PopupHelpWidget::eventFilter(QObject* obj, QEvent* event)
{
if (obj == parentWidget() && event->type() == QEvent::FocusOut) {
hide();
} else if (obj == m_appWindow && (event->type() == QEvent::Move || event->type() == QEvent::Resize)) {
if (isVisible()) {
if (isVisible()) {
if (obj == parentWidget() && event->type() == QEvent::FocusOut && qApp->focusWindow() != windowHandle()) {
hide();
} else if (obj == m_appWindow && (event->type() == QEvent::Move || event->type() == QEvent::Resize)) {
alignWithParent();
}
}
Expand All @@ -83,21 +78,22 @@ void PopupHelpWidget::showEvent(QShowEvent* event)

void PopupHelpWidget::alignWithParent()
{
QPoint pos;
QPoint pos = m_offset;
switch (m_corner) {
case Qt::TopLeftCorner:
pos = parentWidget()->geometry().topLeft() + m_offset - QPoint(0, height());
pos += QPoint(0, -height());
break;
case Qt::TopRightCorner:
pos = parentWidget()->geometry().topRight() + m_offset - QPoint(width(), height());
pos += QPoint(parentWidget()->width(), -height());
break;
case Qt::BottomRightCorner:
pos = parentWidget()->geometry().bottomRight() + m_offset - QPoint(width(), 0);
pos += QPoint(parentWidget()->width(), parentWidget()->height());
break;
case Qt::BottomLeftCorner:
default:
pos = parentWidget()->geometry().bottomLeft() + m_offset;
pos += QPoint(0, parentWidget()->height());
break;
}

move(m_parentWindow->mapToGlobal(pos));
}
move(parentWidget()->mapToGlobal(pos));
}
1 change: 0 additions & 1 deletion src/gui/widgets/PopupHelpWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class PopupHelpWidget : public QFrame

private:
void alignWithParent();
QPointer<QWidget> m_parentWindow;
QPointer<QWidget> m_appWindow;

QPoint m_offset;
Expand Down

0 comments on commit 50e52df

Please sign in to comment.