mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-27 11:05:44 +08:00
Ref T189, CGuiUtility improvements
* only search for main window once * static const QJsonObject for drag and drop * formatting
This commit is contained in:
@@ -51,28 +51,37 @@ namespace BlackGui
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace Private
|
||||||
|
{
|
||||||
|
QWidget *mainApplicationWindowImpl()
|
||||||
|
{
|
||||||
|
CEnableForFramelessWindow *mw = CGuiUtility::mainFramelessEnabledApplicationWindow();
|
||||||
|
if (mw && mw->getWidget())
|
||||||
|
{
|
||||||
|
return mw->getWidget();
|
||||||
|
}
|
||||||
|
|
||||||
|
// second choice, try via QMainWindow
|
||||||
|
const QWidgetList tlw = CGuiUtility::topLevelApplicationWidgetsWithName();
|
||||||
|
for (QWidget *w : tlw)
|
||||||
|
{
|
||||||
|
QMainWindow *qmw = qobject_cast<QMainWindow *>(w);
|
||||||
|
if (!qmw) { continue; }
|
||||||
|
if (!qmw->parentWidget()) { return qmw; }
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
} // ns
|
||||||
|
|
||||||
QWidget *CGuiUtility::mainApplicationWindow()
|
QWidget *CGuiUtility::mainApplicationWindow()
|
||||||
{
|
{
|
||||||
CEnableForFramelessWindow *mw = mainFramelessEnabledApplicationWindow();
|
static QWidget *mw = Private::mainApplicationWindowImpl();
|
||||||
if (mw && mw->getWidget())
|
return mw;
|
||||||
{
|
|
||||||
return mw->getWidget();
|
|
||||||
}
|
|
||||||
|
|
||||||
// second choice, try via QMainWindow
|
|
||||||
const QWidgetList tlw = topLevelApplicationWidgetsWithName();
|
|
||||||
for (QWidget *w : tlw)
|
|
||||||
{
|
|
||||||
QMainWindow *qmw = qobject_cast<QMainWindow *>(w);
|
|
||||||
if (!qmw) { continue; }
|
|
||||||
if (!qmw->parentWidget()) { return qmw; }
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CGuiUtility::isMainWindowFrameless()
|
bool CGuiUtility::isMainWindowFrameless()
|
||||||
{
|
{
|
||||||
CEnableForFramelessWindow *mw = mainFramelessEnabledApplicationWindow();
|
const CEnableForFramelessWindow *mw = mainFramelessEnabledApplicationWindow();
|
||||||
return (mw && mw->isFrameless());
|
return (mw && mw->isFrameless());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +111,7 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < box->count(); i++)
|
for (int i = 0; i < box->count(); i++)
|
||||||
{
|
{
|
||||||
QString t(box->itemText(i));
|
const QString t(box->itemText(i));
|
||||||
if (t.startsWith(candidate, Qt::CaseInsensitive))
|
if (t.startsWith(candidate, Qt::CaseInsensitive))
|
||||||
{
|
{
|
||||||
box->setCurrentIndex(i);
|
box->setCurrentIndex(i);
|
||||||
@@ -115,7 +124,7 @@ namespace BlackGui
|
|||||||
if (unspecified.isEmpty()) { return false; }
|
if (unspecified.isEmpty()) { return false; }
|
||||||
for (int i = 0; i < box->count(); i++)
|
for (int i = 0; i < box->count(); i++)
|
||||||
{
|
{
|
||||||
QString t(box->itemText(i));
|
const QString t(box->itemText(i));
|
||||||
if (t.startsWith(unspecified, Qt::CaseInsensitive))
|
if (t.startsWith(unspecified, Qt::CaseInsensitive))
|
||||||
{
|
{
|
||||||
box->setCurrentIndex(i);
|
box->setCurrentIndex(i);
|
||||||
@@ -142,10 +151,10 @@ namespace BlackGui
|
|||||||
CVariant CGuiUtility::fromSwiftDragAndDropData(const QByteArray &utf8Data)
|
CVariant CGuiUtility::fromSwiftDragAndDropData(const QByteArray &utf8Data)
|
||||||
{
|
{
|
||||||
if (utf8Data.isEmpty()) { return CVariant(); }
|
if (utf8Data.isEmpty()) { return CVariant(); }
|
||||||
QJsonDocument jsonDoc(QJsonDocument::fromJson(utf8Data));
|
const QJsonDocument jsonDoc(QJsonDocument::fromJson(utf8Data));
|
||||||
QJsonObject jsonObj(jsonDoc.object());
|
const QJsonObject jsonObj(jsonDoc.object());
|
||||||
QString typeName(jsonObj.value("type").toString());
|
const QString typeName(jsonObj.value("type").toString());
|
||||||
int typeId = QMetaType::type(qPrintable(typeName));
|
const int typeId = QMetaType::type(qPrintable(typeName));
|
||||||
|
|
||||||
// check if a potential valid value object
|
// check if a potential valid value object
|
||||||
if (typeName.isEmpty() || typeId == QMetaType::UnknownType) { return CVariant(); }
|
if (typeName.isEmpty() || typeId == QMetaType::UnknownType) { return CVariant(); }
|
||||||
@@ -161,12 +170,11 @@ namespace BlackGui
|
|||||||
constexpr int Unknown = static_cast<int>(QMetaType::UnknownType);
|
constexpr int Unknown = static_cast<int>(QMetaType::UnknownType);
|
||||||
|
|
||||||
if (!hasSwiftVariantMimeType(mime)) { return Unknown; }
|
if (!hasSwiftVariantMimeType(mime)) { return Unknown; }
|
||||||
QJsonDocument jsonDoc(QJsonDocument::fromJson(mime->data(swiftJsonDragAndDropMimeType())));
|
static const QJsonObject jsonObj(QJsonDocument::fromJson(mime->data(swiftJsonDragAndDropMimeType())).object());
|
||||||
QJsonObject jsonObj(jsonDoc.object());
|
Q_ASSERT_X(!jsonObj.isEmpty(), Q_FUNC_INFO, "Empty JSON object");
|
||||||
if (jsonObj.isEmpty()) { return Unknown; }
|
const QString typeName(jsonObj.value("type").toString());
|
||||||
QString typeName(jsonObj.value("type").toString());
|
|
||||||
if (typeName.isEmpty()) { return Unknown; }
|
if (typeName.isEmpty()) { return Unknown; }
|
||||||
int typeId = QMetaType::type(qPrintable(typeName));
|
const int typeId = QMetaType::type(qPrintable(typeName));
|
||||||
return typeId;
|
return typeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +233,7 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
QWidgetList tlw = QApplication::topLevelWidgets();
|
QWidgetList tlw = QApplication::topLevelWidgets();
|
||||||
QWidgetList rl;
|
QWidgetList rl;
|
||||||
foreach (QWidget *w, tlw)
|
for (QWidget *w : tlw)
|
||||||
{
|
{
|
||||||
if (w->objectName().isEmpty()) { continue; }
|
if (w->objectName().isEmpty()) { continue; }
|
||||||
rl.append(w);
|
rl.append(w);
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ namespace BlackGui
|
|||||||
//! Delete hierarchy of layouts
|
//! Delete hierarchy of layouts
|
||||||
static void deleteLayout(QLayout *layout, bool deleteWidgets);
|
static void deleteLayout(QLayout *layout, bool deleteWidgets);
|
||||||
|
|
||||||
//! Leninet / relaxed
|
//! Lenient / relaxed
|
||||||
static bool lenientTitleComparison(const QString &title, const QString &comparison);
|
static bool lenientTitleComparison(const QString &title, const QString &comparison);
|
||||||
|
|
||||||
//! Find best match in comboBox
|
//! Find best match in comboBox
|
||||||
|
|||||||
Reference in New Issue
Block a user