Center organise and transcoder dialog on same screen as mainwindow
This commit is contained in:
@@ -25,6 +25,10 @@
|
||||
#include <QtGlobal>
|
||||
#include <QWidget>
|
||||
#include <QDialog>
|
||||
#include <QScreen>
|
||||
#include <QWindow>
|
||||
#include <QGuiApplication>
|
||||
#include <QMainWindow>
|
||||
#include <QAbstractItemModel>
|
||||
#include <QtAlgorithms>
|
||||
#include <QDir>
|
||||
@@ -49,6 +53,8 @@
|
||||
#include <QDialogButtonBox>
|
||||
#include <QSettings>
|
||||
#include <QTimerEvent>
|
||||
#include <QShowEvent>
|
||||
#include <QCloseEvent>
|
||||
|
||||
#include "core/iconloader.h"
|
||||
#include "core/mainwindow.h"
|
||||
@@ -74,8 +80,9 @@ static bool ComparePresetsByName(const TranscoderPreset &left, const TranscoderP
|
||||
return left.name_ < right.name_;
|
||||
}
|
||||
|
||||
TranscodeDialog::TranscodeDialog(QWidget *parent)
|
||||
TranscodeDialog::TranscodeDialog(QMainWindow *mainwindow, QWidget *parent)
|
||||
: QDialog(parent),
|
||||
mainwindow_(mainwindow),
|
||||
ui_(new Ui_TranscodeDialog),
|
||||
log_ui_(new Ui_TranscodeLogDialog),
|
||||
log_dialog_(new QDialog(this)),
|
||||
@@ -85,6 +92,9 @@ TranscodeDialog::TranscodeDialog(QWidget *parent)
|
||||
finished_failed_(0) {
|
||||
|
||||
ui_->setupUi(this);
|
||||
|
||||
setWindowFlags(windowFlags()|Qt::WindowMaximizeButtonHint);
|
||||
|
||||
ui_->files->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
|
||||
log_ui_->setupUi(log_dialog_);
|
||||
@@ -101,12 +111,8 @@ TranscodeDialog::TranscodeDialog(QWidget *parent)
|
||||
// Load settings
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
if (s.contains("geometry")) {
|
||||
restoreGeometry(s.value("geometry").toByteArray());
|
||||
}
|
||||
last_add_dir_ = s.value("last_add_dir", QDir::homePath()).toString();
|
||||
last_import_dir_ = s.value("last_import_dir", QDir::homePath()).toString();
|
||||
|
||||
QString last_output_format = s.value("last_output_format", "audio/x-vorbis").toString();
|
||||
s.endGroup();
|
||||
|
||||
@@ -150,6 +156,65 @@ TranscodeDialog::~TranscodeDialog() {
|
||||
delete ui_;
|
||||
}
|
||||
|
||||
void TranscodeDialog::showEvent(QShowEvent*) {
|
||||
|
||||
LoadGeometry();
|
||||
|
||||
}
|
||||
|
||||
void TranscodeDialog::closeEvent(QCloseEvent*) {
|
||||
|
||||
SaveGeometry();
|
||||
|
||||
}
|
||||
|
||||
void TranscodeDialog::accept() {
|
||||
|
||||
SaveGeometry();
|
||||
QDialog::accept();
|
||||
|
||||
}
|
||||
|
||||
void TranscodeDialog::reject() {
|
||||
|
||||
SaveGeometry();
|
||||
QDialog::reject();
|
||||
|
||||
}
|
||||
|
||||
void TranscodeDialog::LoadGeometry() {
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
if (s.contains("geometry")) {
|
||||
restoreGeometry(s.value("geometry").toByteArray());
|
||||
}
|
||||
s.endGroup();
|
||||
|
||||
// Center the window on the same screen as the mainwindow.
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
QScreen *screen = mainwindow_->screen();
|
||||
#else
|
||||
QScreen *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 TranscodeDialog::SaveGeometry() {
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
s.setValue("geometry", saveGeometry());
|
||||
s.endGroup();
|
||||
|
||||
}
|
||||
|
||||
void TranscodeDialog::SetWorking(bool working) {
|
||||
|
||||
start_button_->setVisible(!working);
|
||||
@@ -390,25 +455,3 @@ QString TranscodeDialog::GetOutputFileName(const QString &input, const Transcode
|
||||
|
||||
}
|
||||
|
||||
void TranscodeDialog::SaveGeometry() {
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
s.setValue("geometry", saveGeometry());
|
||||
s.endGroup();
|
||||
|
||||
}
|
||||
|
||||
void TranscodeDialog::accept() {
|
||||
|
||||
SaveGeometry();
|
||||
QDialog::accept();
|
||||
|
||||
}
|
||||
|
||||
void TranscodeDialog::reject() {
|
||||
|
||||
SaveGeometry();
|
||||
QDialog::reject();
|
||||
|
||||
}
|
||||
|
||||
@@ -30,8 +30,11 @@
|
||||
#include <QStringList>
|
||||
|
||||
class QWidget;
|
||||
class QMainWindow;
|
||||
class QPushButton;
|
||||
class QTimerEvent;
|
||||
class QShowEvent;
|
||||
class QCloseEvent;
|
||||
class Transcoder;
|
||||
class Ui_TranscodeDialog;
|
||||
class Ui_TranscodeLogDialog;
|
||||
@@ -41,7 +44,7 @@ class TranscodeDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TranscodeDialog(QWidget *parent = nullptr);
|
||||
TranscodeDialog(QMainWindow *mainwindow, QWidget *parent = nullptr);
|
||||
~TranscodeDialog();
|
||||
|
||||
static const char *kSettingsGroup;
|
||||
@@ -51,8 +54,19 @@ class TranscodeDialog : public QDialog {
|
||||
void SetFilenames(const QStringList &filenames);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent*);
|
||||
void closeEvent(QCloseEvent*);
|
||||
void timerEvent(QTimerEvent *e);
|
||||
|
||||
private:
|
||||
void LoadGeometry();
|
||||
void SaveGeometry();
|
||||
void SetWorking(bool working);
|
||||
void UpdateStatusText();
|
||||
void UpdateProgress();
|
||||
QString TrimPath(const QString &path) const;
|
||||
QString GetOutputFileName(const QString &input, const TranscoderPreset &preset) const;
|
||||
|
||||
private slots:
|
||||
void Add();
|
||||
void Import();
|
||||
@@ -68,14 +82,7 @@ class TranscodeDialog : public QDialog {
|
||||
void reject();
|
||||
|
||||
private:
|
||||
void SetWorking(bool working);
|
||||
void UpdateStatusText();
|
||||
void UpdateProgress();
|
||||
QString TrimPath(const QString &path) const;
|
||||
QString GetOutputFileName(const QString &input, const TranscoderPreset &preset) const;
|
||||
void SaveGeometry();
|
||||
|
||||
private:
|
||||
QMainWindow *mainwindow_;
|
||||
Ui_TranscodeDialog *ui_;
|
||||
Ui_TranscodeLogDialog *log_ui_;
|
||||
QDialog *log_dialog_;
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>499</width>
|
||||
<height>448</height>
|
||||
<width>500</width>
|
||||
<height>450</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -17,7 +17,7 @@
|
||||
<iconset>
|
||||
<normaloff>:/icons/64x64/strawberry.png</normaloff>:/icons/64x64/strawberry.png</iconset>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="layout_dialog">
|
||||
<layout class="QVBoxLayout" name="layout_transcodedialog">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="input_group">
|
||||
<property name="title">
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>676</width>
|
||||
<height>358</height>
|
||||
<width>680</width>
|
||||
<height>360</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -17,7 +17,7 @@
|
||||
<iconset resource="../../data/icons.qrc">
|
||||
<normaloff>:/icons/64x64/strawberry.png</normaloff>:/icons/64x64/strawberry.png</iconset>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<layout class="QVBoxLayout" name="layout_transcodelogdialog">
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="log">
|
||||
<property name="readOnly">
|
||||
|
||||
Reference in New Issue
Block a user