Browse Source

Merge pull request #7876 from Chocobo1/optionIcons

Fix gui issues on high DPI monitor
adaptive-webui-19844
Mike Tzou 7 years ago committed by GitHub
parent
commit
267362a7a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/base/preferences.cpp
  2. 4
      src/base/preferences.h
  3. 13
      src/base/utils/misc.cpp
  4. 2
      src/base/utils/misc.h
  5. 2
      src/gui/CMakeLists.txt
  6. 12
      src/gui/about.ui
  7. 9
      src/gui/about_imp.h
  8. 39
      src/gui/addnewtorrentdialog.cpp
  9. 26
      src/gui/autoexpandabledialog.cpp
  10. 3
      src/gui/banlistoptions.cpp
  11. 4
      src/gui/categoryfilterwidget.cpp
  12. 5
      src/gui/cookiesdialog.cpp
  13. 12
      src/gui/cookiesdialog.ui
  14. 12
      src/gui/deletionconfirmationdlg.h
  15. 2
      src/gui/downloadfromurldlg.h
  16. 2
      src/gui/gui.pri
  17. 3
      src/gui/ipsubnetwhitelistoptionsdialog.cpp
  18. 6
      src/gui/lineedit/CMakeLists.txt
  19. 1
      src/gui/lineedit/lineedit.pri
  20. 5
      src/gui/lineedit/resources/lineeditimages.qrc
  21. BIN
      src/gui/lineedit/resources/lineeditimages/search.png
  22. 36
      src/gui/lineedit/src/lineedit.cpp
  23. 4
      src/gui/lineedit/src/lineedit.h
  24. 110
      src/gui/mainwindow.cpp
  25. 49
      src/gui/optionsdlg.cpp
  26. 40
      src/gui/optionsdlg.ui
  27. 8
      src/gui/previewselectdialog.cpp
  28. 3
      src/gui/properties/peerlistwidget.cpp
  29. 14
      src/gui/properties/propertieswidget.cpp
  30. 3
      src/gui/properties/propertieswidget.ui
  31. 1
      src/gui/properties/speedwidget.cpp
  32. 3
      src/gui/properties/trackerlist.cpp
  33. 5
      src/gui/rss/automatedrssdownloader.cpp
  34. 23
      src/gui/search/pluginselectdlg.cpp
  35. 3
      src/gui/search/pluginsourcedlg.cpp
  36. 3
      src/gui/search/searchtab.cpp
  37. 3
      src/gui/shutdownconfirmdlg.cpp
  38. 3
      src/gui/speedlimitdlg.cpp
  39. 2
      src/gui/statsdialog.cpp
  40. 13
      src/gui/statusbar.cpp
  41. 4
      src/gui/tagfilterwidget.cpp
  42. 5
      src/gui/torrentcreatordlg.cpp
  43. 6
      src/gui/trackerlogin.cpp
  44. 5
      src/gui/transferlistfilterswidget.cpp
  45. 8
      src/gui/transferlistwidget.cpp
  46. 3
      src/gui/updownratiodlg.cpp
  47. 87
      src/gui/utils.cpp
  48. 58
      src/gui/utils.h

8
src/base/preferences.cpp

@ -1216,9 +1216,9 @@ void Preferences::setMainLastDir(const QString &path) @@ -1216,9 +1216,9 @@ void Preferences::setMainLastDir(const QString &path)
setValue("MainWindowLastDir", path);
}
QSize Preferences::getPrefSize(const QSize &defaultSize) const
QSize Preferences::getPrefSize() const
{
return value("Preferences/State/size", defaultSize).toSize();
return value("Preferences/State/size").toSize();
}
void Preferences::setPrefSize(const QSize &size)
@ -1296,9 +1296,9 @@ void Preferences::setPropTrackerListState(const QByteArray &state) @@ -1296,9 +1296,9 @@ void Preferences::setPropTrackerListState(const QByteArray &state)
setValue("TorrentProperties/Trackers/qt5/TrackerListState", state);
}
QSize Preferences::getRssGeometrySize(const QSize &defaultSize) const
QSize Preferences::getRssGeometrySize() const
{
return value("RssFeedDownloader/geometrySize", defaultSize).toSize();
return value("RssFeedDownloader/geometrySize").toSize();
}
void Preferences::setRssGeometrySize(const QSize &geometry)

4
src/base/preferences.h

@ -301,7 +301,7 @@ public: @@ -301,7 +301,7 @@ public:
void setMainVSplitterState(const QByteArray &state);
QString getMainLastDir() const;
void setMainLastDir(const QString &path);
QSize getPrefSize(const QSize &defaultSize) const;
QSize getPrefSize() const;
void setPrefSize(const QSize &size);
QStringList getPrefHSplitterSizes() const;
void setPrefHSplitterSizes(const QStringList &sizes);
@ -317,7 +317,7 @@ public: @@ -317,7 +317,7 @@ public:
void setPropVisible(const bool visible);
QByteArray getPropTrackerListState() const;
void setPropTrackerListState(const QByteArray &state);
QSize getRssGeometrySize(const QSize &defaultSize) const;
QSize getRssGeometrySize() const;
void setRssGeometrySize(const QSize &geometry);
QByteArray getRssHSplitterSizes() const;
void setRssHSplitterSizes(const QByteArray &sizes);

13
src/base/utils/misc.cpp

@ -632,19 +632,6 @@ void Utils::Misc::openFolderSelect(const QString &absolutePath) @@ -632,19 +632,6 @@ void Utils::Misc::openFolderSelect(const QString &absolutePath)
#endif
}
QSize Utils::Misc::smallIconSize()
{
// Get DPI scaled icon size (device-dependent), see QT source
int s = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
return QSize(s, s);
}
QSize Utils::Misc::largeIconSize()
{
// Get DPI scaled icon size (device-dependent), see QT source
int s = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize);
return QSize(s, s);
}
#endif // DISABLE_GUI
QString Utils::Misc::osName()

2
src/base/utils/misc.h

@ -103,8 +103,6 @@ namespace Utils @@ -103,8 +103,6 @@ namespace Utils
void openFolderSelect(const QString& absolutePath);
QPoint screenCenter(const QWidget *w);
QSize smallIconSize();
QSize largeIconSize();
#endif
#ifdef Q_OS_WIN

2
src/gui/CMakeLists.txt

@ -74,6 +74,7 @@ transferlistfilterswidget.h @@ -74,6 +74,7 @@ transferlistfilterswidget.h
transferlistsortmodel.h
transferlistwidget.h
updownratiodlg.h
utils.h
)
set(QBT_GUI_SOURCES
@ -119,6 +120,7 @@ transferlistfilterswidget.cpp @@ -119,6 +120,7 @@ transferlistfilterswidget.cpp
transferlistsortmodel.cpp
transferlistwidget.cpp
updownratiodlg.cpp
utils.cpp
)
if (APPLE)

12
src/gui/about.ui

@ -18,11 +18,7 @@ @@ -18,11 +18,7 @@
<item>
<layout class="QHBoxLayout" name="titleHBoxLayout">
<item>
<widget class="QLabel" name="logo">
<property name="pixmap">
<pixmap resource="../icons.qrc">:/icons/skin/qbittorrent32.png</pixmap>
</property>
</widget>
<widget class="QLabel" name="logo"/>
</item>
<item>
<widget class="QLabel" name="lb_name">
@ -57,11 +53,7 @@ @@ -57,11 +53,7 @@
</attribute>
<layout class="QGridLayout" name="aboutTabLayout">
<item row="0" column="0">
<widget class="QLabel" name="mascot_lbl">
<property name="pixmap">
<pixmap resource="../icons.qrc">:/icons/skin/mascot.png</pixmap>
</property>
</widget>
<widget class="QLabel" name="labelMascot"/>
</item>
<item row="0" column="1">
<widget class="QLabel" name="lb_about">

9
src/gui/about_imp.h

