Merge branch 'master' into tell-accountmanager-url-changed

This commit is contained in:
ksuprynowicz 2022-01-23 14:08:10 +01:00
commit e2d7e55e0b
16 changed files with 292 additions and 269 deletions

View file

@ -1,75 +1,81 @@
# Build Linux
*Last Updated on December 1, 2020*
*Last Updated on January 6, 2022*
Please read the [general build guide](BUILD.md) for information on dependencies required for all platforms. Only Linux specific instructions are found in this file.
You can use the [Vircadia Builder](https://github.com/vircadia/vircadia-builder) to build on Linux more easily. Alternatively, you can follow the manual steps below.
## Ubuntu 16.04/18.04 specific build guide
### Ubuntu 16.04 only
Add the following line to *.bash_profile*
`export QT_QPA_FONTDIR=/usr/share/fonts/truetype/dejavu/`
### Ubuntu 18.04 server only
## Ubuntu 18.04
### Ubuntu 18.04 Server only
Add the universe repository:
_(This is not enabled by default on the server edition)_
_(This is not enabled by default on the server edition.)_
```bash
sudo add-apt-repository universe
sudo apt-get update
```
#### Install build tools:
### Install build tools:
- First update the repositories:
```bash
sudo apt-get update -y
sudo apt-get upgrade -y
```
- git
- Install git
```bash
sudo apt-get install git -y
```
Verify by git --version
- g++
Verify git was installed by running `git --version`.
- Install g++
```bash
sudo apt-get install g++ -y
```
Verify by g++ --version
- *Ubuntu 18.04* cmake
Verify g++ was installed by running `g++ --version`.
- **Ubuntu 18.04** CMake
```bash
sudo apt-get install cmake -y
```
Verify by cmake --version
- *Ubuntu 16.04* cmake
```bash
wget https://cmake.org/files/v3.14/cmake-3.14.2-Linux-x86_64.sh
sudo sh cmake-3.14.2-Linux-x86_64.sh --prefix=/usr/local --exclude-subdir
```
#### Install build dependencies:
Verify CMake was installed by running `cmake --version`.
### Install build dependencies:
- OpenSSL:
```bash
sudo apt-get install libssl-dev
```
Verify with `openssl version`
Verify OpenSSL was installed by running `openssl version`.
- OpenGL:
```bash
sudo apt-get install libgl1-mesa-dev -y
sudo ln -s /usr/lib/x86_64-linux-gnu/libGL.so.346.35 /usr/lib/x86_64-linux-gnu/libGL.so.1.2.0
```
- Verify OpenGL:
- First install mesa-utils with the command `sudo apt install mesa-utils -y`
- Then run `glxinfo | grep "OpenGL version"`
#### To compile interface in a server you must install:
Verify OpenGL:
- First install mesa-utils with the command `sudo apt install mesa-utils -y`.
- Then run `glxinfo | grep "OpenGL version"`.
### Extra dependencies to compile Interface on a server
- Install the following:
```bash
sudo apt-get -y install libpulse0 libnss3 libnspr4 libfontconfig1 libxcursor1 libxcomposite1 libxtst6 libxslt1.1
```
- Misc dependencies:
```bash
sudo apt-get install libasound2 libxmu-dev libxi-dev freeglut3-dev libasound2-dev libjack0 libjack-dev libxrandr-dev libudev-dev libssl-dev zlib1g-dev
```
- Install Python 3 and required packages:
```bash
sudo apt-get install python python3 python3-distro
```
- Install node, required to build the jsdoc documentation:
- Install Node.js as it is required to build the jsdoc documentation:
```bash
sudo apt-get install nodejs
```
@ -81,16 +87,17 @@ Clone this repository:
git clone https://github.com/vircadia/vircadia.git
```
To compile a DEV version checkout the branch you need. To get a list of all tags:
```bash
git fetch -a
```
Then checkout the main branch with:
Then checkout the master branch with:
```bash
git checkout master
```
If you need a different branch, you can get a list of all tags with:
```bash
git fetch --tags
git tag
```
### Using a custom Qt build
Qt binaries are only provided for Ubuntu. In order to build on other distributions, a Qt5 install
@ -104,6 +111,18 @@ The system's Qt can be used, if the development packages are installed, by setti
also the last version available in the Qt 5 branch. It is expected that Linux distributions will have
Qt 5.15.2 available for a long time.
### Architecture support
If the build is intended to be packaged for distribution, the `VIRCADIA_CPU_ARCHITECTURE`
CMake variable needs to be set to an architecture specific value.
By default, it is set to `-march=native -mtune=native`, which yields builds optimized for a particular
machine, but these builds will not work on machines lacking same CPU instructions.
For packaging, it is recommended to set it to a different value, for example `-msse3`. This will help ensure that the build will run on all reasonably modern CPUs.
Setting `VIRCADIA_CPU_ARCHITECTURE` to an empty string will use the default compiler settings and yield maximum compatibility.
### Compiling
Create the build directory:
@ -118,33 +137,34 @@ Prepare makefiles:
cmake ..
```
- If cmake fails with a vcpkg error - delete /tmp/hifi/vcpkg.
If cmake fails with a vcpkg error, then delete `~/vircadia-files/vcpkg/`.
Start compilation of the server and get a cup of coffee:
#### Server
To compile the Domain server:
```bash
make domain-server assignment-client
```
To compile interface:
*Note: For a server, it is not necessary to compile the Interface.*
#### Interface
To compile the Interface client:
```bash
make interface
```
The commands above will compile with a single thread. If you have enough memory,
you can decrease your build time using the `-j` flag. Since most x64 CPUs
support two threads per core, this works out to CPU_COUNT*2. As an example, if
you have a 2 core machine, you could use:
```
The commands above will compile with a single thread. If you have enough memory, you can decrease your build time using the `-j` flag. Since most x64 CPUs support two threads per core, this works out to CPU_COUNT*2. As an example, if you have a 2 core machine, you could use:
```bash
make -j4 interface
```
In a server, it does not make sense to compile interface.
### Running the software
#### Domain server
Running domain server:
Running Domain server:
```bash
./domain-server/domain-server
```
@ -158,24 +178,16 @@ Running assignment client:
#### Interface
Running interface:
Running Interface:
```bash
./interface/interface
```
Go to localhost in the running interface.
Go to "localhost" in the running Interface to visit your newly launched Domain server.
#### Notes
### Notes
If your goal is to set up a development environment, it is desirable to set the
directory that vcpkg builds into with the `HIFI_VCPKG_BASE` environment variable.
If your goal is to set up a development environment, it is desirable to set the directory that vcpkg builds into with the `HIFI_VCPKG_BASE` environment variable.
For example, you might set `HIFI_VCPKG_BASE` to `/home/$USER/vcpkg`.
By default, vcpkg will build in the system `/tmp` directory.
If build is intended for packaging or creation of AppImage, `VIRCADIA_CPU_ARCHITECTURE`
CMake variable needs to be set to architecture specific value.
It defaults to `-march=native -mtune=native`, which yields builds optimized for particular
machine, but builds will not work on machines lacking same CPU instructions.
For packaging and AppImage it is recommended to set it to different value, for example `-msse3`.
Setting `VIRCADIA_CPU_ARCHITECTURE` to empty string will use default compiler settings and yield
maximum compatibility.
By default, vcpkg will build in the `~/vircadia-files/vcpkg/` directory.

View file

@ -1,6 +1,6 @@
# Build MacOS
# Build macOS
*Last Updated on October 19, 2021*
*Last Updated on December 1, 2021*
Please read the [general build guide](BUILD.md) for information on dependencies required for all platforms. This will include the necessary environment variables to customize your build. Only macOS specific instructions are found in this document.
@ -21,9 +21,9 @@ brew install cmake openssl npm
Download an install Python 3.6.6 or higher from [here](https://www.python.org/downloads/).
Execute the `Update Shell Profile.command` script that is provided with the installer.
### MacOS SDK
### macOS SDK
You will need version `10.12` of the macOS SDK for building, otherwise you may have crashing or other unintended issues due to the deprecation of OpenGL on macOS. You can get that SDK from [here](https://github.com/phracker/MacOSX-SDKs). You must copy it in to your Xcode SDK directory, e.g.
You will need version `10.12` of the macOS SDK for building, otherwise you may experience crashing or other unintended issues due to the deprecation of OpenGL on macOS. You can get that SDK from [here](https://github.com/phracker/MacOSX-SDKs). You must copy it in to your Xcode SDK directory, e.g.
```bash
cp -rp ~/Downloads/MacOSX10.12.sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
@ -64,14 +64,17 @@ You can append `-j4` to assign more threads to build with. The number indicates
To package the installation, you can simply run `make package` afterwards.
## Notes
## Architecture Support
If build is intended for packaging or creation of AppImage, `VIRCADIA_CPU_ARCHITECTURE`
CMake variable needs to be set to architecture specific value.
It defaults to `-march=native -mtune=native`, which yields builds optimized for particular
machine, but builds will not work on machines lacking same CPU instructions.
For packaging and AppImage it is recommended to set it to different value, for example `-msse3`.
Setting `VIRCADIA_CPU_ARCHITECTURE` to empty string will use default compiler settings and yield
If the build is intended to be packaged for distribution, the `VIRCADIA_CPU_ARCHITECTURE`
CMake variable needs to be set to an architecture specific value.
By default, it is set to `-march=native -mtune=native`, which yields builds optimized for a particular
machine, but these builds will not work on machines lacking same CPU instructions.
For packaging, it is recommended to set it to a different value, for example `-msse3`. This will help ensure that the build will run on all reasonably modern CPUs.
Setting `VIRCADIA_CPU_ARCHITECTURE` to an empty string will use the default compiler settings and yield
maximum compatibility.
## FAQ

View file

@ -54,7 +54,6 @@ Vircadia™ is a 3D social software project seeking to incrementally bring about
- [For Windows - Interface & Server](https://github.com/vircadia/vircadia/blob/master/INSTALLER.md)
- [For Mac - Interface](https://github.com/vircadia/vircadia/blob/master/INSTALLER.md#os-x)
- [For Linux - Server .deb - Vircadia Builder](INSTALLER.md#ubuntu-1804--deb)
- [For Linux - Server .rpm - Vircadia Builder](INSTALLER.md#amazon-linux-2--rpm)
- [For Linux - Interface AppImage - Vircadia Builder](https://github.com/vircadia/vircadia-builder/blob/master/README.md#building-appimages)
### Boot to Metaverse: [The Goal](https://vircadia.com/vision/)
@ -94,10 +93,8 @@ Keep in mind that Vircadia consists of multiple smaller projects that might have
#### Supporters of the Vircadia Project
| [ksuprynowicz (74hc595)](https://github.com/ksuprynowicz) |
One (1) anonymous, three (3) total sponsors through GitHub. ❤️
| [Daichi Shimabukuro](https://github.com/mshlomd) |
| --- |
| <p align="center">[<img src="https://vircadia.com/wp-content/uploads/2021/07/74hc595_profile_2-1.png" width="80" alt="ksuprynowicz" />](https://github.com/ksuprynowicz)</p>
#### Sponsors of Open Source
<img src="https://vircadia.com/wp-content/uploads/2021/11/CBT_OS-logo_White-V.png" width="250" alt="CrossBrowserTesting" />
| <p align="center">[<img src="https://avatars.githubusercontent.com/u/4787162?v=4" width="80" alt="Daichi Shimabukuro" />](https://github.com/mshlomd)</p>

View file

@ -144,12 +144,16 @@ endif()
if 'x86_64' == cpu_architecture:
u_major = int( distro.major_version() )
u_minor = int( distro.minor_version() )
if distro.id() == 'ubuntu' or distro.id() == 'linuxmint':
if (distro.id() == 'ubuntu' and u_major == 18) or distro.id() == 'linuxmint' and u_major == 19:
self.qtUrl = self.assets_url + '/dependencies/vcpkg/qt5-install-5.15.2-ubuntu-18.04-amd64.tar.xz'
elif (distro.id() == 'ubuntu' and u_major > 18) or (distro.id() == 'linuxmint' and u_major > 19):
self.__no_qt_package_error()
else:
self.__unsupported_error()
else:
self.__no_qt_package_error()
elif 'aarch64' == cpu_architecture:
if distro.id() == 'ubuntu':

View file

@ -182,7 +182,7 @@ void runTimingTests() {
const int EXTRA_JUNK_SIZE = 200;
extraJunk.append((unsigned char)255);
for (int i = 0; i < EXTRA_JUNK_SIZE; i++) {
extraJunk.append(QString("junk"));
extraJunk.append(QString("junk").toUtf8());
}
{
@ -266,7 +266,7 @@ void runUnitTests() {
QByteArray codedValueBuffer = codedValue;
codedValueBuffer.append((unsigned char)255);
codedValueBuffer.append(QString("junk"));
codedValueBuffer.append(QString("junk").toUtf8());
qDebug() << "codedValueBuffer:";
outputBufferBits((const unsigned char*)codedValueBuffer.constData(), codedValueBuffer.size());

View file

@ -525,7 +525,7 @@ bool Wallet::readSecurityImage(const QString& inputFilePath, unsigned char** out
} else {
foundFooter = (line == IMAGE_FOOTER);
if (!foundFooter) {
base64EncryptedBuffer.append(line);
base64EncryptedBuffer.append(line.toUtf8());
}
}
}

View file

@ -844,7 +844,7 @@ glm::uvec2 OpenGLDisplayPlugin::getSurfacePixels() const {
uvec2 result;
auto window = _container->getPrimaryWidget();
if (window) {
result = toGlm(window->geometry().size() * window->devicePixelRatio());
result = toGlm(window->geometry().size() * window->devicePixelRatioF());
}
return result;
}

View file

@ -573,7 +573,7 @@ void AccountManager::requestAccessToken(const QString& login, const QString& pas
postData.append("grant_type=password&");
postData.append("username=" + QUrl::toPercentEncoding(login) + "&");
postData.append("password=" + QUrl::toPercentEncoding(password) + "&");
postData.append("scope=" + ACCOUNT_MANAGER_REQUESTED_SCOPE);
postData.append("scope=" + ACCOUNT_MANAGER_REQUESTED_SCOPE.toUtf8());
request.setUrl(grantURL);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
@ -594,9 +594,9 @@ void AccountManager::requestAccessTokenWithAuthCode(const QString& authCode, con
QByteArray postData;
postData.append("grant_type=authorization_code&");
postData.append("client_id=" + clientId + "&");
postData.append("client_secret=" + clientSecret + "&");
postData.append("code=" + authCode + "&");
postData.append("client_id=" + clientId.toUtf8() + "&");
postData.append("client_secret=" + clientSecret.toUtf8() + "&");
postData.append("code=" + authCode.toUtf8() + "&");
postData.append("redirect_uri=" + QUrl::toPercentEncoding(redirectUri));
request.setUrl(grantURL);
@ -618,7 +618,7 @@ void AccountManager::requestAccessTokenWithSteam(QByteArray authSessionTicket) {
QByteArray postData;
postData.append("grant_type=password&");
postData.append("steam_auth_ticket=" + QUrl::toPercentEncoding(authSessionTicket) + "&");
postData.append("scope=" + ACCOUNT_MANAGER_REQUESTED_SCOPE);
postData.append("scope=" + ACCOUNT_MANAGER_REQUESTED_SCOPE.toUtf8());
request.setUrl(grantURL);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
@ -639,9 +639,9 @@ void AccountManager::requestAccessTokenWithOculus(const QString& nonce, const QS
QByteArray postData;
postData.append("grant_type=password&");
postData.append("oculus_nonce=" + nonce + "&");
postData.append("oculus_id=" + oculusID + "&");
postData.append("scope=" + ACCOUNT_MANAGER_REQUESTED_SCOPE);
postData.append("oculus_nonce=" + nonce.toUtf8() + "&");
postData.append("oculus_id=" + oculusID.toUtf8() + "&");
postData.append("scope=" + ACCOUNT_MANAGER_REQUESTED_SCOPE.toUtf8());
request.setUrl(grantURL);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
@ -671,7 +671,7 @@ void AccountManager::refreshAccessToken() {
QByteArray postData;
postData.append("grant_type=refresh_token&");
postData.append("refresh_token=" + QUrl::toPercentEncoding(_accountInfo.getAccessToken().refreshToken) + "&");
postData.append("scope=" + ACCOUNT_MANAGER_REQUESTED_SCOPE);
postData.append("scope=" + ACCOUNT_MANAGER_REQUESTED_SCOPE.toUtf8());
request.setUrl(grantURL);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");

View file

@ -92,7 +92,7 @@ void DomainAccountManager::requestAccessToken(const QString& username, const QSt
formData.append("grant_type=password&");
formData.append("username=" + QUrl::toPercentEncoding(username) + "&");
formData.append("password=" + QUrl::toPercentEncoding(password) + "&");
formData.append("client_id=" + _currentAuth.clientID);
formData.append("client_id=" + _currentAuth.clientID.toUtf8());
request.setUrl(_currentAuth.authURL);

View file

@ -52,7 +52,7 @@ void UserActivityLogger::logAction(QString action, QJsonObject details, JSONCall
// Adding the action name
QHttpPart actionPart;
actionPart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"action_name\"");
actionPart.setBody(QByteArray().append(action));
actionPart.setBody(QByteArray().append(action.toUtf8()));
multipart->append(actionPart);
// Log the local-time that this event was logged

View file

@ -63,11 +63,11 @@ bool OctreeUtils::RawOctreeData::readOctreeDataInfoFromFile(QString path) {
QByteArray OctreeUtils::RawOctreeData::toByteArray() {
QByteArray jsonString;
jsonString += QString("{\n \"DataVersion\": %1,\n").arg(dataVersion);
jsonString += QString("{\n \"DataVersion\": %1,\n").arg(dataVersion).toUtf8();
writeSubclassData(jsonString);
jsonString += QString(",\n \"Id\": \"%1\",\n \"Version\": %2\n}").arg(id.toString()).arg(version);
jsonString += QString(",\n \"Id\": \"%1\",\n \"Version\": %2\n}").arg(id.toString()).arg(version).toUtf8();
return jsonString;
}

View file

@ -284,7 +284,7 @@ QQuickItem* OffscreenUi::createMessageBox(Icon icon, const QString& title, const
map.insert("buttons", buttons.operator int());
map.insert("defaultButton", defaultButton);
QVariant result;
bool invokeResult;
bool invokeResult = false;
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
TabletProxy* tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
if (tablet->getToolbarMode() && _desktop) {
@ -580,7 +580,7 @@ QQuickItem* OffscreenUi::createInputDialog(const Icon icon, const QString& title
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
TabletProxy* tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
bool invokeResult;
bool invokeResult = false;
if (tablet->getToolbarMode() && _desktop) {
invokeResult = QMetaObject::invokeMethod(_desktop, "inputDialog",
Q_RETURN_ARG(QVariant, result),
@ -608,7 +608,7 @@ QQuickItem* OffscreenUi::createCustomInputDialog(const Icon icon, const QString&
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
TabletProxy* tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
bool invokeResult;
bool invokeResult = false;
if (tablet->getToolbarMode() && _desktop) {
invokeResult = QMetaObject::invokeMethod(_desktop, "inputDialog",
Q_RETURN_ARG(QVariant, result),
@ -754,7 +754,7 @@ private slots:
QString OffscreenUi::fileDialog(const QVariantMap& properties) {
QVariant buildDialogResult;
bool invokeResult;
bool invokeResult = false;
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
TabletProxy* tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
if (tablet->getToolbarMode() && _desktop) {
@ -783,7 +783,7 @@ QString OffscreenUi::fileDialog(const QVariantMap& properties) {
ModalDialogListener* OffscreenUi::fileDialogAsync(const QVariantMap& properties) {
QVariant buildDialogResult;
bool invokeResult;
bool invokeResult = false;
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
TabletProxy* tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
if (tablet->getToolbarMode() && _desktop) {
@ -1003,7 +1003,7 @@ class AssetDialogListener : public ModalDialogListener {
QString OffscreenUi::assetDialog(const QVariantMap& properties) {
// ATP equivalent of fileDialog().
QVariant buildDialogResult;
bool invokeResult;
bool invokeResult = false;
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
TabletProxy* tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
if (tablet->getToolbarMode() && _desktop) {
@ -1033,7 +1033,7 @@ QString OffscreenUi::assetDialog(const QVariantMap& properties) {
ModalDialogListener *OffscreenUi::assetDialogAsync(const QVariantMap& properties) {
// ATP equivalent of fileDialog().
QVariant buildDialogResult;
bool invokeResult;
bool invokeResult = false;
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
TabletProxy* tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
if (tablet->getToolbarMode() && _desktop) {
@ -1175,10 +1175,6 @@ bool OffscreenUi::eventFilter(QObject* originalDestination, QEvent* event) {
return result;
}
unsigned int OffscreenUi::getMenuUserDataId() const {
return _vrMenu->_userDataId;
}
ModalDialogListener::ModalDialogListener(QQuickItem *dialog) : _dialog(dialog) {
if (!dialog) {
_finished = true;

View file

@ -237,7 +237,6 @@ public:
static ModalDialogListener* getTextAsync(const Icon icon, const QString & title, const QString & label, const QString & text = QString());
static ModalDialogListener* getItemAsync(const Icon icon, const QString & title, const QString & label, const QStringList & items, int current = 0, bool editable = true);
unsigned int getMenuUserDataId() const;
QList<QObject *> &getModalDialogListeners();
signals:

View file

@ -17,25 +17,15 @@
#include "OffscreenUi.h"
#include "ui/Logging.h"
static unsigned int USER_DATA_ID = 0;
// Binds together a Qt Action or Menu with the QML Menu or MenuItem
//
// TODO On reflection, it may be pointless to use the UUID. Perhaps
// simply creating the bidirectional link pointing to both the widget
// and qml object and inject the pointer into both objects
class MenuUserData : public QObjectUserData {
public:
MenuUserData(QAction* action, QObject* qmlObject, QObject* qmlParent) {
if (!USER_DATA_ID) {
USER_DATA_ID = DependencyManager::get<OffscreenUi>()->getMenuUserDataId();
}
MenuUserData::MenuUserData(QAction* action, QObject* qmlObject, QObject* qmlParent) {
_action = action;
_qml = qmlObject;
_qmlParent = qmlParent;
action->setUserData(USER_DATA_ID, this);
qmlObject->setUserData(USER_DATA_ID, this);
action->setProperty(USER_DATA, QVariant::fromValue(this));
qmlObject->setProperty(USER_DATA, QVariant::fromValue(this));
qmlObject->setObjectName(uuid.toString());
// Make sure we can find it again in the future
updateQmlItemFromAction();
@ -59,8 +49,7 @@ public:
virtual bool eventFilter(QObject* o, QEvent* e) override {
if (e->type() == QEvent::DynamicPropertyChange) {
QDynamicPropertyChangeEvent* dpc = static_cast<QDynamicPropertyChangeEvent*>(e);
if (dpc->propertyName() == "exclusionGroup")
{
if (dpc->propertyName() == "exclusionGroup") {
// unfortunately Qt doesn't support passing dynamic properties between C++ / QML, so we have to use this ugly helper function
QMetaObject::invokeMethod(_qmlParent,
"addExclusionGroup",
@ -80,16 +69,16 @@ public:
};
new ExclusionGroupSetter(action, qmlObject, qmlParent);
}
}
~MenuUserData() {
MenuUserData::~MenuUserData() {
QObject::disconnect(_changedConnection);
QObject::disconnect(_shutdownConnection);
_action->setUserData(USER_DATA_ID, nullptr);
_qml->setUserData(USER_DATA_ID, nullptr);
}
_action->setProperty(USER_DATA, QVariant());
_qml->setProperty(USER_DATA, QVariant());
}
void updateQmlItemFromAction() {
void MenuUserData::updateQmlItemFromAction() {
_qml->setProperty("checkable", _action->isCheckable());
_qml->setProperty("enabled", _action->isEnabled());
QString text = _action->text();
@ -97,9 +86,9 @@ public:
_qml->setProperty("shortcut", _action->shortcut().toString());
_qml->setProperty("checked", _action->isChecked());
_qml->setProperty("visible", _action->isVisible());
}
}
void clear() {
void MenuUserData::clear() {
_qml->setProperty("checkable", 0);
_qml->setProperty("enabled", 0);
_qml->setProperty("text", 0);
@ -107,27 +96,26 @@ public:
_qml->setProperty("checked", 0);
_qml->setProperty("visible", 0);
_action->setUserData(USER_DATA_ID, nullptr);
_qml->setUserData(USER_DATA_ID, nullptr);
}
_action->setProperty(USER_DATA, QVariant());
_qml->setProperty(USER_DATA, QVariant());
}
const QUuid uuid{ QUuid::createUuid() };
static bool hasData(QAction* object) {
bool MenuUserData::hasData(QAction* object) {
if (!object) {
qWarning() << "Attempted to fetch MenuUserData for null object";
return false;
}
return (nullptr != static_cast<MenuUserData*>(object->userData(USER_DATA_ID)));
}
return (nullptr != object->property(USER_DATA).value<MenuUserData*>());
}
static MenuUserData* forObject(QAction* object) {
MenuUserData* MenuUserData::forObject(QAction* object) {
if (!object) {
qWarning() << "Attempted to fetch MenuUserData for null object";
return nullptr;
}
auto result = static_cast<MenuUserData*>(object->userData(USER_DATA_ID));
auto result = object->property(USER_DATA).value<MenuUserData*>();
if (!result) {
qWarning() << "Unable to find MenuUserData for object " << object;
if (auto action = dynamic_cast<QAction*>(object)) {
@ -138,18 +126,7 @@ public:
return nullptr;
}
return result;
}
private:
Q_DISABLE_COPY(MenuUserData);
QMetaObject::Connection _shutdownConnection;
QMetaObject::Connection _changedConnection;
QAction* _action { nullptr };
QObject* _qml { nullptr };
QObject* _qmlParent{ nullptr };
};
}
VrMenu::VrMenu(OffscreenUi* parent) : QObject(parent) {
_rootMenu = parent->getRootItem()->findChild<QObject*>("rootMenu");

View file

@ -18,8 +18,44 @@
#include <QSignalMapper>
#include <QAction>
#include <QMenu>
#include <QUuid>
#include "OffscreenUi.h"
// Binds together a Qt Action or Menu with the QML Menu or MenuItem
//
// TODO On reflection, it may be pointless to use the UUID. Perhaps
// simply creating the bidirectional link pointing to both the widget
// and qml object and inject the pointer into both objects
class MenuUserData : public QObject {
Q_OBJECT
public:
MenuUserData(QAction* action, QObject* qmlObject, QObject* qmlParent);
~MenuUserData();
void updateQmlItemFromAction();
void clear();
const QUuid uuid{ QUuid::createUuid() };
static bool hasData(QAction* object);
static MenuUserData* forObject(QAction* object);
private:
Q_DISABLE_COPY(MenuUserData);
static constexpr const char *USER_DATA{"user_data"};
QMetaObject::Connection _shutdownConnection;
QMetaObject::Connection _changedConnection;
QAction* _action { nullptr };
QObject* _qml { nullptr };
QObject* _qmlParent{ nullptr };
};
// FIXME break up the rendering code (VrMenu) and the code for mirroring a Widget based menu in QML
class VrMenu : public QObject {
Q_OBJECT
@ -37,7 +73,6 @@ protected:
friend class MenuUserData;
friend class OffscreenUi;
const unsigned int _userDataId { QObject::registerUserData() };
};
#endif // hifi_VrMenu_h

View file

@ -6488,9 +6488,9 @@
}
},
"follow-redirects": {
"version": "1.12.1",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.12.1.tgz",
"integrity": "sha512-tmRv0AVuR7ZyouUHLeNSiO6pqulF7dYa3s19c6t+wz9LD69/uSzdMxJ2S91nTI9U3rt/IldxpzMOFejp6f0hjg==",
"version": "1.14.7",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.7.tgz",
"integrity": "sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ==",
"dev": true
},
"for-in": {
@ -10662,9 +10662,9 @@
"dev": true
},
"shelljs": {
"version": "0.8.4",
"resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.4.tgz",
"integrity": "sha512-7gk3UZ9kOfPLIAbslLzyWeGiEqx9e3rxwZM0KE6EL8GlGwjym9Mrlx5/p33bWTu9YG6vcS4MBxYZDHYr5lr8BQ==",
"version": "0.8.5",
"resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.5.tgz",
"integrity": "sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==",
"dev": true,
"requires": {
"glob": "^7.0.0",