79 lines
1.8 KiB
C++
Raw Normal View History

2022-09-26 17:51:28 +02:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include "Window.h"
#include "GeometricShape.h"
#include "Stroke.h"
2022-09-26 17:51:28 +02:00
#include <QskQml.h>
2022-09-26 17:51:28 +02:00
#include <QskObjectCounter.h>
#include <SkinnyShortcut.h>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
2022-09-29 16:50:46 +02:00
template< typename T >
static inline int registerType( const char* qmlName )
{
return qmlRegisterType< T >( "Shapes", 1, 0, qmlName );
}
2022-09-29 16:50:46 +02:00
template< typename T >
static inline int registerValueType( const char* qmlName )
{
#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
QByteArray name = qmlName;
name.data()[0] = std::tolower( name.data()[0] );
2022-12-03 17:24:25 +01:00
return registerType< T >( name.constData() );
#else
return qmlRegisterUncreatableType< T >( "Shapes", 1, 0, qmlName, QString() );
#endif
}
static bool doQml( int argc, char* argv[] )
{
for ( int i = 1; i < argc; i++ )
{
if ( strcmp( argv[i], "-qml" ) == 0 )
return true;
}
return false;
2022-09-26 17:51:28 +02:00
}
int main( int argc, char* argv[] )
{
#ifdef ITEM_STATISTICS
QskObjectCounter counter( true );
#endif
QGuiApplication app( argc, argv );
SkinnyShortcut::enable( SkinnyShortcut::AllShortcuts );
if ( doQml( argc, argv ) )
{
qDebug() << "Running QML";
QskQml::registerTypes();
registerType< GeometricShape >( "Shape" );
registerValueType< Stroke >( "Stroke" );
QQmlApplicationEngine engine( QUrl( "qrc:/qml/shapes.qml" ) );
return app.exec();
}
else
{
qDebug() << "Running C++";
Window window;
window.show();
2022-09-26 17:51:28 +02:00
return app.exec();
}
2022-09-26 17:51:28 +02:00
}