mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-12-27 18:28:18 +03:00
Show Add new torrent dialog on main window screen
PR #19963. Closes #19774.
This commit is contained in:
parent
081eace057
commit
c1b63372f1
1 changed files with 36 additions and 0 deletions
|
@ -39,6 +39,7 @@
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QScreen>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
@ -135,6 +136,36 @@ namespace
|
||||||
|
|
||||||
settings()->storeValue(settingsKey, QStringList(pathList.mid(0, maxLength)));
|
settings()->storeValue(settingsKey, QStringList(pathList.mid(0, maxLength)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void adjustDialogGeometry(QWidget *dialog, const QWidget *parentWindow)
|
||||||
|
{
|
||||||
|
// It is preferable to place the dialog in the center of the parent window.
|
||||||
|
// However, if it goes beyond the current screen, then move it so that it fits there
|
||||||
|
// (or, if the dialog is larger than the current screen, at least make sure that
|
||||||
|
// the upper/left coordinates of the dialog are inside it).
|
||||||
|
|
||||||
|
QRect dialogGeometry = dialog->geometry();
|
||||||
|
|
||||||
|
dialogGeometry.moveCenter(parentWindow->geometry().center());
|
||||||
|
|
||||||
|
const QRect screenGeometry = parentWindow->screen()->availableGeometry();
|
||||||
|
|
||||||
|
QPoint delta = screenGeometry.bottomRight() - dialogGeometry.bottomRight();
|
||||||
|
if (delta.x() > 0)
|
||||||
|
delta.setX(0);
|
||||||
|
if (delta.y() > 0)
|
||||||
|
delta.setY(0);
|
||||||
|
dialogGeometry.translate(delta);
|
||||||
|
|
||||||
|
delta = screenGeometry.topLeft() - dialogGeometry.topLeft();
|
||||||
|
if (delta.x() < 0)
|
||||||
|
delta.setX(0);
|
||||||
|
if (delta.y() < 0)
|
||||||
|
delta.setY(0);
|
||||||
|
dialogGeometry.translate(delta);
|
||||||
|
|
||||||
|
dialog->setGeometry(dialogGeometry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AddNewTorrentDialog::TorrentContentAdaptor final
|
class AddNewTorrentDialog::TorrentContentAdaptor final
|
||||||
|
@ -539,9 +570,14 @@ void AddNewTorrentDialog::show(const QString &source, const BitTorrent::AddTorre
|
||||||
: dlg->loadTorrentFile(source);
|
: dlg->loadTorrentFile(source);
|
||||||
|
|
||||||
if (isLoaded)
|
if (isLoaded)
|
||||||
|
{
|
||||||
|
adjustDialogGeometry(dlg, parent);
|
||||||
dlg->QDialog::show();
|
dlg->QDialog::show();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
delete dlg;
|
delete dlg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddNewTorrentDialog::show(const QString &source, QWidget *parent)
|
void AddNewTorrentDialog::show(const QString &source, QWidget *parent)
|
||||||
|
|
Loading…
Reference in a new issue