@ -31,10 +31,12 @@ @@ -31,10 +31,12 @@
#ifndef ABOUT_H
#define ABOUT_H
#include "ui_about.h"
#include <QFile>
#include "base/utils/misc.h"
#include "base/unicodestrings.h"
#include "ui_about.h"
#include "utils.h"
class about: public QDialog, private Ui::AboutDlg
{
@ -53,6 +55,8 @@ public: @@ -53,6 +55,8 @@ public:
lb_name->setText("<b><h2>qBittorrent " QBT_VERSION " (32-bit)</h2></b>");
#endif
logo->setPixmap(Utils::Gui::scaledPixmap(":/icons/skin/qbittorrent32.png", this));
// About
QString aboutText = QString(
"<p style=\"white-space: pre-wrap;\">"
@ -71,6 +75,8 @@ public: @@ -71,6 +75,8 @@ public:
.arg(tr("Bug Tracker:"));
lb_about->setText(aboutText);
labelMascot->setPixmap(Utils::Gui::scaledPixmap(":/icons/skin/mascot.png", this));
// Thanks
QFile thanksfile(":/thanks.html");
if (thanksfile.open(QIODevice::ReadOnly | QIODevice::Text)) {
@ -97,6 +103,7 @@ public: @@ -97,6 +103,7 @@ public:
label_12->setText(Utils::Misc::libtorrentVersionString());
label_13->setText(Utils::Misc::boostVersionString());
Utils::Gui::resize(this);
show();
}
};

39
src/gui/addnewtorrentdialog.cpp

@ -28,36 +28,38 @@ @@ -28,36 +28,38 @@
* Contact : chris@qbittorrent.org
*/
#include "addnewtorrentdialog.h"
#include <QDebug>
#include <QString>
#include <QFile>
#include <QUrl>
#include <QMenu>
#include <QFileDialog>
#include <QMenu>
#include <QPushButton>
#include <QString>
#include <QUrl>
#include "autoexpandabledialog.h"
#include "base/bittorrent/magneturi.h"
#include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h"
#include "base/bittorrent/torrentinfo.h"
#include "base/net/downloadhandler.h"
#include "base/net/downloadmanager.h"
#include "base/preferences.h"
#include "base/settingsstorage.h"
#include "base/settingvalue.h"
#include "base/net/downloadmanager.h"
#include "base/net/downloadhandler.h"
#include "base/bittorrent/session.h"
#include "base/bittorrent/magneturi.h"
#include "base/bittorrent/torrentinfo.h"
#include "base/bittorrent/torrenthandle.h"
#include "base/torrentfileguard.h"
#include "base/unicodestrings.h"
#include "base/utils/fs.h"
#include "base/utils/misc.h"
#include "base/utils/string.h"
#include "base/torrentfileguard.h"
#include "base/unicodestrings.h"
#include "guiiconprovider.h"
#include "autoexpandabledialog.h"
#include "messageboxraised.h"
#include "proplistdelegate.h"
#include "torrentcontentmodel.h"
#include "torrentcontentfiltermodel.h"
#include "torrentcontentmodel.h"
#include "ui_addnewtorrentdialog.h"
#include "addnewtorrentdialog.h"
#include "utils.h"
namespace
{
@ -212,10 +214,11 @@ CachedSettingValue<int> &AddNewTorrentDialog::savePathHistoryLengthSetting() @@ -212,10 +214,11 @@ CachedSettingValue<int> &AddNewTorrentDialog::savePathHistoryLengthSetting()
void AddNewTorrentDialog::loadState()
{
m_headerState = settings()->loadValue(KEY_TREEHEADERSTATE).toByteArray();
int width = settings()->loadValue(KEY_WIDTH, -1).toInt();
QSize geo = size();
geo.setWidth(width);
resize(geo);
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);
ui->adv_button->setChecked(settings()->loadValue(KEY_EXPANDED).toBool());
}

26
src/gui/autoexpandabledialog.cpp

@ -32,6 +32,7 @@ @@ -32,6 +32,7 @@
#include "mainwindow.h"
#include "ui_autoexpandabledialog.h"
#include "utils.h"
AutoExpandableDialog::AutoExpandableDialog(QWidget *parent)
: QDialog(parent)
@ -68,30 +69,29 @@ QString AutoExpandableDialog::getText(QWidget *parent, const QString &title, con @@ -68,30 +69,29 @@ QString AutoExpandableDialog::getText(QWidget *parent, const QString &title, con
void AutoExpandableDialog::showEvent(QShowEvent *e)
{
// Overriding showEvent is required for consistent UI with fixed size under custom DPI
// Show dialog
QDialog::showEvent(e);
// and resize textbox to fit the text
// NOTE: For some strange reason QFontMetrics gets more accurate
// when called from showEvent. Only 6 symbols off instead of 11 symbols off.
int textW = m_ui->textEdit->fontMetrics().width(m_ui->textEdit->text()) + 4;
int wd = textW;
// Show dialog and resize textbox to fit the text
// NOTE: For unknown reason QFontMetrics gets more accurate when called from showEvent.
int wd = m_ui->textEdit->fontMetrics().width(m_ui->textEdit->text()) + 4;
if (!windowTitle().isEmpty()) {
int w = fontMetrics().width(windowTitle());
if (w > wd)
wd = w;
// not really the font metrics in window title, so we enlarge it a bit,
// including the small icon and close button width
int w = fontMetrics().width(windowTitle()) * 1.8;
wd = std::max(wd, w);
}
if (!m_ui->textLabel->text().isEmpty()) {
int w = m_ui->textLabel->fontMetrics().width(m_ui->textLabel->text());
if (w > wd)
wd = w;
wd = std::max(wd, w);
}
// Now resize the dialog to fit the contents
// max width of text from either of: label, title, textedit
// If the value is less than dialog default size, default size is used
if (wd > width())
resize(width() - m_ui->verticalLayout->sizeHint().width() + wd, height());
if (wd > width()) {
QSize size = {width() - m_ui->verticalLayout->sizeHint().width() + wd, height()};
Utils::Gui::resize(this, size);
}
}

3
src/gui/banlistoptions.cpp

@ -36,6 +36,7 @@ @@ -36,6 +36,7 @@
#include "base/bittorrent/session.h"
#include "base/utils/net.h"
#include "ui_banlistoptions.h"
#include "utils.h"
BanListOptions::BanListOptions(QWidget *parent)
: QDialog(parent)
@ -52,6 +53,8 @@ BanListOptions::BanListOptions(QWidget *parent) @@ -52,6 +53,8 @@ BanListOptions::BanListOptions(QWidget *parent)
m_ui->bannedIPList->setModel(m_sortFilter);
m_ui->bannedIPList->sortByColumn(0, Qt::AscendingOrder);
m_ui->buttonBanIP->setEnabled(false);
Utils::Gui::resize(this);
}
BanListOptions::~BanListOptions()

4
src/gui/categoryfilterwidget.cpp

@ -35,11 +35,11 @@ @@ -35,11 +35,11 @@
#include <QMessageBox>
#include "base/bittorrent/session.h"
#include "base/utils/misc.h"
#include "categoryfiltermodel.h"
#include "categoryfilterproxymodel.h"
#include "guiiconprovider.h"
#include "torrentcategorydialog.h"
#include "utils.h"
namespace
{
@ -70,7 +70,7 @@ CategoryFilterWidget::CategoryFilterWidget(QWidget *parent) @@ -70,7 +70,7 @@ CategoryFilterWidget::CategoryFilterWidget(QWidget *parent)
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
setUniformRowHeights(true);
setHeaderHidden(true);
setIconSize(Utils::Misc::smallIconSize());
setIconSize(Utils::Gui::smallIconSize());
#ifdef Q_OS_MAC
setAttribute(Qt::WA_MacShowFocusRect, false);
#endif

5
src/gui/cookiesdialog.cpp

@ -35,6 +35,7 @@ @@ -35,6 +35,7 @@
#include "cookiesmodel.h"
#include "guiiconprovider.h"
#include "ui_cookiesdialog.h"
#include "utils.h"
#define SETTINGS_KEY(name) "CookiesDialog/" name
const QString KEY_SIZE = SETTINGS_KEY("Size");
@ -50,6 +51,8 @@ CookiesDialog::CookiesDialog(QWidget *parent) @@ -50,6 +51,8 @@ CookiesDialog::CookiesDialog(QWidget *parent)
setWindowIcon(GuiIconProvider::instance()->getIcon("preferences-web-browser-cookies"));
m_ui->buttonAdd->setIcon(GuiIconProvider::instance()->getIcon("list-add"));
m_ui->buttonDelete->setIcon(GuiIconProvider::instance()->getIcon("list-remove"));
m_ui->buttonAdd->setIconSize(Utils::Gui::mediumIconSize());
m_ui->buttonDelete->setIconSize(Utils::Gui::mediumIconSize());
m_ui->treeView->setModel(m_cookiesModel);
if (m_cookiesModel->rowCount() > 0)
@ -57,7 +60,7 @@ CookiesDialog::CookiesDialog(QWidget *parent) @@ -57,7 +60,7 @@ CookiesDialog::CookiesDialog(QWidget *parent)
m_cookiesModel->index(0, 0),
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
resize(SettingsStorage::instance()->loadValue(KEY_SIZE, size()).toSize());
Utils::Gui::resize(this, SettingsStorage::instance()->loadValue(KEY_SIZE).toSize());
m_ui->treeView->header()->restoreState(
SettingsStorage::instance()->loadValue(KEY_COOKIESVIEWSTATE).toByteArray());
}

12
src/gui/cookiesdialog.ui

@ -49,12 +49,6 @@ @@ -49,12 +49,6 @@
<property name="text">
<string notr="true"/>
</property>
<property name="iconSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</widget>
</item>
<item>
@ -78,12 +72,6 @@ @@ -78,12 +72,6 @@
<property name="text">
<string notr="true"/>
</property>
<property name="iconSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</widget>
</item>
<item>

12
src/gui/deletionconfirmationdlg.h

@ -33,11 +33,13 @@ @@ -33,11 +33,13 @@
#include <QDialog>
#include <QPushButton>
#include "ui_confirmdeletiondlg.h"
#include "base/preferences.h"
#include "base/utils/misc.h"
#include "base/utils/string.h"
#include "guiiconprovider.h"
#include "ui_confirmdeletiondlg.h"
#include "utils.h"
class DeletionConfirmationDlg : public QDialog, private Ui::confirmDeletionDlg {
Q_OBJECT
@ -50,13 +52,17 @@ class DeletionConfirmationDlg : public QDialog, private Ui::confirmDeletionDlg { @@ -50,13 +52,17 @@ class DeletionConfirmationDlg : public QDialog, private Ui::confirmDeletionDlg {
else
label->setText(tr("Are you sure you want to delete these %1 torrents from the transfer list?", "Are you sure you want to delete these 5 torrents from the transfer list?").arg(QString::number(size)));
// Icons
lbl_warn->setPixmap(GuiIconProvider::instance()->getIcon("dialog-warning").pixmap(lbl_warn->height()));
lbl_warn->setFixedWidth(lbl_warn->height());
const QSize iconSize = Utils::Gui::largeIconSize();
lbl_warn->setPixmap(GuiIconProvider::instance()->getIcon("dialog-warning").pixmap(iconSize));
lbl_warn->setFixedWidth(iconSize.width());
rememberBtn->setIcon(GuiIconProvider::instance()->getIcon("object-locked"));
rememberBtn->setIconSize(Utils::Gui::mediumIconSize());
checkPermDelete->setChecked(defaultDeleteFiles || Preferences::instance()->deleteTorrentFilesAsDefault());
connect(checkPermDelete, SIGNAL(clicked()), this, SLOT(updateRememberButtonState()));
buttonBox->button(QDialogButtonBox::Cancel)->setFocus();
Utils::Gui::resize(this);
}
bool shouldDeleteLocalFiles() const {

2
src/gui/downloadfromurldlg.h

@ -40,6 +40,7 @@ @@ -40,6 +40,7 @@
#include <QStringList>
#include "ui_downloadfromurldlg.h"
#include "utils.h"
class downloadFromURL : public QDialog, private Ui::downloadFromURL
{
@ -82,6 +83,7 @@ class downloadFromURL : public QDialog, private Ui::downloadFromURL @@ -82,6 +83,7 @@ class downloadFromURL : public QDialog, private Ui::downloadFromURL
if (clip_txt_list_cleaned.size() > 0)
textUrls->setText(clip_txt_list_cleaned.join("\n"));
Utils::Gui::resize(this);
show();
}

2
src/gui/gui.pri

@ -64,6 +64,7 @@ HEADERS += \ @@ -64,6 +64,7 @@ HEADERS += \
$$PWD/fspathedit.h \
$$PWD/fspathedit_p.h \
$$PWD/previewselectdialog.h \
$$PWD/utils.h \
SOURCES += \
$$PWD/mainwindow.cpp \
@ -119,6 +120,7 @@ SOURCES += \ @@ -119,6 +120,7 @@ SOURCES += \
$$PWD/fspathedit.cpp \
$$PWD/fspathedit_p.cpp \
$$PWD/previewselectdialog.cpp \
$$PWD/utils.cpp \
win32|macx {
HEADERS += $$PWD/programupdater.h

3
src/gui/ipsubnetwhitelistoptionsdialog.cpp

@ -37,6 +37,7 @@ @@ -37,6 +37,7 @@
#include "base/preferences.h"
#include "base/utils/net.h"
#include "ui_ipsubnetwhitelistoptionsdialog.h"
#include "utils.h"
IPSubnetWhitelistOptionsDialog::IPSubnetWhitelistOptionsDialog(QWidget *parent)
: QDialog(parent)
@ -57,6 +58,8 @@ IPSubnetWhitelistOptionsDialog::IPSubnetWhitelistOptionsDialog(QWidget *parent) @@ -57,6 +58,8 @@ IPSubnetWhitelistOptionsDialog::IPSubnetWhitelistOptionsDialog(QWidget *parent)
m_ui->whitelistedIPSubnetList->setModel(m_sortFilter);
m_ui->whitelistedIPSubnetList->sortByColumn(0, Qt::AscendingOrder);
m_ui->buttonWhitelistIPSubnet->setEnabled(false);
Utils::Gui::resize(this);
}
IPSubnetWhitelistOptionsDialog::~IPSubnetWhitelistOptionsDialog()

6
src/gui/lineedit/CMakeLists.txt

@ -6,11 +6,5 @@ set(QBT_LINEEDIT_HEADERS @@ -6,11 +6,5 @@ set(QBT_LINEEDIT_HEADERS
src/lineedit.h
)
set(QBT_LINEEDIT_RESOURCES
resources/lineeditimages.qrc
)
add_library(qbt_lineedit STATIC ${QBT_LINEEDIT_SOURCES} ${QBT_LINEEDIT_HEADERS})
target_link_libraries(qbt_lineedit Qt5::Widgets)
qbt_target_sources(${QBT_LINEEDIT_RESOURCES})

1
src/gui/lineedit/lineedit.pri

@ -1,4 +1,3 @@ @@ -1,4 +1,3 @@
INCLUDEPATH += $$PWD/src
HEADERS += $$PWD/src/lineedit.h
SOURCES += $$PWD/src/lineedit.cpp
RESOURCES += $$PWD/resources/lineeditimages.qrc

5
src/gui/lineedit/resources/lineeditimages.qrc

@ -1,5 +0,0 @@ @@ -1,5 +0,0 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>lineeditimages/search.png</file>
</qresource>
</RCC>

BIN
src/gui/lineedit/resources/lineeditimages/search.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 292 B

36
src/gui/lineedit/src/lineedit.cpp

@ -8,37 +8,35 @@ @@ -8,37 +8,35 @@
****************************************************************************/
#include "lineedit.h"
#include <algorithm>
#include <QResizeEvent>
#include <QStyle>
#include <QToolButton>
#include <QResizeEvent>
#include "guiiconprovider.h"
LineEdit::LineEdit(QWidget *parent)
: QLineEdit(parent)
{
QPixmap pixmap1(":/lineeditimages/search.png");
searchButton = new QToolButton(this);
searchButton->setIcon(QIcon(pixmap1));
searchButton->setIconSize(pixmap1.size());
searchButton->setCursor(Qt::ArrowCursor);
searchButton->setStyleSheet("QToolButton { border: none; padding: 2px; }");
QSize searchButtonHint = searchButton->sizeHint();
QSize clearButtonHint(0, 0);
m_searchButton = new QToolButton(this);
m_searchButton->setIcon(GuiIconProvider::instance()->getIcon("edit-find"));
m_searchButton->setCursor(Qt::ArrowCursor);
m_searchButton->setStyleSheet("QToolButton {border: none; padding: 2px;}");
// padding between text and widget borders
setStyleSheet(QString("QLineEdit {padding-left: %1px;}").arg(m_searchButton->sizeHint().width()));
setClearButtonEnabled(true);
setStyleSheet(QString("QLineEdit { padding-left: %1px; }").arg(searchButtonHint.width())); // padding between text and widget borders
QSize widgetHint = sizeHint();
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
setMaximumHeight(std::max({ widgetHint.height(), searchButtonHint.height(), clearButtonHint.height() }) + frameWidth * 2);
const int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
setMaximumHeight(std::max(sizeHint().height(), m_searchButton->sizeHint().height()) + frameWidth * 2);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
}
void LineEdit::resizeEvent(QResizeEvent *e)
{
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
QSize sz = searchButton->sizeHint();
searchButton->move(frameWidth, (e->size().height() - sz.height()) / 2);
const int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
m_searchButton->move(frameWidth, (e->size().height() - m_searchButton->sizeHint().height()) / 2);
}

4
src/gui/lineedit/src/lineedit.h

@ -22,10 +22,10 @@ public: @@ -22,10 +22,10 @@ public:
LineEdit(QWidget *parent);
protected:
void resizeEvent(QResizeEvent *e);
void resizeEvent(QResizeEvent *e) override;
private:
QToolButton *searchButton;
QToolButton *m_searchButton;
};
#endif // LIENEDIT_H

110
src/gui/mainwindow.cpp

@ -30,84 +30,84 @@ @@ -30,84 +30,84 @@
#include "mainwindow.h"
#ifdef Q_OS_MAC
#include <QtMacExtras>
#include <QtMac>
#endif
#include <QtGlobal>
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB)
#include <QDBusConnection>
#include "notifications.h"
#endif
#include <QClipboard>
#include <QCloseEvent>
#include <QCryptographicHash>
#include <QDebug>
#include <QDesktopServices>
#include <QFileDialog>
#include <QFileSystemWatcher>
#include <QMessageBox>
#include <QTimer>
#include <QDesktopServices>
#include <QStatusBar>
#include <QClipboard>
#include <QCloseEvent>
#include <QShortcut>
#include <QMimeData>
#include <QProcess>
#include <QScrollBar>
#include <QShortcut>
#include <QSplitter>
#include <QStatusBar>
#include <QSysInfo>
#include <QMimeData>
#include <QCryptographicHash>
#include <QProcess>
#include <QtGlobal>
#include <QTimer>
#include "base/preferences.h"
#include "base/settingsstorage.h"
#include "base/logger.h"
#include "base/utils/misc.h"
#include "base/utils/fs.h"
#ifdef Q_OS_WIN
#include "base/net/downloadmanager.h"
#include "base/net/downloadhandler.h"
#ifdef Q_OS_MAC
#include <QtMac>
#include <QtMacExtras>
#endif
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB)
#include <QDBusConnection>
#include "notifications.h"
#endif
#include "about_imp.h"
#include "addnewtorrentdialog.h"
#include "application.h"
#include "autoexpandabledialog.h"
#include "base/bittorrent/session.h"
#include "base/bittorrent/sessionstatus.h"
#include "base/bittorrent/torrenthandle.h"
#include "base/global.h"
#include "base/logger.h"
#include "base/preferences.h"
#include "base/rss/rss_folder.h"
#include "base/rss/rss_session.h"
#include "application.h"
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
#include "programupdater.h"
#endif
#include "powermanagement.h"
#include "guiiconprovider.h"
#include "torrentmodel.h"
#include "autoexpandabledialog.h"
#include "torrentcreatordlg.h"
#include "downloadfromurldlg.h"
#include "addnewtorrentdialog.h"
#include "statsdialog.h"
#include "base/settingsstorage.h"
#include "base/utils/fs.h"
#include "base/utils/misc.h"
#include "cookiesdialog.h"
#include "speedlimitdlg.h"
#include "transferlistwidget.h"
#include "search/searchwidget.h"
#include "trackerlist.h"
#include "downloadfromurldlg.h"
#include "executionlog.h"
#include "guiiconprovider.h"
#include "hidabletabwidget.h"
#include "lineedit.h"
#include "optionsdlg.h"
#include "peerlistwidget.h"
#include "transferlistfilterswidget.h"
#include "powermanagement.h"
#include "propertieswidget.h"
#include "statusbar.h"
#include "rss/rsswidget.h"
#include "about_imp.h"
#include "optionsdlg.h"
#if LIBTORRENT_VERSION_NUM < 10100
#include "trackerlogin.h"
#endif
#include "lineedit.h"
#include "executionlog.h"
#include "hidabletabwidget.h"
#include "search/searchwidget.h"
#include "speedlimitdlg.h"
#include "statsdialog.h"
#include "statusbar.h"
#include "torrentcreatordlg.h"
#include "torrentmodel.h"
#include "trackerlist.h"
#include "transferlistfilterswidget.h"
#include "transferlistwidget.h"
#include "ui_mainwindow.h"
#include "utils.h"
#ifdef Q_OS_WIN
#include "base/net/downloadhandler.h"
#include "base/net/downloadmanager.h"
#endif
#ifdef Q_OS_MAC
#include "macutilities.h"
#endif
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
#include "programupdater.h"
#endif
#if LIBTORRENT_VERSION_NUM < 10100
#include "trackerlogin.h"
#endif
#ifdef Q_OS_MAC
void qt_mac_set_dock_menu(QMenu *menu);
@ -231,7 +231,7 @@ MainWindow::MainWindow(QWidget *parent) @@ -231,7 +231,7 @@ MainWindow::MainWindow(QWidget *parent)
m_searchFilter = new LineEdit(this);
m_searchFilterAction = m_ui->toolBar->insertWidget(m_ui->actionLock, m_searchFilter);
m_searchFilter->setPlaceholderText(tr("Filter torrent list..."));
m_searchFilter->setFixedWidth(200);
m_searchFilter->setFixedWidth(Utils::Gui::scaledSize(this, 200));
QWidget *spacer = new QWidget(this);
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);

49
src/gui/optionsdlg.cpp

@ -68,6 +68,7 @@ @@ -68,6 +68,7 @@
#include "ipsubnetwhitelistoptionsdialog.h"
#include "guiiconprovider.h"
#include "scanfoldersdelegate.h"
#include "utils.h"
#include "ui_optionsdlg.h"
@ -99,13 +100,21 @@ OptionsDialog::OptionsDialog(QWidget *parent) @@ -99,13 +100,21 @@ OptionsDialog::OptionsDialog(QWidget *parent)
m_ui->tabSelection->item(TAB_WEBUI)->setHidden(true);
#endif
m_ui->tabSelection->item(TAB_ADVANCED)->setIcon(GuiIconProvider::instance()->getIcon("preferences-other"));
// set uniform size for all icons
int maxHeight = -1;
for (int i = 0; i < m_ui->tabSelection->count(); ++i)
maxHeight = std::max(maxHeight, m_ui->tabSelection->visualItemRect(m_ui->tabSelection->item(i)).size().height());
for (int i = 0; i < m_ui->tabSelection->count(); ++i) {
// uniform size for all icons
m_ui->tabSelection->item(i)->setSizeHint(QSize(std::numeric_limits<int>::max(), 62));
const QSize size(std::numeric_limits<int>::max(), static_cast<int>(maxHeight * 1.2));
m_ui->tabSelection->item(i)->setSizeHint(size);
}
m_ui->IpFilterRefreshBtn->setIcon(GuiIconProvider::instance()->getIcon("view-refresh"));
m_ui->labelGlobalRate->setPixmap(Utils::Gui::scaledPixmap(":/icons/slow_off.png", this, 16));
m_ui->labelAltRate->setPixmap(Utils::Gui::scaledPixmap(":/icons/slow.png", this, 16));
m_ui->deleteTorrentWarningIcon->setPixmap(QApplication::style()->standardIcon(QStyle::SP_MessageBoxCritical).pixmap(16, 16));
m_ui->deleteTorrentWarningIcon->hide();
m_ui->deleteTorrentWarningLabel->hide();
@ -139,7 +148,7 @@ OptionsDialog::OptionsDialog(QWidget *parent) @@ -139,7 +148,7 @@ OptionsDialog::OptionsDialog(QWidget *parent)
connect(ScanFoldersModel::instance(), &QAbstractListModel::dataChanged, this, &ThisType::enableApplyButton);
connect(m_ui->scanFoldersView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ThisType::handleScanFolderViewSelectionChanged);
connect(m_ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(applySettings(QAbstractButton*)));
connect(m_ui->buttonBox, &QDialogButtonBox::clicked, this, &OptionsDialog::applySettings);
// Languages supported
initializeLanguageCombo();
@ -445,25 +454,19 @@ void OptionsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previo @@ -445,25 +454,19 @@ void OptionsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previo
void OptionsDialog::loadWindowState()
{
const Preferences* const pref = Preferences::instance();
resize(pref->getPrefSize(this->size()));
Utils::Gui::resize(this, Preferences::instance()->getPrefSize());
}
void OptionsDialog::loadSplitterState()
{
const Preferences* const pref = Preferences::instance();
const QStringList sizesStr = Preferences::instance()->getPrefHSplitterSizes();
const QStringList sizes_str = pref->getPrefHSplitterSizes();
QList<int> sizes;
if (sizes_str.size() == 2) {
sizes << sizes_str.first().toInt();
sizes << sizes_str.last().toInt();
}
else {
sizes << 116;
sizes << m_ui->hsplitter->width() - 116;
}
// width has been modified, use height as width reference instead
const int width = Utils::Gui::scaledSize(this
, (m_ui->tabSelection->item(TAB_UI)->sizeHint().height() * 2));
QList<int> sizes {width, (m_ui->hsplitter->width() - width)};
if (sizesStr.size() == 2)
sizes = {sizesStr.first().toInt(), sizesStr.last().toInt()};
m_ui->hsplitter->setSizes(sizes);
}
@ -1578,7 +1581,7 @@ void OptionsDialog::on_IpFilterRefreshBtn_clicked() @@ -1578,7 +1581,7 @@ void OptionsDialog::on_IpFilterRefreshBtn_clicked()
session->setIPFilteringEnabled(true);
session->setIPFilterFile(""); // forcing Session reload filter file
session->setIPFilterFile(getFilter());
connect(session, SIGNAL(IPFilterParsed(bool, int)), SLOT(handleIPFilterParsed(bool, int)));
connect(session, &BitTorrent::Session::IPFilterParsed, this, &OptionsDialog::handleIPFilterParsed);
setCursor(QCursor(Qt::WaitCursor));
}
@ -1590,7 +1593,7 @@ void OptionsDialog::handleIPFilterParsed(bool error, int ruleCount) @@ -1590,7 +1593,7 @@ void OptionsDialog::handleIPFilterParsed(bool error, int ruleCount)
else
QMessageBox::information(this, tr("Successfully refreshed"), tr("Successfully parsed the provided IP filter: %1 rules were applied.", "%1 is a number").arg(ruleCount));
m_refreshingIpFilter = false;
disconnect(BitTorrent::Session::instance(), SIGNAL(IPFilterParsed(bool, int)), this, SLOT(handleIPFilterParsed(bool, int)));
disconnect(BitTorrent::Session::instance(), &BitTorrent::Session::IPFilterParsed, this, &OptionsDialog::handleIPFilterParsed);
}
QString OptionsDialog::languageToLocalizedString(const QLocale &locale)
@ -1675,11 +1678,11 @@ bool OptionsDialog::setSslKey(const QByteArray &key) @@ -1675,11 +1678,11 @@ bool OptionsDialog::setSslKey(const QByteArray &key)
// try different formats
const bool isKeyValid = (!QSslKey(key, QSsl::Rsa).isNull() || !QSslKey(key, QSsl::Ec).isNull());
if (isKeyValid) {
m_ui->lblSslKeyStatus->setPixmap(QPixmap(":/icons/qbt-theme/security-high.png").scaledToHeight(20, Qt::SmoothTransformation));
m_ui->lblSslKeyStatus->setPixmap(Utils::Gui::scaledPixmap(":/icons/qbt-theme/security-high.png", this, 24));
m_sslKey = key;
}
else {
m_ui->lblSslKeyStatus->setPixmap(QPixmap(":/icons/qbt-theme/security-low.png").scaledToHeight(20, Qt::SmoothTransformation));
m_ui->lblSslKeyStatus->setPixmap(Utils::Gui::scaledPixmap(":/icons/qbt-theme/security-low.png", this, 24));
m_sslKey.clear();
}
return isKeyValid;
@ -1694,11 +1697,11 @@ bool OptionsDialog::setSslCertificate(const QByteArray &cert) @@ -1694,11 +1697,11 @@ bool OptionsDialog::setSslCertificate(const QByteArray &cert)
#ifndef QT_NO_OPENSSL
const bool isCertValid = !QSslCertificate(cert).isNull();
if (isCertValid) {
m_ui->lblSslCertStatus->setPixmap(QPixmap(":/icons/qbt-theme/security-high.png").scaledToHeight(20, Qt::SmoothTransformation));
m_ui->lblSslCertStatus->setPixmap(Utils::Gui::scaledPixmap(":/icons/qbt-theme/security-high.png", this, 24));
m_sslCert = cert;
}
else {
m_ui->lblSslCertStatus->setPixmap(QPixmap(":/icons/qbt-theme/security-low.png").scaledToHeight(20, Qt::SmoothTransformation));
m_ui->lblSslCertStatus->setPixmap(Utils::Gui::scaledPixmap(":/icons/qbt-theme/security-low.png", this, 24));
m_sslCert.clear();
}
return isCertValid;

