Browse Source

Remove obsoleted functions from Utils::Gui namespace

`widget` parameter is kept for now to avoid major disruption for other PR.
Also add comments for loading svg images.

PR #16613.
adaptive-webui-19844
Chocobo1 3 years ago committed by GitHub
parent
commit
88fe94bd6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/gui/aboutdialog.cpp
  2. 2
      src/gui/addnewtorrentdialog.cpp
  3. 2
      src/gui/autoexpandabledialog.cpp
  4. 2
      src/gui/banlistoptionsdialog.cpp
  5. 2
      src/gui/cookiesdialog.cpp
  6. 2
      src/gui/deletionconfirmationdialog.cpp
  7. 2
      src/gui/downloadfromurldialog.cpp
  8. 2
      src/gui/ipsubnetwhitelistoptionsdialog.cpp
  9. 2
      src/gui/mainwindow.cpp
  10. 5
      src/gui/optionsdialog.cpp
  11. 2
      src/gui/previewselectdialog.cpp
  12. 4
      src/gui/properties/propertieswidget.cpp
  13. 4
      src/gui/rss/automatedrssdownloader.cpp
  14. 2
      src/gui/search/pluginselectdialog.cpp
  15. 2
      src/gui/search/pluginsourcedialog.cpp
  16. 2
      src/gui/shutdownconfirmdialog.cpp
  17. 2
      src/gui/speedlimitdialog.cpp
  18. 2
      src/gui/statsdialog.cpp
  19. 2
      src/gui/torrentcreatordialog.cpp
  20. 2
      src/gui/torrentoptionsdialog.cpp
  21. 2
      src/gui/trackerentriesdialog.cpp
  22. 47
      src/gui/utils.cpp
  23. 12
      src/gui/utils.h
  24. 2
      src/gui/watchedfolderoptionsdialog.cpp

2
src/gui/aboutdialog.cpp

@ -113,7 +113,7 @@ AboutDialog::AboutDialog(QWidget *parent)
"The database is licensed under the Creative Commons Attribution 4.0 International License")); "The database is licensed under the Creative Commons Attribution 4.0 International License"));
m_ui->labelDBIP->setText(DBIPText); m_ui->labelDBIP->setText(DBIPText);
Utils::Gui::resize(this, m_storeDialogSize); resize(m_storeDialogSize);
show(); show();
} }

2
src/gui/addnewtorrentdialog.cpp

@ -305,7 +305,7 @@ void AddNewTorrentDialog::setSavePathHistoryLength(const int value)
void AddNewTorrentDialog::loadState() void AddNewTorrentDialog::loadState()
{ {
Utils::Gui::resize(this, m_storeDialogSize); resize(m_storeDialogSize);
m_ui->splitter->restoreState(m_storeSplitterState);; m_ui->splitter->restoreState(m_storeSplitterState);;
} }

2
src/gui/autoexpandabledialog.cpp

@ -101,6 +101,6 @@ void AutoExpandableDialog::showEvent(QShowEvent *e)
if (wd > width()) if (wd > width())
{ {
QSize size = {width() - m_ui->verticalLayout->sizeHint().width() + wd, height()}; QSize size = {width() - m_ui->verticalLayout->sizeHint().width() + wd, height()};
Utils::Gui::resize(this, size); resize(size);
} }
} }

2
src/gui/banlistoptionsdialog.cpp

@ -56,7 +56,7 @@ BanListOptionsDialog::BanListOptionsDialog(QWidget *parent)
m_ui->bannedIPList->sortByColumn(0, Qt::AscendingOrder); m_ui->bannedIPList->sortByColumn(0, Qt::AscendingOrder);
m_ui->buttonBanIP->setEnabled(false); m_ui->buttonBanIP->setEnabled(false);
Utils::Gui::resize(this, m_storeDialogSize); resize(m_storeDialogSize);
} }
BanListOptionsDialog::~BanListOptionsDialog() BanListOptionsDialog::~BanListOptionsDialog()

2
src/gui/cookiesdialog.cpp

@ -64,7 +64,7 @@ CookiesDialog::CookiesDialog(QWidget *parent)
m_cookiesModel->index(0, 0), m_cookiesModel->index(0, 0),
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
Utils::Gui::resize(this, m_storeDialogSize); resize(m_storeDialogSize);
m_ui->treeView->header()->restoreState(m_storeViewState); m_ui->treeView->header()->restoreState(m_storeViewState);
} }

2
src/gui/deletionconfirmationdialog.cpp

@ -55,8 +55,6 @@ DeletionConfirmationDialog::DeletionConfirmationDialog(QWidget *parent, const in
m_ui->checkPermDelete->setChecked(defaultDeleteFiles || Preferences::instance()->deleteTorrentFilesAsDefault()); m_ui->checkPermDelete->setChecked(defaultDeleteFiles || Preferences::instance()->deleteTorrentFilesAsDefault());
connect(m_ui->checkPermDelete, &QCheckBox::clicked, this, &DeletionConfirmationDialog::updateRememberButtonState); connect(m_ui->checkPermDelete, &QCheckBox::clicked, this, &DeletionConfirmationDialog::updateRememberButtonState);
m_ui->buttonBox->button(QDialogButtonBox::Cancel)->setFocus(); m_ui->buttonBox->button(QDialogButtonBox::Cancel)->setFocus();
Utils::Gui::resize(this);
} }
DeletionConfirmationDialog::~DeletionConfirmationDialog() DeletionConfirmationDialog::~DeletionConfirmationDialog()

2
src/gui/downloadfromurldialog.cpp

@ -94,7 +94,7 @@ DownloadFromURLDialog::DownloadFromURLDialog(QWidget *parent)
m_ui->textUrls->setText(text); m_ui->textUrls->setText(text);
m_ui->textUrls->moveCursor(QTextCursor::End); m_ui->textUrls->moveCursor(QTextCursor::End);
Utils::Gui::resize(this, m_storeDialogSize); resize(m_storeDialogSize);
show(); show();
} }

2
src/gui/ipsubnetwhitelistoptionsdialog.cpp

@ -60,7 +60,7 @@ IPSubnetWhitelistOptionsDialog::IPSubnetWhitelistOptionsDialog(QWidget *parent)
m_ui->whitelistedIPSubnetList->sortByColumn(0, Qt::AscendingOrder); m_ui->whitelistedIPSubnetList->sortByColumn(0, Qt::AscendingOrder);
m_ui->buttonWhitelistIPSubnet->setEnabled(false); m_ui->buttonWhitelistIPSubnet->setEnabled(false);
Utils::Gui::resize(this, m_storeDialogSize); resize(m_storeDialogSize);
} }
IPSubnetWhitelistOptionsDialog::~IPSubnetWhitelistOptionsDialog() IPSubnetWhitelistOptionsDialog::~IPSubnetWhitelistOptionsDialog()

2
src/gui/mainwindow.cpp

@ -209,7 +209,7 @@ MainWindow::MainWindow(QWidget *parent)
// Name filter // Name filter
m_searchFilter = new LineEdit(this); m_searchFilter = new LineEdit(this);
m_searchFilter->setPlaceholderText(tr("Filter torrent names...")); m_searchFilter->setPlaceholderText(tr("Filter torrent names..."));
m_searchFilter->setFixedWidth(Utils::Gui::scaledSize(this, 200)); m_searchFilter->setFixedWidth(200);
m_searchFilter->setContextMenuPolicy(Qt::CustomContextMenu); m_searchFilter->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_searchFilter, &QWidget::customContextMenuRequested, this, &MainWindow::showFilterContextMenu); connect(m_searchFilter, &QWidget::customContextMenuRequested, this, &MainWindow::showFilterContextMenu);
m_searchFilterAction = m_ui->toolBar->insertWidget(m_ui->actionLock, m_searchFilter); m_searchFilterAction = m_ui->toolBar->insertWidget(m_ui->actionLock, m_searchFilter);

5
src/gui/optionsdialog.cpp

