Resize organize window when copying to device

Fixes #566
This commit is contained in:
Jonas Kvinge 2020-10-27 17:50:16 +01:00
parent 0ddff2b087
commit 09e0059930
5 changed files with 85 additions and 24 deletions

View File

@ -397,7 +397,7 @@ void ContextAlbumsView::EditTracks() {
void ContextAlbumsView::CopyToDevice() {
#ifndef Q_OS_WIN
if (!organize_dialog_)
organize_dialog_.reset(new OrganizeDialog(app_->task_manager()));
organize_dialog_.reset(new OrganizeDialog(app_->task_manager(), nullptr, this));
organize_dialog_->SetDestinationModel(app_->device_manager()->connected_devices_model(), true);
organize_dialog_->SetCopy(true);

View File

@ -26,6 +26,7 @@
#include <algorithm>
#include <QtGlobal>
#include <QGuiApplication>
#include <QtConcurrent>
#include <QAbstractItemModel>
#include <QDialog>
@ -72,9 +73,8 @@
# include "transcoder/transcoder.h"
#endif
const char *OrganizeDialog::kDefaultFormat = "%albumartist/%album{ (Disc %disc)}/{%track - }{%albumartist - }%album{ (Disc %disc)} - %title.%extension";
const char *OrganizeDialog::kSettingsGroup = "OrganizeDialog";
const char *OrganizeDialog::kDefaultFormat = "%albumartist/%album{ (Disc %disc)}/{%track - }{%albumartist - }%album{ (Disc %disc)} - %title.%extension";
OrganizeDialog::OrganizeDialog(TaskManager *task_manager, CollectionBackend *backend, QWidget *parentwindow, QWidget *parent)
: QDialog(parent),
@ -82,7 +82,8 @@ OrganizeDialog::OrganizeDialog(TaskManager *task_manager, CollectionBackend *bac
ui_(new Ui_OrganizeDialog),
task_manager_(task_manager),
backend_(backend),
total_size_(0) {
total_size_(0),
devices_(false) {
ui_->setupUi(this);
@ -150,12 +151,14 @@ OrganizeDialog::~OrganizeDialog() {
delete ui_;
}
void OrganizeDialog::SetDestinationModel(QAbstractItemModel *model, bool devices) {
void OrganizeDialog::SetDestinationModel(QAbstractItemModel *model, const bool devices) {
ui_->destination->setModel(model);
ui_->eject_after->setVisible(devices);
devices_ = devices;
}
void OrganizeDialog::showEvent(QShowEvent*) {
@ -167,7 +170,7 @@ void OrganizeDialog::showEvent(QShowEvent*) {
void OrganizeDialog::closeEvent(QCloseEvent*) {
SaveGeometry();
if (!devices_) SaveGeometry();
}
@ -204,15 +207,19 @@ void OrganizeDialog::reject() {
void OrganizeDialog::LoadGeometry() {
if (parentwindow_) {
if (devices_) {
AdjustSize();
}
else {
QSettings s;
s.beginGroup(kSettingsGroup);
if (s.contains("geometry")) {
restoreGeometry(s.value("geometry").toByteArray());
}
s.endGroup();
}
if (parentwindow_) {
// Center the window on the same screen as the parentwindow.
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QScreen *screen = parentwindow_->screen();
@ -240,6 +247,39 @@ void OrganizeDialog::SaveGeometry() {
}
void OrganizeDialog::AdjustSize() {
#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
int max_width = 0;
int max_height = 0;
if (screen) {
max_width = screen->geometry().size().width() / 0.5;
max_height = static_cast<int>(float(screen->geometry().size().height()) / float(1.5));
}
int min_width = 0;
int min_height = 0;
if (ui_->preview->isVisible()) {
int h = ui_->layout_copying->sizeHint().height() +
ui_->button_box->sizeHint().height() +
ui_->eject_after->sizeHint().height() +
ui_->free_space->sizeHint().height() +
ui_->groupbox_naming->sizeHint().height();
if (ui_->preview->count() > 0) h += ui_->preview->sizeHintForRow(0) * ui_->preview->count();
else h += ui_->loading_page->sizeHint().height();
min_width = std::min(ui_->preview->sizeHintForColumn(0), max_width);
min_height = std::min(h, max_height);
}
setMinimumSize(min_width, min_height);
adjustSize();
}
void OrganizeDialog::RestoreDefaults() {
ui_->naming->setPlainText(kDefaultFormat);
@ -356,7 +396,7 @@ bool OrganizeDialog::SetFilenames(const QStringList &filenames) {
}
void OrganizeDialog::SetLoadingSongs(bool loading) {
void OrganizeDialog::SetLoadingSongs(const bool loading) {
if (loading) {
ui_->preview_stack->setCurrentWidget(ui_->loading_page);
@ -395,12 +435,11 @@ SongList OrganizeDialog::LoadSongsBlocking(const QStringList &filenames) {
}
void OrganizeDialog::SetCopy(bool copy) {
void OrganizeDialog::SetCopy(const bool copy) {
ui_->aftercopying->setCurrentIndex(copy ? 0 : 1);
}
void OrganizeDialog::SetPlaylist(const QString &playlist)
{
void OrganizeDialog::SetPlaylist(const QString &playlist) {
playlist_ = playlist;
}
@ -497,9 +536,10 @@ void OrganizeDialog::UpdatePreviews() {
}
}
}
if (devices_)
AdjustSize();
QSize OrganizeDialog::sizeHint() const { return QSize(650, 0); }
}
void OrganizeDialog::OrganizeFinished(const QStringList files_with_errors, const QStringList log) {
if (files_with_errors.isEmpty()) return;
@ -508,6 +548,6 @@ void OrganizeDialog::OrganizeFinished(const QStringList files_with_errors, const
error_dialog_->Show(OrganizeErrorDialog::Type_Copy, files_with_errors, log);
}
void OrganizeDialog::AllowExtASCII(bool checked) {
void OrganizeDialog::AllowExtASCII(const bool checked) {
ui_->allow_ascii_ext->setEnabled(checked);
}

View File

@ -59,11 +59,7 @@ class OrganizeDialog : public QDialog {
explicit OrganizeDialog(TaskManager *task_manager, CollectionBackend *backend = nullptr, QWidget *parentwindow = nullptr, QWidget *parent = nullptr);
~OrganizeDialog() override;
static const char *kDefaultFormat;
QSize sizeHint() const override;
void SetDestinationModel(QAbstractItemModel *model, bool devices = false);
void SetDestinationModel(QAbstractItemModel *model, const bool devices = false);
// These functions return true if any songs were actually added to the dialog.
// SetSongs returns immediately, SetUrls and SetFilenames load the songs in the background.
@ -71,7 +67,7 @@ class OrganizeDialog : public QDialog {
bool SetUrls(const QList<QUrl> &urls);
bool SetFilenames(const QStringList &filenames);
void SetCopy(bool copy);
void SetCopy(const bool copy);
static Organize::NewSongInfoList ComputeNewSongsFilenames(const SongList &songs, const OrganizeFormat &format, const QString &extension = QString());
@ -85,9 +81,10 @@ class OrganizeDialog : public QDialog {
void LoadGeometry();
void SaveGeometry();
void LoadSettings();
void AdjustSize();
SongList LoadSongsBlocking(const QStringList &filenames);
void SetLoadingSongs(bool loading);
void SetLoadingSongs(const bool loading);
signals:
void FileCopied(int);
@ -105,10 +102,11 @@ class OrganizeDialog : public QDialog {
void OrganizeFinished(const QStringList files_with_errors, const QStringList log);
void AllowExtASCII(bool checked);
void AllowExtASCII(const bool checked);
private:
static const char *kSettingsGroup;
static const char *kDefaultFormat;
QWidget *parentwindow_;
Ui_OrganizeDialog *ui_;
@ -125,6 +123,8 @@ class OrganizeDialog : public QDialog {
std::unique_ptr<OrganizeErrorDialog> error_dialog_;
bool devices_;
};
#endif // ORGANISEDIALOG_H

View File

@ -18,8 +18,14 @@
<normaloff>:/icons/64x64/strawberry.png</normaloff>:/icons/64x64/strawberry.png</iconset>
</property>
<layout class="QVBoxLayout" name="layout_organizedialog">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<item>
<layout class="QFormLayout" name="layout_copying">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_destination">
<property name="text">
@ -62,8 +68,14 @@
<string>Naming options</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<item>
<widget class="LineTextEdit" name="naming">
<property name="toolTip">
@ -156,6 +168,9 @@
<string>Preview</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<item>
<widget class="QStackedWidget" name="preview_stack">
<property name="currentIndex">
@ -166,6 +181,9 @@
<property name="spacing">
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<property name="leftMargin">
<number>0</number>
</property>
@ -188,6 +206,9 @@
<property name="spacing">
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<property name="leftMargin">
<number>0</number>
</property>

View File

@ -385,7 +385,7 @@ void PlaylistListContainer::CopyToDevice() {
// Reuse the organize dialog, but set the detail about the playlist name
if (!organize_dialog_) {
organize_dialog_.reset(new OrganizeDialog(app_->task_manager()));
organize_dialog_.reset(new OrganizeDialog(app_->task_manager(), nullptr, this));
}
organize_dialog_->SetDestinationModel(app_->device_manager()->connected_devices_model(), true);
organize_dialog_->SetCopy(true);