Files
86Box/src/qt/qt_util.cpp

60 lines
1.3 KiB
C++
Raw Normal View History

2022-02-07 15:00:02 +06:00
/*
2023-01-06 15:36:05 -05:00
* 86Box A hypervisor and IBM PC system emulator that specializes in
* running old operating systems and software designed for IBM
* PC systems and compatibles from 1981 through fairly recent
* system designs based on the PCI bus.
2022-02-07 15:00:02 +06:00
*
2023-01-06 15:36:05 -05:00
* This file is part of the 86Box distribution.
2022-02-07 15:00:02 +06:00
*
2023-01-06 15:36:05 -05:00
* Utility functions.
2022-02-07 15:00:02 +06:00
*
*
*
2023-01-06 15:36:05 -05:00
* Authors: Teemu Korhonen
2022-02-07 15:00:02 +06:00
*
2023-01-06 15:36:05 -05:00
* Copyright 2022 Teemu Korhonen
2022-02-07 15:00:02 +06:00
*/
#include <QStringBuilder>
#include <QStringList>
#include <QWidget>
#include <QApplication>
#if QT_VERSION <= QT_VERSION_CHECK(5, 14, 0)
2022-11-19 08:49:04 -05:00
# include <QDesktopWidget>
#endif
#include "qt_util.hpp"
2022-11-19 08:49:04 -05:00
namespace util {
QScreen *
screenOfWidget(QWidget *widget)
{
#if QT_VERSION <= QT_VERSION_CHECK(5, 14, 0)
2022-11-19 08:49:04 -05:00
return QApplication::screens()[QApplication::desktop()->screenNumber(widget) == -1 ? 0 : QApplication::desktop()->screenNumber(widget)];
#else
2022-11-19 08:49:04 -05:00
return widget->screen();
#endif
2022-11-19 08:49:04 -05:00
}
2022-11-19 08:49:04 -05:00
QString
DlgFilter(std::initializer_list<QString> extensions, bool last)
{
QStringList temp;
2022-11-19 08:49:04 -05:00
for (auto ext : extensions) {
#ifdef Q_OS_UNIX
2022-11-19 08:49:04 -05:00
if (ext == "*") {
temp.append("*");
continue;
}
2022-11-19 08:49:04 -05:00
temp.append("*." % ext.toUpper());
#endif
temp.append("*." % ext);
}
#ifdef Q_OS_UNIX
2022-11-19 08:49:04 -05:00
temp.removeDuplicates();
#endif
2022-11-19 08:49:04 -05:00
return " (" % temp.join(' ') % ")" % (!last ? ";;" : "");
}
2022-02-07 15:00:02 +06:00
}