Browse Source

Moved screenCenter function to misc.h to avoid code duplication

Make sure torrent deletion dialog is now centered on screen
adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
44f6c972d4
  1. 19
      src/GUI.cpp
  2. 1
      src/GUI.h
  3. 2
      src/deletionconfirmationdlg.h
  4. 17
      src/misc.h
  5. 18
      src/torrentadditiondlg.h

19
src/GUI.cpp

@ -35,7 +35,6 @@ @@ -35,7 +35,6 @@
#include <QFileDialog>
#include <QMessageBox>
#include <QDesktopWidget>
#include <QTimer>
#include <QDesktopServices>
#include <QStatusBar>
@ -356,7 +355,7 @@ void GUI::readSettings() { @@ -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) { @@ -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

1
src/GUI.h

@ -156,7 +156,6 @@ public: @@ -156,7 +156,6 @@ public:
~GUI();
// Methods
int getCurrentTabIndex() const;
QPoint screenCenter() const;
TransferListWidget* getTransferList() const { return transferList; }
};

2
src/deletionconfirmationdlg.h

@ -33,6 +33,7 @@ @@ -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 { @@ -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

@ -44,6 +44,7 @@ @@ -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: @@ -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");

18
src/torrentadditiondlg.h

@ -112,7 +112,7 @@ public: @@ -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: @@ -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…
Cancel
Save