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 @@
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>
#include <QDesktopWidget>
#include <QTimer> #include <QTimer>
#include <QDesktopServices> #include <QDesktopServices>
#include <QStatusBar> #include <QStatusBar>
@ -356,7 +355,7 @@ void GUI::readSettings() {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
settings.beginGroup(QString::fromUtf8("MainWindow")); settings.beginGroup(QString::fromUtf8("MainWindow"));
resize(settings.value(QString::fromUtf8("size"), size()).toSize()); 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(); QStringList sizes_str = settings.value("vSplitterSizes", QStringList()).toStringList();
// Splitter size // Splitter size
QList<int> sizes; 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 // Display About Dialog
void GUI::on_actionAbout_triggered() { void GUI::on_actionAbout_triggered() {
//About dialog //About dialog

1
src/GUI.h

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

2
src/deletionconfirmationdlg.h

@ -33,6 +33,7 @@
#include <QDialog> #include <QDialog>
#include "ui_confirmdeletiondlg.h" #include "ui_confirmdeletiondlg.h"
#include "misc.h"
class DeletionConfirmationDlg : public QDialog, private Ui::confirmDeletionDlg { class DeletionConfirmationDlg : public QDialog, private Ui::confirmDeletionDlg {
Q_OBJECT Q_OBJECT
@ -40,6 +41,7 @@ class DeletionConfirmationDlg : public QDialog, private Ui::confirmDeletionDlg {
public: public:
DeletionConfirmationDlg(QWidget *parent=0): QDialog(parent) { DeletionConfirmationDlg(QWidget *parent=0): QDialog(parent) {
setupUi(this); setupUi(this);
move(misc::screenCenter(this));
} }
bool shouldDeleteLocalFiles() const { bool shouldDeleteLocalFiles() const {

17
src/misc.h

@ -44,6 +44,7 @@
#include <QUrl> #include <QUrl>
#include <ctime> #include <ctime>
#include <QDateTime> #include <QDateTime>
#include <QDesktopWidget>
#include <boost/date_time/posix_time/posix_time_types.hpp> #include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/date_time/posix_time/conversion.hpp> #include <boost/date_time/posix_time/conversion.hpp>
@ -265,6 +266,22 @@ public:
#endif #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() { static QString searchEngineLocation() {
QString location = QDir::cleanPath(QDesktopServicesDataLocation() QString location = QDir::cleanPath(QDesktopServicesDataLocation()
+ QDir::separator() + "search_engine"); + QDir::separator() + "search_engine");

18
src/torrentadditiondlg.h

@ -112,7 +112,7 @@ public:
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
// Restore size and position // Restore size and position
resize(settings.value(QString::fromUtf8("TorrentAdditionDlg/size"), size()).toSize()); 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 // Restore column width
QVariantList contentColsWidths = settings.value(QString::fromUtf8("TorrentAdditionDlg/filesColsWidth"), QVariantList()).toList(); QVariantList contentColsWidths = settings.value(QString::fromUtf8("TorrentAdditionDlg/filesColsWidth"), QVariantList()).toList();
if(contentColsWidths.empty()) { 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() { void saveSettings() {
if(is_magnet) return; if(is_magnet) return;
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));

Loading…
Cancel
Save