@ -575,7 +575,7 @@ OptionsDialog::OptionsDialog(QWidget *parent)
m_ui->tabSelection->setCurrentRow(m_storeLastViewedPage); m_ui->tabSelection->setCurrentRow(m_storeLastViewedPage);
Utils::Gui::resize(this, m_storeDialogSize); resize(m_storeDialogSize);
show(); show();
// Have to be called after show(), because splitter width needed // Have to be called after show(), because splitter width needed
loadSplitterState(); loadSplitterState();
@ -639,8 +639,7 @@ void OptionsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previo
void OptionsDialog::loadSplitterState() void OptionsDialog::loadSplitterState()
{ {
// width has been modified, use height as width reference instead // width has been modified, use height as width reference instead
const int width = Utils::Gui::scaledSize(this const int width = m_ui->tabSelection->item(TAB_UI)->sizeHint().height() * 2;
, (m_ui->tabSelection->item(TAB_UI)->sizeHint().height() * 2));
const QStringList defaultSizes = {QString::number(width), QString::number(m_ui->hsplitter->width() - width)}; const QStringList defaultSizes = {QString::number(width), QString::number(m_ui->hsplitter->width() - width)};
QList<int> splitterSizes; QList<int> splitterSizes;

2
src/gui/previewselectdialog.cpp

@ -173,7 +173,7 @@ void PreviewSelectDialog::saveWindowState()
void PreviewSelectDialog::loadWindowState() void PreviewSelectDialog::loadWindowState()
{ {
// Restore dialog size // Restore dialog size
Utils::Gui::resize(this, m_storeDialogSize); resize(m_storeDialogSize);
// Restore TreeView Header state // Restore TreeView Header state
if (!m_storeTreeHeaderState.get().isEmpty()) if (!m_storeTreeHeaderState.get().isEmpty())

4
src/gui/properties/propertieswidget.cpp

@ -94,7 +94,7 @@ PropertiesWidget::PropertiesWidget(QWidget *parent)
// Torrent content filtering // Torrent content filtering
m_contentFilterLine = new LineEdit(this); m_contentFilterLine = new LineEdit(this);
m_contentFilterLine->setPlaceholderText(tr("Filter files...")); m_contentFilterLine->setPlaceholderText(tr("Filter files..."));
m_contentFilterLine->setFixedWidth(Utils::Gui::scaledSize(this, 300)); m_contentFilterLine->setFixedWidth(300);
connect(m_contentFilterLine, &LineEdit::textChanged, this, &PropertiesWidget::filterText); connect(m_contentFilterLine, &LineEdit::textChanged, this, &PropertiesWidget::filterText);
m_ui->contentFilterLayout->insertWidget(3, m_contentFilterLine); m_ui->contentFilterLayout->insertWidget(3, m_contentFilterLine);
@ -117,7 +117,7 @@ PropertiesWidget::PropertiesWidget(QWidget *parent)
connect(m_ui->filesList->header(), &QHeaderView::sortIndicatorChanged, this, &PropertiesWidget::saveSettings); connect(m_ui->filesList->header(), &QHeaderView::sortIndicatorChanged, this, &PropertiesWidget::saveSettings);
// set bar height relative to screen dpi // set bar height relative to screen dpi
const int barHeight = Utils::Gui::scaledSize(this, 18); const int barHeight = 18;
// Downloaded pieces progress bar // Downloaded pieces progress bar
m_ui->tempProgressBarArea->setVisible(false); m_ui->tempProgressBarArea->setVisible(false);

4
src/gui/rss/automatedrssdownloader.cpp

@ -160,8 +160,8 @@ AutomatedRssDownloader::~AutomatedRssDownloader()
void AutomatedRssDownloader::loadSettings() void AutomatedRssDownloader::loadSettings()
{ {
const Preferences *const pref = Preferences::instance(); const auto *pref = Preferences::instance();
Utils::Gui::resize(this, pref->getRssGeometrySize()); resize(pref->getRssGeometrySize());
m_ui->hsplitter->restoreState(pref->getRssHSplitterSizes()); m_ui->hsplitter->restoreState(pref->getRssHSplitterSizes());
} }

2
src/gui/search/pluginselectdialog.cpp

@ -88,7 +88,7 @@ PluginSelectDialog::PluginSelectDialog(SearchPluginManager *pluginManager, QWidg
connect(m_pluginManager, &SearchPluginManager::checkForUpdatesFinished, this, &PluginSelectDialog::checkForUpdatesFinished); connect(m_pluginManager, &SearchPluginManager::checkForUpdatesFinished, this, &PluginSelectDialog::checkForUpdatesFinished);
connect(m_pluginManager, &SearchPluginManager::checkForUpdatesFailed, this, &PluginSelectDialog::checkForUpdatesFailed); connect(m_pluginManager, &SearchPluginManager::checkForUpdatesFailed, this, &PluginSelectDialog::checkForUpdatesFailed);
Utils::Gui::resize(this, m_storeDialogSize); resize(m_storeDialogSize);
show(); show();
} }

2
src/gui/search/pluginsourcedialog.cpp

@ -41,7 +41,7 @@ PluginSourceDialog::PluginSourceDialog(QWidget *parent)
m_ui->setupUi(this); m_ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
Utils::Gui::resize(this, m_storeDialogSize); resize(m_storeDialogSize);
show(); show();
} }

2
src/gui/shutdownconfirmdialog.cpp

@ -66,8 +66,6 @@ ShutdownConfirmDialog::ShutdownConfirmDialog(QWidget *parent, const ShutdownDial
m_timer.setInterval(1000); // 1sec m_timer.setInterval(1000); // 1sec
connect(&m_timer, &QTimer::timeout, this, &ShutdownConfirmDialog::updateSeconds); connect(&m_timer, &QTimer::timeout, this, &ShutdownConfirmDialog::updateSeconds);
Utils::Gui::resize(this);
} }
ShutdownConfirmDialog::~ShutdownConfirmDialog() ShutdownConfirmDialog::~ShutdownConfirmDialog()

