Center cover manager on same screen as mainwindow
This commit is contained in:
parent
8321a48af7
commit
7f39a38d6c
|
@ -210,7 +210,7 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co
|
|||
queue_view_(new QueueView(this)),
|
||||
settings_dialog_(std::bind(&MainWindow::CreateSettingsDialog, this)),
|
||||
cover_manager_([=]() {
|
||||
AlbumCoverManager *cover_manager = new AlbumCoverManager(app, app->collection_backend());
|
||||
AlbumCoverManager *cover_manager = new AlbumCoverManager(app, app->collection_backend(), this);
|
||||
cover_manager->Init();
|
||||
|
||||
// Cover manager connections
|
||||
|
|
|
@ -27,9 +27,11 @@
|
|||
#include <QObject>
|
||||
#include <QMainWindow>
|
||||
#include <QWidget>
|
||||
#include <QScreen>
|
||||
#include <QWindow>
|
||||
#include <QGuiApplication>
|
||||
#include <QItemSelectionModel>
|
||||
#include <QListWidgetItem>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QFile>
|
||||
#include <QSet>
|
||||
#include <QVariant>
|
||||
|
@ -82,17 +84,15 @@
|
|||
|
||||
#include "ui_albumcovermanager.h"
|
||||
|
||||
using std::unique_ptr;
|
||||
using std::stable_sort;
|
||||
|
||||
const char *AlbumCoverManager::kSettingsGroup = "CoverManager";
|
||||
|
||||
AlbumCoverManager::AlbumCoverManager(Application *app, CollectionBackend *collection_backend, QWidget *parent, QNetworkAccessManager *network)
|
||||
AlbumCoverManager::AlbumCoverManager(Application *app, CollectionBackend *collection_backend, QMainWindow *mainwindow, QWidget *parent)
|
||||
: QMainWindow(parent),
|
||||
ui_(new Ui_CoverManager),
|
||||
mainwindow_(mainwindow),
|
||||
app_(app),
|
||||
album_cover_choice_controller_(new AlbumCoverChoiceController(this)),
|
||||
cover_fetcher_(new AlbumCoverFetcher(app_->cover_providers(), this, network)),
|
||||
cover_fetcher_(new AlbumCoverFetcher(app_->cover_providers(), this)),
|
||||
cover_searcher_(nullptr),
|
||||
cover_export_(nullptr),
|
||||
cover_exporter_(new AlbumCoverExporter(this)),
|
||||
|
@ -142,8 +142,10 @@ AlbumCoverManager::AlbumCoverManager(Application *app, CollectionBackend *collec
|
|||
}
|
||||
|
||||
AlbumCoverManager::~AlbumCoverManager() {
|
||||
|
||||
CancelRequests();
|
||||
delete ui_;
|
||||
|
||||
}
|
||||
|
||||
void AlbumCoverManager::ReloadSettings() {
|
||||
|
@ -224,7 +226,10 @@ void AlbumCoverManager::Init() {
|
|||
}
|
||||
|
||||
void AlbumCoverManager::showEvent(QShowEvent *) {
|
||||
|
||||
LoadGeometry();
|
||||
Reset();
|
||||
|
||||
}
|
||||
|
||||
void AlbumCoverManager::closeEvent(QCloseEvent *e) {
|
||||
|
@ -239,15 +244,62 @@ void AlbumCoverManager::closeEvent(QCloseEvent *e) {
|
|||
}
|
||||
}
|
||||
|
||||
// Save geometry
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
|
||||
s.setValue("geometry", saveGeometry());
|
||||
s.setValue("splitter_state", ui_->splitter->saveState());
|
||||
SaveGeometry();
|
||||
|
||||
// Cancel any outstanding requests
|
||||
CancelRequests();
|
||||
|
||||
}
|
||||
|
||||
void AlbumCoverManager::LoadGeometry() {
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
if (s.contains("geometry")) {
|
||||
restoreGeometry(s.value("geometry").toByteArray());
|
||||
}
|
||||
if (s.contains("splitter_state")) {
|
||||
ui_->splitter->restoreState(s.value("splitter_state").toByteArray());
|
||||
}
|
||||
else {
|
||||
// Sensible default size for the artists view
|
||||
ui_->splitter->setSizes(QList<int>() << 200 << width() - 200);
|
||||
}
|
||||
s.endGroup();
|
||||
|
||||
// Resize the window if it's too big
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
QScreen *screen = QWidget::screen();
|
||||
#else
|
||||
QScreen *screen = (window() && window()->windowHandle() ? window()->windowHandle()->screen() : QGuiApplication::primaryScreen());
|
||||
#endif
|
||||
if (screen && screen->availableGeometry().height() < height()) {
|
||||
resize(width(), sizeHint().height());
|
||||
}
|
||||
|
||||
// Center the window on the same screen as the mainwindow.
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
screen = mainwindow_->screen();
|
||||
#else
|
||||
screen = (mainwindow_->window() && mainwindow_->window()->windowHandle() ? mainwindow_->window()->windowHandle()->screen() : nullptr);
|
||||
#endif
|
||||
if (screen) {
|
||||
const QRect sr = screen->availableGeometry();
|
||||
const QRect wr({}, size().boundedTo(sr.size()));
|
||||
resize(wr.size());
|
||||
move(sr.center() - wr.center());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void AlbumCoverManager::SaveGeometry() {
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
s.setValue("geometry", saveGeometry());
|
||||
s.setValue("splitter_state", ui_->splitter->saveState());
|
||||
s.endGroup();
|
||||
|
||||
}
|
||||
|
||||
void AlbumCoverManager::CancelRequests() {
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
|
||||
class QWidget;
|
||||
class QMimeData;
|
||||
class QNetworkAccessManager;
|
||||
class QMenu;
|
||||
class QAction;
|
||||
class QProgressBar;
|
||||
|
@ -63,7 +62,7 @@ class Ui_CoverManager;
|
|||
class AlbumCoverManager : public QMainWindow {
|
||||
Q_OBJECT
|
||||
public:
|
||||
AlbumCoverManager(Application *app, CollectionBackend *collection_backend, QWidget *parent = nullptr, QNetworkAccessManager *network = 0);
|
||||
explicit AlbumCoverManager(Application *app, CollectionBackend *collection_backend, QMainWindow *mainwindow, QWidget *parent = nullptr);
|
||||
~AlbumCoverManager();
|
||||
|
||||
static const char *kSettingsGroup;
|
||||
|
@ -82,16 +81,55 @@ class AlbumCoverManager : public QMainWindow {
|
|||
SongList GetSongsInAlbums(const QModelIndexList &indexes) const;
|
||||
SongMimeData *GetMimeDataForAlbums(const QModelIndexList &indexes) const;
|
||||
|
||||
signals:
|
||||
void AddToPlaylist(QMimeData *data);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *);
|
||||
void closeEvent(QCloseEvent *);
|
||||
void showEvent(QShowEvent*);
|
||||
void closeEvent(QCloseEvent*);
|
||||
|
||||
// For the album view context menu events
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
|
||||
private:
|
||||
enum ArtistItemType {
|
||||
All_Artists,
|
||||
Various_Artists,
|
||||
Specific_Artist
|
||||
};
|
||||
|
||||
enum Role {
|
||||
Role_ArtistName = Qt::UserRole + 1,
|
||||
Role_AlbumArtistName,
|
||||
Role_AlbumName,
|
||||
Role_PathAutomatic,
|
||||
Role_PathManual,
|
||||
Role_FirstUrl
|
||||
};
|
||||
|
||||
enum HideCovers {
|
||||
Hide_None,
|
||||
Hide_WithCovers,
|
||||
Hide_WithoutCovers
|
||||
};
|
||||
|
||||
void LoadGeometry();
|
||||
void SaveGeometry();
|
||||
|
||||
QString InitialPathForOpenCoverDialog(const QString &path_automatic, const QString &first_file_name) const;
|
||||
QString EffectiveAlbumArtistName(const QListWidgetItem &item) const;
|
||||
|
||||
// Returns the selected element in form of a Song ready to be used by AlbumCoverChoiceController or invalid song if there's nothing or multiple elements selected.
|
||||
Song GetSingleSelectionAsSong();
|
||||
// Returns the first of the selected elements in form of a Song ready to be used by AlbumCoverChoiceController or invalid song if there's nothing selected.
|
||||
Song GetFirstSelectedAsSong();
|
||||
|
||||
Song ItemAsSong(QListWidgetItem *item);
|
||||
|
||||
void UpdateStatusText();
|
||||
bool ShouldHide(const QListWidgetItem &item, const QString &filter, HideCovers hide) const;
|
||||
void SaveAndSetCover(QListWidgetItem *item, const QUrl &cover_url, const QImage &image);
|
||||
|
||||
signals:
|
||||
void AddToPlaylist(QMimeData *data);
|
||||
|
||||
private slots:
|
||||
void ArtistChanged(QListWidgetItem *current);
|
||||
void CoverImageLoaded(const quint64 id, const QUrl &cover_url, const QImage &image);
|
||||
|
@ -119,44 +157,9 @@ class AlbumCoverManager : public QMainWindow {
|
|||
void UpdateCoverInList(QListWidgetItem *item, const QUrl &cover);
|
||||
void UpdateExportStatus(int exported, int bad, int count);
|
||||
|
||||
private:
|
||||
enum ArtistItemType {
|
||||
All_Artists,
|
||||
Various_Artists,
|
||||
Specific_Artist
|
||||
};
|
||||
|
||||
enum Role {
|
||||
Role_ArtistName = Qt::UserRole + 1,
|
||||
Role_AlbumArtistName,
|
||||
Role_AlbumName,
|
||||
Role_PathAutomatic,
|
||||
Role_PathManual,
|
||||
Role_FirstUrl
|
||||
};
|
||||
|
||||
enum HideCovers {
|
||||
Hide_None,
|
||||
Hide_WithCovers,
|
||||
Hide_WithoutCovers
|
||||
};
|
||||
|
||||
QString InitialPathForOpenCoverDialog(const QString &path_automatic, const QString &first_file_name) const;
|
||||
QString EffectiveAlbumArtistName(const QListWidgetItem &item) const;
|
||||
|
||||
// Returns the selected element in form of a Song ready to be used by AlbumCoverChoiceController or invalid song if there's nothing or multiple elements selected.
|
||||
Song GetSingleSelectionAsSong();
|
||||
// Returns the first of the selected elements in form of a Song ready to be used by AlbumCoverChoiceController or invalid song if there's nothing selected.
|
||||
Song GetFirstSelectedAsSong();
|
||||
|
||||
Song ItemAsSong(QListWidgetItem *item);
|
||||
|
||||
void UpdateStatusText();
|
||||
bool ShouldHide(const QListWidgetItem &item, const QString &filter, HideCovers hide) const;
|
||||
void SaveAndSetCover(QListWidgetItem *item, const QUrl &cover_url, const QImage &image);
|
||||
|
||||
private:
|
||||
Ui_CoverManager *ui_;
|
||||
QMainWindow *mainwindow_;
|
||||
Application *app_;
|
||||
|
||||
AlbumCoverChoiceController *album_cover_choice_controller_;
|
||||
|
|
Loading…
Reference in New Issue