diff --git a/src/ui/albumcoverchoicecontroller.cpp b/src/ui/albumcoverchoicecontroller.cpp index e5decb124..a6ea8f2cc 100644 --- a/src/ui/albumcoverchoicecontroller.cpp +++ b/src/ui/albumcoverchoicecontroller.cpp @@ -30,16 +30,18 @@ #include "ui/iconloader.h" #include -#include #include #include #include +#include #include #include #include #include -#include #include +#include +#include +#include const char* AlbumCoverChoiceController::kLoadImageFileFilter = QT_TR_NOOP( "Images (*.png *.jpg *.jpeg *.bmp *.gif *.xpm *.pbm *.pgm *.ppm *.xbm)"); @@ -244,10 +246,17 @@ QDialog* AlbumCoverChoiceController::ShowCoverPrivate(const Song& song) { // if the cover is larger than the screen, resize the window // 85% seems to be enough to account for title bar and taskbar etc. - QDesktopWidget desktop; - int current_screen = desktop.screenNumber(this); - int desktop_height = desktop.screenGeometry(current_screen).height(); - int desktop_width = desktop.screenGeometry(current_screen).width(); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) + QScreen* screen = screen(); +#else + QScreen* screen = + (window() && window()->windowHandle() ? window()->windowHandle()->screen() + : QGuiApplication::primaryScreen()); +#endif + + QRect screenGeometry = screen->availableGeometry(); + int desktop_height = screenGeometry.height(); + int desktop_width = screenGeometry.width(); // resize differently if monitor is in portrait mode if (desktop_width < desktop_height) { diff --git a/src/ui/notificationssettingspage.cpp b/src/ui/notificationssettingspage.cpp index a00eedeca..c04dcb3b5 100644 --- a/src/ui/notificationssettingspage.cpp +++ b/src/ui/notificationssettingspage.cpp @@ -220,7 +220,7 @@ void NotificationsSettingsPage::Save() { s.setValue("foreground_color", pretty_popup_->foreground_color()); s.setValue("background_color", pretty_popup_->background_color()); s.setValue("background_opacity", pretty_popup_->background_opacity()); - s.setValue("popup_display", pretty_popup_->popup_display()); + s.setValue("popup_screen", pretty_popup_->popup_screen()); s.setValue("popup_pos", pretty_popup_->popup_pos()); s.setValue("font", pretty_popup_->font().toString()); s.setValue("disable_duration", diff --git a/src/ui/settingsdialog.cpp b/src/ui/settingsdialog.cpp index 354187ade..1296f2d02 100644 --- a/src/ui/settingsdialog.cpp +++ b/src/ui/settingsdialog.cpp @@ -82,10 +82,11 @@ #endif #include -#include #include #include +#include #include +#include SettingsItemDelegate::SettingsItemDelegate(QObject* parent) : QStyledItemDelegate(parent) {} @@ -304,10 +305,18 @@ void SettingsDialog::showEvent(QShowEvent* e) { loading_settings_ = false; // Resize the dialog if it's too big - const QSize available = - QApplication::desktop()->availableGeometry(this).size(); - if (available.height() < height()) { - resize(width(), sizeHint().height()); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) + QScreen* screen = screen(); +#else + QScreen* screen = + (window() && window()->windowHandle() ? window()->windowHandle()->screen() + : QGuiApplication::primaryScreen()); +#endif + if (screen) { + const QRect available = screen->availableGeometry(); + if (available.height() < height()) { + resize(width(), sizeHint().height()); + } } QDialog::showEvent(e); diff --git a/src/widgets/nowplayingwidget.cpp b/src/widgets/nowplayingwidget.cpp index 4085f4c80..36ab8695f 100644 --- a/src/widgets/nowplayingwidget.cpp +++ b/src/widgets/nowplayingwidget.cpp @@ -17,14 +17,16 @@ #include "nowplayingwidget.h" -#include +#include #include #include -#include #include +#include +#include #include #include #include +#include #include #include "fullscreenhypnotoad.h" @@ -647,10 +649,15 @@ void NowPlayingWidget::SearchCoverAutomatically() { } void NowPlayingWidget::Bask() { - QDesktopWidget desktop; - int current_screen = desktop.screenNumber(this); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) + QScreen* screen = screen(); +#else + QScreen* screen = + (window() && window()->windowHandle() ? window()->windowHandle()->screen() + : QGuiApplication::primaryScreen()); +#endif big_hypnotoad_.reset(new FullscreenHypnotoad); - big_hypnotoad_->setGeometry(desktop.screenGeometry(current_screen)); + if (screen) big_hypnotoad_->setGeometry(screen->availableGeometry()); big_hypnotoad_->showFullScreen(); } diff --git a/src/widgets/osdpretty.cpp b/src/widgets/osdpretty.cpp index 9d95716d8..f253d2f58 100644 --- a/src/widgets/osdpretty.cpp +++ b/src/widgets/osdpretty.cpp @@ -22,15 +22,15 @@ #include #include #include -#include +#include #include #include #include +#include #include -#include #include - -#include +#include +#include #ifdef HAVE_X11 #include @@ -60,7 +60,7 @@ OSDPretty::OSDPretty(Mode mode, QWidget* parent) mode_(mode), background_color_(kPresetBlue), background_opacity_(0.85), - popup_display_(0), + popup_screen_(nullptr), font_(QFont()), disable_duration_(false), timeout_(new QTimer(this)), @@ -125,20 +125,25 @@ OSDPretty::OSDPretty(Mode mode, QWidget* parent) int margin = l->margin() + kDropShadowSize; l->setMargin(margin); - // Get current screen resolution - QRect screenResolution = QApplication::desktop()->screenGeometry(); - // Leave 200 px for icon - ui_->summary->setMaximumWidth(screenResolution.width() - 200); - ui_->message->setMaximumWidth(screenResolution.width() - 200); - // Set maximum size for the OSD, a little margin here too - setMaximumSize(screenResolution.width() - 100, - screenResolution.height() - 100); + connect(qApp, SIGNAL(screenAdded(QScreen*)), this, + SLOT(ScreenAdded(QScreen*))); + connect(qApp, SIGNAL(screenRemoved(QScreen*)), this, + SLOT(ScreenRemoved(QScreen*))); // Don't load settings here, they will be reloaded anyway on creation } OSDPretty::~OSDPretty() { delete ui_; } +void OSDPretty::ScreenAdded(QScreen* screen) { + screens_.insert(screen->name(), screen); +} + +void OSDPretty::ScreenRemoved(QScreen* screen) { + if (screens_.contains(screen->name())) screens_.remove(screen->name()); + if (screen == popup_screen_) popup_screen_ = current_screen(); +} + bool OSDPretty::IsTransparencyAvailable() { #if defined(HAVE_X11) && (QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)) return QX11Info::isCompositingManagerRunning(); @@ -149,17 +154,45 @@ bool OSDPretty::IsTransparencyAvailable() { void OSDPretty::Load() { QSettings s; s.beginGroup(kSettingsGroup); - foreground_color_ = QColor(s.value("foreground_color", 0).toInt()); background_color_ = QColor(s.value("background_color", kPresetBlue).toInt()); background_opacity_ = s.value("background_opacity", 0.85).toDouble(); - popup_display_ = s.value("popup_display", -1).toInt(); - popup_pos_ = s.value("popup_pos", QPoint(0, 0)).toPoint(); font_.fromString(s.value("font", "Verdana,9,-1,5,50,0,0,0,0,0").toString()); disable_duration_ = s.value("disable_duration", false).toBool(); + if (s.contains("popup_screen")) { + popup_screen_name_ = s.value("popup_screen").toString(); + if (screens_.contains(popup_screen_name_)) { + popup_screen_ = screens_[popup_screen_name_]; + } else { + popup_screen_ = current_screen(); + if (current_screen()) + popup_screen_name_ = current_screen()->name(); + else + popup_screen_name_.clear(); + } + } else { + popup_screen_ = current_screen(); + if (current_screen()) popup_screen_name_ = current_screen()->name(); + } + + if (s.contains("popup_pos")) { + popup_pos_ = s.value("popup_pos").toPoint(); + } else { + if (popup_screen_) { + QRect geometry = popup_screen_->availableGeometry(); + popup_pos_.setX(geometry.width() - width()); + popup_pos_.setY(0); + } else { + popup_pos_.setX(0); + popup_pos_.setY(0); + } + } + set_font(font()); set_foreground_color(foreground_color()); + + s.endGroup(); } void OSDPretty::ReloadSettings() { @@ -269,10 +302,26 @@ void OSDPretty::ShowMessage(const QString& summary, const QString& message, } void OSDPretty::showEvent(QShowEvent* e) { + screens_.clear(); + for (QScreen* screen : qApp->screens()) { + screens_.insert(screen->name(), screen); + } + + // Get current screen resolution + QRect screenResolution = current_screen()->availableGeometry(); + + // Leave 200 px for icon + ui_->summary->setMaximumWidth(screenResolution.width() - 200); + ui_->message->setMaximumWidth(screenResolution.width() - 200); + // Set maximum size for the OSD, a little margin here too + setMaximumSize(screenResolution.width() - 100, + screenResolution.height() - 100); + setWindowOpacity(fading_enabled_ ? 0.0 : 1.0); QWidget::showEvent(e); + Load(); Reposition(); if (fading_enabled_) { @@ -305,7 +354,6 @@ void OSDPretty::FaderFinished() { void OSDPretty::FaderValueChanged(qreal value) { setWindowOpacity(value); } void OSDPretty::Reposition() { - QDesktopWidget* desktop = QApplication::desktop(); // Make the OSD the proper size layout()->activate(); @@ -313,21 +361,22 @@ void OSDPretty::Reposition() { // Work out where to place the OSD. -1 for x or y means "on the right or // bottom edge". - QRect geometry(desktop->availableGeometry(popup_display_)); + if (popup_screen_) { + QRect geometry = popup_screen_->availableGeometry(); - int x = popup_pos_.x() < 0 ? geometry.right() - width() - : geometry.left() + popup_pos_.x(); - int y = popup_pos_.y() < 0 ? geometry.bottom() - height() - : geometry.top() + popup_pos_.y(); + int x = popup_pos_.x() < 0 ? geometry.right() - width() + : geometry.left() + popup_pos_.x(); + int y = popup_pos_.y() < 0 ? geometry.bottom() - height() + : geometry.top() + popup_pos_.y(); #ifndef Q_OS_WIN32 - // windows needs negative coordinates for monitors - // to the left or above the primary - x = qBound(0, x, geometry.right() - width()); - y = qBound(0, y, geometry.bottom() - height()); + // windows needs negative coordinates for monitors + // to the left or above the primary + x = qBound(0, x, geometry.right() - width()); + y = qBound(0, y, geometry.bottom() - height()); #endif - - move(x, y); + move(x, y); + } // Create a mask for the actual area of the OSD QBitmap mask(size()); @@ -374,8 +423,15 @@ void OSDPretty::mouseMoveEvent(QMouseEvent* e) { QPoint new_pos = original_window_pos_ + delta; // Keep it to the bounds of the desktop - QDesktopWidget* desktop = QApplication::desktop(); - QRect geometry(desktop->availableGeometry(e->globalPos())); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) + QScreen* screen = QGuiApplication::screenAt(e->globalPos()); +#else + QScreen* screen = (window() && window()->windowHandle() + ? window()->windowHandle()->screen() + : QGuiApplication::primaryScreen()); +#endif + if (!screen) return; + QRect geometry = screen->availableGeometry(); new_pos.setX( qBound(geometry.left(), new_pos.x(), geometry.right() - width())); @@ -391,26 +447,36 @@ void OSDPretty::mouseMoveEvent(QMouseEvent* e) { move(new_pos); - popup_display_ = current_display(); - popup_pos_ = current_pos(); + popup_screen_ = screen; + popup_screen_name_ = screen->name(); } } -QPoint OSDPretty::current_pos() const { - QDesktopWidget* desktop = QApplication::desktop(); - QRect geometry(desktop->availableGeometry(current_display())); - - int x = pos().x() >= geometry.right() - width() ? -1 - : pos().x() - geometry.left(); - int y = pos().y() >= geometry.bottom() - height() ? -1 : pos().y() - - geometry.top(); - - return QPoint(x, y); +QScreen* OSDPretty::current_screen() const { +#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) + return QGuiApplication::screenAt(pos()); +#else + return (window() && window()->windowHandle() + ? window()->windowHandle()->screen() + : QGuiApplication::primaryScreen()); +#endif } -int OSDPretty::current_display() const { - QDesktopWidget* desktop = QApplication::desktop(); - return desktop->screenNumber(pos()); +QPoint OSDPretty::current_pos() const { + if (current_screen()) { + QRect geometry = current_screen()->availableGeometry(); + + int x = pos().x() >= geometry.right() - width() + ? -1 + : pos().x() - geometry.left(); + int y = pos().y() >= geometry.bottom() - height() + ? -1 + : pos().y() - geometry.top(); + + return QPoint(x, y); + } + + return QPoint(0, 0); } void OSDPretty::set_background_color(QRgb color) { @@ -436,8 +502,9 @@ void OSDPretty::set_foreground_color(QRgb color) { void OSDPretty::set_popup_duration(int msec) { timeout_->setInterval(msec); } void OSDPretty::mouseReleaseEvent(QMouseEvent*) { - if (mode_ == Mode_Draggable) { - popup_display_ = current_display(); + if (current_screen() && mode_ == Mode_Draggable) { + popup_screen_ = current_screen(); + popup_screen_name_ = current_screen()->name(); popup_pos_ = current_pos(); } } diff --git a/src/widgets/osdpretty.h b/src/widgets/osdpretty.h index 50bf1eeda..ec5ea7354 100644 --- a/src/widgets/osdpretty.h +++ b/src/widgets/osdpretty.h @@ -18,10 +18,12 @@ #ifndef OSDPRETTY_H #define OSDPRETTY_H +#include #include class Ui_OSDPretty; +class QScreen; class QTimeLine; class OSDPretty : public QWidget { @@ -66,7 +68,7 @@ class OSDPretty : public QWidget { QRgb foreground_color() const { return foreground_color_.rgb(); } QRgb background_color() const { return background_color_.rgb(); } qreal background_opacity() const { return background_opacity_; } - int popup_display() const { return popup_display_; } + QString popup_screen() const { return popup_screen_name_; } QPoint popup_pos() const { return popup_pos_; } QFont font() const { return font_; } bool disable_duration() const { return disable_duration_; } @@ -74,7 +76,7 @@ class OSDPretty : public QWidget { // When the user has been moving the popup, use these to get its current // position and screen. Note that these return invalid values if the popup // is hidden. - int current_display() const; + QScreen* current_screen() const; QPoint current_pos() const; // QWidget @@ -104,6 +106,8 @@ class OSDPretty : public QWidget { private slots: void FaderValueChanged(qreal value); void FaderFinished(); + void ScreenAdded(QScreen* screen); + void ScreenRemoved(QScreen* screen); private: Ui_OSDPretty* ui_; @@ -114,8 +118,9 @@ class OSDPretty : public QWidget { QColor foreground_color_; QColor background_color_; float background_opacity_; - int popup_display_; // -1 for default + QString popup_screen_name_; QPoint popup_pos_; + QScreen* popup_screen_; QFont font_; // The OSD is kept always on top until you click (no timer) bool disable_duration_; @@ -138,6 +143,8 @@ class OSDPretty : public QWidget { // Toggling requested, we have to show or hide the OSD bool toggle_mode_; + + QMap screens_; }; #endif // OSDPRETTY_H diff --git a/src/widgets/prettyimage.cpp b/src/widgets/prettyimage.cpp index bfb3959f6..0bc713c48 100644 --- a/src/widgets/prettyimage.cpp +++ b/src/widgets/prettyimage.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include #include @@ -28,8 +27,10 @@ #include #include #include +#include #include #include +#include #include #include "core/closure.h" @@ -189,25 +190,35 @@ void PrettyImage::contextMenuEvent(QContextMenuEvent* e) { } void PrettyImage::ShowFullsize() { - // Work out how large to make the window, based on the size of the screen - QRect desktop_rect(QApplication::desktop()->availableGeometry(this)); - QSize window_size(qMin(desktop_rect.width() - 20, image_.width()), - qMin(desktop_rect.height() - 20, image_.height())); // Create the window - QScrollArea* window = new QScrollArea; - window->setAttribute(Qt::WA_DeleteOnClose, true); - window->setWindowTitle(tr("Clementine image viewer")); - window->resize(window_size); + QScrollArea* pwindow = new QScrollArea; + pwindow->setAttribute(Qt::WA_DeleteOnClose, true); + pwindow->setWindowTitle(tr("Clementine image viewer")); + + // Work out how large to make the window, based on the size of the screen +#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) + QScreen* screen = screen(); +#else + QScreen* screen = + (window() && window()->windowHandle() ? window()->windowHandle()->screen() + : QGuiApplication::primaryScreen()); +#endif + if (screen) { + QRect desktop_rect(screen->availableGeometry()); + QSize window_size(qMin(desktop_rect.width() - 20, image_.width()), + qMin(desktop_rect.height() - 20, image_.height())); + pwindow->resize(window_size); + } // Create the label that displays the image - QLabel* label = new QLabel(window); + QLabel* label = new QLabel(pwindow); label->setPixmap(QPixmap::fromImage(image_)); // Show the label in the window - window->setWidget(label); - window->setFrameShape(QFrame::NoFrame); - window->show(); + pwindow->setWidget(label); + pwindow->setFrameShape(QFrame::NoFrame); + pwindow->show(); } void PrettyImage::SaveAs() {