qskinny/examples/iotdashboard/StorageBar.cpp

121 lines
2.4 KiB
C++
Raw Normal View History

2023-01-05 17:08:50 +01:00
/******************************************************************************
* Copyright (C) 2022 Edelhirsch Software GmbH
2023-04-06 10:15:03 +02:00
* SPDX-License-Identifier: BSD-3-Clause
2023-01-05 17:08:50 +01:00
*****************************************************************************/
2023-01-04 17:17:17 +01:00
#include "StorageBar.h"
2023-01-05 17:08:50 +01:00
#include <QskAnimator.h>
2023-01-04 17:17:17 +01:00
#include <QskBox.h>
#include <QskBoxShapeMetrics.h>
#include <QskSkinlet.h>
2023-01-05 17:08:50 +01:00
QSK_SUBCONTROL( StorageBar, Pictures )
QSK_SUBCONTROL( StorageBar, Music )
QSK_SUBCONTROL( StorageBar, Videos )
QSK_SUBCONTROL( StorageBar, Documents )
2023-01-04 17:17:17 +01:00
QSK_SUBCONTROL( StorageBar, Others )
QSK_SUBCONTROL( StorageBar, Free )
2023-01-05 17:08:50 +01:00
using S = StorageBar;
2023-01-04 17:17:17 +01:00
2024-02-02 14:13:33 +01:00
StorageBar::StorageBar( QskItem* const parent )
2023-01-05 17:08:50 +01:00
: Inherited( parent )
2023-01-04 17:17:17 +01:00
{
2023-01-05 17:08:50 +01:00
static constexpr qreal size = 16.0;
static constexpr qreal radius = size / 2.0;
2023-01-04 17:17:17 +01:00
2023-01-05 17:08:50 +01:00
setMinimumSize( -1, size );
setMaximumSize( -1, size );
2023-01-04 17:17:17 +01:00
2023-01-05 17:08:50 +01:00
setBoxShapeHint( S::Pictures, { radius, 0.0, radius, 0.0 } );
setBoxShapeHint( S::Free, { 0.0, radius, 0.0, radius } );
2023-01-04 17:17:17 +01:00
}
qreal StorageBar::pictures() const
{
2023-01-05 17:08:50 +01:00
return m_pictures;
2023-01-04 17:17:17 +01:00
}
2023-01-05 17:08:50 +01:00
void StorageBar::setPictures( qreal newPictures )
2023-01-04 17:17:17 +01:00
{
2023-01-05 17:08:50 +01:00
if ( qFuzzyCompare( m_pictures, newPictures ) )
{
return;
}
2023-01-04 17:17:17 +01:00
2023-01-05 17:08:50 +01:00
m_pictures = newPictures;
Q_EMIT picturesChanged( m_pictures );
update();
2023-01-04 17:17:17 +01:00
}
qreal StorageBar::music() const
{
2023-01-05 17:08:50 +01:00
return m_music;
2023-01-04 17:17:17 +01:00
}
2023-01-05 17:08:50 +01:00
void StorageBar::setMusic( qreal newMusic )
2023-01-04 17:17:17 +01:00
{
2023-01-05 17:08:50 +01:00
if ( qFuzzyCompare( m_music, newMusic ) )
{
return;
}
m_music = newMusic;
Q_EMIT musicChanged( m_music );
update();
2023-01-04 17:17:17 +01:00
}
qreal StorageBar::videos() const
{
2023-01-05 17:08:50 +01:00
return m_videos;
2023-01-04 17:17:17 +01:00
}
2023-01-05 17:08:50 +01:00
void StorageBar::setVideos( qreal newVideos )
2023-01-04 17:17:17 +01:00
{
2023-01-05 17:08:50 +01:00
if ( qFuzzyCompare( m_videos, newVideos ) )
{
return;
}
m_videos = newVideos;
Q_EMIT videosChanged( m_videos );
update();
2023-01-04 17:17:17 +01:00
}
qreal StorageBar::documents() const
{
2023-01-05 17:08:50 +01:00
return m_documents;
2023-01-04 17:17:17 +01:00
}
2023-01-05 17:08:50 +01:00
void StorageBar::setDocuments( qreal newDocuments )
2023-01-04 17:17:17 +01:00
{
2023-01-05 17:08:50 +01:00
if ( qFuzzyCompare( m_documents, newDocuments ) )
{
return;
}
m_documents = newDocuments;
Q_EMIT documentsChanged( m_documents );
update();
2023-01-04 17:17:17 +01:00
}
qreal StorageBar::others() const
{
2023-01-05 17:08:50 +01:00
return m_others;
2023-01-04 17:17:17 +01:00
}
2023-01-05 17:08:50 +01:00
void StorageBar::setOthers( qreal newOthers )
2023-01-04 17:17:17 +01:00
{
2023-01-05 17:08:50 +01:00
if ( qFuzzyCompare( m_others, newOthers ) )
{
return;
}
m_others = newOthers;
Q_EMIT othersChanged( m_others );
update();
2023-01-04 17:17:17 +01:00
}
qreal StorageBar::free() const
{
2023-01-05 17:08:50 +01:00
return 1.0 - m_pictures - m_music - m_videos - m_documents - m_others;
2023-01-04 17:17:17 +01:00
}
2023-01-06 18:00:08 +01:00
#include "moc_StorageBar.cpp"