QskListView updates needed for M3 skins
This commit is contained in:
parent
23f970650f
commit
c40457fbea
@ -1124,7 +1124,6 @@ void Editor::setupScrollView()
|
||||
using Q = QskScrollView;
|
||||
|
||||
setGradient( Q::Panel, m_pal.background );
|
||||
|
||||
setGradient( Q::Viewport, m_pal.secondaryContainer );
|
||||
|
||||
for ( auto subControl : { Q::HorizontalScrollBar, Q::VerticalScrollBar } )
|
||||
@ -1153,13 +1152,14 @@ void Editor::setupListView()
|
||||
{
|
||||
using Q = QskListView;
|
||||
|
||||
setStrutSize( Q::Cell, { -1, 56 } );
|
||||
setPadding( Q::Cell, { 16_dp, 12_dp, 16_dp, 12_dp } );
|
||||
setBoxBorderMetrics( Q::Cell, { 0, 0, 0, 1_dp } );
|
||||
setBoxBorderColors( Q::Cell, m_pal.outline );
|
||||
setColor( Q::Cell, m_pal.surface );
|
||||
setColor( Q::Cell | Q::Selected, m_pal.primary12 );
|
||||
|
||||
setColor( Q::Text, m_pal.onSurfaceVariant );
|
||||
setBoxBorderColors( Q::Cell, m_pal.outline );
|
||||
setGradient( Q::Cell, m_pal.surface );
|
||||
setGradient( Q::Cell | Q::Selected, m_pal.primary12 );
|
||||
|
||||
setColor( Q::Text, m_pal.onSurface );
|
||||
}
|
||||
|
||||
void Editor::setupSubWindow()
|
||||
|
@ -1041,18 +1041,20 @@ void Editor::setupScrollView()
|
||||
|
||||
void Editor::setupListView()
|
||||
{
|
||||
using A = QskAspect;
|
||||
using Q = QskListView;
|
||||
|
||||
// padding for each cell
|
||||
setPadding( Q::Cell, QskMargins( 4, 8 ) );
|
||||
|
||||
setColor( Q::Text, m_pal.themeForeground );
|
||||
setColor( Q::Cell, m_pal.contrasted );
|
||||
|
||||
// alternating row colors
|
||||
setColor( Q::Cell | A::Lower, Qt::white );
|
||||
setColor( Q::Cell | A::Upper, m_pal.contrasted );
|
||||
|
||||
setColor( Q::Cell | Q::Selected, m_pal.highlighted );
|
||||
setColor( Q::Text | Q::Selected, m_pal.highlightedText );
|
||||
|
||||
setFlag( Q::Cell | QskAspect::Style, true ); // alternating colors
|
||||
}
|
||||
|
||||
void Editor::setupSubWindow()
|
||||
|
@ -67,23 +67,6 @@ bool QskListView::preferredWidthFromColumns() const
|
||||
return m_data->preferredWidthFromColumns;
|
||||
}
|
||||
|
||||
void QskListView::setAlternatingRowColors( bool on )
|
||||
{
|
||||
if ( setFlagHint( Cell | QskAspect::Style, on ) )
|
||||
Q_EMIT alternatingRowColorsChanged();
|
||||
}
|
||||
|
||||
bool QskListView::alternatingRowColors() const
|
||||
{
|
||||
return flagHint< bool >( Cell | QskAspect::Style, false );
|
||||
}
|
||||
|
||||
void QskListView::resetAlternatingRowColors()
|
||||
{
|
||||
if ( resetSkinHint( Cell | QskAspect::Style ) )
|
||||
Q_EMIT alternatingRowColorsChanged();
|
||||
}
|
||||
|
||||
void QskListView::setTextOptions( const QskTextOptions& textOptions )
|
||||
{
|
||||
if ( setTextOptionsHint( Text, textOptions ) )
|
||||
|
@ -13,10 +13,6 @@ class QSK_EXPORT QskListView : public QskScrollView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY( bool alternatingRowColors READ alternatingRowColors
|
||||
WRITE setAlternatingRowColors RESET resetAlternatingRowColors
|
||||
NOTIFY alternatingRowColorsChanged FINAL )
|
||||
|
||||
Q_PROPERTY( SelectionMode selectionMode READ selectionMode
|
||||
WRITE setSelectionMode NOTIFY selectionModeChanged FINAL )
|
||||
|
||||
@ -50,10 +46,6 @@ class QSK_EXPORT QskListView : public QskScrollView
|
||||
void setPreferredWidthFromColumns( bool );
|
||||
bool preferredWidthFromColumns() const;
|
||||
|
||||
void setAlternatingRowColors( bool );
|
||||
void resetAlternatingRowColors();
|
||||
bool alternatingRowColors() const;
|
||||
|
||||
void setSelectionMode( SelectionMode );
|
||||
SelectionMode selectionMode() const;
|
||||
|
||||
@ -84,7 +76,6 @@ class QSK_EXPORT QskListView : public QskScrollView
|
||||
void selectedRowChanged( int row );
|
||||
|
||||
void selectionModeChanged();
|
||||
void alternatingRowColorsChanged();
|
||||
void preferredWidthFromColumnsChanged();
|
||||
void textOptionsChanged();
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "QskColorFilter.h"
|
||||
#include "QskGraphic.h"
|
||||
#include "QskBoxHints.h"
|
||||
#include "QskSGNode.h"
|
||||
#include "QskSkinStateChanger.h"
|
||||
|
||||
@ -113,32 +114,39 @@ void QskListViewSkinlet::updateBackgroundNodes(
|
||||
const QskListView* listView, QskListViewNode* listViewNode ) const
|
||||
{
|
||||
using Q = QskListView;
|
||||
using A = QskAspect;
|
||||
|
||||
QSGNode* backgroundNode = listViewNode->backgroundNode();
|
||||
auto backgroundNode = listViewNode->backgroundNode();
|
||||
|
||||
const qreal cellHeight = listView->rowHeight();
|
||||
const auto cellHeight = listView->rowHeight();
|
||||
const auto viewRect = listView->viewContentsRect();
|
||||
|
||||
const QPointF scrolledPos = listView->scrollPos();
|
||||
const auto scrolledPos = listView->scrollPos();
|
||||
const int rowMin = qFloor( scrolledPos.y() / cellHeight );
|
||||
|
||||
int rowMax = qCeil( ( scrolledPos.y() + viewRect.height() ) / cellHeight );
|
||||
if ( rowMax >= listView->rowCount() )
|
||||
rowMax = listView->rowCount() - 1;
|
||||
|
||||
const int rowSelected = listView->selectedRow();
|
||||
const auto x0 = viewRect.left() + scrolledPos.x();
|
||||
const auto y0 = viewRect.top();
|
||||
|
||||
auto rowNode = backgroundNode->firstChild();
|
||||
|
||||
if ( listView->alternatingRowColors() )
|
||||
{
|
||||
const auto boxHints1 = listView->boxHints( Q::Cell | A::Lower );
|
||||
const auto boxHints2 = listView->boxHints( Q::Cell | A::Upper );
|
||||
|
||||
for ( int row = rowMin; row <= rowMax; row++ )
|
||||
{
|
||||
if ( row % 2 )
|
||||
{
|
||||
const auto rect = sampleRect( listView, listView->contentsRect(), Q::Cell, row );
|
||||
/*
|
||||
We do not use sampleRect to avoid doing the calculation
|
||||
of viewRect for each row.
|
||||
*/
|
||||
const QRectF rect( x0, y0 + row * cellHeight, viewRect.width(), cellHeight );
|
||||
|
||||
auto newNode = updateBoxNode( listView, rowNode, rect,
|
||||
( row % 2 ) ? boxHints2 : boxHints1 );
|
||||
|
||||
auto newNode = updateBoxNode( listView, rowNode, rect, Q::Cell );
|
||||
if ( newNode )
|
||||
{
|
||||
if ( newNode->parent() != backgroundNode )
|
||||
@ -147,15 +155,15 @@ void QskListViewSkinlet::updateBackgroundNodes(
|
||||
rowNode = newNode->nextSibling();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const int rowSelected = listView->selectedRow();
|
||||
if ( rowSelected >= rowMin && rowSelected <= rowMax )
|
||||
{
|
||||
QskSkinStateChanger stateChanger( listView );
|
||||
stateChanger.setStates( listView->skinStates() | QskListView::Selected );
|
||||
|
||||
const auto rect = sampleRect( listView, listView->contentsRect(), Q::Cell, rowSelected );
|
||||
const QRectF rect( x0, y0 + rowSelected * cellHeight,
|
||||
viewRect.width(), cellHeight );
|
||||
|
||||
rowNode = updateBoxNode( listView, rowNode, rect, Q::Cell );
|
||||
if ( rowNode && rowNode->parent() != backgroundNode )
|
||||
@ -239,8 +247,8 @@ void QskListViewSkinlet::updateForegroundNodes(
|
||||
// finally putting the nodes into their position
|
||||
auto node = parentNode->firstChild();
|
||||
|
||||
const qreal rowHeight = listView->rowHeight();
|
||||
qreal y = cr.top() + rowMin * rowHeight;
|
||||
const auto rowHeight = listView->rowHeight();
|
||||
auto y = cr.top() + rowMin * rowHeight;
|
||||
|
||||
for ( int row = rowMin; row <= rowMax; row++ )
|
||||
{
|
||||
@ -286,11 +294,11 @@ void QskListViewSkinlet::updateVisibleForegroundNodes(
|
||||
|
||||
for ( int row = rowMin; row <= rowMax; row++ )
|
||||
{
|
||||
const qreal h = listView->rowHeight() - ( margins.top() + margins.bottom() );
|
||||
const auto h = listView->rowHeight() - ( margins.top() + margins.bottom() );
|
||||
|
||||
for ( int col = 0; col < listView->columnCount(); col++ )
|
||||
{
|
||||
const qreal w = listView->columnWidth( col ) - ( margins.left() + margins.right() );
|
||||
const auto w = listView->columnWidth( col ) - ( margins.left() + margins.right() );
|
||||
|
||||
node = updateForegroundNode( listView,
|
||||
parentNode, static_cast< QSGTransformNode* >( node ),
|
||||
@ -313,7 +321,7 @@ void QskListViewSkinlet::updateVisibleForegroundNodes(
|
||||
|
||||
for ( int col = listView->columnCount() - 1; col >= 0; col-- )
|
||||
{
|
||||
const qreal w = listView->columnWidth( col ) - ( margins.left() + margins.right() );
|
||||
const auto w = listView->columnWidth( col ) - ( margins.left() + margins.right() );
|
||||
|
||||
node = updateForegroundNode( listView,
|
||||
parentNode, static_cast< QSGTransformNode* >( node ),
|
||||
@ -501,8 +509,7 @@ QRectF QskListViewSkinlet::sampleRect( const QskSkinnable* skinnable,
|
||||
const double x0 = viewRect.left() + scrolledPos.x();
|
||||
const double y0 = viewRect.top();
|
||||
|
||||
const QRectF rect( x0, y0 + index * cellHeight, viewRect.width(), cellHeight );
|
||||
return rect;
|
||||
return QRectF( x0, y0 + index * cellHeight, viewRect.width(), cellHeight );
|
||||
}
|
||||
|
||||
return Inherited::sampleRect( skinnable, contentsRect, subControl, index );
|
||||
|
@ -48,7 +48,6 @@ class QskScrollView::PrivateData
|
||||
qSwap( oldStates, newStates );
|
||||
|
||||
scrollView->startHintTransitions( { subControl }, oldStates, newStates );
|
||||
|
||||
}
|
||||
|
||||
Qt::ScrollBarPolicy horizontalScrollBarPolicy = Qt::ScrollBarAsNeeded;
|
||||
@ -122,11 +121,10 @@ QskAspect::States QskScrollView::scrollHandleStates( Qt::Orientation orientation
|
||||
|
||||
QRectF QskScrollView::viewContentsRect() const
|
||||
{
|
||||
// This code should be done in the skinlet. TODO ...
|
||||
const qreal bw = boxBorderMetricsHint( Viewport ).widthAt( Qt::TopEdge );
|
||||
const auto borderMetrics = boxBorderMetricsHint( Viewport );
|
||||
|
||||
const QRectF r = subControlRect( Viewport );
|
||||
return r.adjusted( bw, bw, -bw, -bw );
|
||||
return r.marginsRemoved( borderMetrics.widths() );
|
||||
}
|
||||
|
||||
void QskScrollView::mousePressEvent( QMouseEvent* event )
|
||||
|
@ -123,9 +123,13 @@ QSGNode* QskScrollViewSkinlet::updateSubNode(
|
||||
}
|
||||
|
||||
case HorizontalScrollBarRole:
|
||||
{
|
||||
return updateBoxNode( skinnable, node, Q::HorizontalScrollBar );
|
||||
}
|
||||
|
||||
case VerticalScrollBarRole:
|
||||
{
|
||||
return nullptr;
|
||||
return updateBoxNode( skinnable, node, Q::VerticalScrollBar );
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user