diff --git a/src/GUI.cpp b/src/GUI.cpp index 4996bb9e6..da0430f66 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -35,7 +35,6 @@ #include #include -#include #include #include #include @@ -356,7 +355,7 @@ void GUI::readSettings() { QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); settings.beginGroup(QString::fromUtf8("MainWindow")); resize(settings.value(QString::fromUtf8("size"), size()).toSize()); - move(settings.value(QString::fromUtf8("pos"), screenCenter()).toPoint()); + move(settings.value(QString::fromUtf8("pos"), misc::screenCenter(this)).toPoint()); QStringList sizes_str = settings.value("vSplitterSizes", QStringList()).toStringList(); // Splitter size QList sizes; @@ -475,22 +474,6 @@ void GUI::toggleVisibility(QSystemTrayIcon::ActivationReason e) { } } -// Center window -QPoint GUI::screenCenter() const{ - int scrn = 0; - QWidget *w = this->topLevelWidget(); - - if(w) - scrn = QApplication::desktop()->screenNumber(w); - else if(QApplication::desktop()->isVirtualDesktop()) - scrn = QApplication::desktop()->screenNumber(QCursor::pos()); - else - scrn = QApplication::desktop()->screenNumber(this); - - QRect desk(QApplication::desktop()->availableGeometry(scrn)); - return QPoint((desk.width() - this->frameGeometry().width()) / 2, (desk.height() - this->frameGeometry().height()) / 2); -} - // Display About Dialog void GUI::on_actionAbout_triggered() { //About dialog diff --git a/src/GUI.h b/src/GUI.h index 2c4dfeaab..0bf1812c8 100644 --- a/src/GUI.h +++ b/src/GUI.h @@ -156,7 +156,6 @@ public: ~GUI(); // Methods int getCurrentTabIndex() const; - QPoint screenCenter() const; TransferListWidget* getTransferList() const { return transferList; } }; diff --git a/src/deletionconfirmationdlg.h b/src/deletionconfirmationdlg.h index 845cc1d19..b5c0edd89 100644 --- a/src/deletionconfirmationdlg.h +++ b/src/deletionconfirmationdlg.h @@ -33,6 +33,7 @@ #include #include "ui_confirmdeletiondlg.h" +#include "misc.h" class DeletionConfirmationDlg : public QDialog, private Ui::confirmDeletionDlg { Q_OBJECT @@ -40,6 +41,7 @@ class DeletionConfirmationDlg : public QDialog, private Ui::confirmDeletionDlg { public: DeletionConfirmationDlg(QWidget *parent=0): QDialog(parent) { setupUi(this); + move(misc::screenCenter(this)); } bool shouldDeleteLocalFiles() const { diff --git a/src/misc.h b/src/misc.h index 8378a73a2..aac2b09d7 100644 --- a/src/misc.h +++ b/src/misc.h @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -265,6 +266,22 @@ public: #endif } + // Get screen center + static QPoint screenCenter(QWidget *win) { + int scrn = 0; + QWidget *w = win->window(); + + if(w) + scrn = QApplication::desktop()->screenNumber(w); + else if(QApplication::desktop()->isVirtualDesktop()) + scrn = QApplication::desktop()->screenNumber(QCursor::pos()); + else + scrn = QApplication::desktop()->screenNumber(win); + + QRect desk(QApplication::desktop()->availableGeometry(scrn)); + return QPoint((desk.width() - win->frameGeometry().width()) / 2, (desk.height() - win->frameGeometry().height()) / 2); + } + static QString searchEngineLocation() { QString location = QDir::cleanPath(QDesktopServicesDataLocation() + QDir::separator() + "search_engine"); diff --git a/src/torrentadditiondlg.h b/src/torrentadditiondlg.h index 1bd5ab081..576ee2262 100644 --- a/src/torrentadditiondlg.h +++ b/src/torrentadditiondlg.h @@ -112,7 +112,7 @@ public: QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); // Restore size and position resize(settings.value(QString::fromUtf8("TorrentAdditionDlg/size"), size()).toSize()); - move(settings.value(QString::fromUtf8("TorrentAdditionDlg/pos"), screenCenter()).toPoint()); + move(settings.value(QString::fromUtf8("TorrentAdditionDlg/pos"), misc::screenCenter(this)).toPoint()); // Restore column width QVariantList contentColsWidths = settings.value(QString::fromUtf8("TorrentAdditionDlg/filesColsWidth"), QVariantList()).toList(); if(contentColsWidths.empty()) { @@ -124,22 +124,6 @@ public: } } - // Screen center point - QPoint screenCenter() const{ - int scrn = 0; - QWidget *w = this->topLevelWidget(); - - if(w) - scrn = QApplication::desktop()->screenNumber(w); - else if(QApplication::desktop()->isVirtualDesktop()) - scrn = QApplication::desktop()->screenNumber(QCursor::pos()); - else - scrn = QApplication::desktop()->screenNumber(this); - - QRect desk(QApplication::desktop()->availableGeometry(scrn)); - return QPoint((desk.width() - this->frameGeometry().width()) / 2, (desk.height() - this->frameGeometry().height()) / 2); - } - void saveSettings() { if(is_magnet) return; QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));