2017-07-21 18:21:34 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
2023-04-06 09:23:37 +02:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2017-07-21 18:21:34 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2018-10-04 10:34:44 +02:00
|
|
|
#include "QskQml.h"
|
2022-11-30 17:05:37 +01:00
|
|
|
#include "QskQml.hpp"
|
|
|
|
|
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>
|
2023-03-10 15:45:53 +01:00
|
|
|
#include <QskComboBox.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>
|
2022-11-29 10:59:09 +01:00
|
|
|
#include <QskGradientDirection.h>
|
2019-05-12 13:54:22 +02:00
|
|
|
#include <QskGraphicLabel.h>
|
2023-03-10 15:45:53 +01:00
|
|
|
#include <QskIcon.h>
|
2020-05-02 11:57:58 +02:00
|
|
|
#include <QskIntervalF.h>
|
2021-12-15 08:45:29 +01:00
|
|
|
#include <QskLayoutMetrics.h>
|
2023-03-10 15:45:53 +01:00
|
|
|
#include <QskLabelData.h>
|
|
|
|
#include <QskMainView.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>
|
2023-03-10 15:45:53 +01:00
|
|
|
#include <QskRadioBox.h>
|
2019-05-12 13:54:22 +02:00
|
|
|
#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>
|
2023-03-10 15:45:53 +01:00
|
|
|
#include <QskSpinBox.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-20 15:36:30 +01:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK( 6, 2, 0 )
|
2022-11-30 17:05:37 +01:00
|
|
|
QSK_QT_PRIVATE_BEGIN
|
|
|
|
#include <private/qqmlmetatype_p.h>
|
|
|
|
QSK_QT_PRIVATE_END
|
2022-11-20 15:36:30 +01:00
|
|
|
#endif
|
|
|
|
|
2022-11-30 17:05:37 +01:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK( 6, 5, 0 )
|
2022-11-29 17:24:40 +01:00
|
|
|
|
2022-11-30 17:05:37 +01:00
|
|
|
#include <qjsvalue.h>
|
|
|
|
#include <qjsvalueiterator.h>
|
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
|
|
|
/*
|
2022-11-30 17:05:37 +01:00
|
|
|
Since Qt 6.5 we have QML_STRUCTURED_VALUE and do not need to
|
|
|
|
write our own converter.
|
2022-11-29 17:24:40 +01:00
|
|
|
|
2022-11-30 17:05:37 +01:00
|
|
|
However: we should also be able to implement a generic converter from the
|
|
|
|
metatype information: TODO ...
|
2022-11-20 15:36:30 +01:00
|
|
|
|
2022-11-30 17:05:37 +01:00
|
|
|
For the moment we have these converters:
|
|
|
|
*/
|
|
|
|
QskGradientStop toGradientStop( const QJSValue& value )
|
2022-11-18 18:48:28 +01:00
|
|
|
{
|
2022-11-30 17:05:37 +01:00
|
|
|
return QskGradientStop(
|
|
|
|
value.property( QStringLiteral( "position" ) ).toNumber(),
|
|
|
|
value.property( QStringLiteral( "color" ) ).toVariant().value< QColor >()
|
|
|
|
);
|
2022-11-18 18:48:28 +01:00
|
|
|
}
|
|
|
|
|
2022-11-30 17:05:37 +01:00
|
|
|
QskLinearDirection toLinearDirection( const QJSValue& value )
|
2022-11-18 18:48:28 +01:00
|
|
|
{
|
2022-11-30 17:05:37 +01:00
|
|
|
return QskLinearDirection(
|
|
|
|
value.property( QStringLiteral( "x1" ) ).toNumber(),
|
|
|
|
value.property( QStringLiteral( "y1" ) ).toNumber(),
|
|
|
|
value.property( QStringLiteral( "x2" ) ).toNumber(),
|
|
|
|
value.property( QStringLiteral( "y2" ) ).toNumber() );
|
2022-11-18 18:48:28 +01:00
|
|
|
}
|
|
|
|
|
2022-11-30 17:05:37 +01:00
|
|
|
QskConicDirection toConicDirection( const QJSValue& value )
|
2022-11-18 18:48:28 +01:00
|
|
|
{
|
2022-11-30 17:05:37 +01:00
|
|
|
return QskConicDirection(
|
|
|
|
value.property( QStringLiteral( "x" ) ).toNumber(),
|
|
|
|
value.property( QStringLiteral( "y" ) ).toNumber(),
|
|
|
|
value.property( QStringLiteral( "startAngle" ) ).toNumber(),
|
|
|
|
value.property( QStringLiteral( "spanAngle" ) ).toNumber() );
|
2022-11-18 18:48:28 +01:00
|
|
|
}
|
2022-11-20 15:36:30 +01:00
|
|
|
|
2022-11-30 17:05:37 +01:00
|
|
|
QskRadialDirection toRadialDirection( const QJSValue& value )
|
2022-11-18 18:48:28 +01:00
|
|
|
{
|
2022-11-30 17:05:37 +01:00
|
|
|
return QskRadialDirection(
|
|
|
|
value.property( QStringLiteral( "x" ) ).toNumber(),
|
|
|
|
value.property( QStringLiteral( "y" ) ).toNumber(),
|
2022-12-23 14:57:46 +01:00
|
|
|
value.property( QStringLiteral( "radiusX" ) ).toNumber(),
|
|
|
|
value.property( QStringLiteral( "radiusY" ) ).toNumber() );
|
2022-11-18 18:48:28 +01:00
|
|
|
}
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2022-11-30 17:05:37 +01:00
|
|
|
QskGradient toGradient( const QJSValue& value )
|
2022-11-20 15:36:30 +01:00
|
|
|
{
|
2022-11-30 17:05:37 +01:00
|
|
|
QskGradient gradient;
|
|
|
|
|
|
|
|
QJSValueIterator it( value );
|
|
|
|
|
|
|
|
while ( it.hasNext() )
|
2022-11-21 17:31:56 +01:00
|
|
|
{
|
2022-11-30 17:05:37 +01:00
|
|
|
it.next();
|
|
|
|
|
|
|
|
auto v = it.value();
|
|
|
|
|
|
|
|
if ( v.isObject() )
|
|
|
|
{
|
|
|
|
if ( v.isArray() )
|
|
|
|
{
|
|
|
|
if ( it.name() == QStringLiteral( "stops" ) )
|
|
|
|
{
|
|
|
|
QskGradientStops stops;
|
|
|
|
|
|
|
|
const int n = v.property( QStringLiteral( "length" ) ).toInt();
|
|
|
|
for ( int i = 0; i < n; i++ )
|
|
|
|
stops += toGradientStop( v.property( i ) );
|
|
|
|
|
|
|
|
gradient.setStops( stops );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( it.name() == QStringLiteral( "linear" ) )
|
|
|
|
{
|
|
|
|
gradient.setLinearDirection( toLinearDirection( v ) );
|
|
|
|
}
|
|
|
|
else if ( it.name() == QStringLiteral( "conic" ) )
|
|
|
|
{
|
|
|
|
gradient.setConicDirection( toConicDirection( v ) );
|
|
|
|
}
|
|
|
|
else if ( it.name() == QStringLiteral( "radial" ) )
|
|
|
|
{
|
|
|
|
gradient.setRadialDirection( toRadialDirection( v ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-01 12:03:36 +01:00
|
|
|
else if ( v.isNumber() )
|
|
|
|
{
|
2022-12-22 11:45:23 +01:00
|
|
|
if ( it.name() == QStringLiteral( "spreadMode" ) )
|
2022-12-01 12:03:36 +01:00
|
|
|
{
|
|
|
|
const auto s = v.toNumber();
|
|
|
|
if ( s >= QskGradient::PadSpread && s <= QskGradient::RepeatSpread )
|
2022-12-22 11:45:23 +01:00
|
|
|
{
|
|
|
|
gradient.setSpreadMode(
|
|
|
|
static_cast< QskGradient::SpreadMode >( s ) );
|
|
|
|
}
|
2022-12-01 12:03:36 +01:00
|
|
|
}
|
|
|
|
}
|
2022-11-21 17:31:56 +01:00
|
|
|
}
|
2020-10-29 16:45:57 +01:00
|
|
|
|
2022-11-30 17:05:37 +01:00
|
|
|
return gradient;
|
2022-11-20 15:36:30 +01:00
|
|
|
}
|
|
|
|
|
2022-11-30 17:05:37 +01:00
|
|
|
void registerJSConverters()
|
2022-11-20 15:36:30 +01:00
|
|
|
{
|
2022-11-30 17:05:37 +01:00
|
|
|
QMetaType::registerConverter< QJSValue, QskGradient >( toGradient );
|
|
|
|
QMetaType::registerConverter< QJSValue, QskLinearDirection >( toLinearDirection );
|
|
|
|
QMetaType::registerConverter< QJSValue, QskConicDirection >( toConicDirection );
|
|
|
|
QMetaType::registerConverter< QJSValue, QskRadialDirection >( toRadialDirection );
|
|
|
|
QMetaType::registerConverter< QJSValue, QskGradientStop >( toGradientStop );
|
2022-11-20 15:36:30 +01:00
|
|
|
}
|
|
|
|
}
|
2020-10-29 16:45:57 +01:00
|
|
|
|
2022-11-30 17:05:37 +01:00
|
|
|
#endif
|
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
|
|
|
{
|
|
|
|
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 >();
|
2023-03-10 15:45:53 +01:00
|
|
|
|
|
|
|
registerObject< QskMainView >();
|
|
|
|
registerObject< QskComboBox >();
|
2022-11-20 15:36:30 +01:00
|
|
|
registerObject< QskGraphicLabel >();
|
|
|
|
registerObject< QskVirtualKeyboard >();
|
2023-03-10 15:45:53 +01:00
|
|
|
registerObject< QskRadioBox >();
|
|
|
|
registerObject< QskSpinBox >();
|
2022-11-20 15:36:30 +01:00
|
|
|
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 >();
|
|
|
|
|
2023-03-10 15:45:53 +01:00
|
|
|
registerGadget< QskIcon >();
|
|
|
|
registerGadget< QskLabelData >();
|
2022-11-20 15:36:30 +01:00
|
|
|
registerGadget< QskGradient >();
|
|
|
|
registerGadget< QskGradientStop >();
|
2022-11-29 10:59:09 +01:00
|
|
|
registerGadget< QskLinearDirection >();
|
|
|
|
registerGadget< QskConicDirection >();
|
|
|
|
registerGadget< QskRadialDirection >();
|
|
|
|
|
|
|
|
registerGadget< QskAspect >();
|
2022-11-20 15:36:30 +01:00
|
|
|
registerGadget< QskPlacementPolicy >();
|
|
|
|
registerGadget< QskSizePolicy >();
|
|
|
|
registerGadget< QskTextOptions >();
|
|
|
|
|
|
|
|
registerNamespace( QskStandardSymbol::staticMetaObject );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2022-11-30 17:05:37 +01:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK( 6, 5, 0 )
|
|
|
|
registerJSConverters();
|
|
|
|
#endif
|
|
|
|
|
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 )
|
2022-11-30 17:05:37 +01:00
|
|
|
/*
|
|
|
|
Since Qt 6.5 invokable constructors are accessible from QML, something
|
|
|
|
what was possibe until Qt 6.2 with string converters. For Qt [6.2,6.4]
|
|
|
|
we do not have any solution.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
}
|