mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-07 05:31:25 -07:00
Show Add new torrent dialog on main window screen
PR #19963. Closes #19774.
This commit is contained in:
parent
6f7f418ec1
commit
c3adc90f7e
1 changed files with 37 additions and 0 deletions
|
@ -29,6 +29,8 @@
|
||||||
|
|
||||||
#include "guiaddtorrentmanager.h"
|
#include "guiaddtorrentmanager.h"
|
||||||
|
|
||||||
|
#include <QScreen>
|
||||||
|
|
||||||
#include "base/bittorrent/session.h"
|
#include "base/bittorrent/session.h"
|
||||||
#include "base/bittorrent/torrentdescriptor.h"
|
#include "base/bittorrent/torrentdescriptor.h"
|
||||||
#include "base/logger.h"
|
#include "base/logger.h"
|
||||||
|
@ -40,6 +42,39 @@
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "raisedmessagebox.h"
|
#include "raisedmessagebox.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GUIAddTorrentManager::GUIAddTorrentManager(IGUIApplication *app, BitTorrent::Session *session, QObject *parent)
|
GUIAddTorrentManager::GUIAddTorrentManager(IGUIApplication *app, BitTorrent::Session *session, QObject *parent)
|
||||||
: GUIApplicationComponent(app, session, parent)
|
: GUIApplicationComponent(app, session, parent)
|
||||||
{
|
{
|
||||||
|
@ -200,6 +235,8 @@ bool GUIAddTorrentManager::processTorrent(const QString &source, const BitTorren
|
||||||
|
|
||||||
m_dialogs.remove(infoHash);
|
m_dialogs.remove(infoHash);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
adjustDialogGeometry(dlg, app()->mainWindow());
|
||||||
dlg->show();
|
dlg->show();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue