Skip to content

Commit

Permalink
code moved from QskPopupSkinlet to QskSlideInNode
Browse files Browse the repository at this point in the history
  • Loading branch information
uwerat committed Oct 15, 2023
1 parent 56446c2 commit 3ecd8f3
Show file tree
Hide file tree
Showing 7 changed files with 228 additions and 147 deletions.
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ list(APPEND HEADERS
nodes/QskRichTextRenderer.h
nodes/QskScaleRenderer.h
nodes/QskSGNode.h
nodes/QskSlideInNode.h
nodes/QskStrokeNode.h
nodes/QskStippledLineRenderer.h
nodes/QskShapeNode.h
Expand Down Expand Up @@ -146,6 +147,7 @@ list(APPEND SOURCES
nodes/QskRichTextRenderer.cpp
nodes/QskScaleRenderer.cpp
nodes/QskSGNode.cpp
nodes/QskSlideInNode.cpp
nodes/QskStrokeNode.cpp
nodes/QskStippledLineRenderer.cpp
nodes/QskShapeNode.cpp
Expand Down
42 changes: 39 additions & 3 deletions src/controls/QskMenuSkinlet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
#include "QskGraphic.h"
#include "QskColorFilter.h"
#include "QskTextOptions.h"
#include "QskSGNode.h"
#include "QskFunctions.h"
#include "QskMargins.h"
#include "QskFunctions.h"
#include "QskLabelData.h"

#include "QskSGNode.h"
#include "QskSlideInNode.h"

#include <qfontmetrics.h>
#include <qmath.h>

Expand Down Expand Up @@ -209,11 +211,44 @@ QskMenuSkinlet::QskMenuSkinlet( QskSkin* skin )
: Inherited( skin )
, m_data( new PrivateData() )
{
appendNodeRoles( { PanelRole } );
appendNodeRoles( { ContentsRole, PanelRole } );
}

QskMenuSkinlet::~QskMenuSkinlet() = default;

QSGNode* QskMenuSkinlet::updateSubNode(
const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const
{
switch ( nodeRole )
{
case ContentsRole:
{
/*
QskSlideInNode works for controls made of nodes - not for
containers of other quick items. TODO ...
*/

const auto popup = static_cast< const QskPopup* >( skinnable );

auto rect = popup->contentsRect();
if ( rect.isEmpty() )
return nullptr;

auto slideInNode = QskSGNode::ensureNode< QskSlideInNode >( node );

const auto progress = popup->metric( popup->faderAspect() );
slideInNode->updateTranslation( rect, Qt::TopEdge, progress );

auto contentsNode = updateContentsNode( popup, slideInNode->contentsNode() );
slideInNode->setContentsNode( contentsNode );

return slideInNode;
}
}

return Inherited::updateSubNode( skinnable, nodeRole, node );
}

QRectF QskMenuSkinlet::cursorRect(
const QskSkinnable* skinnable, const QRectF& contentsRect, int index ) const
{
Expand Down Expand Up @@ -407,7 +442,8 @@ QskAspect::States QskMenuSkinlet::sampleStates(
}
}

const auto cursorPos = menu->effectiveSkinHint( Q::Segment | Q::Hovered | A::Metric | A::Position ).toPointF();
const auto cursorPos = menu->effectiveSkinHint(
Q::Segment | Q::Hovered | A::Metric | A::Position ).toPointF();

if( !cursorPos.isNull() && menu->indexAtPosition( cursorPos ) == index )
{
Expand Down
9 changes: 7 additions & 2 deletions src/controls/QskMenuSkinlet.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class QSK_EXPORT QskMenuSkinlet : public QskPopupSkinlet
public:
enum NodeRole
{
PanelRole = QskPopupSkinlet::RoleCount,
ContentsRole = Inherited::RoleCount,
PanelRole,

RoleCount
};

Expand Down Expand Up @@ -48,7 +50,10 @@ class QSK_EXPORT QskMenuSkinlet : public QskPopupSkinlet
Qt::SizeHint, const QSizeF& ) const override;

protected:
QSGNode* updateContentsNode( const QskPopup*, QSGNode* ) const override;
QSGNode* updateSubNode( const QskSkinnable*,
quint8 nodeRole, QSGNode* ) const override;

QSGNode* updateContentsNode( const QskPopup*, QSGNode* ) const;
QSGNode* updateMenuNode( const QskSkinnable*, QSGNode* ) const;

QSGNode* updateSampleNode( const QskSkinnable*,
Expand Down
138 changes: 1 addition & 137 deletions src/controls/QskPopupSkinlet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,108 +5,11 @@

#include "QskPopupSkinlet.h"
#include "QskPopup.h"
#include "QskSGNode.h"

#include <qtransform.h>
#include <qsgnode.h>
#include <qquickwindow.h>

namespace
{
class RootNode : public QSGNode
{
public:
~RootNode() override
{
delete m_clipNode;
delete m_transformNode;
delete m_contentsNode;
}

void setClipRect( const QRectF& rect )
{
if ( m_clipNode == nullptr )
{
m_clipNode = new QSGClipNode();
m_clipNode->setFlag( QSGNode::OwnedByParent, false );
m_clipNode->setIsRectangular( true );
}

m_clipNode->setClipRect( rect );
}

void resetClip()
{
delete m_clipNode;
m_clipNode = nullptr;
}

void setTranslation( qreal dx, qreal dy )
{
if ( dx != 0.0 || dy != 0.0 )
{
if ( m_transformNode == nullptr )
{
m_transformNode = new QSGTransformNode();
m_transformNode->setFlag( QSGNode::OwnedByParent, false );
}

QTransform transform;
transform.translate( dx, dy );

m_transformNode->setMatrix( transform );
}
else
{
delete m_transformNode;
m_transformNode = nullptr;
}
}

void setContentsNode( QSGNode* contentsNode )
{
if ( m_contentsNode != contentsNode )
{
if ( contentsNode )
contentsNode->setFlag( QSGNode::OwnedByParent, false );

delete m_contentsNode;
m_contentsNode = contentsNode;
}
}

void rearrangeNodes()
{
const std::initializer_list< QSGNode* > nodes =
{ m_clipNode, m_transformNode, m_contentsNode };

QSGNode* parentNode = this;
for ( auto node : nodes )
{
if ( node )
{
QskSGNode::setParentNode( node, parentNode );
parentNode = node;
}
}
}

inline QSGNode* contentsNode()
{
return m_contentsNode;
}

private:
QSGClipNode* m_clipNode = nullptr;
QSGTransformNode* m_transformNode = nullptr;
QSGNode* m_contentsNode = nullptr;
};
}

QskPopupSkinlet::QskPopupSkinlet( QskSkin* skin )
: Inherited( skin )
{
appendNodeRoles( { OverlayRole, ContentsRole } );
appendNodeRoles( { OverlayRole } );
}

QskPopupSkinlet::~QskPopupSkinlet() = default;
Expand All @@ -131,48 +34,9 @@ QSGNode* QskPopupSkinlet::updateSubNode(
{
case OverlayRole:
return updateBoxNode( skinnable, node, QskPopup::Overlay );

case ContentsRole:
return updateExtraNode( popup, node );
}

return Inherited::updateSubNode( skinnable, nodeRole, node );
}

QSGNode* QskPopupSkinlet::updateExtraNode( const QskPopup* popup, QSGNode* node ) const
{
auto cr = popup->contentsRect();
if ( cr.isEmpty() )
return nullptr;

auto rootNode = QskSGNode::ensureNode< RootNode >( node );

const auto faderProgress = popup->metric( popup->faderAspect() );
if ( faderProgress > 0.0 && faderProgress <= 1.0 )
{
auto clipRect = QRectF( popup->mapFromScene( QPointF() ), popup->window()->size() );
clipRect.setTop( cr.top() );

rootNode->setClipRect( clipRect );
}
else
{
rootNode->resetClip();
}

rootNode->setTranslation( 0.0, -faderProgress * cr.height() );

auto contentsNode = updateContentsNode( popup, rootNode->contentsNode() );
rootNode->setContentsNode( contentsNode );

rootNode->rearrangeNodes();

return rootNode;
}

QSGNode* QskPopupSkinlet::updateContentsNode( const QskPopup*, QSGNode* ) const
{
return nullptr;
}

#include "moc_QskPopupSkinlet.cpp"
5 changes: 0 additions & 5 deletions src/controls/QskPopupSkinlet.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class QSK_EXPORT QskPopupSkinlet : public QskSkinlet
enum NodeRole
{
OverlayRole,
ContentsRole,

RoleCount
};

Expand All @@ -35,10 +33,7 @@ class QSK_EXPORT QskPopupSkinlet : public QskSkinlet
QSGNode* updateSubNode( const QskSkinnable*,
quint8 nodeRole, QSGNode* ) const override;

virtual QSGNode* updateContentsNode( const QskPopup*, QSGNode* ) const;

private:
QSGNode* updateExtraNode( const QskPopup*, QSGNode* ) const;
QSGNode* updateOverlayNode( const QskPopup*, QSGNode* ) const;
};

Expand Down
Loading

0 comments on commit 3ecd8f3

Please sign in to comment.