-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuiengine.cpp
More file actions
94 lines (77 loc) · 2.1 KB
/
uiengine.cpp
File metadata and controls
94 lines (77 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// SPDX-License-Identifier: GPL-3.0-or-later
#include <QCoreApplication>
#include <QPushButton>
#ifdef Q_OS_LINUX
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusConnectionInterface>
#endif
#include "uiengine.h"
using namespace scratchcpp::ui;
std::shared_ptr<UiEngine> UiEngine::m_instance = std::make_shared<UiEngine>();
UiEngine::UiEngine(QObject *parent) :
QObject(parent)
{
}
UiEngine::~UiEngine()
{
if (m_dialogButtonBox)
m_dialogButtonBox->deleteLater();
}
std::shared_ptr<UiEngine> UiEngine::instance()
{
return m_instance;
}
QQmlEngine *UiEngine::qmlEngine() const
{
return m_qmlEngine;
}
void UiEngine::setQmlEngine(QQmlEngine *engine)
{
m_qmlEngine = engine;
}
QString UiEngine::standardButtonText(QDialogButtonBox::StandardButton button) const
{
if (!m_dialogButtonBox)
m_dialogButtonBox = new QDialogButtonBox; // construct on first use because widgets need QApplication
QPushButton *btn = m_dialogButtonBox->button(button);
if (!btn) {
m_dialogButtonBox->addButton(button);
btn = m_dialogButtonBox->button(button);
}
if (btn)
return btn->text();
else
return QString();
}
QQuickItem *UiEngine::activeFocusItem() const
{
return m_activeFocusItem;
}
void UiEngine::setActiveFocusItem(QQuickItem *newActiveFocusItem)
{
if (m_activeFocusItem == newActiveFocusItem)
return;
m_activeFocusItem = newActiveFocusItem;
emit activeFocusItemChanged();
}
bool UiEngine::useNativeMenuBar() const
{
#if defined(Q_OS_MACOS)
#if QT_VERSION < QT_VERSION_CHECK(6, 8, 0)
return true;
#else
// Since Qt 6.8, Qt Quick Controls menu bar is native
// However, it's currently broken, so use our native menu bar
return /*false*/ true;
#endif
#elif defined(Q_OS_LINUX)
const QDBusConnection connection = QDBusConnection::sessionBus();
static const QString registrarService = QStringLiteral("com.canonical.AppMenu.Registrar");
if (const auto iface = connection.interface())
return iface->isServiceRegistered(registrarService);
else
return false;
#else
return false;
#endif
}