2017-07-21 18:21:34 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the QSkinny License, Version 1.0
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "QskTabButton.h"
|
2018-08-03 08:15:28 +02:00
|
|
|
#include "QskSkinlet.h"
|
2017-07-21 18:21:34 +02:00
|
|
|
#include "QskTabBar.h"
|
|
|
|
#include "QskTextOptions.h"
|
2019-04-18 16:16:44 +02:00
|
|
|
#include "QskQuick.h"
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2018-07-19 14:10:48 +02:00
|
|
|
#include <qfontmetrics.h>
|
|
|
|
#include <qpointer.h>
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
QSK_SUBCONTROL( QskTabButton, Panel )
|
|
|
|
QSK_SUBCONTROL( QskTabButton, Text )
|
|
|
|
|
2021-08-04 09:31:16 +02:00
|
|
|
static inline QskTabBar* qskFindTabBar( const QskTabButton* button )
|
2019-04-18 16:16:44 +02:00
|
|
|
{
|
|
|
|
return qskFindAncestorOf< QskTabBar* >( button->parentItem() );
|
|
|
|
}
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
class QskTabButton::PrivateData
|
|
|
|
{
|
2018-08-03 08:15:28 +02:00
|
|
|
public:
|
|
|
|
PrivateData( const QString& txt )
|
|
|
|
: text( txt )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QString text;
|
|
|
|
QskTextOptions textOptions;
|
|
|
|
QPointer< QskTabBar > tabBar;
|
|
|
|
};
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
QskTabButton::QskTabButton( QQuickItem* parent )
|
|
|
|
: QskTabButton( QString(), parent )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
QskTabButton::QskTabButton( const QString& text, QQuickItem* parent )
|
|
|
|
: Inherited( parent )
|
|
|
|
, m_data( new PrivateData( text ) )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2019-04-18 16:16:44 +02:00
|
|
|
if ( parent )
|
|
|
|
m_data->tabBar = qskFindTabBar( this );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2020-03-13 14:50:09 +01:00
|
|
|
initSizePolicy( QskSizePolicy::MinimumExpanding,
|
|
|
|
QskSizePolicy::QskSizePolicy::MinimumExpanding );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
setExclusive( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
QskTabButton::~QskTabButton()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-08-04 08:24:36 +02:00
|
|
|
bool QskTabButton::isCheckable() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
void QskTabButton::setText( const QString& text )
|
|
|
|
{
|
|
|
|
if ( m_data->text == text )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_data->text = text;
|
|
|
|
Q_EMIT textChanged( text );
|
|
|
|
|
|
|
|
resetImplicitSize();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString QskTabButton::text() const
|
|
|
|
{
|
|
|
|
return m_data->text;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskTabButton::setTextOptions( const QskTextOptions& options )
|
|
|
|
{
|
|
|
|
if ( options != m_data->textOptions )
|
|
|
|
{
|
|
|
|
m_data->textOptions = options;
|
|
|
|
Q_EMIT textOptionsChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QskTextOptions QskTabButton::textOptions() const
|
|
|
|
{
|
|
|
|
return m_data->textOptions;
|
|
|
|
}
|
|
|
|
|
2019-04-26 18:09:59 +02:00
|
|
|
QRectF QskTabButton::layoutRectForSize( const QSizeF& size ) const
|
2017-11-17 08:03:38 +01:00
|
|
|
{
|
2020-12-29 12:57:03 +01:00
|
|
|
return subControlContentsRect( size, Panel );
|
2017-11-17 08:03:38 +01:00
|
|
|
}
|
|
|
|
|
2017-10-17 17:34:00 +02:00
|
|
|
QskAspect::Placement QskTabButton::effectivePlacement() const
|
|
|
|
{
|
|
|
|
if ( m_data->tabBar )
|
2019-04-18 16:16:44 +02:00
|
|
|
return m_data->tabBar->effectivePlacement();
|
2017-10-17 17:34:00 +02:00
|
|
|
|
2019-04-17 16:33:17 +02:00
|
|
|
return QskAspect::NoPlacement;
|
2017-10-17 17:34:00 +02:00
|
|
|
}
|
|
|
|
|
2019-04-18 16:16:44 +02:00
|
|
|
const QskTabBar* QskTabButton::tabBar() const
|
|
|
|
{
|
|
|
|
return m_data->tabBar;
|
|
|
|
}
|
|
|
|
|
|
|
|
QskTabBar* QskTabButton::tabBar()
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
return m_data->tabBar;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskTabButton::changeEvent( QEvent* event )
|
|
|
|
{
|
2018-08-03 08:15:28 +02:00
|
|
|
switch ( event->type() )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
case QEvent::LocaleChange:
|
|
|
|
{
|
|
|
|
if ( !m_data->text.isEmpty() )
|
|
|
|
{
|
|
|
|
// maybe QLocale::textDirection() has changed
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QEvent::ParentChange:
|
|
|
|
{
|
2019-04-18 16:16:44 +02:00
|
|
|
m_data->tabBar = qskFindTabBar( this );
|
2017-07-21 18:21:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Inherited::changeEvent( event );
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "moc_QskTabButton.cpp"
|