From 6580d232633e81fce64db95dcf72cf7b5d6fa8d6 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sat, 22 Jan 2011 19:51:06 +0000 Subject: [PATCH] Make sure the main windows is initially centered --- src/mainwindow.cpp | 14 ++++++++++++-- src/mainwindow.h | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e14aafaaf..dec526d4e 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -92,7 +92,7 @@ using namespace libtorrent; *****************************************************/ // Constructor -MainWindow::MainWindow(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), force_exit(false) { +MainWindow::MainWindow(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), m_posInitialized(false), force_exit(false) { setupUi(this); Preferences pref; ui_locked = pref.isUILocked(); @@ -458,7 +458,10 @@ void MainWindow::writeSettings() { void MainWindow::readSettings() { QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); settings.beginGroup(QString::fromUtf8("MainWindow")); - restoreGeometry(settings.value("geometry").toByteArray()); + if(settings.contains("geometry")) { + restoreGeometry(settings.value("geometry").toByteArray()); + m_posInitialized = true; + } const QByteArray splitterState = settings.value("vsplitterState").toByteArray(); if(splitterState.isEmpty()) { // Default sizes @@ -680,7 +683,14 @@ void MainWindow::showEvent(QShowEvent *e) { if(getCurrentTabWidget() == transferList) { properties->loadDynamicData(); } + e->accept(); + + // Make sure the window is initially centered + if(!m_posInitialized) { + move(misc::screenCenter(this)); + m_posInitialized = true; + } } // Called when we close the program diff --git a/src/mainwindow.h b/src/mainwindow.h index 12276b7b6..0416e4c08 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -147,6 +147,7 @@ private: // Bittorrent QList > unauthenticated_trackers; // Still needed? // GUI related + bool m_posInitialized; QTimer *guiUpdater; HidableTabWidget *tabs; StatusBar *status_bar;