Merge branch 'qml-sidebar'

This commit is contained in:
Adriaan de Groot 2020-03-12 15:39:25 +01:00
commit 6ff0ac72de
7 changed files with 99 additions and 28 deletions

View File

@ -45,7 +45,7 @@ windowPlacement: center
# - "widget" or unset, use traditional sidebar (logo, items) # - "widget" or unset, use traditional sidebar (logo, items)
# - "none", hide it entirely # - "none", hide it entirely
# - "qml", use sidebar.qml from branding folder # - "qml", use sidebar.qml from branding folder
sidebar: none sidebar: widget
# These are strings shown to the user in the user interface. # These are strings shown to the user in the user interface.
# There is no provision for translating them -- since they # There is no provision for translating them -- since they

View File

@ -11,22 +11,19 @@ set( calamaresSources
) )
include_directories( include_directories(
.
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/../libcalamares
${CMAKE_SOURCE_DIR}/src/libcalamares ${CMAKE_SOURCE_DIR}/src/libcalamares
${CMAKE_SOURCE_DIR}/src//libcalamaresui ${CMAKE_SOURCE_DIR}/src/libcalamaresui
${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/src/libcalamares
${CMAKE_CURRENT_SOURCE_DIR}
) )
# Translations # Translations
include( CalamaresAddTranslations ) include( CalamaresAddTranslations )
add_calamares_translations( ${CALAMARES_TRANSLATION_LANGUAGES} ) add_calamares_translations( ${CALAMARES_TRANSLATION_LANGUAGES} )
qt5_add_resources( calamaresRc calamares.qrc )
set( final_src ${calamaresSources} ${calamaresRc} ${trans_outfile} ) add_executable( calamares_bin ${calamaresSources} ${calamaresRc} ${trans_outfile} )
target_include_directories( calamares_bin PRIVATE ${CMAKE_SOURCE_DIR} )
add_executable( calamares_bin ${final_src} )
set_target_properties(calamares_bin set_target_properties(calamares_bin
PROPERTIES PROPERTIES
ENABLE_EXPORTS TRUE ENABLE_EXPORTS TRUE
@ -37,7 +34,7 @@ calamares_autouic( calamares_bin )
target_link_libraries( calamares_bin target_link_libraries( calamares_bin
PRIVATE PRIVATE
${CALAMARES_LIBRARIES} calamares
calamaresui calamaresui
Qt5::Core Qt5::Core
Qt5::Widgets Qt5::Widgets
@ -63,6 +60,6 @@ install( FILES ${CMAKE_SOURCE_DIR}/data/images/squid.svg
if( BUILD_TESTING ) if( BUILD_TESTING )
add_executable( loadmodule testmain.cpp ) add_executable( loadmodule testmain.cpp )
target_link_libraries( loadmodule ${CALAMARES_LIBRARIES} Qt5::Core Qt5::Widgets calamaresui ) target_link_libraries( loadmodule PRIVATE Qt5::Core Qt5::Widgets calamares calamaresui )
# Don't install, it's just for enable_testing # Don't install, it's just for enable_testing
endif() endif()

View File

@ -136,7 +136,8 @@ CalamaresWindow::getQmlSidebar( int desiredWidth )
{ {
CalamaresUtils::registerCalamaresModels(); CalamaresUtils::registerCalamaresModels();
QQuickWidget* w = new QQuickWidget( this ); QQuickWidget* w = new QQuickWidget( this );
w->setSource( QUrl( ":/sidebar.qml" ) ); w->setSource( QUrl(
CalamaresUtils::searchQmlFile( CalamaresUtils::QmlSearch::Both, QStringLiteral( "calamares-sidebar" ) ) ) );
return w; return w;
} }

View File

@ -0,0 +1,35 @@
import QtQuick 2.3
import io.calamares.ui 1.0
import io.calamares.core 1.0
Column {
Rectangle {
id: hello
width: 200
height: 100
color: "red"
Text {
anchors.centerIn: parent
text: Branding.string(Branding.VersionedName)
}
}
/* perhaps we could show a branding image here */
Repeater {
model: ViewManager
Rectangle {
width: 200
height: 75
color: "black"
Text {
color: completed ? "green" : "yellow"
text: display
}
}
}
}

View File

@ -0,0 +1,5 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file alias="calamares-sidebar.qml">calamares-sidebar.qml</file>
</qresource>
</RCC>

View File

@ -52,30 +52,48 @@ callQMLFunction( QQuickItem* qmlObject, const char* method )
} }
} }
/** @brief Appends to @p candidates suitable expansions of @p names
QString *
searchQmlFile( QmlSearch method, const QString& configuredName, const Calamares::ModuleSystem::InstanceKey& i ) * Depending on @p method, adds search expansions for branding, or QRC,
* or both (with branding having precedence).
*/
static void
addExpansions( QmlSearch method, QStringList& candidates, const QStringList& names )
{ {
QString bPath( QStringLiteral( "%1/%2.qml" ) ); QString bPath( QStringLiteral( "%1/%2.qml" ) );
QString qrPath( QStringLiteral( ":/%1.qml" ) ); QString qrPath( QStringLiteral( ":/%1.qml" ) );
cDebug() << "Looking for QML for" << i.toString(); if ( ( method == QmlSearch::Both ) || ( method == QmlSearch::BrandingOnly ) )
{
QString brandDir = Calamares::Branding::instance()->componentDirectory();
std::transform( names.constBegin(),
names.constEnd(),
std::back_inserter( candidates ),
[&]( const QString& s ) { return s.isEmpty() ? QString() : bPath.arg( brandDir, s ); } );
}
if ( ( method == QmlSearch::Both ) || ( method == QmlSearch::QrcOnly ) )
{
std::transform( names.constBegin(),
names.constEnd(),
std::back_inserter( candidates ),
[&]( const QString& s ) { return s.isEmpty() ? QString() : qrPath.arg( s ); } );
}
}
/** @brief Does actual search and returns result.
*
* Empty items in @p candidates are ignored.
*/
static QString
searchQmlFile( QmlSearch method, const QString& configuredName, const QStringList& hints )
{
QStringList candidates; QStringList candidates;
if ( configuredName.startsWith( '/' ) ) if ( configuredName.startsWith( '/' ) )
{ {
candidates << configuredName; candidates << configuredName;
} }
if ( ( method == QmlSearch::Both ) || ( method == QmlSearch::BrandingOnly ) ) addExpansions( method, candidates, hints );
{
QString brandDir = Calamares::Branding::instance()->componentDirectory();
candidates << ( configuredName.isEmpty() ? QString() : bPath.arg( brandDir, configuredName ) )
<< bPath.arg( brandDir, i.toString() ) << bPath.arg( brandDir, i.module() );
}
if ( ( method == QmlSearch::Both ) || ( method == QmlSearch::QrcOnly ) )
{
candidates << ( configuredName.isEmpty() ? QString() : qrPath.arg( configuredName ) )
<< qrPath.arg( i.toString() ) << qrPath.arg( i.module() );
}
for ( const QString& candidate : candidates ) for ( const QString& candidate : candidates )
{ {
if ( candidate.isEmpty() ) if ( candidate.isEmpty() )
@ -98,6 +116,20 @@ searchQmlFile( QmlSearch method, const QString& configuredName, const Calamares:
return QString(); return QString();
} }
QString
searchQmlFile( QmlSearch method, const QString& configuredName, const Calamares::ModuleSystem::InstanceKey& i )
{
cDebug() << "Looking for QML for" << i.toString();
return searchQmlFile( method, configuredName, { configuredName, i.toString(), i.module() } );
}
QString
searchQmlFile( QmlSearch method, const QString& configuredName )
{
cDebug() << "Looking for QML for" << configuredName;
return searchQmlFile( method, configuredName, { configuredName } );
}
const NamedEnumTable< QmlSearch >& const NamedEnumTable< QmlSearch >&
qmlSearchNames() qmlSearchNames()
{ {

View File

@ -70,6 +70,7 @@ UIDLLEXPORT const NamedEnumTable< QmlSearch >& qmlSearchNames();
UIDLLEXPORT QString searchQmlFile( QmlSearch method, UIDLLEXPORT QString searchQmlFile( QmlSearch method,
const QString& configuredName, const QString& configuredName,
const Calamares::ModuleSystem::InstanceKey& i ); const Calamares::ModuleSystem::InstanceKey& i );
UIDLLEXPORT QString searchQmlFile( QmlSearch method, const QString& fileNameNoSuffix );
} // namespace CalamaresUtils } // namespace CalamaresUtils