suing QskMenu::Segement instead of Qskmenu::Cell to be in line with other
controls
This commit is contained in:
parent
22060f6aaf
commit
e689575510
@ -247,9 +247,9 @@ void Editor::setupMenu()
|
|||||||
setBoxBorderMetrics( Q::Separator, 0 );
|
setBoxBorderMetrics( Q::Separator, 0 );
|
||||||
setGradient( Q::Separator, m_pal.darker125 );
|
setGradient( Q::Separator, m_pal.darker125 );
|
||||||
|
|
||||||
setPadding( Q::Cell, QskMargins( 2, 10, 2, 10 ) );
|
setPadding( Q::Segment, QskMargins( 2, 10, 2, 10 ) );
|
||||||
setSpacing( Q::Cell, 5 );
|
setSpacing( Q::Segment, 5 );
|
||||||
setGradient( Q::Cell, Qt::transparent );
|
setGradient( Q::Segment, Qt::transparent );
|
||||||
|
|
||||||
setGradient( Q::Cursor, m_pal.accentColor );
|
setGradient( Q::Cursor, m_pal.accentColor );
|
||||||
|
|
||||||
|
@ -346,9 +346,9 @@ void Editor::setupMenu()
|
|||||||
setMetric( Q::Separator | A::Size, qskDpiScaled( 2 ) );
|
setMetric( Q::Separator | A::Size, qskDpiScaled( 2 ) );
|
||||||
setSeparator( Q::Separator | A::Horizontal );
|
setSeparator( Q::Separator | A::Horizontal );
|
||||||
|
|
||||||
setPadding( Q::Cell, QskMargins( 2, 10, 2, 10 ) );
|
setPadding( Q::Segment, QskMargins( 2, 10, 2, 10 ) );
|
||||||
setSpacing( Q::Cell, 5 );
|
setSpacing( Q::Segment, 5 );
|
||||||
setGradient( Q::Cell, Qt::transparent );
|
setGradient( Q::Segment, Qt::transparent );
|
||||||
|
|
||||||
setGradient( Q::Cursor, m_pal.highlighted );
|
setGradient( Q::Cursor, m_pal.highlighted );
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
#include <qeventloop.h>
|
#include <qeventloop.h>
|
||||||
|
|
||||||
QSK_SUBCONTROL( QskMenu, Panel )
|
QSK_SUBCONTROL( QskMenu, Panel )
|
||||||
QSK_SUBCONTROL( QskMenu, Cell )
|
QSK_SUBCONTROL( QskMenu, Segment )
|
||||||
QSK_SUBCONTROL( QskMenu, Cursor )
|
QSK_SUBCONTROL( QskMenu, Cursor )
|
||||||
QSK_SUBCONTROL( QskMenu, Text )
|
QSK_SUBCONTROL( QskMenu, Text )
|
||||||
QSK_SUBCONTROL( QskMenu, Graphic )
|
QSK_SUBCONTROL( QskMenu, Graphic )
|
||||||
@ -30,8 +30,11 @@ namespace
|
|||||||
: graphicSource( graphicSource )
|
: graphicSource( graphicSource )
|
||||||
, text( text )
|
, text( text )
|
||||||
{
|
{
|
||||||
|
#if 1
|
||||||
|
// lazy loading TODO ...
|
||||||
if( !graphicSource.isEmpty() )
|
if( !graphicSource.isEmpty() )
|
||||||
graphic = Qsk::loadGraphic( graphicSource );
|
graphic = Qsk::loadGraphic( graphicSource );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QUrl graphicSource;
|
QUrl graphicSource;
|
||||||
@ -287,19 +290,16 @@ void QskMenu::traverse( int steps )
|
|||||||
if ( newIndex < 0 )
|
if ( newIndex < 0 )
|
||||||
newIndex += count();
|
newIndex += count();
|
||||||
|
|
||||||
if ( hasAnimationHint( Cursor | QskAspect::Position | QskAspect::Metric ) )
|
// when cycling we want slide in
|
||||||
{
|
|
||||||
// when cycling we want slide in
|
|
||||||
|
|
||||||
if ( index < 0 )
|
int startIndex = m_data->currentIndex;
|
||||||
setPositionHint( Cursor, count() );
|
|
||||||
|
|
||||||
if ( index >= count() )
|
if ( index < 0 )
|
||||||
setPositionHint( Cursor, -1 );
|
startIndex = count();
|
||||||
|
else if ( index >= count() )
|
||||||
movePositionHint( Cursor, newIndex );
|
startIndex = -1;
|
||||||
}
|
|
||||||
|
|
||||||
|
movePositionHint( Cursor, startIndex, newIndex );
|
||||||
setCurrentIndex( newIndex );
|
setCurrentIndex( newIndex );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,13 +374,13 @@ void QskMenu::setSelectedIndex( int index )
|
|||||||
QRectF QskMenu::cellRect( int index ) const
|
QRectF QskMenu::cellRect( int index ) const
|
||||||
{
|
{
|
||||||
return effectiveSkinlet()->sampleRect(
|
return effectiveSkinlet()->sampleRect(
|
||||||
this, contentsRect(), QskMenu::Cell, index );
|
this, contentsRect(), QskMenu::Segment, index );
|
||||||
}
|
}
|
||||||
|
|
||||||
int QskMenu::indexAtPosition( const QPointF& pos ) const
|
int QskMenu::indexAtPosition( const QPointF& pos ) const
|
||||||
{
|
{
|
||||||
return effectiveSkinlet()->sampleIndexAt(
|
return effectiveSkinlet()->sampleIndexAt(
|
||||||
this, contentsRect(), QskMenu::Cell, pos );
|
this, contentsRect(), QskMenu::Segment, pos );
|
||||||
}
|
}
|
||||||
|
|
||||||
int QskMenu::exec()
|
int QskMenu::exec()
|
||||||
|
@ -32,7 +32,7 @@ class QSK_EXPORT QskMenu : public QskPopup
|
|||||||
using Inherited = QskPopup;
|
using Inherited = QskPopup;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QSK_SUBCONTROLS( Panel, Cell, Cursor, Text, Graphic, Separator )
|
QSK_SUBCONTROLS( Panel, Segment, Cursor, Text, Graphic, Separator )
|
||||||
QSK_STATES( Selected )
|
QSK_STATES( Selected )
|
||||||
|
|
||||||
QskMenu( QQuickItem* parentItem = nullptr );
|
QskMenu( QQuickItem* parentItem = nullptr );
|
||||||
@ -45,7 +45,7 @@ class QSK_EXPORT QskMenu : public QskPopup
|
|||||||
void setOrigin( const QPointF& );
|
void setOrigin( const QPointF& );
|
||||||
QPointF origin() const;
|
QPointF origin() const;
|
||||||
|
|
||||||
void setTextOptions( const QskTextOptions& textOptions );
|
void setTextOptions( const QskTextOptions& );
|
||||||
QskTextOptions textOptions() const;
|
QskTextOptions textOptions() const;
|
||||||
|
|
||||||
// insert, remove, functors, actions, QskGraphic ...
|
// insert, remove, functors, actions, QskGraphic ...
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
#include <QskTextOptions.h>
|
#include <QskTextOptions.h>
|
||||||
#include <QskSGNode.h>
|
#include <QskSGNode.h>
|
||||||
#include <QskFunctions.h>
|
#include <QskFunctions.h>
|
||||||
#include <QskSkinStateChanger.h>
|
|
||||||
#include <QskMargins.h>
|
#include <QskMargins.h>
|
||||||
#include <QskFunctions.h>
|
#include <QskFunctions.h>
|
||||||
|
|
||||||
@ -60,7 +59,7 @@ class QskMenuSkinlet::PrivateData
|
|||||||
void enableCache( bool on )
|
void enableCache( bool on )
|
||||||
{
|
{
|
||||||
m_isCaching = on;
|
m_isCaching = on;
|
||||||
m_cellHeight = m_cellWidth = m_graphicWidth = m_textWidth = -1.0;
|
m_segmentHeight = m_segmentWidth = m_graphicWidth = m_textWidth = -1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int separatorsBefore( const QskMenu* menu, int index ) const
|
inline int separatorsBefore( const QskMenu* menu, int index ) const
|
||||||
@ -101,30 +100,30 @@ class QskMenuSkinlet::PrivateData
|
|||||||
return textWidthInternal( menu );
|
return textWidthInternal( menu );
|
||||||
}
|
}
|
||||||
|
|
||||||
inline qreal cellWidth( const QskMenu* menu ) const
|
inline qreal segmentWidth( const QskMenu* menu ) const
|
||||||
{
|
{
|
||||||
if ( m_isCaching )
|
if ( m_isCaching )
|
||||||
{
|
{
|
||||||
if ( m_cellWidth < 0.0 )
|
if ( m_segmentWidth < 0.0 )
|
||||||
m_cellWidth = cellWidthInternal( menu );
|
m_segmentWidth = segmentWidthInternal( menu );
|
||||||
|
|
||||||
return m_cellWidth;
|
return m_segmentWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cellWidthInternal( menu );
|
return segmentWidthInternal( menu );
|
||||||
}
|
}
|
||||||
|
|
||||||
inline qreal cellHeight( const QskMenu* menu ) const
|
inline qreal segmentHeight( const QskMenu* menu ) const
|
||||||
{
|
{
|
||||||
if ( m_isCaching )
|
if ( m_isCaching )
|
||||||
{
|
{
|
||||||
if ( m_cellHeight < 0.0 )
|
if ( m_segmentHeight < 0.0 )
|
||||||
m_cellHeight = cellHeightInternal( menu );
|
m_segmentHeight = segmentHeightInternal( menu );
|
||||||
|
|
||||||
return m_cellHeight;
|
return m_segmentHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cellHeightInternal( menu );
|
return segmentHeightInternal( menu );
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -182,33 +181,33 @@ class QskMenuSkinlet::PrivateData
|
|||||||
return maxWidth;
|
return maxWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal cellWidthInternal( const QskMenu* menu ) const
|
qreal segmentWidthInternal( const QskMenu* menu ) const
|
||||||
{
|
{
|
||||||
using Q = QskMenu;
|
using Q = QskMenu;
|
||||||
|
|
||||||
const auto spacing = menu->spacingHint( Q::Cell );
|
const auto spacing = menu->spacingHint( Q::Segment );
|
||||||
const auto padding = menu->paddingHint( Q::Cell );
|
const auto padding = menu->paddingHint( Q::Segment );
|
||||||
|
|
||||||
auto w = graphicWidth( menu ) + spacing + textWidth( menu );
|
auto w = graphicWidth( menu ) + spacing + textWidth( menu );
|
||||||
|
|
||||||
w += padding.left() + padding.right();
|
w += padding.left() + padding.right();
|
||||||
|
|
||||||
const auto minWidth = menu->strutSizeHint( Q::Cell ).width();
|
const auto minWidth = menu->strutSizeHint( Q::Segment ).width();
|
||||||
return qMax( w, minWidth );
|
return qMax( w, minWidth );
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal cellHeightInternal( const QskMenu* menu ) const
|
qreal segmentHeightInternal( const QskMenu* menu ) const
|
||||||
{
|
{
|
||||||
using Q = QskMenu;
|
using Q = QskMenu;
|
||||||
|
|
||||||
const auto graphicHeight = menu->strutSizeHint( Q::Graphic ).height();
|
const auto graphicHeight = menu->strutSizeHint( Q::Graphic ).height();
|
||||||
const auto textHeight = menu->effectiveFontHeight( Q::Text );
|
const auto textHeight = menu->effectiveFontHeight( Q::Text );
|
||||||
const auto padding = menu->paddingHint( Q::Cell );
|
const auto padding = menu->paddingHint( Q::Segment );
|
||||||
|
|
||||||
qreal h = qMax( graphicHeight, textHeight );
|
qreal h = qMax( graphicHeight, textHeight );
|
||||||
h += padding.top() + padding.bottom();
|
h += padding.top() + padding.bottom();
|
||||||
|
|
||||||
const auto minHeight = menu->strutSizeHint( Q::Cell ).height();
|
const auto minHeight = menu->strutSizeHint( Q::Segment ).height();
|
||||||
h = qMax( h, minHeight );
|
h = qMax( h, minHeight );
|
||||||
|
|
||||||
return h;
|
return h;
|
||||||
@ -218,8 +217,8 @@ class QskMenuSkinlet::PrivateData
|
|||||||
|
|
||||||
mutable qreal m_graphicWidth = -1.0;
|
mutable qreal m_graphicWidth = -1.0;
|
||||||
mutable qreal m_textWidth = -1.0;
|
mutable qreal m_textWidth = -1.0;
|
||||||
mutable qreal m_cellHeight = -1.0;
|
mutable qreal m_segmentHeight = -1.0;
|
||||||
mutable qreal m_cellWidth = -1.0;
|
mutable qreal m_segmentWidth = -1.0;
|
||||||
};
|
};
|
||||||
|
|
||||||
QskMenuSkinlet::QskMenuSkinlet( QskSkin* skin )
|
QskMenuSkinlet::QskMenuSkinlet( QskSkin* skin )
|
||||||
@ -234,10 +233,10 @@ QskMenuSkinlet::~QskMenuSkinlet() = default;
|
|||||||
QRectF QskMenuSkinlet::cursorRect(
|
QRectF QskMenuSkinlet::cursorRect(
|
||||||
const QskSkinnable* skinnable, const QRectF& contentsRect, int index ) const
|
const QskSkinnable* skinnable, const QRectF& contentsRect, int index ) const
|
||||||
{
|
{
|
||||||
const auto count = sampleCount( skinnable, QskMenu::Cell );
|
const auto count = sampleCount( skinnable, QskMenu::Segment );
|
||||||
|
|
||||||
auto rect = sampleRect( skinnable, contentsRect,
|
auto rect = sampleRect( skinnable, contentsRect,
|
||||||
QskMenu::Cell, qBound( 0, index, count ) );
|
QskMenu::Segment, qBound( 0, index, count ) );
|
||||||
|
|
||||||
if ( index < 0 )
|
if ( index < 0 )
|
||||||
rect.setBottom( rect.top() );
|
rect.setBottom( rect.top() );
|
||||||
@ -295,11 +294,11 @@ QRectF QskMenuSkinlet::sampleRect(
|
|||||||
|
|
||||||
const auto menu = static_cast< const QskMenu* >( skinnable );
|
const auto menu = static_cast< const QskMenu* >( skinnable );
|
||||||
|
|
||||||
if ( subControl == Q::Cell )
|
if ( subControl == Q::Segment )
|
||||||
{
|
{
|
||||||
const auto r = menu->subControlContentsRect( Q::Panel );
|
const auto r = menu->subControlContentsRect( Q::Panel );
|
||||||
|
|
||||||
auto h = m_data->cellHeight( menu );
|
auto h = m_data->segmentHeight( menu );
|
||||||
|
|
||||||
if ( int n = m_data->separatorsBefore( menu, index ) )
|
if ( int n = m_data->separatorsBefore( menu, index ) )
|
||||||
{
|
{
|
||||||
@ -314,7 +313,7 @@ QRectF QskMenuSkinlet::sampleRect(
|
|||||||
|
|
||||||
if ( subControl == QskMenu::Graphic || subControl == QskMenu::Text )
|
if ( subControl == QskMenu::Graphic || subControl == QskMenu::Text )
|
||||||
{
|
{
|
||||||
const auto r = sampleRect( menu, contentsRect, Q::Cell, index );
|
const auto r = sampleRect( menu, contentsRect, Q::Segment, index );
|
||||||
const auto graphicWidth = m_data->graphicWidth( menu );
|
const auto graphicWidth = m_data->graphicWidth( menu );
|
||||||
|
|
||||||
if ( subControl == QskMenu::Graphic )
|
if ( subControl == QskMenu::Graphic )
|
||||||
@ -330,7 +329,7 @@ QRectF QskMenuSkinlet::sampleRect(
|
|||||||
|
|
||||||
if ( graphicWidth > 0.0 )
|
if ( graphicWidth > 0.0 )
|
||||||
{
|
{
|
||||||
const auto spacing = skinnable->spacingHint( Q::Cell );
|
const auto spacing = skinnable->spacingHint( Q::Segment );
|
||||||
textRect.setX( r.x() + graphicWidth + spacing );
|
textRect.setX( r.x() + graphicWidth + spacing );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -348,8 +347,8 @@ QRectF QskMenuSkinlet::sampleRect(
|
|||||||
|
|
||||||
if ( pos < menu->count() )
|
if ( pos < menu->count() )
|
||||||
{
|
{
|
||||||
const auto cellRect = sampleRect( skinnable, contentsRect, Q::Cell, pos );
|
const auto segmentRect = sampleRect( skinnable, contentsRect, Q::Segment, pos );
|
||||||
r.setBottom( cellRect.top() ); // spacing ???
|
r.setBottom( segmentRect.top() ); // spacing ???
|
||||||
}
|
}
|
||||||
|
|
||||||
const qreal h = menu->metric( Q::Separator | QskAspect::Size );
|
const qreal h = menu->metric( Q::Separator | QskAspect::Size );
|
||||||
@ -375,7 +374,7 @@ int QskMenuSkinlet::sampleCount(
|
|||||||
{
|
{
|
||||||
using Q = QskMenu;
|
using Q = QskMenu;
|
||||||
|
|
||||||
if ( subControl == Q::Cell || subControl == Q::Graphic || subControl == Q::Text )
|
if ( subControl == Q::Segment || subControl == Q::Graphic || subControl == Q::Text )
|
||||||
{
|
{
|
||||||
const auto menu = static_cast< const QskMenu* >( skinnable );
|
const auto menu = static_cast< const QskMenu* >( skinnable );
|
||||||
return menu->count();
|
return menu->count();
|
||||||
@ -397,7 +396,7 @@ QskAspect::States QskMenuSkinlet::sampleStates(
|
|||||||
|
|
||||||
auto states = Inherited::sampleStates( skinnable, subControl, index );
|
auto states = Inherited::sampleStates( skinnable, subControl, index );
|
||||||
|
|
||||||
if ( subControl == Q::Cell || subControl == Q::Graphic || subControl == Q::Text )
|
if ( subControl == Q::Segment || subControl == Q::Graphic || subControl == Q::Text )
|
||||||
{
|
{
|
||||||
const auto menu = static_cast< const QskMenu* >( skinnable );
|
const auto menu = static_cast< const QskMenu* >( skinnable );
|
||||||
if ( menu->currentIndex() == index )
|
if ( menu->currentIndex() == index )
|
||||||
@ -433,8 +432,8 @@ QSGNode* QskMenuSkinlet::updateContentsNode(
|
|||||||
QSGNode* QskMenuSkinlet::updateMenuNode(
|
QSGNode* QskMenuSkinlet::updateMenuNode(
|
||||||
const QskSkinnable* skinnable, QSGNode* contentsNode ) const
|
const QskSkinnable* skinnable, QSGNode* contentsNode ) const
|
||||||
{
|
{
|
||||||
enum { Panel, Cell, Cursor, Graphic, Text, Separator };
|
enum { Panel, Segment, Cursor, Graphic, Text, Separator };
|
||||||
static QVector< quint8 > roles = { Panel, Separator, Cell, Cursor, Graphic, Text };
|
static QVector< quint8 > roles = { Panel, Separator, Segment, Cursor, Graphic, Text };
|
||||||
|
|
||||||
if ( contentsNode == nullptr )
|
if ( contentsNode == nullptr )
|
||||||
contentsNode = new QSGNode();
|
contentsNode = new QSGNode();
|
||||||
@ -452,9 +451,9 @@ QSGNode* QskMenuSkinlet::updateMenuNode(
|
|||||||
newNode = updateBoxNode( skinnable, oldNode, QskMenu::Panel );
|
newNode = updateBoxNode( skinnable, oldNode, QskMenu::Panel );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Cell:
|
case Segment:
|
||||||
{
|
{
|
||||||
newNode = updateSeriesNode( skinnable, QskMenu::Cell, oldNode );
|
newNode = updateSeriesNode( skinnable, QskMenu::Segment, oldNode );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Cursor:
|
case Cursor:
|
||||||
@ -494,7 +493,7 @@ QSGNode* QskMenuSkinlet::updateSampleNode( const QskSkinnable* skinnable,
|
|||||||
|
|
||||||
const auto rect = sampleRect( menu, menu->contentsRect(), subControl, index );
|
const auto rect = sampleRect( menu, menu->contentsRect(), subControl, index );
|
||||||
|
|
||||||
if ( subControl == Q::Cell )
|
if ( subControl == Q::Segment )
|
||||||
{
|
{
|
||||||
return updateBoxNode( menu, node, rect, subControl );
|
return updateBoxNode( menu, node, rect, subControl );
|
||||||
}
|
}
|
||||||
@ -522,7 +521,7 @@ QSGNode* QskMenuSkinlet::updateSampleNode( const QskSkinnable* skinnable,
|
|||||||
subControl, Qt::AlignVCenter | Qt::AlignLeft );
|
subControl, Qt::AlignVCenter | Qt::AlignLeft );
|
||||||
|
|
||||||
return QskSkinlet::updateTextNode( menu, node, rect, alignment,
|
return QskSkinlet::updateTextNode( menu, node, rect, alignment,
|
||||||
text, QskTextOptions(), Q::Text );
|
text, menu->textOptions(), Q::Text );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( subControl == Q::Separator )
|
if ( subControl == Q::Separator )
|
||||||
@ -547,10 +546,10 @@ QSizeF QskMenuSkinlet::sizeHint( const QskSkinnable* skinnable,
|
|||||||
qreal w = 0.0;
|
qreal w = 0.0;
|
||||||
qreal h = 0.0;
|
qreal h = 0.0;
|
||||||
|
|
||||||
if ( const auto count = sampleCount( skinnable, Q::Cell ) )
|
if ( const auto count = sampleCount( skinnable, Q::Segment ) )
|
||||||
{
|
{
|
||||||
w = m_data->cellWidth( menu );
|
w = m_data->segmentWidth( menu );
|
||||||
h = count * m_data->cellHeight( menu );
|
h = count * m_data->segmentHeight( menu );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( const auto count = sampleCount( skinnable, Q::Separator ) )
|
if ( const auto count = sampleCount( skinnable, Q::Separator ) )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user