Make the popup bigger by default, but shrink it if it would go off the screen

This commit is contained in:
David Sansome 2011-09-17 15:12:00 +01:00
parent 61b3493c01
commit 9596377de1
2 changed files with 12 additions and 3 deletions

View File

@ -32,6 +32,7 @@
# include "spotifysearchprovider.h"
#endif
#include <QDesktopWidget>
#include <QListView>
#include <QPainter>
#include <QSortFilterProxyModel>
@ -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)));

View File

@ -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