Make the popup bigger by default, but shrink it if it would go off the screen
This commit is contained in:
parent
61b3493c01
commit
9596377de1
@ -32,6 +32,7 @@
|
|||||||
# include "spotifysearchprovider.h"
|
# include "spotifysearchprovider.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <QDesktopWidget>
|
||||||
#include <QListView>
|
#include <QListView>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
@ -39,7 +40,7 @@
|
|||||||
|
|
||||||
|
|
||||||
const int GlobalSearchWidget::kMinVisibleItems = 3;
|
const int GlobalSearchWidget::kMinVisibleItems = 3;
|
||||||
const int GlobalSearchWidget::kMaxVisibleItems = 12;
|
const int GlobalSearchWidget::kMaxVisibleItems = 25;
|
||||||
|
|
||||||
|
|
||||||
GlobalSearchWidget::GlobalSearchWidget(QWidget* parent)
|
GlobalSearchWidget::GlobalSearchWidget(QWidget* parent)
|
||||||
@ -52,7 +53,8 @@ GlobalSearchWidget::GlobalSearchWidget(QWidget* parent)
|
|||||||
proxy_(new GlobalSearchSortModel(this)),
|
proxy_(new GlobalSearchSortModel(this)),
|
||||||
view_(new QListView),
|
view_(new QListView),
|
||||||
eat_focus_out_(false),
|
eat_focus_out_(false),
|
||||||
background_(":allthethings.png")
|
background_(":allthethings.png"),
|
||||||
|
desktop_(qApp->desktop())
|
||||||
{
|
{
|
||||||
ui_->setupUi(this);
|
ui_->setupUi(this);
|
||||||
|
|
||||||
@ -210,7 +212,11 @@ void GlobalSearchWidget::RepositionPopup() {
|
|||||||
qBound(kMinVisibleItems, model_->rowCount(), kMaxVisibleItems));
|
qBound(kMinVisibleItems, model_->rowCount(), kMaxVisibleItems));
|
||||||
int w = ui_->search->width();
|
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_->setGeometry(QRect(pos, QSize(w, h)));
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ class GlobalSearch;
|
|||||||
class LibraryBackendInterface;
|
class LibraryBackendInterface;
|
||||||
class Ui_GlobalSearchWidget;
|
class Ui_GlobalSearchWidget;
|
||||||
|
|
||||||
|
class QDesktopWidget;
|
||||||
class QListView;
|
class QListView;
|
||||||
class QMimeData;
|
class QMimeData;
|
||||||
class QModelIndex;
|
class QModelIndex;
|
||||||
@ -98,6 +99,8 @@ private:
|
|||||||
|
|
||||||
QPixmap background_;
|
QPixmap background_;
|
||||||
QPixmap background_scaled_;
|
QPixmap background_scaled_;
|
||||||
|
|
||||||
|
QDesktopWidget* desktop_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GLOBALSEARCHWIDGET_H
|
#endif // GLOBALSEARCHWIDGET_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user