40
src/gui/optionsdlg.ui

@ -1823,11 +1823,7 @@ @@ -1823,11 +1823,7 @@
</widget>
</item>
<item row="0" column="0" rowspan="2">
<widget class="QLabel" name="label_5">
<property name="pixmap">
<pixmap resource="../icons.qrc">:/icons/slow_off.png</pixmap>
</property>
</widget>
<widget class="QLabel" name="labelGlobalRate"/>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="checkDownloadLimit">
@ -1970,11 +1966,7 @@ @@ -1970,11 +1966,7 @@
</widget>
</item>
<item row="0" column="0" rowspan="2">
<widget class="QLabel" name="label_16">
<property name="pixmap">
<pixmap resource="../icons.qrc">:/icons/slow.png</pixmap>
</property>
</widget>
<widget class="QLabel" name="labelAltRate"/>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="checkUploadLimitAlt">
@ -2853,20 +2845,8 @@ Use ';' to split multiple entries. Can use wildcard '*'.</string> @@ -2853,20 +2845,8 @@ Use ';' to split multiple entries. Can use wildcard '*'.</string>
<layout class="QGridLayout" name="gridLayout_11">
<item row="0" column="0">
<widget class="QLabel" name="lblSslCertStatus">
<property name="minimumSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="text">
<string/>
<string notr="true"/>
</property>
</widget>
</item>
@ -2906,20 +2886,8 @@ Use ';' to split multiple entries. Can use wildcard '*'.</string> @@ -2906,20 +2886,8 @@ Use ';' to split multiple entries. Can use wildcard '*'.</string>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lblSslKeyStatus">
<property name="minimumSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="text">
<string/>
<string notr="true"/>
</property>
</widget>
</item>

8
src/gui/previewselectdialog.cpp

@ -39,6 +39,7 @@ @@ -39,6 +39,7 @@
#include "base/utils/fs.h"
#include "base/utils/misc.h"
#include "previewlistdelegate.h"
#include "utils.h"
#define SETTINGS_KEY(name) "PreviewSelectDialog/" name
@ -146,7 +147,7 @@ void PreviewSelectDialog::previewButtonClicked() @@ -146,7 +147,7 @@ void PreviewSelectDialog::previewButtonClicked()
void PreviewSelectDialog::saveWindowState()
{
// Persist dialog size
m_storeDialogSize = this->size();
m_storeDialogSize = size();
// Persist TreeView Header state
m_storeTreeHeaderState = previewList->header()->saveState();
}
@ -154,9 +155,8 @@ void PreviewSelectDialog::saveWindowState() @@ -154,9 +155,8 @@ void PreviewSelectDialog::saveWindowState()
void PreviewSelectDialog::loadWindowState()
{
// Restore dialog size
if (m_storeDialogSize.value().isValid()) {
resize(m_storeDialogSize);
}
Utils::Gui::resize(this, m_storeDialogSize);
// Restore TreeView Header state
if (!m_storeTreeHeaderState.value().isEmpty()) {
m_headerStateInitialized = previewList->header()->restoreState(m_storeTreeHeaderState);

3
src/gui/properties/peerlistwidget.cpp

@ -180,10 +180,9 @@ void PeerListWidget::displayToggleColumnsMenu(const QPoint &) @@ -180,10 +180,9 @@ void PeerListWidget::displayToggleColumnsMenu(const QPoint &)
Q_ASSERT(visibleCols > 0);
if (!isColumnHidden(col) && (visibleCols == 1))
return;
qDebug("Toggling column %d visibility", col);
setColumnHidden(col, !isColumnHidden(col));
if (!isColumnHidden(col) && (columnWidth(col) <= 5))
setColumnWidth(col, 100);
resizeColumnToContents(col);
saveSettings();
}
}

14
src/gui/properties/propertieswidget.cpp

@ -62,6 +62,7 @@ @@ -62,6 +62,7 @@
#include "torrentcontentmodel.h"
#include "trackerlist.h"
#include "transferlistwidget.h"
#include "utils.h"
#include "ui_propertieswidget.h"
@ -87,10 +88,11 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow *mainWindow, Tran @@ -87,10 +88,11 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow *mainWindow, Tran
m_propListDelegate = new PropListDelegate(this);
m_ui->filesList->setItemDelegate(m_propListDelegate);
m_ui->filesList->setSortingEnabled(true);
// Torrent content filtering
m_contentFilterLine = new LineEdit(this);
m_contentFilterLine->setPlaceholderText(tr("Filter files..."));
m_contentFilterLine->setMaximumSize(300, m_contentFilterLine->size().height());
m_contentFilterLine->setFixedWidth(Utils::Gui::scaledSize(this, 300));
connect(m_contentFilterLine, SIGNAL(textChanged(QString)), this, SLOT(filterText(QString)));
m_ui->contentFilterLayout->insertWidget(3, m_contentFilterLine);
@ -112,7 +114,7 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow *mainWindow, Tran @@ -112,7 +114,7 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow *mainWindow, Tran
connect(m_ui->filesList->header(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(saveSettings()));
// set bar height relative to screen dpi
int barHeight = devicePixelRatio() * 18;
const int barHeight = Utils::Gui::scaledSize(this, 18);
// Downloaded pieces progress bar
m_ui->tempProgressBarArea->setVisible(false);
@ -131,9 +133,9 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow *mainWindow, Tran @@ -131,9 +133,9 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow *mainWindow, Tran
// Tracker list
m_trackerList = new TrackerList(this);
m_ui->trackerUpButton->setIcon(GuiIconProvider::instance()->getIcon("go-up"));
m_ui->trackerUpButton->setIconSize(Utils::Misc::smallIconSize());
m_ui->trackerUpButton->setIconSize(Utils::Gui::smallIconSize());
m_ui->trackerDownButton->setIcon(GuiIconProvider::instance()->getIcon("go-down"));
m_ui->trackerDownButton->setIconSize(Utils::Misc::smallIconSize());
m_ui->trackerDownButton->setIconSize(Utils::Gui::smallIconSize());
connect(m_ui->trackerUpButton, SIGNAL(clicked()), m_trackerList, SLOT(moveSelectionUp()));
connect(m_ui->trackerDownButton, SIGNAL(clicked()), m_trackerList, SLOT(moveSelectionDown()));
m_ui->horizontalLayout_trackers->insertWidget(0, m_trackerList);
@ -369,9 +371,7 @@ void PropertiesWidget::readSettings() @@ -369,9 +371,7 @@ void PropertiesWidget::readSettings()
}
const int current_tab = pref->getPropCurTab();
const bool visible = pref->getPropVisible();
// the following will call saveSettings but shouldn't change any state
if (!m_ui->filesList->header()->restoreState(pref->getPropFileListState()))
m_ui->filesList->header()->resizeSection(0, 400); // Default
m_ui->filesList->header()->restoreState(pref->getPropFileListState());
m_tabBar->setCurrentIndex(current_tab);
if (!visible)
setVisibility(false);

3
src/gui/properties/propertieswidget.ui

@ -1000,6 +1000,9 @@ @@ -1000,6 +1000,9 @@
</widget>
<widget class="QWidget" name="pageContents">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>3</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>

1
src/gui/properties/speedwidget.cpp

@ -61,6 +61,7 @@ SpeedWidget::SpeedWidget(PropertiesWidget *parent) @@ -61,6 +61,7 @@ SpeedWidget::SpeedWidget(PropertiesWidget *parent)
{
m_layout = new QVBoxLayout(this);
m_layout->setContentsMargins(0, 0, 0, 0);
m_layout->setSpacing(3);
m_hlayout = new QHBoxLayout();
m_hlayout->setContentsMargins(0, 0, 0, 0);

3
src/gui/properties/trackerlist.cpp

@ -627,9 +627,8 @@ void TrackerList::displayToggleColumnsMenu(const QPoint &) @@ -627,9 +627,8 @@ void TrackerList::displayToggleColumnsMenu(const QPoint &)
Q_ASSERT(visibleColumnsCount() > 0);
if (!isColumnHidden(col) && (visibleColumnsCount() == 1))
return;
qDebug("Toggling column %d visibility", col);
setColumnHidden(col, !isColumnHidden(col));
if (!isColumnHidden(col) && (columnWidth(col) <= 5))
setColumnWidth(col, 100);
resizeColumnToContents(col);
saveSettings();
}

5
src/gui/rss/automatedrssdownloader.cpp

@ -53,6 +53,7 @@ @@ -53,6 +53,7 @@
#include "guiiconprovider.h"
#include "autoexpandabledialog.h"
#include "ui_automatedrssdownloader.h"
#include "utils.h"
const QString EXT_JSON {QStringLiteral(".json")};
const QString EXT_LEGACY {QStringLiteral(".rssrules")};
@ -155,14 +156,14 @@ AutomatedRssDownloader::~AutomatedRssDownloader() @@ -155,14 +156,14 @@ AutomatedRssDownloader::~AutomatedRssDownloader()
void AutomatedRssDownloader::loadSettings()
{
const Preferences *const pref = Preferences::instance();
resize(pref->getRssGeometrySize(this->size()));
Utils::Gui::resize(this, pref->getRssGeometrySize());
m_ui->hsplitter->restoreState(pref->getRssHSplitterSizes());
}
void AutomatedRssDownloader::saveSettings()
{
Preferences *const pref = Preferences::instance();
pref->setRssGeometrySize(this->size());
pref->setRssGeometrySize(size());
pref->setRssHSplitterSizes(m_ui->hsplitter->saveState());
}

23
src/gui/search/pluginselectdlg.cpp

@ -31,25 +31,26 @@ @@ -31,25 +31,26 @@
#include "pluginselectdlg.h"
#include <QClipboard>
#include <QDropEvent>
#include <QFileDialog>
#include <QHeaderView>
#include <QImageReader>
#include <QMenu>
#include <QMessageBox>
#include <QFileDialog>
#include <QDropEvent>
#include <QMimeData>
#include <QClipboard>
#include <QTableView>
#include <QImageReader>
#include "autoexpandabledialog.h"
#include "base/net/downloadhandler.h"
#include "base/net/downloadmanager.h"
#include "base/utils/fs.h"
#include "base/utils/misc.h"
#include "base/net/downloadmanager.h"
#include "base/net/downloadhandler.h"
#include "searchwidget.h"
#include "pluginsourcedlg.h"
#include "guiiconprovider.h"
#include "autoexpandabledialog.h"
#include "pluginsourcedlg.h"
#include "searchwidget.h"
#include "ui_pluginselectdlg.h"
#include "utils.h"
enum PluginColumns
{
@ -78,9 +79,6 @@ PluginSelectDlg::PluginSelectDlg(SearchEngine *pluginManager, QWidget *parent) @@ -78,9 +79,6 @@ PluginSelectDlg::PluginSelectDlg(SearchEngine *pluginManager, QWidget *parent)
unused.setVerticalHeader(new QHeaderView(Qt::Horizontal));
m_ui->pluginsTree->setRootIsDecorated(false);
m_ui->pluginsTree->header()->resizeSection(0, 160);
m_ui->pluginsTree->header()->resizeSection(1, 80);
m_ui->pluginsTree->header()->resizeSection(2, 200);
m_ui->pluginsTree->hideColumn(PLUGIN_ID);
m_ui->pluginsTree->header()->setSortIndicator(0, Qt::AscendingOrder);
@ -99,6 +97,7 @@ PluginSelectDlg::PluginSelectDlg(SearchEngine *pluginManager, QWidget *parent) @@ -99,6 +97,7 @@ PluginSelectDlg::PluginSelectDlg(SearchEngine *pluginManager, QWidget *parent)
connect(m_pluginManager, &SearchEngine::checkForUpdatesFinished, this, &PluginSelectDlg::checkForUpdatesFinished);
connect(m_pluginManager, &SearchEngine::checkForUpdatesFailed, this, &PluginSelectDlg::checkForUpdatesFailed);
Utils::Gui::resize(this);
show();
}

3
src/gui/search/pluginsourcedlg.cpp

@ -31,6 +31,7 @@ @@ -31,6 +31,7 @@
#include "pluginsourcedlg.h"
#include "ui_pluginsourcedlg.h"
#include "utils.h"
PluginSourceDlg::PluginSourceDlg(QWidget *parent)
: QDialog(parent)
@ -38,6 +39,8 @@ PluginSourceDlg::PluginSourceDlg(QWidget *parent) @@ -38,6 +39,8 @@ PluginSourceDlg::PluginSourceDlg(QWidget *parent)
{
m_ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
Utils::Gui::resize(this);
show();
}

3
src/gui/search/searchtab.cpp

@ -334,10 +334,9 @@ void SearchTab::displayToggleColumnsMenu(const QPoint&) @@ -334,10 +334,9 @@ void SearchTab::displayToggleColumnsMenu(const QPoint&)
Q_ASSERT(visibleCols > 0);
if ((!m_ui->resultsBrowser->isColumnHidden(col)) && (visibleCols == 1))
return;
qDebug("Toggling column %d visibility", col);
m_ui->resultsBrowser->setColumnHidden(col, !m_ui->resultsBrowser->isColumnHidden(col));
if ((!m_ui->resultsBrowser->isColumnHidden(col)) && (m_ui->resultsBrowser->columnWidth(col) <= 5))
m_ui->resultsBrowser->setColumnWidth(col, 100);
m_ui->resultsBrowser->resizeColumnToContents(col);
saveSettings();
}
}

3
src/gui/shutdownconfirmdlg.cpp

@ -37,6 +37,7 @@ @@ -37,6 +37,7 @@
#include "base/preferences.h"
#include "base/utils/misc.h"
#include "ui_shutdownconfirmdlg.h"
#include "utils.h"
ShutdownConfirmDlg::ShutdownConfirmDlg(QWidget *parent, const ShutdownDialogAction &action)
: QDialog(parent)
@ -66,6 +67,8 @@ ShutdownConfirmDlg::ShutdownConfirmDlg(QWidget *parent, const ShutdownDialogActi @@ -66,6 +67,8 @@ ShutdownConfirmDlg::ShutdownConfirmDlg(QWidget *parent, const ShutdownDialogActi
m_timer.setInterval(1000); // 1sec
connect(&m_timer, SIGNAL(timeout()), this, SLOT(updateSeconds()));
Utils::Gui::resize(this);
}
ShutdownConfirmDlg::~ShutdownConfirmDlg()

3
src/gui/speedlimitdlg.cpp

@ -30,6 +30,7 @@ @@ -30,6 +30,7 @@
#include "base/unicodestrings.h"
#include "ui_bandwidth_limit.h"
#include "utils.h"
SpeedLimitDialog::SpeedLimitDialog(QWidget *parent)
: QDialog(parent)
@ -41,6 +42,8 @@ SpeedLimitDialog::SpeedLimitDialog(QWidget *parent) @@ -41,6 +42,8 @@ SpeedLimitDialog::SpeedLimitDialog(QWidget *parent)
// Connect to slots
connect(m_ui->bandwidthSlider, SIGNAL(valueChanged(int)), this, SLOT(updateSpinValue(int)));
connect(m_ui->spinBandwidth, SIGNAL(valueChanged(int)), this, SLOT(updateSliderValue(int)));
Utils::Gui::resize(this);
}
SpeedLimitDialog::~SpeedLimitDialog()

2
src/gui/statsdialog.cpp

@ -35,6 +35,7 @@ @@ -35,6 +35,7 @@
#include "base/utils/misc.h"
#include "base/utils/string.h"
#include "ui_statsdialog.h"
#include "utils.h"
StatsDialog::StatsDialog(QWidget *parent)
: QDialog(parent)
@ -48,6 +49,7 @@ StatsDialog::StatsDialog(QWidget *parent) @@ -48,6 +49,7 @@ StatsDialog::StatsDialog(QWidget *parent)
connect(BitTorrent::Session::instance(), &BitTorrent::Session::statsUpdated
, this, &StatsDialog::update);
Utils::Gui::resize(this);
show();
}

13
src/gui/statusbar.cpp

@ -41,6 +41,7 @@ @@ -41,6 +41,7 @@
#include "base/utils/misc.h"
#include "guiiconprovider.h"
#include "speedlimitdlg.h"
#include "utils.h"
StatusBar::StatusBar(QWidget *parent)
: QStatusBar(parent)
@ -100,15 +101,15 @@ StatusBar::StatusBar(QWidget *parent) @@ -100,15 +101,15 @@ StatusBar::StatusBar(QWidget *parent)
// Because on some platforms the default icon size is bigger
// and it will result in taller/fatter statusbar, even if the
// icons are actually 16x16
m_connecStatusLblIcon->setIconSize(QSize(16, 16));
m_dlSpeedLbl->setIconSize(QSize(16, 16));
m_upSpeedLbl->setIconSize(QSize(16, 16));
m_altSpeedsBtn->setIconSize(QSize(28, 16));
m_connecStatusLblIcon->setIconSize(Utils::Gui::smallIconSize());
m_dlSpeedLbl->setIconSize(Utils::Gui::smallIconSize());
m_upSpeedLbl->setIconSize(Utils::Gui::smallIconSize());
m_altSpeedsBtn->setIconSize(QSize(Utils::Gui::mediumIconSize().width(), Utils::Gui::smallIconSize().height()));
// Set to the known maximum width(plus some padding)
// so the speed widgets will take the rest of the space
m_connecStatusLblIcon->setMaximumWidth(16 + 6);
m_altSpeedsBtn->setMaximumWidth(28 + 6);
m_connecStatusLblIcon->setMaximumWidth(Utils::Gui::largeIconSize().width());
m_altSpeedsBtn->setMaximumWidth(Utils::Gui::largeIconSize().width());
QFrame *statusSep1 = new QFrame(this);
statusSep1->setFrameStyle(QFrame::VLine);

4
src/gui/tagfilterwidget.cpp

@ -36,11 +36,11 @@ @@ -36,11 +36,11 @@
#include <QMessageBox>
#include "base/bittorrent/session.h"
#include "base/utils/misc.h"
#include "autoexpandabledialog.h"
#include "guiiconprovider.h"
#include "tagfiltermodel.h"
#include "tagfilterproxymodel.h"
#include "utils.h"
namespace
{
@ -70,7 +70,7 @@ TagFilterWidget::TagFilterWidget(QWidget *parent) @@ -70,7 +70,7 @@ TagFilterWidget::TagFilterWidget(QWidget *parent)
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
setUniformRowHeights(true);
setHeaderHidden(true);
setIconSize(Utils::Misc::smallIconSize());
setIconSize(Utils::Gui::smallIconSize());
#if defined(Q_OS_MAC)
setAttribute(Qt::WA_MacShowFocusRect, false);
#endif

5
src/gui/torrentcreatordlg.cpp

@ -41,8 +41,8 @@ @@ -41,8 +41,8 @@
#include "base/bittorrent/torrentinfo.h"
#include "base/global.h"
#include "base/utils/fs.h"
#include "ui_torrentcreatordlg.h"
#include "utils.h"
#define SETTINGS_KEY(name) "TorrentCreator/" name
@ -264,6 +264,5 @@ void TorrentCreatorDlg::loadSettings() @@ -264,6 +264,5 @@ void TorrentCreatorDlg::loadSettings()
m_ui->txtComment->setPlainText(m_storeComments);
m_ui->lineEditSource->setText(m_storeSource);
if (m_storeDialogSize.value().isValid())
resize(m_storeDialogSize);
Utils::Gui::resize(this, m_storeDialogSize);
}

6
src/gui/trackerlogin.cpp

@ -30,9 +30,12 @@ @@ -30,9 +30,12 @@
#include "trackerlogin.h"
#include <QPushButton>
#include <libtorrent/version.hpp>
#include <QPushButton>
#include "base/bittorrent/torrenthandle.h"
#include "utils.h"
trackerLogin::trackerLogin(QWidget *parent, BitTorrent::TorrentHandle *const torrent)
: QDialog(parent)
@ -53,6 +56,7 @@ trackerLogin::trackerLogin(QWidget *parent, BitTorrent::TorrentHandle *const tor @@ -53,6 +56,7 @@ trackerLogin::trackerLogin(QWidget *parent, BitTorrent::TorrentHandle *const tor
connect(this, SIGNAL(trackerLoginCancelled(QPair<BitTorrent::TorrentHandle*, QString>)), // TODO: use Qt5 connect syntax
parent, SLOT(addUnauthenticatedTracker(QPair<BitTorrent::TorrentHandle*, QString>)));
Utils::Gui::resize(this);
show();
}

5
src/gui/transferlistfilterswidget.cpp

@ -38,6 +38,7 @@ @@ -38,6 +38,7 @@
#include <QMessageBox>
#include <QScrollArea>
#include <QVBoxLayout>
#include <QUrl>
#include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h"
@ -48,7 +49,6 @@ @@ -48,7 +49,6 @@
#include "base/preferences.h"
#include "base/torrentfilter.h"
#include "base/utils/fs.h"
#include "base/utils/misc.h"
#include "base/utils/string.h"
#include "autoexpandabledialog.h"
#include "categoryfilterwidget.h"
@ -57,6 +57,7 @@ @@ -57,6 +57,7 @@
#include "torrentmodel.h"
#include "transferlistdelegate.h"
#include "transferlistwidget.h"
#include "utils.h"
const QLatin1String GOOGLE_FAVICON_URL("https://www.google.com/s2/favicons?domain=");
@ -71,7 +72,7 @@ FiltersBase::FiltersBase(QWidget *parent, TransferListWidget *transferList) @@ -71,7 +72,7 @@ FiltersBase::FiltersBase(QWidget *parent, TransferListWidget *transferList)
setUniformItemSizes(true);
setSpacing(0);
setIconSize(Utils::Misc::smallIconSize());
setIconSize(Utils::Gui::smallIconSize());
#if defined(Q_OS_MAC)
setAttribute(Qt::WA_MacShowFocusRect, false);

8
src/gui/transferlistwidget.cpp

@ -716,10 +716,9 @@ void TransferListWidget::displayDLHoSMenu(const QPoint&) @@ -716,10 +716,9 @@ void TransferListWidget::displayDLHoSMenu(const QPoint&)
Q_ASSERT(visibleCols > 0);
if (!isColumnHidden(col) && visibleCols == 1)
return;
qDebug("Toggling column %d visibility", col);
setColumnHidden(col, !isColumnHidden(col));
if (!isColumnHidden(col) && columnWidth(col) <= 5)
setColumnWidth(col, 100);
resizeColumnToContents(col);
saveSettings();
}
}
@ -1193,10 +1192,7 @@ void TransferListWidget::saveSettings() @@ -1193,10 +1192,7 @@ void TransferListWidget::saveSettings()
bool TransferListWidget::loadSettings()
{
bool ok = header()->restoreState(Preferences::instance()->getTransHeaderState());
if (!ok)
header()->resizeSection(0, 200); // Default
return ok;
return header()->restoreState(Preferences::instance()->getTransHeaderState());
}
void TransferListWidget::wheelEvent(QWheelEvent *event)

3
src/gui/updownratiodlg.cpp

@ -33,6 +33,7 @@ @@ -33,6 +33,7 @@
#include "base/bittorrent/session.h"
#include "ui_updownratiodlg.h"
#include "utils.h"
UpDownRatioDlg::UpDownRatioDlg(bool useDefault, qreal initialRatioValue,
qreal maxRatioValue, int initialTimeValue,
@ -73,6 +74,8 @@ UpDownRatioDlg::UpDownRatioDlg(bool useDefault, qreal initialRatioValue, @@ -73,6 +74,8 @@ UpDownRatioDlg::UpDownRatioDlg(bool useDefault, qreal initialRatioValue,
connect(m_ui->checkMaxTime, SIGNAL(toggled(bool)), this, SLOT(enableTimeSpin()));
handleRatioTypeChanged();
Utils::Gui::resize(this);
}
void UpDownRatioDlg::accept()

87
src/gui/utils.cpp

@ -0,0 +1,87 @@ @@ -0,0 +1,87 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2017 Mike Tzou
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*/
#include "utils.h"
#include <QApplication>
#include <QDesktopWidget>
#include <QScreen>
#include <QStyle>
#include <QWidget>
#include <QWindow>
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)
{
#ifdef Q_OS_WIN
const int screen = qApp->desktop()->screenNumber(widget);
return (QApplication::screens()[screen]->logicalDotsPerInch() / 96);
#else
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
return widget->devicePixelRatioF();
#else
return widget->devicePixelRatio();
#endif
#endif // Q_OS_WIN
}
QPixmap Utils::Gui::scaledPixmap(const QString &path, const QWidget *widget, const int height)
{
const QPixmap pixmap(path);
const int scaledHeight = ((height > 0) ? height : pixmap.height()) * Utils::Gui::screenScalingFactor(widget);
return pixmap.scaledToHeight(scaledHeight, Qt::SmoothTransformation);
}
QSize Utils::Gui::smallIconSize(const QWidget *widget)
{
// Get DPI scaled icon size (device-dependent), see QT source
// under a 1080p screen is usually 16x16
const int s = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, widget);
return QSize(s, s);
}
QSize Utils::Gui::mediumIconSize(const QWidget *widget)
{
// under a 1080p screen is usually 24x24
return ((smallIconSize(widget) + largeIconSize(widget)) / 2);
}
QSize Utils::Gui::largeIconSize(const QWidget *widget)
{
// Get DPI scaled icon size (device-dependent), see QT source
// under a 1080p screen is usually 32x32
const int s = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize, nullptr, widget);
return QSize(s, s);
}

58
src/gui/utils.h

@ -0,0 +1,58 @@ @@ -0,0 +1,58 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2017 Mike Tzou
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*/
#ifndef UTILS_GUI_H
#define UTILS_GUI_H
#include <QtGlobal>
#include <QPixmap>
#include <QSize>
class QWidget;
namespace Utils
{
namespace 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 QString &path, const QWidget *widget, const int height = 0);
QSize smallIconSize(const QWidget *widget = nullptr);
QSize mediumIconSize(const QWidget *widget = nullptr);
QSize largeIconSize(const QWidget *widget = nullptr);
}
}
#endif // UTILS_GUI_H
Loading…
Cancel
Save