From 62c72091ce90d06afd33c0a68c197272ec40e5aa Mon Sep 17 00:00:00 2001 From: Evgeny Lensky Date: Sun, 21 Oct 2018 18:51:58 +0700 Subject: [PATCH] Change "Add new torrent" dialog to horizontal layout --- src/base/unicodestrings.h | 2 - src/gui/addnewtorrentdialog.cpp | 89 +---- src/gui/addnewtorrentdialog.h | 7 +- src/gui/addnewtorrentdialog.ui | 685 ++++++++++++++++---------------- 4 files changed, 378 insertions(+), 405 deletions(-) diff --git a/src/base/unicodestrings.h b/src/base/unicodestrings.h index 9f44b1192..b49fdcc95 100644 --- a/src/base/unicodestrings.h +++ b/src/base/unicodestrings.h @@ -38,8 +38,6 @@ // See issue #3059 for more details (https://github.com/qbittorrent/qBittorrent/issues/3059). const char C_INFINITY[] = "∞"; const char C_NON_BREAKING_SPACE[] = " "; -const char C_UP[] = "▲"; -const char C_DOWN[] = "▼"; const char C_COPYRIGHT[] = "©"; const char C_THIN_SPACE[] = " "; const char C_UTP[] = "μTP"; diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index f4eebfe86..b516f8468 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -30,9 +30,9 @@ #include #include -#include #include #include +#include #include #include #include @@ -41,13 +41,11 @@ #include "base/bittorrent/magneturi.h" #include "base/bittorrent/session.h" #include "base/bittorrent/torrenthandle.h" -#include "base/bittorrent/torrentinfo.h" #include "base/global.h" #include "base/net/downloadmanager.h" #include "base/preferences.h" #include "base/settingsstorage.h" #include "base/torrentfileguard.h" -#include "base/unicodestrings.h" #include "base/utils/fs.h" #include "base/utils/misc.h" #include "base/utils/string.h" @@ -62,16 +60,14 @@ namespace { -#define SETTINGS_KEY(name) QStringLiteral("AddNewTorrentDialog/" name) - const QString KEY_ENABLED = SETTINGS_KEY("Enabled"); - const QString KEY_DEFAULTCATEGORY = SETTINGS_KEY("DefaultCategory"); - const QString KEY_TREEHEADERSTATE = SETTINGS_KEY("TreeHeaderState"); - const QString KEY_WIDTH = SETTINGS_KEY("Width"); - const QString KEY_EXPANDED = SETTINGS_KEY("Expanded"); - const QString KEY_TOPLEVEL = SETTINGS_KEY("TopLevel"); - const QString KEY_SAVEPATHHISTORY = SETTINGS_KEY("SavePathHistory"); - const QString KEY_SAVEPATHHISTORYLENGTH = SETTINGS_KEY("SavePathHistoryLength"); - const QString KEY_REMEMBERLASTSAVEPATH = SETTINGS_KEY("RememberLastSavePath"); +#define SETTINGS_KEY(name) "AddNewTorrentDialog/" name + const QString KEY_ENABLED = QStringLiteral(SETTINGS_KEY("Enabled")); + const QString KEY_DEFAULTCATEGORY = QStringLiteral(SETTINGS_KEY("DefaultCategory")); + const QString KEY_TREEHEADERSTATE = QStringLiteral(SETTINGS_KEY("TreeHeaderState")); + const QString KEY_TOPLEVEL = QStringLiteral(SETTINGS_KEY("TopLevel")); + const QString KEY_SAVEPATHHISTORY = QStringLiteral(SETTINGS_KEY("SavePathHistory")); + const QString KEY_SAVEPATHHISTORYLENGTH = QStringLiteral(SETTINGS_KEY("SavePathHistoryLength")); + const QString KEY_REMEMBERLASTSAVEPATH = QStringLiteral(SETTINGS_KEY("RememberLastSavePath")); // just a shortcut inline SettingsStorage *settings() @@ -91,6 +87,8 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inP , m_hasMetadata(false) , m_oldIndex(0) , m_torrentParams(inParams) + , m_storeDialogSize(SETTINGS_KEY("DialogSize")) + , m_storeSplitterState(SETTINGS_KEY("SplitterState")) { // TODO: set dialog file properties using m_torrentParams.filePriorities m_ui->setupUi(this); @@ -155,7 +153,6 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inP m_ui->contentTreeView->header()->setSortIndicator(0, Qt::AscendingOrder); loadState(); // Signal / slots - connect(m_ui->toolButtonAdvanced, &QToolButton::clicked, this, &AddNewTorrentDialog::showAdvancedSettings); connect(m_ui->doNotDeleteTorrentCheckBox, &QCheckBox::clicked, this, &AddNewTorrentDialog::doNotDeleteTorrentClicked); QShortcut *editHotkey = new QShortcut(Qt::Key_F2, m_ui->contentTreeView, nullptr, nullptr, Qt::WidgetShortcut); connect(editHotkey, &QShortcut::activated, this, &AddNewTorrentDialog::renameSelectedFile); @@ -213,22 +210,17 @@ void AddNewTorrentDialog::setSavePathHistoryLength(int value) void AddNewTorrentDialog::loadState() { + Utils::Gui::resize(this, m_storeDialogSize); + m_ui->splitter->restoreState(m_storeSplitterState); m_headerState = settings()->loadValue(KEY_TREEHEADERSTATE).toByteArray(); - - const QSize newSize = Utils::Gui::scaledSize(this, size()); - const int width = settings()->loadValue(KEY_WIDTH, newSize.width()).toInt(); - const int height = newSize.height(); - resize(width, height); - - m_ui->toolButtonAdvanced->setChecked(settings()->loadValue(KEY_EXPANDED).toBool()); } void AddNewTorrentDialog::saveState() { + m_storeDialogSize = size(); + m_storeSplitterState = m_ui->splitter->saveState(); if (m_contentModel) settings()->storeValue(KEY_TREEHEADERSTATE, m_ui->contentTreeView->header()->saveState()); - settings()->storeValue(KEY_WIDTH, width()); - settings()->storeValue(KEY_EXPANDED, m_ui->toolButtonAdvanced->isChecked()); } void AddNewTorrentDialog::show(const QString &source, const BitTorrent::AddTorrentParams &inParams, QWidget *parent) @@ -303,7 +295,7 @@ bool AddNewTorrentDialog::loadTorrentImpl() return false; } - m_ui->lblhash->setText(m_hash); + m_ui->labelHashData->setText(m_hash); setupTreeview(); TMMChanged(m_ui->comboTTM->currentIndex()); return true; @@ -348,7 +340,7 @@ bool AddNewTorrentDialog::loadMagnet(const BitTorrent::MagnetUri &magnetUri) BitTorrent::Session::instance()->loadMetadata(magnetUri); setMetadataProgressIndicator(true, tr("Retrieving metadata...")); - m_ui->lblhash->setText(m_hash); + m_ui->labelHashData->setText(m_hash); return true; } @@ -362,27 +354,6 @@ void AddNewTorrentDialog::showEvent(QShowEvent *event) raise(); } -void AddNewTorrentDialog::showAdvancedSettings(bool show) -{ - const int minimumW = minimumWidth(); - setMinimumWidth(width()); // to remain the same width - if (show) { - m_ui->toolButtonAdvanced->setText(QString::fromUtf8(C_UP)); - m_ui->groupBoxSettings->setVisible(true); - m_ui->infoGroup->setVisible(true); - m_ui->contentTreeView->setVisible(m_hasMetadata); - static_cast(layout())->insertWidget(layout()->indexOf(m_ui->checkBoxNeverShow) + 1, m_ui->toolButtonAdvanced); - } - else { - m_ui->toolButtonAdvanced->setText(QString::fromUtf8(C_DOWN)); - m_ui->groupBoxSettings->setVisible(false); - m_ui->infoGroup->setVisible(false); - m_ui->buttonsHLayout->insertWidget(0, layout()->takeAt(layout()->indexOf(m_ui->checkBoxNeverShow) + 1)->widget()); - } - adjustSize(); - setMinimumWidth(minimumW); -} - void AddNewTorrentDialog::saveSavePathHistory() const { // Get current history @@ -436,7 +407,7 @@ void AddNewTorrentDialog::updateDiskSpaceLabel() sizeString += tr("Free space on disk: %1").arg(Utils::Misc::friendlyUnit(Utils::Fs::freeDiskSpaceOnPath( m_ui->savePath->selectedPath()))); sizeString += ')'; - m_ui->labelSize->setText(sizeString); + m_ui->labelSizeData->setText(sizeString); } void AddNewTorrentDialog::onSavePathChanged(const QString &newPath) @@ -719,16 +690,16 @@ void AddNewTorrentDialog::setMetadataProgressIndicator(bool visibleIndicator, co void AddNewTorrentDialog::setupTreeview() { if (!m_hasMetadata) { - setCommentText(tr("Not Available", "This comment is unavailable")); - m_ui->labelDate->setText(tr("Not Available", "This date is unavailable")); + m_ui->labelCommentData->setText(tr("Not Available", "This comment is unavailable")); + m_ui->labelDateData->setText(tr("Not Available", "This date is unavailable")); } else { // Set dialog title setWindowTitle(m_torrentInfo.name()); // Set torrent information - setCommentText(Utils::Misc::parseHtmlLinks(m_torrentInfo.comment())); - m_ui->labelDate->setText(!m_torrentInfo.creationDate().isNull() ? m_torrentInfo.creationDate().toString(Qt::DefaultLocaleShortDate) : tr("Not available")); + m_ui->labelCommentData->setText(Utils::Misc::parseHtmlLinks(m_torrentInfo.comment())); + m_ui->labelDateData->setText(!m_torrentInfo.creationDate().isNull() ? m_torrentInfo.creationDate().toString(Qt::DefaultLocaleShortDate) : tr("Not available")); // Prepare content tree m_contentModel = new TorrentContentFilterModel(this); @@ -755,7 +726,6 @@ void AddNewTorrentDialog::setupTreeview() } updateDiskSpaceLabel(); - showAdvancedSettings(settings()->loadValue(KEY_EXPANDED, false).toBool()); } void AddNewTorrentDialog::handleDownloadFinished(const Net::DownloadResult &result) @@ -797,7 +767,6 @@ void AddNewTorrentDialog::TMMChanged(int index) m_ui->groupBoxSavePath->setEnabled(true); m_ui->savePath->blockSignals(false); m_ui->savePath->setCurrentIndex(m_oldIndex < m_ui->savePath->count() ? m_oldIndex : m_ui->savePath->count() - 1); - m_ui->toolButtonAdvanced->setEnabled(true); } else { m_ui->groupBoxSavePath->setEnabled(false); @@ -805,23 +774,9 @@ void AddNewTorrentDialog::TMMChanged(int index) m_ui->savePath->clear(); QString savePath = BitTorrent::Session::instance()->categorySavePath(m_ui->categoryComboBox->currentText()); m_ui->savePath->addItem(savePath); - m_ui->toolButtonAdvanced->setChecked(true); - m_ui->toolButtonAdvanced->setEnabled(false); - showAdvancedSettings(true); } } -void AddNewTorrentDialog::setCommentText(const QString &str) const -{ - m_ui->commentLabel->setText(str); - - // workaround for the additional space introduced by QScrollArea - int lineHeight = m_ui->commentLabel->fontMetrics().lineSpacing(); - int lines = 1 + str.count('\n'); - int height = lineHeight * lines; - m_ui->scrollArea->setMaximumHeight(height); -} - void AddNewTorrentDialog::doNotDeleteTorrentClicked(bool checked) { m_torrentGuard->setAutoRemove(!checked); diff --git a/src/gui/addnewtorrentdialog.h b/src/gui/addnewtorrentdialog.h index 49fe4279b..eb8f9d598 100644 --- a/src/gui/addnewtorrentdialog.h +++ b/src/gui/addnewtorrentdialog.h @@ -32,11 +32,11 @@ #include #include -#include #include "base/bittorrent/addtorrentparams.h" #include "base/bittorrent/infohash.h" #include "base/bittorrent/torrentinfo.h" +#include "base/settingvalue.h" namespace BitTorrent { @@ -79,7 +79,6 @@ public: static void show(const QString &source, QWidget *parent); private slots: - void showAdvancedSettings(bool show); void displayContentTreeMenu(const QPoint &); void updateDiskSpaceLabel(); void onSavePathChanged(const QString &newPath); @@ -105,7 +104,6 @@ private: void saveState(); void setMetadataProgressIndicator(bool visibleIndicator, const QString &labelText = {}); void setupTreeview(); - void setCommentText(const QString &str) const; void setSavePath(const QString &newPath); void showEvent(QShowEvent *event) override; @@ -120,6 +118,9 @@ private: int m_oldIndex; std::unique_ptr m_torrentGuard; BitTorrent::AddTorrentParams m_torrentParams; + + CachedSettingValue m_storeDialogSize; + CachedSettingValue m_storeSplitterState; }; #endif // ADDNEWTORRENTDIALOG_H diff --git a/src/gui/addnewtorrentdialog.ui b/src/gui/addnewtorrentdialog.ui index 629f33909..23140e37d 100644 --- a/src/gui/addnewtorrentdialog.ui +++ b/src/gui/addnewtorrentdialog.ui @@ -6,336 +6,363 @@ 0 0 - 414 - 630 + 900 + 620 - - - - - Torrent Management Mode: + + + Qt::Horizontal + + + false + + + + + 0 - - - - - - Automatic mode means that various torrent properties(eg save path) will be decided by the associated category + + 0 + + + 0 + + + 0 - - Manual - + + + + + Torrent Management Mode: + + + + + + + Automatic mode means that various torrent properties(eg save path) will be decided by the associated category + + + + Manual + + + + + Automatic + + + + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + - - Automatic - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Save at - - - - - - - - - Remember last used save path - - - - - - - - - - When checked, the .torrent file will not be deleted despite the settings at the "Download" page of the options dialog - - - Do not delete .torrent file - - - - - - - Never show again - - - - - - - - - - true - - - - - - - Torrent settings - - - - - - Set as default category - - - - - - - - - Category: - - - - - - - - 0 - 0 - - - - true - - - QComboBox::InsertAtTop - - - - - - - - - Start torrent - - - true - - - - - - - Skip hash check - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 35 - 0 - - - - - - - - Create subfolder - - - true - - - - - - - Download in sequential order - - - - - - - Download first and last pieces first - - - - - - - - - - Torrent information - - - - - - - - - Qt::PlainText - - - Qt::TextSelectableByMouse - - - - - - - Hash: - - - - - - - Qt::CustomContextMenu - - - QAbstractItemView::ExtendedSelection - - - true - - - - - - - - - - - - - - Date: - - - - - - - Size: - - - - - - - - - - - - - - Comment: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - - - QFrame::NoFrame - - - true - - - - - 0 - 0 - 321 - 69 - + + + Save at - - 0 - - - 0 - - - 0 - - - 0 - - + + + + + + Remember last used save path + + + + + + + + + + Torrent settings + + + + + + + + Category: + + + + + + + + 0 + 0 + + + + true + + + QComboBox::InsertAtTop + + + + + + + + + Set as default category + + + + + + + + + When checked, the .torrent file will not be deleted despite the settings at the "Download" page of the options dialog + + + Do not delete .torrent file + + + + + + + Download first and last pieces first + + + + + + + Skip hash check + + + + + + + Download in sequential order + + + + + + + Create subfolder + + + + + + + Start torrent + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + 0 + 0 + + + + Torrent information + + + + - + Date: + + + + + + + + + + + + Size: + + + + + - Qt::RichText + Qt::PlainText - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + Qt::TextSelectableByMouse - - true + + + + + + background-color: rgba(0, 0, 0, 0); - + + QFrame::NoFrame + + true - - Qt::TextBrowserInteraction + + + + 0 + 0 + 421 + 68 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::RichText + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + true + + + Qt::TextBrowserInteraction + + + + + + + + + + + Hash: + + + + + + + Comment: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - + + + + + + + 1 + 0 + + + + Qt::CustomContextMenu + + + QAbstractItemView::ExtendedSelection + + + true + + + + + + Never show again + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + @@ -353,13 +380,17 @@ false - - %p% - - + + + + 0 + 0 + + + @@ -405,18 +436,6 @@ 1 - - savePath - checkBoxRememberLastSavePath - checkBoxNeverShow - toolButtonAdvanced - startTorrentCheckBox - skipCheckingCheckBox - categoryComboBox - defaultCategoryCheckbox - scrollArea - contentTreeView - @@ -426,8 +445,8 @@ accept() - 403 - 579 + 928 + 855 157 @@ -442,8 +461,8 @@ reject() - 403 - 579 + 928 + 855 286 @@ -452,34 +471,34 @@ - categoryComboBox + comboTTM currentIndexChanged(int) AddNewTorrentDialog - categoryChanged(int) + TMMChanged(int) - 337 - 205 + 250 + 53 - 403 - 160 + 467 + 249 - comboTTM + categoryComboBox currentIndexChanged(int) AddNewTorrentDialog - TMMChanged(int) + categoryChanged(int) - 200 - 19 + 266 + 231 - 206 - 294 + 467 + 249