From fd9ae50a57420287984441e0451368d6601aea82 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 20 May 2012 18:14:02 +0300 Subject: [PATCH] Center new torrent addition dialog --- src/addnewtorrentdialog.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/addnewtorrentdialog.cpp b/src/addnewtorrentdialog.cpp index 489ef59f6..e2a7a49b8 100644 --- a/src/addnewtorrentdialog.cpp +++ b/src/addnewtorrentdialog.cpp @@ -80,9 +80,7 @@ AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent) : foreach (const QString& label, customLabels) { ui->label_combo->addItem(label); } - showAdvancedSettings(false); - QTimer::singleShot(0, this, SLOT(setdialogPosition())); } AddNewTorrentDialog::~AddNewTorrentDialog() @@ -127,7 +125,7 @@ void AddNewTorrentDialog::showAdvancedSettings(bool show) ui->buttonsHLayout->insertWidget(0, layout()->takeAt(layout()->indexOf(ui->never_show_cb)+1)->widget()); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); } - QTimer::singleShot(0, this, SLOT(relayout())); + relayout(); } bool AddNewTorrentDialog::loadTorrent(const QString& torrent_path, const QString& from_url) @@ -203,6 +201,9 @@ bool AddNewTorrentDialog::loadTorrent(const QString& torrent_path, const QString } } + // Set dialog position + setdialogPosition(); + return true; } @@ -220,6 +221,9 @@ bool AddNewTorrentDialog::loadMagnet(const QString &magnet_uri) QString torrent_name = misc::magnetUriToName(m_url); setWindowTitle(torrent_name.isEmpty() ? tr("Magnet link") : torrent_name); + // Set dialog position + setdialogPosition(); + return true; } @@ -334,13 +338,14 @@ void AddNewTorrentDialog::onSavePathChanged(int index) } // Toggle default save path setting checkbox visibility ui->default_save_path_cb->setVisible(QDir(ui->save_path_combo->itemData(ui->save_path_combo->currentIndex()).toString()) != defaultSaveDir); - QTimer::singleShot(0, this, SLOT(relayout())); + relayout(); // Remember index old_index = ui->save_path_combo->currentIndex(); } void AddNewTorrentDialog::relayout() { + qApp->processEvents(); int min_width = minimumWidth(); setMinimumWidth(width()); adjustSize(); @@ -447,7 +452,12 @@ void AddNewTorrentDialog::renameSelectedFile() void AddNewTorrentDialog::setdialogPosition() { - move(QPoint(misc::screenCenter(this).x(), 0)); + qApp->processEvents(); + QPoint center(misc::screenCenter(this)); + center.ry() -= 120; + if (center.y() < 0) + center.setY(0); + move(center); } void AddNewTorrentDialog::loadSavePathHistory()