qskinny/examples/iot-dashboard/MainContent.cpp

124 lines
3.4 KiB
C++
Raw Normal View History

2020-05-22 09:48:05 +00:00
#include "MainContent.h"
2020-09-17 14:14:29 +00:00
#include "Box.h"
2021-03-31 14:46:15 +00:00
#include "BoxWithButtons.h"
2020-08-26 15:22:43 +00:00
#include "Diagram.h"
2020-09-08 15:21:54 +00:00
#include "LightIntensity.h"
2020-08-17 15:19:05 +00:00
#include "MyDevices.h"
2020-05-22 13:15:38 +00:00
#include "PieChart.h"
2020-06-12 13:51:13 +00:00
#include "TopBar.h"
2020-08-12 15:11:00 +00:00
#include "Usage.h"
2020-05-22 09:48:05 +00:00
2020-08-12 15:11:00 +00:00
#include <QskBoxBorderColors.h>
#include <QskBoxBorderMetrics.h>
#include <QskBoxShapeMetrics.h>
#include <QskGridBox.h>
2020-05-22 09:48:05 +00:00
#include <QskTextLabel.h>
#include "src/shadowedrectangle.h"
#include <QTimer>
2020-09-23 15:45:06 +00:00
QSK_SUBCONTROL( MainContent, Panel )
2021-03-26 16:03:02 +00:00
QSK_SUBCONTROL( MainContentGridBox, Panel )
2020-09-23 15:45:06 +00:00
ShadowPositioner::ShadowPositioner( QQuickItem* parent ) : QskControl( parent )
{
setAutoLayoutChildren( true );
}
void ShadowPositioner::setGridBox( QskGridBox* gridBox )
{
m_gridBox = gridBox;
2020-12-17 08:28:54 +00:00
m_rectangles.reserve( m_gridBox->elementCount() );
2020-12-17 08:28:54 +00:00
for( int i = 0; i < m_gridBox->elementCount(); ++i )
{
auto* r = new ShadowedRectangle( this );
r->setZ( 5 );
r->shadow()->setColor( Qt::black );
r->shadow()->setSize( 15 );
r->setColor( Qt::white ); // ### opacity should only be for the shadow, not the background
r->setOpacity( 0.1 );
r->corners()->setTopLeft( 6 );
r->corners()->setTopRight( 6 );
r->corners()->setBottomLeft( 6 );
r->corners()->setBottomRight( 6 );
m_rectangles.append( r );
}
}
void ShadowPositioner::updateLayout()
{
auto* mainContent = static_cast<QskLinearBox*>( parentItem() );
QTimer::singleShot( 0, this, [this, mainContent]()
{
for( int i = 0; i < m_rectangles.count(); ++i )
{
auto* item = m_gridBox->itemAtIndex( i );
m_rectangles[i]->setSize( item->size() );
m_rectangles[i]->setPosition( mainContent->itemAtIndex( 1 )->position() + item->position() );
}
} );
}
2020-08-26 15:22:43 +00:00
MainContent::MainContent( QQuickItem* parent ) : QskLinearBox( Qt::Vertical, parent )
2020-05-22 09:48:05 +00:00
{
setAutoAddChildren( false );
2020-05-22 09:48:05 +00:00
setSizePolicy( QskSizePolicy::Expanding, QskSizePolicy::Expanding );
2020-08-26 15:22:43 +00:00
setDefaultAlignment( Qt::AlignTop );
2020-09-21 14:31:36 +00:00
setSpacing( 24 );
2020-09-23 15:45:06 +00:00
setPanel( true );
2020-05-22 09:48:05 +00:00
auto* topBar = new TopBar( this );
addItem( topBar );
2020-05-22 09:48:05 +00:00
2021-03-26 16:03:02 +00:00
auto* gridBox = new MainContentGridBox( this );
2020-08-26 15:22:43 +00:00
gridBox->setPanel( true );
2021-03-26 16:03:02 +00:00
gridBox->setSpacing( 15 );
addItem( gridBox );
2020-08-12 15:11:00 +00:00
2020-08-26 15:22:43 +00:00
auto* usage = new Usage( gridBox );
gridBox->addItem( usage, 0, 0, 2, 1 );
2020-08-14 10:48:15 +00:00
2020-08-26 15:22:43 +00:00
auto* indoorTemperature = new IndoorTemperature( gridBox );
gridBox->addItem( indoorTemperature, 0, 1 );
2020-08-14 14:28:47 +00:00
2020-08-26 15:22:43 +00:00
auto* humidity = new Humidity( gridBox );
gridBox->addItem( humidity, 1, 1 );
2020-08-17 15:19:05 +00:00
2020-08-26 15:22:43 +00:00
auto* myDevices = new MyDevices( gridBox );
gridBox->addItem( myDevices, 0, 2, 2, 1 );
auto* diagram = new Diagram( gridBox );
gridBox->addItem( diagram, 2, 0, 0, 2 );
2020-09-08 15:21:54 +00:00
auto* lightIntensity = new LightIntensity( gridBox );
gridBox->addItem( lightIntensity, 2, 2 );
2020-12-17 09:05:34 +00:00
gridBox->setColumnStretchFactor( 0, 37 ); // factors add up to 100
gridBox->setColumnStretchFactor( 1, 37 );
gridBox->setColumnStretchFactor( 2, 26 );
m_shadowPositioner = new ShadowPositioner( this );
m_shadowPositioner->setGridBox( gridBox );
}
2020-09-23 15:45:06 +00:00
QskAspect::Subcontrol MainContent::effectiveSubcontrol( QskAspect::Subcontrol subControl ) const
{
if( subControl == QskBox::Panel )
{
return MainContent::Panel;
}
return subControl;
}
2020-12-17 08:28:54 +00:00
void MainContent::geometryChangeEvent( QskGeometryChangeEvent* event )
{
2020-12-17 08:28:54 +00:00
QskLinearBox::geometryChangeEvent( event );
m_shadowPositioner->polish();
2020-05-22 09:48:05 +00:00
}