2023-07-17 10:50:36 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "SkinFactory.h"
|
|
|
|
|
|
|
|
#include <SkinnyShortcut.h>
|
|
|
|
|
|
|
|
#include <QskObjectCounter.h>
|
|
|
|
#include <QskSkinManager.h>
|
|
|
|
#include <QskWindow.h>
|
|
|
|
|
|
|
|
#include <QskIntervalF.h>
|
2023-07-25 13:08:00 +00:00
|
|
|
#include <QskLevelingSensor.h>
|
2023-07-17 10:50:36 +00:00
|
|
|
#include <QskLinearBox.h>
|
2023-07-25 13:08:00 +00:00
|
|
|
#include <QskScaleTickmarks.h>
|
2023-07-17 10:50:36 +00:00
|
|
|
#include <QskSlider.h>
|
|
|
|
#include <QskTextLabel.h>
|
|
|
|
|
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QQuickWindow>
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
void updateTickmarks( const Qt::Axis axis, const QskIntervalF& intervalA,
|
|
|
|
const QskIntervalF& intervalB, QskLevelingSensor* const sensor )
|
|
|
|
{
|
|
|
|
QskScaleTickmarks tickmarks;
|
|
|
|
QVector< qreal > major;
|
|
|
|
QVector< qreal > medium;
|
|
|
|
QVector< qreal > minor;
|
|
|
|
|
|
|
|
for ( const auto& interval : { intervalA, intervalB } )
|
|
|
|
{
|
|
|
|
for ( int deg = ( int ) interval.lowerBound(); deg < ( int ) interval.upperBound();
|
|
|
|
++deg )
|
|
|
|
{
|
|
|
|
if ( deg % 45 == 0 )
|
|
|
|
{
|
|
|
|
major << deg;
|
|
|
|
}
|
|
|
|
if ( deg % 45 != 0 && deg % 5 == 0 )
|
|
|
|
{
|
|
|
|
medium << deg;
|
|
|
|
}
|
|
|
|
if ( deg % 45 != 0 && deg % 5 != 0 )
|
|
|
|
{
|
|
|
|
minor << deg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tickmarks.setMajorTicks( major );
|
|
|
|
tickmarks.setMediumTicks( medium );
|
|
|
|
tickmarks.setMinorTicks( minor );
|
|
|
|
sensor->setTickmarks( axis, tickmarks );
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateTickmarksLabels( const Qt::Axis axis, const QskIntervalF& intervalA,
|
|
|
|
const QskIntervalF& intervalB, int step, QskLevelingSensor* const sensor )
|
|
|
|
{
|
|
|
|
QskLevelingSensor::TickmarksLabels labels;
|
|
|
|
for ( const auto& interval : { intervalA, intervalB } )
|
|
|
|
{
|
|
|
|
for ( int deg = ( ( int ) interval.lowerBound() / step ) * step;
|
|
|
|
deg < ( int ) interval.upperBound(); deg += step )
|
|
|
|
{
|
|
|
|
labels << QskLevelingSensor::TickmarksLabels::value_type{ ( float ) deg,
|
|
|
|
QString( deg > 0 ? "+" : "" ) + QString::number( deg ) };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sensor->setTickmarksLabels( axis, labels );
|
|
|
|
}
|
|
|
|
|
2023-07-26 15:39:13 +00:00
|
|
|
Q_REQUIRED_RESULT QskSlider* makeAngleSlider( const Qt::Axis axis,
|
|
|
|
QskLevelingSensor* const sensor, double min = 0, double max = 90, QQuickItem* const parent = nullptr)
|
|
|
|
{
|
|
|
|
auto* const slider = new QskSlider( Qt::Horizontal, parent );
|
|
|
|
slider->setMinimum( min );
|
|
|
|
slider->setMaximum( max );
|
2023-08-02 07:16:33 +00:00
|
|
|
slider->setValue( sensor->angles()[ axis ] );
|
2023-07-26 15:39:13 +00:00
|
|
|
|
|
|
|
QObject::connect(slider, &QskSlider::valueChanged, sensor, [axis, sensor](const qreal v){
|
2023-08-02 07:16:33 +00:00
|
|
|
auto angles = sensor->angles();
|
2023-07-26 15:39:13 +00:00
|
|
|
angles[axis] = v;
|
|
|
|
sensor->setAngle(angles);
|
|
|
|
});
|
|
|
|
|
|
|
|
return slider;
|
|
|
|
}
|
|
|
|
|
2023-07-24 07:39:32 +00:00
|
|
|
Q_REQUIRED_RESULT QskSlider* makeTickmarksSlider( const Qt::Axis axis,
|
|
|
|
QskLevelingSensor* const sensor, int min, int max,
|
|
|
|
std::function< QskIntervalF( qreal ) > intervalA,
|
|
|
|
std::function< QskIntervalF( qreal ) > intervalB, QQuickItem* const parent = nullptr )
|
2023-07-17 10:50:36 +00:00
|
|
|
{
|
|
|
|
auto* const slider = new QskSlider( Qt::Horizontal, parent );
|
|
|
|
slider->setMinimum( min );
|
|
|
|
slider->setMaximum( max );
|
|
|
|
|
2023-07-24 07:39:32 +00:00
|
|
|
QObject::connect( slider, &QskSlider::valueChanged, sensor, [ = ]( const qreal degree ) {
|
|
|
|
updateTickmarks( axis, intervalA( degree ), intervalB( degree ), sensor );
|
2023-07-17 10:50:36 +00:00
|
|
|
updateTickmarksLabels( axis, intervalA( degree ), intervalB( degree ), 10, sensor );
|
|
|
|
} );
|
|
|
|
|
|
|
|
return slider;
|
|
|
|
}
|
|
|
|
|
2023-07-24 07:39:32 +00:00
|
|
|
Q_REQUIRED_RESULT QskSlider* makeRotationSlider( const Qt::Axis axis,
|
|
|
|
QskLevelingSensor* const sensor, const QskAspect::Subcontrol subControl,
|
|
|
|
QQuickItem* const parent = nullptr )
|
2023-07-17 10:50:36 +00:00
|
|
|
{
|
|
|
|
auto* const slider = new QskSlider( Qt::Horizontal, parent );
|
|
|
|
slider->setMinimum( -360 );
|
|
|
|
slider->setMaximum( +360 );
|
|
|
|
|
2023-07-20 10:01:16 +00:00
|
|
|
QObject::connect( sensor, &QskLevelingSensor::subControlRotationChanged, slider,
|
2023-07-24 07:39:32 +00:00
|
|
|
[ = ]( const QskAspect::Subcontrol control, const QVector3D& degree ) {
|
|
|
|
if ( control == subControl )
|
2023-07-20 10:01:16 +00:00
|
|
|
{
|
|
|
|
slider->setValue( degree[ axis ] );
|
|
|
|
}
|
|
|
|
} );
|
2023-07-17 10:50:36 +00:00
|
|
|
|
2023-07-24 07:39:32 +00:00
|
|
|
QObject::connect( slider, &QskSlider::valueChanged, sensor, [ = ]( const qreal degree ) {
|
|
|
|
auto d = sensor->subControlRotation( subControl );
|
|
|
|
d[ axis ] = degree;
|
|
|
|
sensor->setSubControlRotation( subControl, d );
|
|
|
|
} );
|
2023-07-17 10:50:36 +00:00
|
|
|
|
|
|
|
return slider;
|
|
|
|
}
|
|
|
|
|
|
|
|
class Window : public QskWindow
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Window()
|
|
|
|
{
|
|
|
|
auto* const root = new QskLinearBox( Qt::Horizontal, contentItem() );
|
2023-07-24 07:39:32 +00:00
|
|
|
root->setSpacing( 8 );
|
|
|
|
root->setMargins( 8 );
|
2023-07-17 10:50:36 +00:00
|
|
|
auto* const left = new QskLinearBox( Qt::Vertical, root );
|
|
|
|
auto* const right = new QskLinearBox( Qt::Vertical, root );
|
|
|
|
auto* const sensor = new QskLevelingSensor( left );
|
|
|
|
|
2023-07-24 07:39:32 +00:00
|
|
|
auto linearIntervalA = []( const qreal degree ) -> QskIntervalF {
|
|
|
|
return { -degree, +degree };
|
|
|
|
};
|
2023-08-02 15:07:44 +00:00
|
|
|
auto linearIntervalB = []( const qreal /*degree*/ ) -> QskIntervalF { return {}; };
|
2023-07-24 07:39:32 +00:00
|
|
|
|
|
|
|
auto radialIntervalA = []( const qreal degree ) -> QskIntervalF {
|
|
|
|
return { -degree, +degree };
|
|
|
|
};
|
|
|
|
auto radialIntervalB = []( const qreal degree ) -> QskIntervalF {
|
|
|
|
return { 180 - degree, 180 + degree };
|
|
|
|
};
|
2023-07-17 10:50:36 +00:00
|
|
|
|
2023-07-26 15:39:13 +00:00
|
|
|
( void ) new QskTextLabel( "Angles XYZ", right );
|
|
|
|
(void) makeAngleSlider(Qt::XAxis, sensor, 0, 45, right);
|
|
|
|
(void) makeAngleSlider(Qt::YAxis, sensor, 0, 45, right);
|
|
|
|
(void) makeAngleSlider(Qt::ZAxis, sensor, 0, 45, right);
|
|
|
|
|
|
|
|
( void ) new QskTextLabel( "Tickmarks XXZ", right );
|
2023-07-24 07:39:32 +00:00
|
|
|
auto* const sliderTickmarksX = makeTickmarksSlider(
|
|
|
|
Qt::XAxis, sensor, 0, 90, linearIntervalA, linearIntervalB, right );
|
|
|
|
auto* const sliderTickmarksY = makeTickmarksSlider(
|
|
|
|
Qt::YAxis, sensor, 0, 90, linearIntervalA, linearIntervalB, right );
|
|
|
|
auto* const sliderTickmarksZ = makeTickmarksSlider(
|
|
|
|
Qt::ZAxis, sensor, 0, 90, radialIntervalA, radialIntervalB, right );
|
2023-07-17 10:50:36 +00:00
|
|
|
|
2023-07-20 10:01:16 +00:00
|
|
|
( void ) new QskTextLabel( "Rotation X Plane", right );
|
|
|
|
( void ) makeRotationSlider( Qt::XAxis, sensor, QskLevelingSensor::TickmarksX, right );
|
|
|
|
( void ) makeRotationSlider( Qt::YAxis, sensor, QskLevelingSensor::TickmarksX, right );
|
|
|
|
( void ) makeRotationSlider( Qt::ZAxis, sensor, QskLevelingSensor::TickmarksX, right );
|
|
|
|
( void ) new QskTextLabel( "Rotation Y Plane", right );
|
|
|
|
( void ) makeRotationSlider( Qt::XAxis, sensor, QskLevelingSensor::TickmarksY, right );
|
|
|
|
( void ) makeRotationSlider( Qt::YAxis, sensor, QskLevelingSensor::TickmarksY, right );
|
|
|
|
( void ) makeRotationSlider( Qt::ZAxis, sensor, QskLevelingSensor::TickmarksY, right );
|
|
|
|
( void ) new QskTextLabel( "Rotation Z Plane", right );
|
|
|
|
( void ) makeRotationSlider( Qt::XAxis, sensor, QskLevelingSensor::TickmarksZ, right );
|
|
|
|
( void ) makeRotationSlider( Qt::YAxis, sensor, QskLevelingSensor::TickmarksZ, right );
|
|
|
|
( void ) makeRotationSlider( Qt::ZAxis, sensor, QskLevelingSensor::TickmarksZ, right );
|
2023-07-26 15:39:13 +00:00
|
|
|
( void ) new QskTextLabel( "Horizon", right );
|
|
|
|
( void ) makeRotationSlider( Qt::XAxis, sensor, QskLevelingSensor::Horizon, right );
|
|
|
|
( void ) makeRotationSlider( Qt::YAxis, sensor, QskLevelingSensor::Horizon, right );
|
|
|
|
( void ) makeRotationSlider( Qt::ZAxis, sensor, QskLevelingSensor::Horizon, right );
|
2023-07-17 10:50:36 +00:00
|
|
|
|
2023-07-24 07:39:32 +00:00
|
|
|
sliderTickmarksX->setValue( 15 );
|
|
|
|
sliderTickmarksY->setValue( 15 );
|
|
|
|
sliderTickmarksZ->setValue( 30 );
|
2023-07-17 10:50:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
int main( int argc, char** argv )
|
|
|
|
{
|
|
|
|
#ifdef ITEM_STATISTICS
|
|
|
|
QskObjectCounter counter( true );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
qskSkinManager->setPluginPaths( QStringList() ); // no skin plugins
|
|
|
|
qskSkinManager->registerFactory( QStringLiteral( "sample" ), new SkinFactory() );
|
|
|
|
|
|
|
|
QGuiApplication app( argc, argv );
|
|
|
|
|
|
|
|
SkinnyShortcut::enable( SkinnyShortcut::AllShortcuts );
|
|
|
|
|
|
|
|
Window window;
|
|
|
|
window.showMaximized();
|
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
}
|