mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-25 02:36:10 +03:00
Moved screenCenter function to misc.h to avoid code duplication
Make sure torrent deletion dialog is now centered on screen
This commit is contained in:
parent
6a6077bf1d
commit
44f6c972d4
5 changed files with 21 additions and 36 deletions
19
src/GUI.cpp
19
src/GUI.cpp
|
@ -35,7 +35,6 @@
|
|||
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QDesktopWidget>
|
||||
#include <QTimer>
|
||||
#include <QDesktopServices>
|
||||
#include <QStatusBar>
|
||||
|
@ -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<int> 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
|
||||
|
|
|
@ -156,7 +156,6 @@ public:
|
|||
~GUI();
|
||||
// Methods
|
||||
int getCurrentTabIndex() const;
|
||||
QPoint screenCenter() const;
|
||||
TransferListWidget* getTransferList() const { return transferList; }
|
||||
};
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
#include <QDialog>
|
||||
#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 {
|
||||
|
|
17
src/misc.h
17
src/misc.h
|
@ -44,6 +44,7 @@
|
|||
#include <QUrl>
|
||||
#include <ctime>
|
||||
#include <QDateTime>
|
||||
#include <QDesktopWidget>
|
||||
#include <boost/date_time/posix_time/posix_time_types.hpp>
|
||||
#include <boost/date_time/posix_time/conversion.hpp>
|
||||
|
||||
|
@ -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");
|
||||
|
|
|
@ -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"));
|
||||
|
|
Loading…
Reference in a new issue