3dec5d3b71
* LYN-2537 Moved the Engine and Editor folder to be within the EngineAssets folder * Fixed Documentation in bootstrap.cfg to correct the path to the user project specific registry file * Adding a newline to the output of AssetCatalog 'Registering asset..., but type is not set' message * Updating the AssetProcessorPlatformConfig.setreg Scan Folder to detect the @ENGINEROOT@/EngineAssets/Engine path for engine runtime assets and @ENGINEROOT@/EngineAssets/Editor path for engine tool assets * Updating references to Icons and other assets to account for moving the Engine and Editor folder under a single EngineAssets folder * Moving the Engine Settings Registry folder from Engine/Registry -> Registry * Removed the LY_PROJECT_CMAKE_PATH define as it is not portable to other locations. It is hard coded to the project location that was used for the CMake configuration. Furthermore it paths with backslashes within it are treated as escape characters and not a path separator * Updated the LyTestTools asset_processor.py script to copy the exclude.filetag from the EngineAssets/Engine directory now * Fixed Atom Shader Preprocessing when running using an External Project * Updated the TSGenerateAction.cpp to fix the build error with using a renamed variable * Updated the Install_Common.cmake ly_setup_others function to install the EngineAssets directory and the each of the Gem's Assets directory while maintaining the relative directory structure to the Engine Root Also updated the install step to install the Registry folder at the engine root * Fixed the copying of the Registry folder to be in the install root, instead of under a second 'Registry' folder * Moving the AssetProcessorPlatformConfig.setreg file over to the Registry folder * Updated the LyTestTools and C++ code to point that the new location of the AssetProcessorPlatformConfig.setreg file inside of the Registry folder * Renamed Test AssetProcessor*Config.ini files to have the .setreg extension * Converted the AssetProcessor test setreg files from ini format to json format using the SerializeContextTools convert-ini command * Updated the AssetProcessor CMakeLists.txt to copy over the test setreg files to the build folder * Updated the assetprocessor test file list to point at the renamed AsssetProcessor*Config setreg filenames * Removed the Output Prefix code from the AssetProcessor. The complexity that it brought to the AP code is not needed, as users can replicate the behavior by just moving there assets underneath a another folder, underneath the scan folder * Adding back support to read the AssetProcessorPlatformConfig.setreg file from the asset root. This is only needed for C++ UnitTests as they run in an environment where the accessing the Engine Settings Registry is not available * Updating the Install_common.cmake logic to copy any "Assets" folder to the install layout. The Script has also been updated to copy over the "Assets" folder in the Engine Root to the install layout instead of an "EngineAssets" folder * Updating References to EngineAssets source asset folder in code to be the Assets source folder * Moved the Engine Source Asset folder of 'EngineAssets' to a new folder name of 'Assets'. This is inline with the naming scheme we use for Gem asset folders * Adding the EngineFinder.cmake to the AutomatedTesting project to allow it to work in a project centric manner * Updating the LyTestTools copy_assets_to_project function to be able to copy assets with folders to the temporary project root Fixed an issue in LyTestTools where the temporary log directory could have shutil.rmtree being called twice on it leading to an exception which fails an automated test Updated the asset_procesor_gui_tests_2 AddScanFolder test to not use the output prefix, but instead place the source asset root into a subdirectory * Correct the AssetProcessorPlatformConfig Scan Folders for the EngineAssets directory to point at the Assets directory * Updated the asset procesor batch dependency test scan folder to point at the 'Assets' folder instead of 'EngineAssets'
297 lines
11 KiB
C++
297 lines
11 KiB
C++
/*
|
|
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
* its licensors.
|
|
*
|
|
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
* distribution (the "License"). All use of this software is governed by the License,
|
|
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
*
|
|
*/
|
|
|
|
#include <AzCore/Debug/Trace.h>
|
|
#include <AzCore/IO/Path/Path.h>
|
|
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
|
|
#include <AzQtComponents/Components/StyleManager.h>
|
|
#include <QTextStream>
|
|
#include <QApplication>
|
|
#include <QPalette>
|
|
AZ_PUSH_DISABLE_WARNING(4251, "-Wunknown-warning-option") // 4251: 'QFileInfo::d_ptr': class 'QSharedDataPointer<QFileInfoPrivate>' needs to have dll-interface to be used by clients of class 'QFileInfo'
|
|
#include <QDir>
|
|
AZ_POP_DISABLE_WARNING
|
|
#include <QString>
|
|
#include <QFile>
|
|
#include <QFontDatabase>
|
|
#include <QStyleFactory>
|
|
#include <QPointer>
|
|
#include <QStyle>
|
|
#include <QWidget>
|
|
#include <QDebug>
|
|
|
|
#include <QtWidgets/private/qstylesheetstyle_p.h>
|
|
|
|
#include <AzQtComponents/Components/StylesheetPreprocessor.h>
|
|
#include <AzQtComponents/Utilities/QtPluginPaths.h>
|
|
#include <AzQtComponents/Components/StyleSheetCache.h>
|
|
#include <AzQtComponents/Components/Style.h>
|
|
#include <AzQtComponents/Components/TitleBarOverdrawHandler.h>
|
|
#include <AzQtComponents/Components/AutoCustomWindowDecorations.h>
|
|
|
|
namespace AzQtComponents
|
|
{
|
|
|
|
constexpr QStringView g_styleSheetRelativePath {u"Code/Framework/AzQtComponents/AzQtComponents/Components/Widgets"};
|
|
constexpr QStringView g_styleSheetResourcePath {u":AzQtComponents/Widgets"};
|
|
constexpr QStringView g_globalStyleSheetName {u"BaseStyleSheet.qss"};
|
|
constexpr QStringView g_searchPathPrefix {u"AzQtComponentWidgets"};
|
|
|
|
StyleManager* StyleManager::s_instance = nullptr;
|
|
|
|
static QStyle* createBaseStyle()
|
|
{
|
|
return QStyleFactory::create("Fusion");
|
|
|
|
}
|
|
|
|
void StyleManager::addSearchPaths(const QString& searchPrefix, const QString& pathOnDisk, const QString& qrcPrefix,
|
|
const AZ::IO::PathView& engineRootPath)
|
|
{
|
|
if (!s_instance)
|
|
{
|
|
qFatal("StyleManager::addSearchPaths called before instance was created");
|
|
return;
|
|
}
|
|
|
|
s_instance->m_stylesheetCache->addSearchPaths(searchPrefix, pathOnDisk, qrcPrefix, engineRootPath);
|
|
}
|
|
|
|
bool StyleManager::setStyleSheet(QWidget* widget, QString styleFileName)
|
|
{
|
|
if (!s_instance)
|
|
{
|
|
qFatal("StyleManager::setStyleSheet called before instance was created");
|
|
return false;
|
|
}
|
|
|
|
if (!widget)
|
|
{
|
|
qFatal("StyleManager::setStyleSheet called with null widget pointer");
|
|
return false;
|
|
}
|
|
|
|
if (!styleFileName.endsWith(StyleSheetCache::styleSheetExtension()))
|
|
{
|
|
styleFileName.append(StyleSheetCache::styleSheetExtension());
|
|
}
|
|
|
|
const auto styleSheet = s_instance->m_stylesheetCache->loadStyleSheet(styleFileName);
|
|
if (styleSheet.isEmpty())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
s_instance->m_widgetToStyleSheetMap.insert(widget, styleFileName);
|
|
|
|
connect(widget, &QObject::destroyed, s_instance, &StyleManager::stopTrackingWidget, Qt::UniqueConnection);
|
|
|
|
widget->setStyleSheet(styleSheet);
|
|
|
|
return true;
|
|
}
|
|
|
|
QStyleSheetStyle* StyleManager::styleSheetStyle(const QWidget* widget)
|
|
{
|
|
Q_UNUSED(widget);
|
|
// widget is currently unused, but would be required if Qt::AA_ManualStyleSheetStyle was
|
|
// not set.
|
|
|
|
if (!s_instance)
|
|
{
|
|
AZ_Warning("StyleManager", false, "StyleManager::styleSheetStyle called before instance was created");
|
|
return nullptr;
|
|
}
|
|
|
|
if (!QApplication::testAttribute(Qt::AA_ManualStyleSheetStyle))
|
|
{
|
|
qFatal("StyleManager::styleSheetStyle has not been implemented for automatically created QStyleSheetStyles");
|
|
return nullptr;
|
|
}
|
|
|
|
return s_instance->m_styleSheetStyle;
|
|
}
|
|
|
|
QStyle *StyleManager::baseStyle(const QWidget *widget)
|
|
{
|
|
const auto sss = styleSheetStyle(widget);
|
|
return sss ? sss->baseStyle() : nullptr;
|
|
}
|
|
|
|
void StyleManager::repolishStyleSheet(QWidget* widget)
|
|
{
|
|
StyleManager::styleSheetStyle(widget)->repolish(widget);
|
|
}
|
|
|
|
StyleManager::StyleManager(QObject* parent)
|
|
: QObject(parent)
|
|
, m_stylesheetPreprocessor(new StylesheetPreprocessor(this))
|
|
, m_stylesheetCache(new StyleSheetCache(this))
|
|
{
|
|
if (s_instance)
|
|
{
|
|
qFatal("A StyleManager already exists");
|
|
}
|
|
}
|
|
|
|
StyleManager::~StyleManager()
|
|
{
|
|
delete m_stylesheetPreprocessor;
|
|
s_instance = nullptr;
|
|
|
|
if (m_style)
|
|
{
|
|
delete m_style.data();
|
|
m_style.clear();
|
|
m_styleSheetStyle = nullptr;
|
|
}
|
|
}
|
|
|
|
void StyleManager::initialize([[maybe_unused]] QApplication* application, const AZ::IO::PathView& engineRootPath)
|
|
{
|
|
if (s_instance)
|
|
{
|
|
qFatal("StyleManager::Initialize called more than once");
|
|
return;
|
|
}
|
|
s_instance = this;
|
|
|
|
QApplication::setAttribute(Qt::AA_ManualStyleSheetStyle, true);
|
|
QApplication::setAttribute(Qt::AA_PropagateStyleToChildren, true);
|
|
|
|
connect(application, &QCoreApplication::aboutToQuit, this, &StyleManager::cleanupStyles);
|
|
|
|
initializeSearchPaths(application, engineRootPath);
|
|
initializeFonts();
|
|
|
|
m_titleBarOverdrawHandler = TitleBarOverdrawHandler::createHandler(application, this);
|
|
|
|
// The window decoration wrappers require the titlebar overdraw handler
|
|
// so we can't initialize the custom window decoration monitor until the
|
|
// titlebar overdraw handler has been initialized.
|
|
m_autoCustomWindowDecorations = new AutoCustomWindowDecorations(this);
|
|
m_autoCustomWindowDecorations->setMode(AutoCustomWindowDecorations::Mode_AnyWindow);
|
|
|
|
// Style is chained as: Style -> QStyleSheetStyle -> native, meaning any CSS limitation can be tackled in Style.cpp
|
|
m_styleSheetStyle = new QStyleSheetStyle(createBaseStyle());
|
|
m_style = new Style(m_styleSheetStyle);
|
|
|
|
QApplication::setStyle(m_style);
|
|
m_style->setParent(this);
|
|
refresh();
|
|
|
|
connect(m_stylesheetCache, &StyleSheetCache::styleSheetsChanged, this, [this]
|
|
{
|
|
refresh();
|
|
});
|
|
}
|
|
|
|
void StyleManager::cleanupStyles()
|
|
{
|
|
QApplication::setStyle(createBaseStyle());
|
|
}
|
|
|
|
void StyleManager::stopTrackingWidget(QObject* object)
|
|
{
|
|
const auto widget = qobject_cast<QWidget* const>(object);
|
|
if (!widget)
|
|
{
|
|
return;
|
|
}
|
|
|
|
m_widgetToStyleSheetMap.remove(widget);
|
|
|
|
// Remove any old stylesheet
|
|
widget->setStyleSheet(QString());
|
|
}
|
|
|
|
void StyleManager::initializeFonts()
|
|
{
|
|
// yes, the path specifier could've included OpenSans- and .ttf, but I
|
|
// wanted anyone searching for OpenSans-Bold.ttf to find something so left it this way
|
|
QString openSansPathSpecifier = QStringLiteral(":/AzQtFonts/Fonts/Open_Sans/%1");
|
|
QFontDatabase::addApplicationFont(openSansPathSpecifier.arg("OpenSans-Bold.ttf"));
|
|
QFontDatabase::addApplicationFont(openSansPathSpecifier.arg("OpenSans-BoldItalic.ttf"));
|
|
QFontDatabase::addApplicationFont(openSansPathSpecifier.arg("OpenSans-ExtraBold.ttf"));
|
|
QFontDatabase::addApplicationFont(openSansPathSpecifier.arg("OpenSans-ExtraBoldItalic.ttf"));
|
|
QFontDatabase::addApplicationFont(openSansPathSpecifier.arg("OpenSans-Italic.ttf"));
|
|
QFontDatabase::addApplicationFont(openSansPathSpecifier.arg("OpenSans-Light.ttf"));
|
|
QFontDatabase::addApplicationFont(openSansPathSpecifier.arg("OpenSans-LightItalic.ttf"));
|
|
QFontDatabase::addApplicationFont(openSansPathSpecifier.arg("OpenSans-Regular.ttf"));
|
|
QFontDatabase::addApplicationFont(openSansPathSpecifier.arg("OpenSans-Semibold.ttf"));
|
|
QFontDatabase::addApplicationFont(openSansPathSpecifier.arg("OpenSans-SemiboldItalic.ttf"));
|
|
}
|
|
|
|
void StyleManager::initializeSearchPaths([[maybe_unused]] QApplication* application, const AZ::IO::PathView& engineRootPath)
|
|
{
|
|
// now that QT is initialized, we can use its path manipulation functions to set the rest up:
|
|
|
|
QString rootDir = QString::fromUtf8(engineRootPath.Native().data(), aznumeric_cast<int>(engineRootPath.Native().size()));
|
|
|
|
if (!rootDir.isEmpty())
|
|
{
|
|
QDir appPath(rootDir);
|
|
|
|
// Set the StyleSheetCache fallback prefix
|
|
const auto pathOnDisk = appPath.absoluteFilePath(g_styleSheetRelativePath.toString());
|
|
m_stylesheetCache->setFallbackSearchPaths(g_searchPathPrefix.toString(), pathOnDisk, g_styleSheetResourcePath.toString());
|
|
|
|
// add the expected editor paths
|
|
// this allows you to refer to your assets relative, like
|
|
// STYLESHEETIMAGES:something.txt
|
|
// UI:blah/blah.png
|
|
// EDITOR:blah/something.txt
|
|
QDir::addSearchPath("STYLESHEETIMAGES", appPath.filePath("Assets/Editor/Styles/StyleSheetImages"));
|
|
QDir::addSearchPath("UI", appPath.filePath("Assets/Editor/UI"));
|
|
QDir::addSearchPath("EDITOR", appPath.filePath("Assets/Editor"));
|
|
}
|
|
}
|
|
|
|
void StyleManager::refresh()
|
|
{
|
|
const auto globalStyleSheet = m_stylesheetCache->loadStyleSheet(g_globalStyleSheetName.toString());
|
|
m_styleSheetStyle->setGlobalSheet(globalStyleSheet);
|
|
|
|
// Iterate widgets and update the stylesheet (the base style has already been set)
|
|
auto i = m_widgetToStyleSheetMap.constBegin();
|
|
while (i != m_widgetToStyleSheetMap.constEnd())
|
|
{
|
|
const auto styleSheet = m_stylesheetCache->loadStyleSheet(i.value());
|
|
i.key()->setStyleSheet(styleSheet);
|
|
++i;
|
|
}
|
|
|
|
// QMessageBox uses "QMdiSubWindowTitleBar" class to query the titlebar font
|
|
// through QApplication::font() and (buggily) calculate required width of itself
|
|
// to fit the title. It bypassess stylesheets. See QMessageBoxPrivate::updateSize().
|
|
QFont titleBarFont("Open Sans");
|
|
titleBarFont.setPixelSize(18);
|
|
QApplication::setFont(titleBarFont, "QMdiSubWindowTitleBar");
|
|
}
|
|
|
|
const QColor& StyleManager::getColorByName(const QString& name)
|
|
{
|
|
return m_stylesheetPreprocessor->GetColorByName(name);
|
|
}
|
|
} // namespace AzQtComponents
|
|
|
|
#include "Components/moc_StyleManager.cpp"
|
|
|
|
#if defined(AZ_QT_COMPONENTS_STATIC)
|
|
// If we're statically compiling the lib, we need to include the compiled rcc resources
|
|
// somewhere to ensure that the linker doesn't optimize the symbols out (with Visual Studio at least)
|
|
// With dlls, there's no step to optimize out the symbols, so we don't need to do this.
|
|
#include <Components/rcc_resources.h>
|
|
#endif // #if defined(AZ_QT_COMPONENTS_STATIC)
|
|
|
|
|