2022-12-09 12:07:46 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the 3-clause BSD License
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2022-12-20 16:30:49 +01:00
|
|
|
#include "GradientView.h"
|
|
|
|
|
2022-12-09 12:07:46 +01:00
|
|
|
#include <SkinnyNamespace.h>
|
2022-12-20 16:30:49 +01:00
|
|
|
|
2022-12-09 12:07:46 +01:00
|
|
|
#include <QskGradient.h>
|
2022-12-20 16:30:49 +01:00
|
|
|
#include <QskLinearBox.h>
|
|
|
|
#include <QskWindow.h>
|
2022-12-09 12:07:46 +01:00
|
|
|
|
2022-12-20 16:30:49 +01:00
|
|
|
#include <QGuiApplication>
|
2022-12-09 12:07:46 +01:00
|
|
|
|
2022-12-20 16:30:49 +01:00
|
|
|
namespace
|
2022-12-09 12:07:46 +01:00
|
|
|
{
|
2022-12-20 16:30:49 +01:00
|
|
|
class MainView : public QskLinearBox
|
2022-12-09 12:07:46 +01:00
|
|
|
{
|
2022-12-20 16:30:49 +01:00
|
|
|
Q_OBJECT
|
2022-12-09 12:07:46 +01:00
|
|
|
|
2022-12-20 16:30:49 +01:00
|
|
|
public:
|
|
|
|
MainView( QQuickItem* parent = nullptr )
|
|
|
|
: QskLinearBox( Qt::Horizontal, 2, parent )
|
2022-12-09 12:07:46 +01:00
|
|
|
{
|
2022-12-20 16:30:49 +01:00
|
|
|
for ( int i = 0; i < GradientView::NumNodeTypes; i++ )
|
|
|
|
{
|
|
|
|
const auto nodeType = static_cast< GradientView::NodeType >( i );
|
|
|
|
m_views[i] = new GradientView( nodeType, this );
|
|
|
|
}
|
2022-12-09 12:07:46 +01:00
|
|
|
|
2022-12-20 16:30:49 +01:00
|
|
|
showColors( { Qt::green, Qt::red, Qt::yellow, Qt::cyan, Qt::darkCyan } );
|
|
|
|
}
|
2022-12-09 12:07:46 +01:00
|
|
|
|
2022-12-20 16:30:49 +01:00
|
|
|
void showColors( const QVector< QColor >& colors )
|
|
|
|
{
|
|
|
|
const auto step = 1.0 / colors.size();
|
2022-12-09 12:07:46 +01:00
|
|
|
|
2022-12-20 16:30:49 +01:00
|
|
|
QskGradientStops stops;
|
2022-12-09 12:07:46 +01:00
|
|
|
|
2022-12-20 16:30:49 +01:00
|
|
|
for ( int i = 0; i < colors.size(); i++ )
|
|
|
|
{
|
|
|
|
stops += { i * step, colors[i] };
|
|
|
|
stops += { ( i + 1 ) * step, colors[i] };
|
|
|
|
}
|
2022-12-09 12:07:46 +01:00
|
|
|
|
2022-12-20 16:30:49 +01:00
|
|
|
QskGradient gradient;
|
2022-12-22 20:29:35 +01:00
|
|
|
#if 1
|
2022-12-20 16:30:49 +01:00
|
|
|
gradient.setLinearDirection( 0.0, 0.0, 1.0, 1.0 );
|
2022-12-22 20:29:35 +01:00
|
|
|
#endif
|
|
|
|
#if 0
|
|
|
|
gradient.setLinearDirection( 0.2, 0.2, 0.7, 0.5 );
|
|
|
|
gradient.setSpreadMode( QskGradient::PadSpread );
|
|
|
|
#endif
|
|
|
|
#if 0
|
|
|
|
gradient.setRadialDirection( 0.25, 0.75, 0.25 );
|
|
|
|
gradient.setSpreadMode( QskGradient::ReflectSpread );
|
|
|
|
#endif
|
|
|
|
#if 0
|
|
|
|
gradient.setConicDirection( 0.25, 0.75, 0, 90 );
|
|
|
|
gradient.setSpreadMode( QskGradient::ReflectSpread );
|
|
|
|
#endif
|
|
|
|
|
2022-12-20 16:30:49 +01:00
|
|
|
gradient.setStops( stops );
|
2022-12-09 12:07:46 +01:00
|
|
|
|
2022-12-20 16:30:49 +01:00
|
|
|
showGradient( gradient );
|
|
|
|
}
|
2022-12-09 12:07:46 +01:00
|
|
|
|
2022-12-20 16:30:49 +01:00
|
|
|
public Q_SLOTS:
|
|
|
|
void showGradient( const QskGradient& gradient )
|
2022-12-09 12:07:46 +01:00
|
|
|
{
|
2022-12-20 16:30:49 +01:00
|
|
|
for ( auto view : m_views )
|
|
|
|
{
|
|
|
|
if ( view )
|
|
|
|
view->setGradient( gradient );
|
|
|
|
}
|
2022-12-09 12:07:46 +01:00
|
|
|
}
|
|
|
|
|
2022-12-20 16:30:49 +01:00
|
|
|
private:
|
|
|
|
GradientView* m_views[ GradientView::NumNodeTypes ];
|
|
|
|
};
|
|
|
|
}
|
2022-12-09 12:07:46 +01:00
|
|
|
|
|
|
|
int main( int argc, char** argv )
|
|
|
|
{
|
2022-12-20 16:30:49 +01:00
|
|
|
QGuiApplication app( argc, argv );
|
2022-12-09 12:07:46 +01:00
|
|
|
Skinny::init(); // we need a skin
|
|
|
|
|
2022-12-20 16:30:49 +01:00
|
|
|
QskWindow window;
|
|
|
|
window.addItem( new MainView() );
|
|
|
|
window.resize( 600, 600 );
|
|
|
|
window.show();
|
2022-12-09 12:07:46 +01:00
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "main.moc"
|