36 #include <QApplication>
37 #include <QDesktopServices>
41 #include <QPixmapCache>
44 #include <QRegularExpression>
56 if (newSize.isValid())
57 widget->resize(newSize);
72 return icon.pixmap(scaledHeight);
77 const QPixmap pixmap(path);
79 return pixmap.scaledToHeight(scaledHeight, Qt::SmoothTransformation);
85 const QString normalizedKey = path +
'@' + QString::number(scaledHeight);
89 if (!cache.find(normalizedKey, &pm))
91 pm = QIcon(path).pixmap(scaledHeight);
92 cache.insert(normalizedKey, pm);
101 const int s = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize,
nullptr, widget);
115 const int s = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize,
nullptr, widget);
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)};
129 const QWidget *parent = w->parentWidget();
131 return primaryScreenCenter;
133 const QWindow *window = parent->window()->windowHandle();
135 return primaryScreenCenter;
137 const QScreen *screen = window->screen();
139 return primaryScreenCenter;
141 r = screen->availableGeometry();
142 return {(r.x() + (r.width() - w->frameSize().width()) / 2), (r.y() + (r.height() - w->frameSize().height()) / 2)};
150 if (path.startsWith(
"//"))
153 QDesktopServices::openUrl(QUrl::fromLocalFile(path));
161 const QFileInfo pathInfo {path};
163 if (!pathInfo.exists(path))
165 openPath(path.left(path.lastIndexOf(
'/')));
170 HRESULT hresult = ::CoInitializeEx(
nullptr, COINIT_MULTITHREADED);
174 ::SHOpenFolderAndSelectItems(pidl, 0,
nullptr, 0);
177 if ((hresult == S_OK) || (hresult == S_FALSE))
179 #elif defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
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"))
188 else if ((
output ==
"nautilus.desktop") || (
output ==
"org.gnome.Nautilus.desktop")
189 || (
output ==
"nautilus-folder-handler.desktop"))
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.]"));
197 if (NautilusVersion::tryParse(nautilusVerStr, {1, 0, 0}) > NautilusVersion {3, 28})
198 proc.startDetached(
"nautilus", {Utils::Fs::toNativePath(path)});
202 else if (
output ==
"nemo.desktop")
204 if (pathInfo.isDir())
205 path = path.left(path.lastIndexOf(
'/'));
208 else if ((
output ==
"konqueror.desktop") || (
output ==
"kfmclient_dir.desktop"))
215 openPath(path.left(path.lastIndexOf(
'/')));
218 openPath(path.left(path.lastIndexOf(
'/')));
QString toUniformPath(const QString &path)
QString toNativePath(const QString &path)
QSize mediumIconSize(const QWidget *widget=nullptr)
qreal screenScalingFactor(const QWidget *widget)
QSize smallIconSize(const QWidget *widget=nullptr)
QPixmap scaledPixmap(const QIcon &icon, const QWidget *widget, int height)
void openFolderSelect(const QString &absolutePath)
void resize(QWidget *widget, const QSize &newSize={})
void openPath(const QString &absolutePath)
QPoint screenCenter(const QWidget *w)
QPixmap scaledPixmapSvg(const QString &path, const QWidget *widget, int baseHeight)
QSize largeIconSize(const QWidget *widget=nullptr)