qBittorrent
Utils::Gui Namespace Reference

Functions

void resize (QWidget *widget, const QSize &newSize={})
 
qreal screenScalingFactor (const QWidget *widget)
 
template<typename T >
scaledSize (const QWidget *widget, const T &size)
 
QPixmap scaledPixmap (const QIcon &icon, const QWidget *widget, int height)
 
QPixmap scaledPixmap (const QString &path, const QWidget *widget, int height=0)
 
QPixmap scaledPixmapSvg (const QString &path, const QWidget *widget, int baseHeight)
 
QSize smallIconSize (const QWidget *widget=nullptr)
 
QSize mediumIconSize (const QWidget *widget=nullptr)
 
QSize largeIconSize (const QWidget *widget=nullptr)
 
QPoint screenCenter (const QWidget *w)
 
void openPath (const QString &absolutePath)
 
void openFolderSelect (const QString &absolutePath)
 

Function Documentation

◆ largeIconSize()

QSize Utils::Gui::largeIconSize ( const QWidget *  widget = nullptr)

Definition at line 111 of file utils.cpp.

112 {
113  // Get DPI scaled icon size (device-dependent), see QT source
114  // under a 1080p screen is usually 32x32
115  const int s = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize, nullptr, widget);
116  return {s, s};
117 }

Referenced by DeletionConfirmationDialog::DeletionConfirmationDialog(), mediumIconSize(), and StatusBar::StatusBar().

Here is the caller graph for this function:

◆ mediumIconSize()

QSize Utils::Gui::mediumIconSize ( const QWidget *  widget = nullptr)

Definition at line 105 of file utils.cpp.

106 {
107  // under a 1080p screen is usually 24x24
108  return ((smallIconSize(widget) + largeIconSize(widget)) / 2);
109 }
QSize smallIconSize(const QWidget *widget=nullptr)
Definition: utils.cpp:97
QSize largeIconSize(const QWidget *widget=nullptr)
Definition: utils.cpp:111

References largeIconSize(), and smallIconSize().

Referenced by CookiesDialog::CookiesDialog(), DeletionConfirmationDialog::DeletionConfirmationDialog(), and StatusBar::StatusBar().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ openFolderSelect()

void Utils::Gui::openFolderSelect ( const QString &  absolutePath)

Definition at line 158 of file utils.cpp.

159 {
160  QString path {Utils::Fs::toUniformPath(absolutePath)};
161  const QFileInfo pathInfo {path};
162  // If the item to select doesn't exist, try to open its parent
163  if (!pathInfo.exists(path))
164  {
165  openPath(path.left(path.lastIndexOf('/')));
166  return;
167  }
168 
169 #ifdef Q_OS_WIN
170  HRESULT hresult = ::CoInitializeEx(nullptr, COINIT_MULTITHREADED);
171  PIDLIST_ABSOLUTE pidl = ::ILCreateFromPathW(reinterpret_cast<PCTSTR>(Utils::Fs::toNativePath(path).utf16()));
172  if (pidl)
173  {
174  ::SHOpenFolderAndSelectItems(pidl, 0, nullptr, 0);
175  ::ILFree(pidl);
176  }
177  if ((hresult == S_OK) || (hresult == S_FALSE))
178  ::CoUninitialize();
179 #elif defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
180  QProcess proc;
181  proc.start("xdg-mime", {"query", "default", "inode/directory"});
182  proc.waitForFinished();
183  const QString output = proc.readLine().simplified();
184  if ((output == "dolphin.desktop") || (output == "org.kde.dolphin.desktop"))
185  {
186  proc.startDetached("dolphin", {"--select", Utils::Fs::toNativePath(path)});
187  }
188  else if ((output == "nautilus.desktop") || (output == "org.gnome.Nautilus.desktop")
189  || (output == "nautilus-folder-handler.desktop"))
190  {
191  if (pathInfo.isDir())
192  path = path.left(path.lastIndexOf('/'));
193  proc.start("nautilus", {"--version"});
194  proc.waitForFinished();
195  const QString nautilusVerStr = QString(proc.readLine()).remove(QRegularExpression("[^0-9.]"));
196  using NautilusVersion = Utils::Version<int, 3>;
197  if (NautilusVersion::tryParse(nautilusVerStr, {1, 0, 0}) > NautilusVersion {3, 28})
198  proc.startDetached("nautilus", {Utils::Fs::toNativePath(path)});
199  else
200  proc.startDetached("nautilus", {"--no-desktop", Utils::Fs::toNativePath(path)});
201  }
202  else if (output == "nemo.desktop")
203  {
204  if (pathInfo.isDir())
205  path = path.left(path.lastIndexOf('/'));
206  proc.startDetached("nemo", {"--no-desktop", Utils::Fs::toNativePath(path)});
207  }
208  else if ((output == "konqueror.desktop") || (output == "kfmclient_dir.desktop"))
209  {
210  proc.startDetached("konqueror", {"--select", Utils::Fs::toNativePath(path)});
211  }
212  else
213  {
214  // "caja" manager can't pinpoint the file, see: https://github.com/qbittorrent/qBittorrent/issues/5003
215  openPath(path.left(path.lastIndexOf('/')));
216  }
217 #else
218  openPath(path.left(path.lastIndexOf('/')));
219 #endif
220 }
QString toUniformPath(const QString &path)
Definition: fs.cpp:69
QString toNativePath(const QString &path)
Definition: fs.cpp:64
void openPath(const QString &absolutePath)
Definition: utils.cpp:146

References openPath(), update_qrc_files::output, Utils::Fs::toNativePath(), and Utils::Fs::toUniformPath().

Referenced by anonymous_namespace{transferlistwidget.cpp}::openDestinationFolder(), PropertiesWidget::openParentFolder(), and TransferListWidget::openSelectedTorrentsFolder().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ openPath()

void Utils::Gui::openPath ( const QString &  absolutePath)

Definition at line 146 of file utils.cpp.

147 {
148  const QString path = Utils::Fs::toUniformPath(absolutePath);
149  // Hack to access samba shares with QDesktopServices::openUrl
150  if (path.startsWith("//"))
151  QDesktopServices::openUrl(Utils::Fs::toNativePath("file:" + path));
152  else
153  QDesktopServices::openUrl(QUrl::fromLocalFile(path));
154 }

References Utils::Fs::toNativePath(), and Utils::Fs::toUniformPath().

Referenced by anonymous_namespace{transferlistwidget.cpp}::openDestinationFolder(), openFolderSelect(), PropertiesWidget::openItem(), TransferListWidget::openSelectedTorrentsFolder(), and TransferListWidget::previewFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resize()

◆ scaledPixmap() [1/2]

QPixmap Utils::Gui::scaledPixmap ( const QIcon &  icon,
const QWidget *  widget,
int  height 
)

Definition at line 68 of file utils.cpp.

69 {
70  Q_ASSERT(height > 0);
71  const int scaledHeight = height * Utils::Gui::screenScalingFactor(widget);
72  return icon.pixmap(scaledHeight);
73 }

References screenScalingFactor().

Referenced by AboutDialog::AboutDialog(), OptionsDialog::OptionsDialog(), and SpeedLimitDialog::SpeedLimitDialog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scaledPixmap() [2/2]

QPixmap Utils::Gui::scaledPixmap ( const QString &  path,
const QWidget *  widget,
int  height = 0 
)

Definition at line 75 of file utils.cpp.

76 {
77  const QPixmap pixmap(path);
78  const int scaledHeight = ((height > 0) ? height : pixmap.height()) * Utils::Gui::screenScalingFactor(widget);
79  return pixmap.scaledToHeight(scaledHeight, Qt::SmoothTransformation);
80 }

References screenScalingFactor().

Here is the call graph for this function:

◆ scaledPixmapSvg()

QPixmap Utils::Gui::scaledPixmapSvg ( const QString &  path,
const QWidget *  widget,
int  baseHeight 
)

Definition at line 82 of file utils.cpp.

83 {
84  const int scaledHeight = baseHeight * Utils::Gui::screenScalingFactor(widget);
85  const QString normalizedKey = path + '@' + QString::number(scaledHeight);
86 
87  QPixmap pm;
88  QPixmapCache cache;
89  if (!cache.find(normalizedKey, &pm))
90  {
91  pm = QIcon(path).pixmap(scaledHeight);
92  cache.insert(normalizedKey, pm);
93  }
94  return pm;
95 }

References screenScalingFactor().

Referenced by AboutDialog::AboutDialog(), OptionsDialog::webUIHttpsCertChanged(), and OptionsDialog::webUIHttpsKeyChanged().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scaledSize()

template<typename T >
T Utils::Gui::scaledSize ( const QWidget *  widget,
const T &  size 
)

Definition at line 46 of file utils.h.

47  {
48  return (size * screenScalingFactor(widget));
49  }

References screenScalingFactor().

Referenced by OptionsDialog::loadSplitterState(), MainWindow::MainWindow(), and PropertiesWidget::PropertiesWidget().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ screenCenter()

QPoint Utils::Gui::screenCenter ( const QWidget *  w)

Definition at line 119 of file utils.cpp.

120 {
121  // Returns the QPoint which the widget will be placed center on screen (where parent resides)
122 
123  if (!w)
124  return {};
125 
126  QRect r = QGuiApplication::primaryScreen()->availableGeometry();
127  const QPoint primaryScreenCenter {(r.x() + (r.width() - w->frameSize().width()) / 2), (r.y() + (r.height() - w->frameSize().height()) / 2)};
128 
129  const QWidget *parent = w->parentWidget();
130  if (!parent)
131  return primaryScreenCenter;
132 
133  const QWindow *window = parent->window()->windowHandle();
134  if (!window)
135  return primaryScreenCenter;
136 
137  const QScreen *screen = window->screen();
138  if (!screen)
139  return primaryScreenCenter;
140 
141  r = screen->availableGeometry();
142  return {(r.x() + (r.width() - w->frameSize().width()) / 2), (r.y() + (r.height() - w->frameSize().height()) / 2)};
143 }

Referenced by displayBadArgMessage(), displayUsage(), Application::exec(), MainWindow::showEvent(), ShutdownConfirmDialog::ShutdownConfirmDialog(), and userAgreesWithLegalNotice().

Here is the caller graph for this function:

◆ screenScalingFactor()

qreal Utils::Gui::screenScalingFactor ( const QWidget *  widget)

Definition at line 62 of file utils.cpp.

63 {
64  Q_UNUSED(widget);
65  return 1;
66 }

Referenced by resize(), scaledPixmap(), scaledPixmapSvg(), and scaledSize().

Here is the caller graph for this function:

◆ smallIconSize()

QSize Utils::Gui::smallIconSize ( const QWidget *  widget = nullptr)

Definition at line 97 of file utils.cpp.

98 {
99  // Get DPI scaled icon size (device-dependent), see QT source
100  // under a 1080p screen is usually 16x16
101  const int s = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, widget);
102  return {s, s};
103 }

Referenced by BaseFilterWidget::BaseFilterWidget(), CategoryFilterWidget::CategoryFilterWidget(), mediumIconSize(), PropertiesWidget::PropertiesWidget(), StatusBar::StatusBar(), and TagFilterWidget::TagFilterWidget().

Here is the caller graph for this function: