Merge branch 'master' into material-theme
This commit is contained in:
commit
526003f173
|
@ -135,20 +135,23 @@ void Editor::setupControl()
|
||||||
|
|
||||||
void Editor::setupCheckBox()
|
void Editor::setupCheckBox()
|
||||||
{
|
{
|
||||||
|
using A = QskAspect;
|
||||||
using Q = QskCheckBox;
|
using Q = QskCheckBox;
|
||||||
|
|
||||||
const qreal radius = qskDpiScaled( 18 );
|
const qreal size = qskDpiScaled( 18 );
|
||||||
|
|
||||||
setMargin( QskCheckBox::Tick, QMarginsF( 3, 5, 3, 3 ) );
|
setStrutSize( Q::Panel, size, size );
|
||||||
setStrutSize( Q::Box, radius, radius );
|
setPadding( Q::Panel, 3 );
|
||||||
|
|
||||||
setBoxShape( Q::Box, 2 );
|
setBoxShape( Q::Panel, 2 );
|
||||||
|
|
||||||
setColor( Q::Box, m_pal.secondaryNoSaturation);
|
setGradient( Q::Panel, m_pal.secondaryNoSaturation );
|
||||||
setColor( Q::Box | Q::Checked, m_pal.secondary );
|
setGradient( Q::Panel | Q::Checked, m_pal.secondary );
|
||||||
setGradient( Q::Box | Q::Checked | Q::Disabled, QskRgb::Grey );
|
setGradient( Q::Panel | Q::Checked | Q::Disabled, QskRgb::Grey );
|
||||||
|
|
||||||
setColor( Q::Tick, m_pal.primary );
|
setColor( Q::Indicator, m_pal.primary );
|
||||||
|
|
||||||
|
setAnimation( Q::Panel | A::Color, qskDuration );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::setupBox()
|
void Editor::setupBox()
|
||||||
|
|
|
@ -297,19 +297,24 @@ void Editor::setupBox()
|
||||||
|
|
||||||
void Editor::setupCheckBox()
|
void Editor::setupCheckBox()
|
||||||
{
|
{
|
||||||
|
using A = QskAspect;
|
||||||
using Q = QskCheckBox;
|
using Q = QskCheckBox;
|
||||||
|
|
||||||
const qreal size = qskDpiScaled( 26 );
|
const qreal size = qskDpiScaled( 26 );
|
||||||
|
|
||||||
setMargin( Q::Tick, QskMargins( qskDpiScaled( 5 ) ) );
|
setStrutSize( Q::Panel, size, size );
|
||||||
|
|
||||||
setStrutSize( Q::Box, QSizeF( size, size ) );
|
setPadding( Q::Panel, qskDpiScaled( 5 ) );
|
||||||
setBoxShape( Q::Box, qskDpiScaled( 3 ) );
|
setBoxShape( Q::Panel, qskDpiScaled( 3 ) );
|
||||||
setBoxBorderMetrics( Q::Box, qskDpiScaled( 1 ) );
|
setBoxBorderMetrics( Q::Panel, qskDpiScaled( 1 ) );
|
||||||
setBoxBorderColors( Q::Box, m_pal.darker125 );
|
|
||||||
setColor( Q::Box, m_pal.lighter135 );
|
setBoxBorderColors( Q::Panel, m_pal.darker125 );
|
||||||
setColor( Q::Box | Q::Checked, m_pal.highlighted );
|
setGradient( Q::Panel, m_pal.lighter135 );
|
||||||
setColor( Q::Tick, m_pal.lighter135 );
|
setGradient( Q::Panel | Q::Checked, m_pal.highlighted );
|
||||||
|
|
||||||
|
setColor( Q::Indicator, m_pal.lighter135 );
|
||||||
|
|
||||||
|
setAnimation( Q::Panel | A::Color, qskDuration );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::setupPopup()
|
void Editor::setupPopup()
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
|
|
||||||
#include <qset.h>
|
#include <qset.h>
|
||||||
|
|
||||||
QSK_SUBCONTROL( QskCheckBox, Box )
|
QSK_SUBCONTROL( QskCheckBox, Panel )
|
||||||
QSK_SUBCONTROL( QskCheckBox, Tick )
|
QSK_SUBCONTROL( QskCheckBox, Indicator )
|
||||||
|
|
||||||
QSK_SYSTEM_STATE( QskCheckBox, PartiallyChecked, QskAspect::LastUserState << 2 )
|
QSK_SYSTEM_STATE( QskCheckBox, PartiallyChecked, QskAspect::LastUserState << 2 )
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ class QskCheckBox::PrivateData
|
||||||
|
|
||||||
int groupItemsChecked = 0;
|
int groupItemsChecked = 0;
|
||||||
|
|
||||||
int checkState : 2;
|
Qt::CheckState checkState : 2;
|
||||||
bool checkStateChanging : 1;
|
bool checkStateChanging : 1;
|
||||||
bool toggleChanging : 1;
|
bool toggleChanging : 1;
|
||||||
bool tristate : 1;
|
bool tristate : 1;
|
||||||
|
@ -57,7 +57,7 @@ bool QskCheckBox::isCheckable() const
|
||||||
|
|
||||||
Qt::CheckState QskCheckBox::checkState() const
|
Qt::CheckState QskCheckBox::checkState() const
|
||||||
{
|
{
|
||||||
return static_cast< Qt::CheckState >( m_data->checkState );
|
return m_data->checkState;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskCheckBox::setCheckStateInternal( Qt::CheckState checkState )
|
void QskCheckBox::setCheckStateInternal( Qt::CheckState checkState )
|
||||||
|
@ -162,8 +162,7 @@ void QskCheckBox::addToGroup( QskCheckBox* groupItem )
|
||||||
connect( groupItem, &QskAbstractButton::toggled,
|
connect( groupItem, &QskAbstractButton::toggled,
|
||||||
this, [ this, groupItem ]( bool toggled )
|
this, [ this, groupItem ]( bool toggled )
|
||||||
{
|
{
|
||||||
auto& groupItemsChecked = m_data->groupItemsChecked;
|
m_data->groupItemsChecked += toggled ? 1 : -1;
|
||||||
groupItemsChecked += toggled ? 1 : -1;
|
|
||||||
updated();
|
updated();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ class QSK_EXPORT QskCheckBox : public QskAbstractButton
|
||||||
using Inherited = QskAbstractButton;
|
using Inherited = QskAbstractButton;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QSK_SUBCONTROLS( Box, Tick )
|
QSK_SUBCONTROLS( Panel, Indicator )
|
||||||
QSK_STATES( PartiallyChecked )
|
QSK_STATES( PartiallyChecked )
|
||||||
|
|
||||||
QskCheckBox( QQuickItem* parent = nullptr );
|
QskCheckBox( QQuickItem* parent = nullptr );
|
||||||
|
|
|
@ -5,132 +5,129 @@
|
||||||
|
|
||||||
#include "QskCheckBoxSkinlet.h"
|
#include "QskCheckBoxSkinlet.h"
|
||||||
#include "QskCheckBox.h"
|
#include "QskCheckBox.h"
|
||||||
|
#include "QskSGNode.h"
|
||||||
|
|
||||||
#include <QSGFlatColorMaterial>
|
#include <QSGFlatColorMaterial>
|
||||||
#include <qsgnode.h>
|
#include <qsgnode.h>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
class Tick : public QSGGeometryNode
|
class IndicatorNode : public QSGGeometryNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Tick()
|
IndicatorNode()
|
||||||
: geometry( QSGGeometry::defaultAttributes_Point2D(), 3 )
|
: m_geometry( QSGGeometry::defaultAttributes_Point2D(), 3 )
|
||||||
{
|
{
|
||||||
geometry.setDrawingMode( QSGGeometry::DrawLineStrip );
|
m_geometry.setDrawingMode( QSGGeometry::DrawLineStrip );
|
||||||
geometry.setLineWidth( 2 );
|
m_geometry.setLineWidth( 2 );
|
||||||
setGeometry( &geometry );
|
setGeometry( &m_geometry );
|
||||||
|
|
||||||
setMaterial( &material );
|
setMaterial( &m_material );
|
||||||
}
|
}
|
||||||
|
|
||||||
void setColor( const QColor& color )
|
void update( bool isPartially, const QRectF& rect, const QColor& color )
|
||||||
{
|
{
|
||||||
material.setColor( color );
|
if ( color != m_material.color() )
|
||||||
markDirty( QSGNode::DirtyMaterial );
|
{
|
||||||
}
|
m_material.setColor( color );
|
||||||
|
markDirty( QSGNode::DirtyMaterial );
|
||||||
|
}
|
||||||
|
|
||||||
void makeTick( const QRectF& rect )
|
if ( rect != m_rect || isPartially != m_isPartially )
|
||||||
{
|
{
|
||||||
const auto x = rect.x();
|
m_rect = rect;
|
||||||
const auto y = rect.y();
|
m_isPartially = isPartially;
|
||||||
|
|
||||||
auto vertexData = geometry.vertexDataAsPoint2D();
|
const auto x = rect.x();
|
||||||
|
const auto y = rect.y();
|
||||||
|
const auto w = rect.width();
|
||||||
|
const auto h = rect.height();
|
||||||
|
|
||||||
vertexData[0].set( x, y + rect.height() / 2 );
|
auto points = m_geometry.vertexDataAsPoint2D();
|
||||||
vertexData[1].set( x + rect.width() / 3, y + rect.height() );
|
|
||||||
vertexData[2].set( x + rect.width(), y );
|
|
||||||
|
|
||||||
markDirty( QSGNode::DirtyGeometry );
|
if ( isPartially )
|
||||||
}
|
{
|
||||||
|
points[0].set( x, y + h / 2 );
|
||||||
void makePartially( const QRectF& rect )
|
points[1] = points[0];
|
||||||
{
|
points[2].set( x + w, y + h / 2 );
|
||||||
const auto x = rect.x();
|
}
|
||||||
const auto y = rect.y();
|
else
|
||||||
|
{
|
||||||
auto vertexData = geometry.vertexDataAsPoint2D();
|
points[0].set( x, y + h / 2 );
|
||||||
|
points[1].set( x + w / 3, y + h );
|
||||||
vertexData[0].set( x, y + rect.height() / 2 );
|
points[2].set( x + w, y );
|
||||||
vertexData[1].set( x, y + rect.height() / 2 );
|
}
|
||||||
vertexData[2].set( x + rect.width(), y + rect.height() / 2 );
|
|
||||||
|
markDirty( QSGNode::DirtyGeometry );
|
||||||
markDirty( QSGNode::DirtyGeometry );
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSGFlatColorMaterial material;
|
QSGFlatColorMaterial m_material;
|
||||||
QSGGeometry geometry;
|
QSGGeometry m_geometry;
|
||||||
|
|
||||||
|
QRectF m_rect;
|
||||||
|
bool m_isPartially;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
QskCheckBoxSkinlet::QskCheckBoxSkinlet( QskSkin* skin )
|
QskCheckBoxSkinlet::QskCheckBoxSkinlet( QskSkin* skin )
|
||||||
: QskSkinlet( skin )
|
: QskSkinlet( skin )
|
||||||
{
|
{
|
||||||
setNodeRoles( { BoxRole, TickRole } );
|
setNodeRoles( { PanelRole, IndicatorRole } );
|
||||||
}
|
}
|
||||||
|
|
||||||
QskCheckBoxSkinlet::~QskCheckBoxSkinlet()
|
QskCheckBoxSkinlet::~QskCheckBoxSkinlet()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF QskCheckBoxSkinlet::subControlRect(
|
QRectF QskCheckBoxSkinlet::subControlRect( const QskSkinnable* skinnable,
|
||||||
const QskSkinnable*, const QRectF& contentsRect, QskAspect::Subcontrol ) const
|
const QRectF& contentsRect, QskAspect::Subcontrol subControl ) const
|
||||||
{
|
{
|
||||||
|
if ( subControl == QskCheckBox::Indicator )
|
||||||
|
return skinnable->innerBox( QskCheckBox::Panel, contentsRect );
|
||||||
|
|
||||||
return contentsRect;
|
return contentsRect;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSGNode* QskCheckBoxSkinlet::updateSubNode(
|
QSGNode* QskCheckBoxSkinlet::updateSubNode(
|
||||||
const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const
|
const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const
|
||||||
{
|
{
|
||||||
|
auto checkBox = static_cast< const QskCheckBox* >( skinnable );
|
||||||
|
|
||||||
switch( nodeRole )
|
switch( nodeRole )
|
||||||
{
|
{
|
||||||
case BoxRole:
|
case PanelRole:
|
||||||
{
|
return updateBoxNode( skinnable, node, QskCheckBox::Panel );
|
||||||
return updateBoxNode( skinnable, node, QskCheckBox::Box );
|
|
||||||
}
|
|
||||||
|
|
||||||
case TickRole:
|
case IndicatorRole:
|
||||||
{
|
return updateIndicatorNode( checkBox, node );
|
||||||
auto checkBox = static_cast< const QskCheckBox* >( skinnable );
|
|
||||||
return updateTickNode( checkBox, node );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Inherited::updateSubNode( skinnable, nodeRole, node );
|
return Inherited::updateSubNode( skinnable, nodeRole, node );
|
||||||
}
|
}
|
||||||
|
|
||||||
QSGNode* QskCheckBoxSkinlet::updateTickNode(
|
QSGNode* QskCheckBoxSkinlet::updateIndicatorNode(
|
||||||
const QskCheckBox* checkBox, QSGNode* node ) const
|
const QskCheckBox* checkBox, QSGNode* node ) const
|
||||||
{
|
{
|
||||||
using Q = QskCheckBox;
|
using Q = QskCheckBox;
|
||||||
|
|
||||||
if ( checkBox->checkState() == Qt::Unchecked )
|
const auto state = checkBox->checkState();
|
||||||
|
if ( state == Qt::Unchecked )
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
auto rect = checkBox->subControlRect( Q::Tick );
|
const auto rect = checkBox->subControlRect( Q::Indicator );
|
||||||
rect = rect.marginsRemoved( checkBox->marginHint( Q::Tick ) );
|
if ( rect.isEmpty() )
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
auto tick = static_cast< Tick* >( node );
|
auto indicatorNode = QskSGNode::ensureNode< IndicatorNode >( node );
|
||||||
if ( tick == nullptr )
|
indicatorNode->update( state != Qt::Checked, rect, checkBox->color( Q::Indicator ) );
|
||||||
tick = new Tick();
|
|
||||||
|
|
||||||
if ( checkBox->checkState() == Qt::PartiallyChecked )
|
return indicatorNode;
|
||||||
{
|
|
||||||
tick->setColor( checkBox->color( Q::Tick | Q::PartiallyChecked ) );
|
|
||||||
tick->makePartially( rect );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
tick->setColor( checkBox->color( Q::Tick | Q::Checked ) );
|
|
||||||
tick->makeTick( rect );
|
|
||||||
}
|
|
||||||
|
|
||||||
return tick;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSizeF QskCheckBoxSkinlet::sizeHint( const QskSkinnable* skinnable,
|
QSizeF QskCheckBoxSkinlet::sizeHint( const QskSkinnable* skinnable,
|
||||||
Qt::SizeHint, const QSizeF& ) const
|
Qt::SizeHint, const QSizeF& ) const
|
||||||
{
|
{
|
||||||
return skinnable->strutSizeHint( QskCheckBox::Box );
|
return skinnable->strutSizeHint( QskCheckBox::Panel );
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,8 @@ class QSK_EXPORT QskCheckBoxSkinlet : public QskSkinlet
|
||||||
public:
|
public:
|
||||||
enum NodeRole
|
enum NodeRole
|
||||||
{
|
{
|
||||||
BoxRole,
|
PanelRole,
|
||||||
TickRole,
|
IndicatorRole,
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_INVOKABLE QskCheckBoxSkinlet( QskSkin* = nullptr );
|
Q_INVOKABLE QskCheckBoxSkinlet( QskSkin* = nullptr );
|
||||||
|
@ -36,8 +36,8 @@ class QSK_EXPORT QskCheckBoxSkinlet : public QskSkinlet
|
||||||
QSGNode* updateSubNode( const QskSkinnable*,
|
QSGNode* updateSubNode( const QskSkinnable*,
|
||||||
quint8 nodeRole, QSGNode* ) const override;
|
quint8 nodeRole, QSGNode* ) const override;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
QSGNode* updateTickNode( const QskCheckBox*, QSGNode* ) const;
|
virtual QSGNode* updateIndicatorNode( const QskCheckBox*, QSGNode* ) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue