diff --git a/src/globalsearch/globalsearchwidget.cpp b/src/globalsearch/globalsearchwidget.cpp index d4eb31735..2b940667b 100644 --- a/src/globalsearch/globalsearchwidget.cpp +++ b/src/globalsearch/globalsearchwidget.cpp @@ -32,6 +32,7 @@ # include "spotifysearchprovider.h" #endif +#include #include #include #include @@ -39,7 +40,7 @@ const int GlobalSearchWidget::kMinVisibleItems = 3; -const int GlobalSearchWidget::kMaxVisibleItems = 12; +const int GlobalSearchWidget::kMaxVisibleItems = 25; GlobalSearchWidget::GlobalSearchWidget(QWidget* parent) @@ -52,7 +53,8 @@ GlobalSearchWidget::GlobalSearchWidget(QWidget* parent) proxy_(new GlobalSearchSortModel(this)), view_(new QListView), eat_focus_out_(false), - background_(":allthethings.png") + background_(":allthethings.png"), + desktop_(qApp->desktop()) { ui_->setupUi(this); @@ -210,7 +212,11 @@ void GlobalSearchWidget::RepositionPopup() { qBound(kMinVisibleItems, model_->rowCount(), kMaxVisibleItems)); int w = ui_->search->width(); - QPoint pos = ui_->search->mapToGlobal(ui_->search->rect().bottomLeft()); + const QPoint pos = ui_->search->mapToGlobal(ui_->search->rect().bottomLeft()); + + // Shrink the popup if it would otherwise go off the screen + const QRect screen = desktop_->availableGeometry(ui_->search); + h = qMin(h, screen.bottom() - pos.y()); view_->setGeometry(QRect(pos, QSize(w, h))); diff --git a/src/globalsearch/globalsearchwidget.h b/src/globalsearch/globalsearchwidget.h index 347df22ee..8ade50c78 100644 --- a/src/globalsearch/globalsearchwidget.h +++ b/src/globalsearch/globalsearchwidget.h @@ -26,6 +26,7 @@ class GlobalSearch; class LibraryBackendInterface; class Ui_GlobalSearchWidget; +class QDesktopWidget; class QListView; class QMimeData; class QModelIndex; @@ -98,6 +99,8 @@ private: QPixmap background_; QPixmap background_scaled_; + + QDesktopWidget* desktop_; }; #endif // GLOBALSEARCHWIDGET_H