optional QskTextLabel::Panel added
This commit is contained in:
parent
de36bf5371
commit
f8c04461a3
|
@ -19,12 +19,17 @@ class TextBox : public QskLinearBox
|
||||||
TextBox( QQuickItem* parent = nullptr )
|
TextBox( QQuickItem* parent = nullptr )
|
||||||
: QskLinearBox( Qt::Vertical, 3, parent )
|
: QskLinearBox( Qt::Vertical, 3, parent )
|
||||||
{
|
{
|
||||||
|
setMargins( 10 );
|
||||||
|
setDefaultAlignment( Qt::AlignTop );
|
||||||
|
setExtraSpacingAt( Qt::BottomEdge );
|
||||||
|
|
||||||
const QStringList texts =
|
const QStringList texts =
|
||||||
{ "Default", "Tiny", "Small", "Medium", "Large", "Huge" };
|
{ "Default", "Tiny", "Small", "Medium", "Large", "Huge" };
|
||||||
|
|
||||||
for ( int i = 0; i < texts.size(); i++ )
|
for ( int i = 0; i < texts.size(); i++ )
|
||||||
{
|
{
|
||||||
auto label = new QskTextLabel( texts[ i ] + " Font", this );
|
auto label = new QskTextLabel( texts[ i ] + " Font", this );
|
||||||
|
label->setPanel( true );
|
||||||
label->setFontRole( i );
|
label->setFontRole( i );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,12 +44,12 @@ int main( int argc, char* argv[] )
|
||||||
QGuiApplication app( argc, argv );
|
QGuiApplication app( argc, argv );
|
||||||
|
|
||||||
SkinnyFont::init( &app );
|
SkinnyFont::init( &app );
|
||||||
SkinnyShortcut::enable( SkinnyShortcut::Quit |
|
SkinnyShortcut::enable( SkinnyShortcut::AllShortcuts );
|
||||||
SkinnyShortcut::DebugShortcuts );
|
|
||||||
|
|
||||||
auto box = new TextBox();
|
auto box = new TextBox();
|
||||||
|
|
||||||
QskWindow window;
|
QskWindow window;
|
||||||
|
window.setColor( Qt::lightGray );
|
||||||
window.addItem( box );
|
window.addItem( box );
|
||||||
window.resize( box->sizeHint().toSize() );
|
window.resize( box->sizeHint().toSize() );
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include "QskMaterialSkin.h"
|
#include "QskMaterialSkin.h"
|
||||||
|
|
||||||
|
#include <QskBox.h>
|
||||||
#include <QskDialogButton.h>
|
#include <QskDialogButton.h>
|
||||||
#include <QskDialogButtonBox.h>
|
#include <QskDialogButtonBox.h>
|
||||||
#include <QskFocusIndicator.h>
|
#include <QskFocusIndicator.h>
|
||||||
|
@ -124,6 +125,7 @@ void QskMaterialSkin::initHints()
|
||||||
{
|
{
|
||||||
initCommonHints();
|
initCommonHints();
|
||||||
|
|
||||||
|
initBoxHints();
|
||||||
initDialogButtonBoxHints();
|
initDialogButtonBoxHints();
|
||||||
initDialogButtonHints();
|
initDialogButtonHints();
|
||||||
initFocusIndicatorHints();
|
initFocusIndicatorHints();
|
||||||
|
@ -167,6 +169,18 @@ void QskMaterialSkin::initCommonHints()
|
||||||
qskShadedColor( m_data->palette.textColor, 0.6 ) );
|
qskShadedColor( m_data->palette.textColor, 0.6 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QskMaterialSkin::initBoxHints()
|
||||||
|
{
|
||||||
|
using namespace QskAspect;
|
||||||
|
using Q = QskBox;
|
||||||
|
|
||||||
|
const ColorPalette& pal = m_data->palette;
|
||||||
|
|
||||||
|
setGradient( Q::Panel, pal.baseColor );
|
||||||
|
setBoxShape( Q::Panel, 4 );
|
||||||
|
setBoxBorderMetrics( Q::Panel, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
void QskMaterialSkin::initPopupHints()
|
void QskMaterialSkin::initPopupHints()
|
||||||
{
|
{
|
||||||
using namespace QskAspect;
|
using namespace QskAspect;
|
||||||
|
@ -191,6 +205,12 @@ void QskMaterialSkin::initTextLabelHints()
|
||||||
|
|
||||||
setSkinHint( Q::Text | Alignment, Qt::AlignCenter );
|
setSkinHint( Q::Text | Alignment, Qt::AlignCenter );
|
||||||
setColor( Q::Text, pal.textColor );
|
setColor( Q::Text, pal.textColor );
|
||||||
|
|
||||||
|
setMargins( Q::Panel | Padding, 5 );
|
||||||
|
setBoxShape( Q::Panel, 4 );
|
||||||
|
setBoxBorderMetrics( Q::Panel, 2 );
|
||||||
|
setBoxBorderColors( Q::Panel, pal.darker125 );
|
||||||
|
setGradient( Q::Panel, pal.baseColor );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskMaterialSkin::initTextInputHints()
|
void QskMaterialSkin::initTextInputHints()
|
||||||
|
|
|
@ -27,6 +27,7 @@ class QSK_MATERIAL_EXPORT QskMaterialSkin : public QskSkin
|
||||||
|
|
||||||
void initCommonHints();
|
void initCommonHints();
|
||||||
|
|
||||||
|
void initBoxHints();
|
||||||
void initDialogButtonBoxHints();
|
void initDialogButtonBoxHints();
|
||||||
void initDialogButtonHints();
|
void initDialogButtonHints();
|
||||||
void initFocusIndicatorHints();
|
void initFocusIndicatorHints();
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include "QskSquiekSkin.h"
|
#include "QskSquiekSkin.h"
|
||||||
|
|
||||||
|
#include <QskBox.h>
|
||||||
#include <QskDialogButton.h>
|
#include <QskDialogButton.h>
|
||||||
#include <QskDialogButtonBox.h>
|
#include <QskDialogButtonBox.h>
|
||||||
#include <QskFocusIndicator.h>
|
#include <QskFocusIndicator.h>
|
||||||
|
@ -251,6 +252,7 @@ void QskSquiekSkin::initHints()
|
||||||
{
|
{
|
||||||
initCommonHints();
|
initCommonHints();
|
||||||
|
|
||||||
|
initBoxHints();
|
||||||
initDialogButtonBoxHints();
|
initDialogButtonBoxHints();
|
||||||
initDialogButtonHints();
|
initDialogButtonHints();
|
||||||
initFocusIndicatorHints();
|
initFocusIndicatorHints();
|
||||||
|
@ -292,6 +294,11 @@ void QskSquiekSkin::initCommonHints()
|
||||||
setColor( Control | StyleColor | Q::Disabled, pal.theme );
|
setColor( Control | StyleColor | Q::Disabled, pal.theme );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QskSquiekSkin::initBoxHints()
|
||||||
|
{
|
||||||
|
setPanel( QskBox::Panel, Plain );
|
||||||
|
}
|
||||||
|
|
||||||
void QskSquiekSkin::initPopupHints()
|
void QskSquiekSkin::initPopupHints()
|
||||||
{
|
{
|
||||||
using namespace QskAspect;
|
using namespace QskAspect;
|
||||||
|
@ -310,6 +317,19 @@ void QskSquiekSkin::initTextLabelHints()
|
||||||
|
|
||||||
setSkinHint( Q::Text | Alignment, Qt::AlignCenter );
|
setSkinHint( Q::Text | Alignment, Qt::AlignCenter );
|
||||||
setColor( Q::Text, pal.themeForeground );
|
setColor( Q::Text, pal.themeForeground );
|
||||||
|
|
||||||
|
setMargins( Q::Panel | Padding, 5 );
|
||||||
|
setBoxBorderMetrics( Q::Panel, 2 );
|
||||||
|
setBoxShape( Q::Panel, 4 );
|
||||||
|
|
||||||
|
const QColor c = pal.base;
|
||||||
|
|
||||||
|
const QskBoxBorderColors borderColors(
|
||||||
|
c.darker( 170 ), c.darker( 170 ),
|
||||||
|
c.darker( 105 ), c.darker( 105 ) );
|
||||||
|
|
||||||
|
setBoxBorderColors( Q::Panel, borderColors );
|
||||||
|
setGradient( Q::Panel, c );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskSquiekSkin::initTextInputHints()
|
void QskSquiekSkin::initTextInputHints()
|
||||||
|
|
|
@ -27,6 +27,7 @@ class QSK_SQUIEK_EXPORT QskSquiekSkin : public QskSkin
|
||||||
|
|
||||||
void initCommonHints();
|
void initCommonHints();
|
||||||
|
|
||||||
|
void initBoxHints();
|
||||||
void initDialogButtonHints();
|
void initDialogButtonHints();
|
||||||
void initDialogButtonBoxHints();
|
void initDialogButtonBoxHints();
|
||||||
void initFocusIndicatorHints();
|
void initFocusIndicatorHints();
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <qfontmetrics.h>
|
#include <qfontmetrics.h>
|
||||||
#include <qmath.h>
|
#include <qmath.h>
|
||||||
|
|
||||||
|
QSK_SUBCONTROL( QskTextLabel, Panel )
|
||||||
QSK_SUBCONTROL( QskTextLabel, Text )
|
QSK_SUBCONTROL( QskTextLabel, Text )
|
||||||
|
|
||||||
class QskTextLabel::PrivateData
|
class QskTextLabel::PrivateData
|
||||||
|
@ -18,6 +19,7 @@ class QskTextLabel::PrivateData
|
||||||
public:
|
public:
|
||||||
PrivateData( const QString& txt )
|
PrivateData( const QString& txt )
|
||||||
: text( txt )
|
: text( txt )
|
||||||
|
, hasPanel( false )
|
||||||
{
|
{
|
||||||
effectiveTextFormat = textOptions.format();
|
effectiveTextFormat = textOptions.format();
|
||||||
}
|
}
|
||||||
|
@ -40,6 +42,8 @@ class QskTextLabel::PrivateData
|
||||||
|
|
||||||
QskTextOptions textOptions;
|
QskTextOptions textOptions;
|
||||||
mutable QskTextOptions::TextFormat effectiveTextFormat;
|
mutable QskTextOptions::TextFormat effectiveTextFormat;
|
||||||
|
|
||||||
|
bool hasPanel : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
QskTextLabel::QskTextLabel( QQuickItem* parent )
|
QskTextLabel::QskTextLabel( QQuickItem* parent )
|
||||||
|
@ -58,6 +62,24 @@ QskTextLabel::~QskTextLabel()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QskTextLabel::setPanel( bool on )
|
||||||
|
{
|
||||||
|
if ( on == m_data->hasPanel )
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_data->hasPanel = on;
|
||||||
|
|
||||||
|
resetImplicitSize();
|
||||||
|
update();
|
||||||
|
|
||||||
|
Q_EMIT panelChanged( on );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QskTextLabel::hasPanel() const
|
||||||
|
{
|
||||||
|
return m_data->hasPanel;
|
||||||
|
}
|
||||||
|
|
||||||
void QskTextLabel::setText( const QString& text )
|
void QskTextLabel::setText( const QString& text )
|
||||||
{
|
{
|
||||||
if ( text == m_data->text )
|
if ( text == m_data->text )
|
||||||
|
@ -246,9 +268,13 @@ QSizeF QskTextLabel::contentsSizeHint(
|
||||||
}
|
}
|
||||||
|
|
||||||
QSizeF size( constraint.width(), maxHeight );
|
QSizeF size( constraint.width(), maxHeight );
|
||||||
|
|
||||||
size = QskTextRenderer::textSize(
|
size = QskTextRenderer::textSize(
|
||||||
m_data->text, font, m_data->effectiveOptions(), size );
|
m_data->text, font, m_data->effectiveOptions(), size );
|
||||||
|
|
||||||
|
if ( m_data->hasPanel )
|
||||||
|
size = outerBoxSize( Panel, size );
|
||||||
|
|
||||||
hint.setHeight( qCeil( size.height() ) );
|
hint.setHeight( qCeil( size.height() ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,15 +283,22 @@ QSizeF QskTextLabel::contentsSizeHint(
|
||||||
const qreal maxWidth = std::numeric_limits< qreal >::max();
|
const qreal maxWidth = std::numeric_limits< qreal >::max();
|
||||||
|
|
||||||
QSizeF size( maxWidth, constraint.height() );
|
QSizeF size( maxWidth, constraint.height() );
|
||||||
|
|
||||||
size = QskTextRenderer::textSize( m_data->text, font,
|
size = QskTextRenderer::textSize( m_data->text, font,
|
||||||
m_data->effectiveOptions(), size );
|
m_data->effectiveOptions(), size );
|
||||||
|
|
||||||
|
if ( m_data->hasPanel )
|
||||||
|
size = outerBoxSize( Panel, size );
|
||||||
|
|
||||||
hint.setWidth( qCeil( size.width() ) );
|
hint.setWidth( qCeil( size.width() ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
hint = QskTextRenderer::textSize(
|
hint = QskTextRenderer::textSize(
|
||||||
m_data->text, font, m_data->effectiveOptions() );
|
m_data->text, font, m_data->effectiveOptions() );
|
||||||
|
|
||||||
|
if ( m_data->hasPanel )
|
||||||
|
hint = outerBoxSize( Panel, hint );
|
||||||
}
|
}
|
||||||
|
|
||||||
return hint;
|
return hint;
|
||||||
|
|
|
@ -27,10 +27,13 @@ class QSK_EXPORT QskTextLabel : public QskControl
|
||||||
Q_PROPERTY( Qt::Alignment alignment READ alignment
|
Q_PROPERTY( Qt::Alignment alignment READ alignment
|
||||||
WRITE setAlignment NOTIFY alignmentChanged )
|
WRITE setAlignment NOTIFY alignmentChanged )
|
||||||
|
|
||||||
|
Q_PROPERTY( bool panel READ hasPanel
|
||||||
|
WRITE setPanel NOTIFY panelChanged FINAL )
|
||||||
|
|
||||||
using Inherited = QskControl;
|
using Inherited = QskControl;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QSK_SUBCONTROLS( Text )
|
QSK_SUBCONTROLS( Panel, Text )
|
||||||
|
|
||||||
QskTextLabel( QQuickItem* parent = nullptr );
|
QskTextLabel( QQuickItem* parent = nullptr );
|
||||||
QskTextLabel( const QString& text, QQuickItem* parent = nullptr );
|
QskTextLabel( const QString& text, QQuickItem* parent = nullptr );
|
||||||
|
@ -62,19 +65,25 @@ class QSK_EXPORT QskTextLabel : public QskControl
|
||||||
|
|
||||||
QFont font() const;
|
QFont font() const;
|
||||||
|
|
||||||
|
void setPanel( bool );
|
||||||
|
bool hasPanel() const;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void textChanged( const QString& );
|
void textChanged( const QString& );
|
||||||
void textColorChanged( const QColor& );
|
void textColorChanged( const QColor& );
|
||||||
void textOptionsChanged( const QskTextOptions& );
|
void textOptionsChanged( const QskTextOptions& );
|
||||||
void fontRoleChanged();
|
void fontRoleChanged();
|
||||||
void alignmentChanged();
|
void alignmentChanged();
|
||||||
|
void panelChanged( bool );
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void setText( const QString& );
|
void setText( const QString& );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void changeEvent( QEvent* ) override;
|
void changeEvent( QEvent* ) override;
|
||||||
QSizeF contentsSizeHint( Qt::SizeHint, const QSizeF& ) const override;
|
|
||||||
|
QSizeF contentsSizeHint(
|
||||||
|
Qt::SizeHint, const QSizeF& ) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class PrivateData;
|
class PrivateData;
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
QskTextLabelSkinlet::QskTextLabelSkinlet( QskSkin* skin )
|
QskTextLabelSkinlet::QskTextLabelSkinlet( QskSkin* skin )
|
||||||
: Inherited( skin )
|
: Inherited( skin )
|
||||||
{
|
{
|
||||||
setNodeRoles( { TextRole } );
|
setNodeRoles( { PanelRole, TextRole } );
|
||||||
}
|
}
|
||||||
|
|
||||||
QskTextLabelSkinlet::~QskTextLabelSkinlet() = default;
|
QskTextLabelSkinlet::~QskTextLabelSkinlet() = default;
|
||||||
|
@ -19,10 +19,22 @@ QskTextLabelSkinlet::~QskTextLabelSkinlet() = default;
|
||||||
QRectF QskTextLabelSkinlet::subControlRect( const QskSkinnable* skinnable,
|
QRectF QskTextLabelSkinlet::subControlRect( const QskSkinnable* skinnable,
|
||||||
const QRectF& contentsRect, QskAspect::Subcontrol subControl ) const
|
const QRectF& contentsRect, QskAspect::Subcontrol subControl ) const
|
||||||
{
|
{
|
||||||
if ( subControl == QskTextLabel::Text )
|
const auto label = static_cast< const QskTextLabel* >( skinnable );
|
||||||
|
|
||||||
|
if ( subControl == QskTextLabel::Panel )
|
||||||
{
|
{
|
||||||
return contentsRect;
|
return contentsRect;
|
||||||
}
|
}
|
||||||
|
else if ( subControl == QskTextLabel::Text )
|
||||||
|
{
|
||||||
|
if ( label->hasPanel() )
|
||||||
|
{
|
||||||
|
auto r = subControlRect( label, contentsRect, QskTextLabel::Panel );
|
||||||
|
return label->innerBox( QskTextLabel::Panel, r );
|
||||||
|
}
|
||||||
|
|
||||||
|
return contentsRect;
|
||||||
|
}
|
||||||
|
|
||||||
return Inherited::subControlRect( skinnable, contentsRect, subControl );
|
return Inherited::subControlRect( skinnable, contentsRect, subControl );
|
||||||
}
|
}
|
||||||
|
@ -34,6 +46,13 @@ QSGNode* QskTextLabelSkinlet::updateSubNode(
|
||||||
|
|
||||||
switch ( nodeRole )
|
switch ( nodeRole )
|
||||||
{
|
{
|
||||||
|
case PanelRole:
|
||||||
|
{
|
||||||
|
if ( !label->hasPanel() )
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return updateBoxNode( label, node, QskTextLabel::Panel );
|
||||||
|
}
|
||||||
case TextRole:
|
case TextRole:
|
||||||
{
|
{
|
||||||
return updateTextNode( label, node,
|
return updateTextNode( label, node,
|
||||||
|
|
|
@ -17,7 +17,7 @@ class QSK_EXPORT QskTextLabelSkinlet : public QskSkinlet
|
||||||
public:
|
public:
|
||||||
enum NodeRole
|
enum NodeRole
|
||||||
{
|
{
|
||||||
TextRole
|
PanelRole, TextRole
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_INVOKABLE QskTextLabelSkinlet( QskSkin* = nullptr );
|
Q_INVOKABLE QskTextLabelSkinlet( QskSkin* = nullptr );
|
||||||
|
|
Loading…
Reference in New Issue