2017-07-27 08:26:23 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the 3-clause BSD License
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include <SkinnyShapeFactory.h>
|
2018-08-03 08:15:28 +02:00
|
|
|
#include <SkinnyShortcut.h>
|
2017-07-27 08:26:23 +02:00
|
|
|
|
2017-07-30 14:31:05 +02:00
|
|
|
#include <QskAspect.h>
|
2018-01-16 20:26:18 +01:00
|
|
|
#include <QskBoxBorderColors.h>
|
2018-08-03 08:15:28 +02:00
|
|
|
#include <QskBoxBorderMetrics.h>
|
|
|
|
#include <QskBoxShapeMetrics.h>
|
2018-01-12 15:46:15 +01:00
|
|
|
#include <QskFocusIndicator.h>
|
2018-08-03 08:15:28 +02:00
|
|
|
#include <QskGraphic.h>
|
|
|
|
#include <QskLinearBox.h>
|
|
|
|
#include <QskObjectCounter.h>
|
|
|
|
#include <QskPushButton.h>
|
|
|
|
#include <QskScrollArea.h>
|
|
|
|
#include <QskWindow.h>
|
2017-07-27 08:26:23 +02:00
|
|
|
|
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
const int gridSize = 20;
|
|
|
|
const int thumbnailSize = 150;
|
|
|
|
|
|
|
|
static QColor randomColor()
|
|
|
|
{
|
|
|
|
static const char* colors[] =
|
|
|
|
{
|
|
|
|
"HotPink",
|
|
|
|
"MediumVioletRed",
|
|
|
|
"FireBrick",
|
|
|
|
"PeachPuff",
|
|
|
|
"Gold",
|
|
|
|
"RosyBrown",
|
|
|
|
"Maroon",
|
|
|
|
"Turquoise",
|
|
|
|
"CadetBlue",
|
|
|
|
"Teal",
|
|
|
|
"LightSteelBlue",
|
|
|
|
"CornflowerBlue",
|
|
|
|
"Thistle",
|
|
|
|
"Plum",
|
|
|
|
"DarkViolet",
|
|
|
|
"DarkSlateBlue",
|
|
|
|
"AntiqueWhite",
|
|
|
|
"MistyRose",
|
|
|
|
"Silver",
|
|
|
|
"DarkSlateGray"
|
|
|
|
};
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
const int index = qrand() % int( ( sizeof( colors ) / sizeof( colors[ 0 ] ) ) );
|
2017-07-27 08:26:23 +02:00
|
|
|
return QColor( colors[ index ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
static int randomShape()
|
|
|
|
{
|
|
|
|
return qrand() % SkinnyShapeFactory::ShapeCount;
|
|
|
|
}
|
|
|
|
|
2018-01-12 15:46:15 +01:00
|
|
|
class Thumbnail : public QskPushButton
|
2017-07-27 08:26:23 +02:00
|
|
|
{
|
2018-08-03 08:15:28 +02:00
|
|
|
public:
|
|
|
|
Thumbnail( const QColor& color, int shape, QQuickItem* parentItem )
|
|
|
|
: QskPushButton( parentItem )
|
2017-07-27 08:26:23 +02:00
|
|
|
{
|
|
|
|
using namespace SkinnyShapeFactory;
|
|
|
|
|
|
|
|
const QSizeF size( thumbnailSize, thumbnailSize );
|
|
|
|
|
|
|
|
QskGraphic graphic;
|
|
|
|
|
|
|
|
QPen pen( Qt::black, 3 );
|
|
|
|
pen.setJoinStyle( Qt::MiterJoin );
|
|
|
|
pen.setCosmetic( true );
|
|
|
|
|
|
|
|
QPainter painter( &graphic );
|
|
|
|
painter.setRenderHint( QPainter::Antialiasing, true );
|
|
|
|
painter.setPen( pen );
|
|
|
|
painter.setBrush( color );
|
|
|
|
|
|
|
|
painter.drawPath( shapePath( static_cast< Shape >( shape ), size ) );
|
|
|
|
painter.end();
|
|
|
|
|
|
|
|
setGraphic( graphic );
|
|
|
|
setFixedSize( size );
|
2018-01-12 15:46:15 +01:00
|
|
|
|
|
|
|
setFlat( true );
|
2017-07-27 08:26:23 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class IconGrid : public QskLinearBox
|
|
|
|
{
|
2018-08-03 08:15:28 +02:00
|
|
|
public:
|
|
|
|
IconGrid( QQuickItem* parentItem = nullptr )
|
|
|
|
: QskLinearBox( Qt::Horizontal, gridSize, parentItem )
|
2017-07-27 08:26:23 +02:00
|
|
|
{
|
|
|
|
setMargins( 20 );
|
|
|
|
setSpacing( 20 );
|
|
|
|
|
|
|
|
for ( int col = 0; col < gridSize; col++ )
|
|
|
|
{
|
|
|
|
for ( int row = 0; row < gridSize; row++ )
|
2018-08-03 08:15:28 +02:00
|
|
|
( void ) new Thumbnail( randomColor(), randomShape(), this );
|
2017-07-27 08:26:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-08-22 20:15:11 +02:00
|
|
|
class ScrollArea : public QskScrollArea
|
|
|
|
{
|
2018-08-03 08:15:28 +02:00
|
|
|
public:
|
|
|
|
ScrollArea( QQuickItem* parentItem = nullptr )
|
|
|
|
: QskScrollArea( parentItem )
|
2017-08-22 20:15:11 +02:00
|
|
|
{
|
|
|
|
using namespace QskAspect;
|
|
|
|
|
|
|
|
// settings usually done in the skins
|
2017-10-18 20:00:06 +02:00
|
|
|
setBoxBorderMetricsHint( Viewport, 2 );
|
2017-10-17 17:34:00 +02:00
|
|
|
setBoxShapeHint( Viewport, 20 );
|
|
|
|
|
|
|
|
for ( auto subControl : { HorizontalScrollBar, VerticalScrollBar } )
|
|
|
|
setMetric( subControl | Size, 20 );
|
|
|
|
|
2017-10-18 20:00:06 +02:00
|
|
|
setBoxBorderMetricsHint( VerticalScrollHandle, 1 );
|
2017-10-17 17:34:00 +02:00
|
|
|
setBoxShapeHint( VerticalScrollHandle, 8 );
|
|
|
|
|
2017-10-18 20:00:06 +02:00
|
|
|
setBoxBorderMetricsHint( HorizontalScrollHandle, 1 );
|
2017-10-17 17:34:00 +02:00
|
|
|
setBoxShapeHint( HorizontalScrollHandle, 8 );
|
2017-08-22 20:15:11 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-07-27 08:26:23 +02:00
|
|
|
int main( int argc, char* argv[] )
|
|
|
|
{
|
|
|
|
#ifdef ITEM_STATISTICS
|
|
|
|
QskObjectCounter counter( true );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QGuiApplication app( argc, argv );
|
|
|
|
|
|
|
|
SkinnyShortcut::enable( SkinnyShortcut::AllShortcuts );
|
|
|
|
|
|
|
|
/*
|
2017-07-30 14:31:05 +02:00
|
|
|
In a real world application a thumbnail viewer would probably be implemented
|
2017-07-27 08:26:23 +02:00
|
|
|
with QskScrollView using scene graph node composition - like done
|
2017-07-30 14:31:05 +02:00
|
|
|
with QskListView.
|
2017-07-27 08:26:23 +02:00
|
|
|
|
2018-01-12 15:46:15 +01:00
|
|
|
The thumbnails are implemented as buttons, so that we can see if the gesture
|
2018-08-03 08:15:28 +02:00
|
|
|
recognition for the flicking works without stopping the buttons from being functional.
|
2018-01-12 15:46:15 +01:00
|
|
|
|
2017-07-27 08:26:23 +02:00
|
|
|
This example also shows, that blocking of the scene graph node creation
|
2018-08-03 08:15:28 +02:00
|
|
|
( QskControl::DeferredUpdate + QskControl::CleanupOnVisibility )
|
2017-07-30 14:31:05 +02:00
|
|
|
could be improved to also respect being inside the window or a clip region.
|
2017-07-27 08:26:23 +02:00
|
|
|
|
|
|
|
But here we only want to demonstrate how QskScrollArea works.
|
|
|
|
*/
|
|
|
|
|
2018-01-16 20:26:18 +01:00
|
|
|
auto box = new QskLinearBox( Qt::Vertical );
|
|
|
|
box->setMargins( 20 );
|
|
|
|
|
|
|
|
auto buttonBox = new QskLinearBox( Qt::Horizontal, box );
|
|
|
|
buttonBox->setSizePolicy( Qt::Vertical, QskSizePolicy::Fixed );
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
new QskPushButton( "Push Me", buttonBox );
|
|
|
|
new QskPushButton( "Push Me", buttonBox );
|
2018-01-16 20:26:18 +01:00
|
|
|
|
|
|
|
auto scrollArea = new ScrollArea( box );
|
2017-07-30 14:31:05 +02:00
|
|
|
scrollArea->setMargins( QMarginsF( 25, 25, 5, 5 ) );
|
2017-07-27 08:26:23 +02:00
|
|
|
scrollArea->setScrolledItem( new IconGrid() );
|
|
|
|
|
2018-01-16 20:26:18 +01:00
|
|
|
auto focusIndicator = new QskFocusIndicator();
|
|
|
|
focusIndicator->setBoxBorderColorsHint( QskFocusIndicator::Panel, Qt::darkRed );
|
|
|
|
|
2017-07-27 08:26:23 +02:00
|
|
|
QskWindow window;
|
|
|
|
window.resize( 600, 600 );
|
2017-07-30 14:31:05 +02:00
|
|
|
window.setColor( "SteelBlue" );
|
2018-01-16 20:26:18 +01:00
|
|
|
window.addItem( box );
|
|
|
|
window.addItem( focusIndicator );
|
2017-07-27 08:26:23 +02:00
|
|
|
|
|
|
|
window.show();
|
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
}
|