+bool Popup::eventFilter(QObject *obj, QEvent *evt)
+{
+ QKeyEvent *keyEvent;
+
+ (void)obj;
+
+ if (evt->type() == QEvent::KeyPress) {
+ keyEvent = static_cast<QKeyEvent*>(evt);
+ if (keyEvent->key() == Qt::Key_Enter ||
+ keyEvent->key() == Qt::Key_Return) {
+ close();
+ return true;
+ }
+ }
+
+ return false;
+}
+
+void Popup::show()
+{
+ QLineEdit* le;
+
+ QWidget::show();
+
+ // We want to close the popup when the Enter key was
+ // pressed and the first editable widget had focus.
+ if ((le = this->findChild<QLineEdit*>())) {
+
+ // For combo boxes we need to hook into the parent of
+ // the line edit (i.e. the QComboBox). For edit boxes
+ // we hook into the widget directly.
+ if (le->parent()->metaObject()->className() ==
+ this->metaObject()->className())
+ le->installEventFilter(this);
+ else
+ le->parent()->installEventFilter(this);
+
+ le->selectAll();
+ le->setFocus();
+ }
+}
+
+bool Popup::space_for_arrow() const
+{
+ // Check if there is room for the arrow
+ switch (pos_) {
+ case Right:
+ if (point_.x() > x())
+ return false;
+ return true;
+
+ case Bottom:
+ if (point_.y() > y())
+ return false;
+ return true;
+
+ case Left:
+ if (point_.x() < (x() + width()))
+ return false;
+ return true;
+
+ case Top:
+ if (point_.y() < (y() + height()))
+ return false;
+ return true;
+ }
+
+ return true;
+}
+