qskinny/examples/iot-dashboard/MainContent.cpp

168 lines
5.6 KiB
C++
Raw Normal View History

2021-04-21 10:00:34 +00:00
/****************************************************************************
**
** Copyright 2021 Edelhirsch Software GmbH. All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
**
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of the copyright holder nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
****************************************************************************/
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"
2021-04-16 07:41:16 +00:00
#include "UsageDiagram.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>
2021-04-07 15:03:21 +00:00
#include <QskSetup.h>
#include <QskSkin.h>
2020-05-22 09:48:05 +00:00
#include <QskTextLabel.h>
2021-04-21 09:21:22 +00:00
#include "kirigami/shadowedrectangle.h"
#include <QTimer>
2021-04-07 15:03:21 +00:00
QSK_SUBCONTROL( ShadowPositioner, Panel )
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 );
2021-04-07 15:03:21 +00:00
r->setColor( Qt::transparent );
r->shadow()->setColor( color( ShadowPositioner::Panel ) );
connect( qskSetup, &QskSetup::skinChanged, [this, r]()
{
r->shadow()->setColor( color( ShadowPositioner::Panel ) );
} );
r->shadow()->setSize( metric( ShadowPositioner::Panel | QskAspect::Size ) );
r->setOpacity( 0.1 );
2021-04-07 15:03:21 +00:00
auto shape = boxShapeHint( ShadowPositioner::Panel );
r->corners()->setTopLeft( shape.radius( Qt::TopLeftCorner ).width() );
r->corners()->setTopRight( shape.radius( Qt::TopRightCorner ).width() );
r->corners()->setBottomLeft( shape.radius( Qt::BottomLeftCorner ).width() );
r->corners()->setBottomRight( shape.radius( Qt::BottomRightCorner ).width() );
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 );
2021-04-16 07:41:16 +00:00
auto* diagram = new UsageDiagram( gridBox );
2020-08-26 15:22:43 +00:00
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
}