2017-07-21 18:21:34 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the QSkinny License, Version 1.0
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2018-10-04 10:34:44 +02:00
|
|
|
#include "QskQml.h"
|
2019-05-12 13:54:22 +02:00
|
|
|
#include "QskLayoutQml.h"
|
|
|
|
#include "QskShortcutQml.h"
|
2020-10-29 18:53:43 +01:00
|
|
|
#include "QskMainQml.h"
|
2019-05-12 13:54:22 +02:00
|
|
|
|
2022-06-29 16:17:58 +02:00
|
|
|
#include <QskAspect.h>
|
2021-09-18 15:01:04 +02:00
|
|
|
#include <QskBoxBorderMetrics.h>
|
2021-09-15 17:54:44 +02:00
|
|
|
#include <QskBoxShapeMetrics.h>
|
2019-05-12 13:54:22 +02:00
|
|
|
#include <QskDialog.h>
|
|
|
|
#include <QskDialogButton.h>
|
|
|
|
#include <QskDialogButtonBox.h>
|
|
|
|
#include <QskDialogSubWindow.h>
|
|
|
|
#include <QskDialogWindow.h>
|
|
|
|
#include <QskFocusIndicator.h>
|
|
|
|
#include <QskGradient.h>
|
|
|
|
#include <QskGraphicLabel.h>
|
2020-05-02 11:57:58 +02:00
|
|
|
#include <QskIntervalF.h>
|
2021-12-15 08:45:29 +01:00
|
|
|
#include <QskLayoutMetrics.h>
|
2020-10-28 15:52:55 +01:00
|
|
|
#include <QskMargins.h>
|
2019-05-12 13:54:22 +02:00
|
|
|
#include <QskMessageWindow.h>
|
2022-11-18 18:48:28 +01:00
|
|
|
#include <QskPlacementPolicy.h>
|
2019-05-12 13:54:22 +02:00
|
|
|
#include <QskPopup.h>
|
2020-08-01 17:54:31 +02:00
|
|
|
#include <QskProgressBar.h>
|
2019-05-12 13:54:22 +02:00
|
|
|
#include <QskPushButton.h>
|
|
|
|
#include <QskScrollArea.h>
|
|
|
|
#include <QskScrollView.h>
|
|
|
|
#include <QskSelectionWindow.h>
|
|
|
|
#include <QskSeparator.h>
|
|
|
|
#include <QskSetup.h>
|
2021-09-18 15:01:04 +02:00
|
|
|
#include <QskShadowMetrics.h>
|
2019-05-12 13:54:22 +02:00
|
|
|
#include <QskSimpleListBox.h>
|
|
|
|
#include <QskSkin.h>
|
|
|
|
#include <QskSkinManager.h>
|
|
|
|
#include <QskSlider.h>
|
2022-11-18 18:48:28 +01:00
|
|
|
#include <QskStandardSymbol.h>
|
2019-05-12 13:54:22 +02:00
|
|
|
#include <QskStatusIndicator.h>
|
|
|
|
#include <QskSubWindow.h>
|
|
|
|
#include <QskSubWindowArea.h>
|
|
|
|
#include <QskTabBar.h>
|
|
|
|
#include <QskTabButton.h>
|
|
|
|
#include <QskTabView.h>
|
|
|
|
#include <QskTextLabel.h>
|
|
|
|
#include <QskTextOptions.h>
|
|
|
|
#include <QskVirtualKeyboard.h>
|
|
|
|
#include <QskWindow.h>
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2022-11-18 18:48:28 +01:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK( 5, 14, 0 )
|
|
|
|
#include <qqmlengine.h>
|
|
|
|
#endif
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2022-11-20 15:36:30 +01:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK( 6, 2, 0 )
|
2017-07-21 18:21:34 +02:00
|
|
|
QSK_QT_PRIVATE_BEGIN
|
2018-08-03 08:15:28 +02:00
|
|
|
#include <private/qqmlmetatype_p.h>
|
2017-07-21 18:21:34 +02:00
|
|
|
QSK_QT_PRIVATE_END
|
2022-11-20 15:36:30 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <ctype.h>
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
#define QSK_MODULE_NAME "Skinny"
|
2022-11-18 18:48:28 +01:00
|
|
|
#define QSK_VERSION_MAJOR 1
|
|
|
|
#define QSK_VERSION_MINOR 0
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
// Required for QFlags to be constructed from an enum value
|
|
|
|
#define QSK_REGISTER_FLAGS( Type ) \
|
2022-11-20 15:36:30 +01:00
|
|
|
QMetaType::registerConverter< int, Type >( []( int value ) { return Type( value ); } )
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2022-11-18 18:48:28 +01:00
|
|
|
namespace
|
|
|
|
{
|
2022-11-20 15:36:30 +01:00
|
|
|
inline const char* classNameQml( const QMetaObject& metaObject )
|
2022-11-18 18:48:28 +01:00
|
|
|
{
|
2022-11-20 15:36:30 +01:00
|
|
|
// without the "Qsk" prefix
|
|
|
|
return metaObject.className() + 3;
|
2022-11-18 18:48:28 +01:00
|
|
|
}
|
|
|
|
|
2022-11-20 15:36:30 +01:00
|
|
|
/*
|
|
|
|
There are several undocumented methods for QML registrations in qqml.h
|
|
|
|
f.e qmlRegisterCustomType, where you can pass your own parser. TODO ..
|
|
|
|
*/
|
|
|
|
|
|
|
|
template< typename T >
|
|
|
|
inline int registerType( const char* qmlName )
|
2022-11-18 18:48:28 +01:00
|
|
|
{
|
2022-11-20 15:36:30 +01:00
|
|
|
return qmlRegisterType< T >(
|
|
|
|
QSK_MODULE_NAME, QSK_VERSION_MAJOR, QSK_VERSION_MINOR,
|
|
|
|
qmlName );
|
2022-11-18 18:48:28 +01:00
|
|
|
}
|
|
|
|
|
2022-11-20 15:36:30 +01:00
|
|
|
template< typename T >
|
|
|
|
inline int registerUncreatableType( const char* qmlName )
|
2022-11-18 18:48:28 +01:00
|
|
|
{
|
2022-11-20 15:36:30 +01:00
|
|
|
return qmlRegisterUncreatableType< T >(
|
|
|
|
QSK_MODULE_NAME, QSK_VERSION_MAJOR, QSK_VERSION_MINOR,
|
|
|
|
qmlName, QString() );
|
2022-11-18 18:48:28 +01:00
|
|
|
}
|
|
|
|
|
2022-11-20 15:36:30 +01:00
|
|
|
int registerUncreatableMetaObject(
|
|
|
|
const QMetaObject& staticMetaObject, const char* qmlName )
|
2022-11-18 18:48:28 +01:00
|
|
|
{
|
2022-11-20 15:36:30 +01:00
|
|
|
return qmlRegisterUncreatableMetaObject(
|
|
|
|
staticMetaObject,
|
|
|
|
QSK_MODULE_NAME, QSK_VERSION_MAJOR, QSK_VERSION_MINOR,
|
|
|
|
qmlName, QString() );
|
2022-11-18 18:48:28 +01:00
|
|
|
}
|
2022-11-20 15:36:30 +01:00
|
|
|
|
|
|
|
template< typename T >
|
|
|
|
inline void registerObject( const char* qmlName = nullptr )
|
2022-11-18 18:48:28 +01:00
|
|
|
{
|
2022-11-20 15:36:30 +01:00
|
|
|
// the class name without the "Qsk" prefix
|
|
|
|
if ( qmlName == nullptr )
|
|
|
|
qmlName = classNameQml( T::staticMetaObject );
|
|
|
|
|
|
|
|
( void ) registerType< T >( qmlName );
|
2022-11-18 18:48:28 +01:00
|
|
|
}
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2022-11-20 15:36:30 +01:00
|
|
|
template< typename T >
|
|
|
|
inline void registerGadget()
|
|
|
|
{
|
|
|
|
auto className = classNameQml( T::staticMetaObject );
|
2020-10-29 16:45:57 +01:00
|
|
|
|
2022-11-20 15:36:30 +01:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
|
|
|
|
registerUncreatableType< T >( className );
|
|
|
|
#else
|
|
|
|
// the class name without the "Qsk" prefix
|
2020-10-29 16:45:57 +01:00
|
|
|
|
2022-11-20 15:36:30 +01:00
|
|
|
/*
|
|
|
|
According to the QML naming rules uncreatables have to
|
|
|
|
start with a lowercase letter ( since Qt6 ) , while namespaces
|
|
|
|
and creatable items usually start with a upper letter.
|
|
|
|
This results in an odd naming scheme for the enums defined inside of gadgets.
|
2020-10-29 16:45:57 +01:00
|
|
|
|
2022-11-20 15:36:30 +01:00
|
|
|
To work around this we register the gadget twice - starting with
|
|
|
|
upper or lower letter.
|
2020-10-29 16:45:57 +01:00
|
|
|
|
2022-11-20 15:36:30 +01:00
|
|
|
Maybe it would make sense to only pass stripped metaObjects, where all
|
|
|
|
enums are removed from the first and everything else than the enums from
|
|
|
|
the second. TODO ...
|
|
|
|
*/
|
|
|
|
registerUncreatableMetaObject( T::staticMetaObject, className );
|
2020-10-29 16:45:57 +01:00
|
|
|
|
2022-11-20 15:36:30 +01:00
|
|
|
QByteArray name = className;
|
|
|
|
name.data()[0] = std::tolower( name.data()[0] );
|
|
|
|
registerUncreatableType< T >( name.constData() );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int registerNamespace( const QMetaObject& metaObject )
|
|
|
|
{
|
|
|
|
return registerUncreatableMetaObject( metaObject, classNameQml( metaObject ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
template< typename T >
|
|
|
|
inline int registerSingleton( QObject* singleton )
|
|
|
|
{
|
|
|
|
const auto name = classNameQml( T::staticMetaObject );
|
|
|
|
|
|
|
|
#if QT_VERSION < QT_VERSION_CHECK( 5, 14, 0 )
|
|
|
|
auto callback =
|
|
|
|
[]( QQmlEngine*, QJSEngine* )
|
|
|
|
{
|
|
|
|
QQmlEngine::setObjectOwnership( singleton, QQmlEngine::CppOwnership );
|
|
|
|
return singleton;
|
|
|
|
};
|
2020-10-29 16:45:57 +01:00
|
|
|
|
2022-11-20 15:36:30 +01:00
|
|
|
return qmlRegisterSingletonType< T >( QSK_MODULE_NAME,
|
|
|
|
QSK_VERSION_MAJOR, QSK_VERSION_MINOR, name, callback );
|
|
|
|
#else
|
|
|
|
return qmlRegisterSingletonInstance( QSK_MODULE_NAME,
|
|
|
|
QSK_VERSION_MAJOR, QSK_VERSION_MINOR, name, singleton );
|
2020-10-29 16:45:57 +01:00
|
|
|
#endif
|
2022-11-20 15:36:30 +01:00
|
|
|
}
|
|
|
|
}
|
2020-10-29 16:45:57 +01:00
|
|
|
|
2022-11-18 18:48:28 +01:00
|
|
|
static inline QskGradientStop qskJSToGradientStop( const QJSValue& value )
|
2020-10-30 07:33:29 +01:00
|
|
|
{
|
|
|
|
return QskGradientStop(
|
2022-03-25 10:32:14 +01:00
|
|
|
value.property( QStringLiteral( "position" ) ).toNumber(),
|
|
|
|
value.property( QStringLiteral( "color" ) ).toVariant().value< QColor >()
|
2020-10-30 07:33:29 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-10-04 10:34:44 +02:00
|
|
|
void QskQml::registerTypes()
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2020-10-29 19:26:16 +01:00
|
|
|
#if 0
|
|
|
|
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
|
2017-07-21 18:21:34 +02:00
|
|
|
qmlRegisterRevision< QQuickItem, 6 >( QSK_MODULE_NAME, 1, 0 );
|
2020-10-29 19:26:16 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
qmlRegisterUncreatableType< QskSetup >( QSK_MODULE_NAME, 1, 0, "Setup", QString() );
|
|
|
|
qmlRegisterUncreatableType< QskSkin >( QSK_MODULE_NAME, 1, 0, "Skin", QString() );
|
|
|
|
qRegisterMetaType< QskSkin* >();
|
|
|
|
|
2022-11-20 15:36:30 +01:00
|
|
|
registerObject< QskMain >();
|
|
|
|
registerObject< QskShortcutQml >( "Shortcut" );
|
|
|
|
|
|
|
|
registerObject< QskWindow >();
|
|
|
|
|
|
|
|
registerObject< QskDialogWindow >();
|
|
|
|
registerObject< QskMessageWindow >();
|
|
|
|
registerObject< QskSelectionWindow >();
|
|
|
|
|
|
|
|
registerObject< QskGridBoxQml >( "GridBox" );
|
|
|
|
registerObject< QskLinearBoxQml >( "LinearBox" );
|
|
|
|
|
|
|
|
registerObject< QskControl >();
|
|
|
|
registerObject< QskGraphicLabel >();
|
|
|
|
registerObject< QskVirtualKeyboard >();
|
|
|
|
registerObject< QskTextLabel >();
|
|
|
|
registerObject< QskTabButton >();
|
|
|
|
registerObject< QskTabBar >();
|
|
|
|
registerObject< QskTabView >();
|
|
|
|
registerObject< QskFocusIndicator >();
|
|
|
|
registerObject< QskSeparator >();
|
|
|
|
registerObject< QskProgressBar >();
|
|
|
|
registerObject< QskPushButton >();
|
|
|
|
registerObject< QskScrollView >();
|
|
|
|
registerObject< QskScrollArea >();
|
|
|
|
registerObject< QskSlider >();
|
|
|
|
registerObject< QskSimpleListBox >();
|
|
|
|
registerObject< QskDialogButton >();
|
|
|
|
registerObject< QskDialogButtonBox >();
|
|
|
|
registerObject< QskPopup >();
|
|
|
|
registerObject< QskStatusIndicator >();
|
|
|
|
registerObject< QskSubWindow >();
|
|
|
|
registerObject< QskSubWindowArea >();
|
|
|
|
registerObject< QskDialogSubWindow >();
|
|
|
|
|
|
|
|
registerSingleton< QskDialog >( QskDialog::instance() );
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
qmlRegisterUncreatableType< QskSkin >( "Skinny.Skins",
|
|
|
|
QSK_VERSION_MAJOR, QSK_VERSION_MINOR, "Skin", QString() );
|
|
|
|
#endif
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2021-02-09 08:13:20 +01:00
|
|
|
QSK_REGISTER_FLAGS( QskQuickItem::UpdateFlag );
|
|
|
|
QSK_REGISTER_FLAGS( QskQuickItem::UpdateFlags );
|
2017-07-21 18:21:34 +02:00
|
|
|
QSK_REGISTER_FLAGS( QskSizePolicy::Policy );
|
|
|
|
|
2018-11-05 13:29:52 +01:00
|
|
|
QSK_REGISTER_FLAGS( QskDialog::Actions );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2022-11-20 15:36:30 +01:00
|
|
|
registerGadget< QskBoxBorderMetrics >();
|
|
|
|
registerGadget< QskBoxShapeMetrics >();
|
|
|
|
registerGadget< QskShadowMetrics >();
|
|
|
|
registerGadget< QskIntervalF >();
|
|
|
|
registerGadget< QskLayoutMetrics >();
|
|
|
|
registerGadget< QskMargins >();
|
|
|
|
|
|
|
|
registerGadget< QskAspect >();
|
|
|
|
registerGadget< QskGradient >();
|
|
|
|
registerGadget< QskGradientStop >();
|
|
|
|
registerGadget< QskPlacementPolicy >();
|
|
|
|
registerGadget< QskSizePolicy >();
|
|
|
|
registerGadget< QskTextOptions >();
|
|
|
|
|
|
|
|
registerNamespace( QskStandardSymbol::staticMetaObject );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2022-11-18 18:48:28 +01:00
|
|
|
QMetaType::registerConverter< QJSValue, QskGradientStop >( qskJSToGradientStop );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2021-09-21 10:28:13 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK( 6, 2, 0 )
|
|
|
|
// how to do this with >= 6.2 TODO ...
|
2020-10-28 19:35:51 +01:00
|
|
|
QQmlMetaType::registerCustomStringConverter( qMetaTypeId< QskMargins >(),
|
|
|
|
[]( const QString& s ) { return QVariant::fromValue( QskMargins( s.toDouble() ) ); } );
|
2021-09-21 10:28:13 +02:00
|
|
|
#endif
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|