2
src/gui/speedlimitdialog.cpp

@ -108,7 +108,7 @@ SpeedLimitDialog::SpeedLimitDialog(QWidget *parent)
connect(m_ui->spinAltDownloadLimit, qOverload<int>(&QSpinBox::valueChanged) connect(m_ui->spinAltDownloadLimit, qOverload<int>(&QSpinBox::valueChanged)
, this, [this](const int value) { updateSliderValue(m_ui->sliderAltDownloadLimit, value); }); , this, [this](const int value) { updateSliderValue(m_ui->sliderAltDownloadLimit, value); });
Utils::Gui::resize(this, m_storeDialogSize); resize(m_storeDialogSize);
} }
SpeedLimitDialog::~SpeedLimitDialog() SpeedLimitDialog::~SpeedLimitDialog()

2
src/gui/statsdialog.cpp

@ -60,7 +60,7 @@ StatsDialog::StatsDialog(QWidget *parent)
m_ui->labelCacheHits->hide(); m_ui->labelCacheHits->hide();
#endif #endif
Utils::Gui::resize(this, m_storeDialogSize); resize(m_storeDialogSize);
show(); show();
} }

2
src/gui/torrentcreatordialog.cpp

@ -344,5 +344,5 @@ void TorrentCreatorDialog::loadSettings()
m_ui->txtComment->setPlainText(m_storeComments); m_ui->txtComment->setPlainText(m_storeComments);
m_ui->lineEditSource->setText(m_storeSource); m_ui->lineEditSource->setText(m_storeSource);
Utils::Gui::resize(this, m_storeDialogSize); resize(m_storeDialogSize);
} }

2
src/gui/torrentoptionsdialog.cpp

@ -390,7 +390,7 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTor
connect(m_ui->buttonGroup, &QButtonGroup::idClicked, this, &TorrentOptionsDialog::handleRatioTypeChanged); connect(m_ui->buttonGroup, &QButtonGroup::idClicked, this, &TorrentOptionsDialog::handleRatioTypeChanged);
Utils::Gui::resize(this, m_storeDialogSize); resize(m_storeDialogSize);
} }
TorrentOptionsDialog::~TorrentOptionsDialog() TorrentOptionsDialog::~TorrentOptionsDialog()

2
src/gui/trackerentriesdialog.cpp

@ -110,5 +110,5 @@ void TrackerEntriesDialog::saveSettings()
void TrackerEntriesDialog::loadSettings() void TrackerEntriesDialog::loadSettings()
{ {
Utils::Gui::resize(this, m_storeDialogSize); resize(m_storeDialogSize);
} }

47
src/gui/utils.cpp

@ -35,7 +35,6 @@
#include <QApplication> #include <QApplication>
#include <QDesktopServices> #include <QDesktopServices>
#include <QFileInfo>
#include <QIcon> #include <QIcon>
#include <QPixmap> #include <QPixmap>
#include <QPixmapCache> #include <QPixmapCache>
@ -52,47 +51,41 @@
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "base/utils/version.h" #include "base/utils/version.h"
void Utils::Gui::resize(QWidget *widget, const QSize &newSize)
{
if (newSize.isValid())
widget->resize(newSize);
else // depends on screen DPI
widget->resize(widget->size() * screenScalingFactor(widget));
}
qreal Utils::Gui::screenScalingFactor(const QWidget *widget)
{
Q_UNUSED(widget);
return 1;
}
QPixmap Utils::Gui::scaledPixmap(const QIcon &icon, const QWidget *widget, const int height) QPixmap Utils::Gui::scaledPixmap(const QIcon &icon, const QWidget *widget, const int height)
{ {
Q_UNUSED(widget); // TODO: remove it
Q_ASSERT(height > 0); Q_ASSERT(height > 0);
const int scaledHeight = height * Utils::Gui::screenScalingFactor(widget);
return icon.pixmap(scaledHeight); return icon.pixmap(height);
} }
QPixmap Utils::Gui::scaledPixmap(const Path &path, const QWidget *widget, const int height) QPixmap Utils::Gui::scaledPixmap(const Path &path, const QWidget *widget, const int height)
{ {
Q_UNUSED(widget);
Q_ASSERT(height >= 0);
const QPixmap pixmap {path.data()}; const QPixmap pixmap {path.data()};
const int scaledHeight = ((height > 0) ? height : pixmap.height()) * Utils::Gui::screenScalingFactor(widget); return (height == 0) ? pixmap : pixmap.scaledToHeight(height, Qt::SmoothTransformation);
return pixmap.scaledToHeight(scaledHeight, Qt::SmoothTransformation);
} }
QPixmap Utils::Gui::scaledPixmapSvg(const Path &path, const QWidget *widget, const int baseHeight) QPixmap Utils::Gui::scaledPixmapSvg(const Path &path, const QWidget *widget, const int height)
{ {
const int scaledHeight = baseHeight * Utils::Gui::screenScalingFactor(widget); // (workaround) svg images require the use of `QIcon()` to load and scale losslessly,
const QString normalizedKey = path.data() + '@' + QString::number(scaledHeight); // otherwise other image classes will convert it to pixmap first and follow-up scaling will become lossy.
Q_UNUSED(widget);
Q_ASSERT(height > 0);
const QString cacheKey = path.data() + u'@' + QString::number(height);
QPixmap pm; QPixmap pixmap;
QPixmapCache cache; QPixmapCache cache;
if (!cache.find(normalizedKey, &pm)) if (!cache.find(cacheKey, &pixmap))
{ {
pm = QIcon(path.data()).pixmap(scaledHeight); pixmap = QIcon(path.data()).pixmap(height);
cache.insert(normalizedKey, pm); cache.insert(cacheKey, pixmap);
} }
return pm; return pixmap;
} }
QSize Utils::Gui::smallIconSize(const QWidget *widget) QSize Utils::Gui::smallIconSize(const QWidget *widget)

12
src/gui/utils.h

@ -39,18 +39,10 @@ class QWidget;
namespace Utils::Gui namespace Utils::Gui
{ {
void resize(QWidget *widget, const QSize &newSize = {});
qreal screenScalingFactor(const QWidget *widget);
template <typename T>
T scaledSize(const QWidget *widget, const T &size)
{
return (size * screenScalingFactor(widget));
}
QPixmap scaledPixmap(const QIcon &icon, const QWidget *widget, int height); QPixmap scaledPixmap(const QIcon &icon, const QWidget *widget, int height);
QPixmap scaledPixmap(const Path &path, const QWidget *widget, int height = 0); QPixmap scaledPixmap(const Path &path, const QWidget *widget, int height = 0);
QPixmap scaledPixmapSvg(const Path &path, const QWidget *widget, int baseHeight); QPixmap scaledPixmapSvg(const Path &path, const QWidget *widget, int height);
QSize smallIconSize(const QWidget *widget = nullptr); QSize smallIconSize(const QWidget *widget = nullptr);
QSize mediumIconSize(const QWidget *widget = nullptr); QSize mediumIconSize(const QWidget *widget = nullptr);
QSize largeIconSize(const QWidget *widget = nullptr); QSize largeIconSize(const QWidget *widget = nullptr);

2
src/gui/watchedfolderoptionsdialog.cpp

@ -125,7 +125,7 @@ TorrentFilesWatcher::WatchedFolderOptions WatchedFolderOptionsDialog::watchedFol
void WatchedFolderOptionsDialog::loadState() void WatchedFolderOptionsDialog::loadState()
{ {
Utils::Gui::resize(this, m_storeDialogSize); resize(m_storeDialogSize);
} }
void WatchedFolderOptionsDialog::saveState() void WatchedFolderOptionsDialog::saveState()

Loading…
Cancel
Save