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"
|
|
|
|
|
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 )
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
resolveTabBar();
|
|
|
|
|
2017-08-31 09:09:05 +02:00
|
|
|
initSizePolicy( QskSizePolicy::Minimum, QskSizePolicy::Fixed );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
setCheckable( true );
|
|
|
|
setExclusive( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
QskTabButton::~QskTabButton()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF QskTabButton::contentsSizeHint() const
|
|
|
|
{
|
|
|
|
QSizeF size( metric( Panel | QskAspect::MinimumWidth ),
|
|
|
|
metric( Panel | QskAspect::MinimumHeight ) );
|
|
|
|
|
|
|
|
if ( !m_data->text.isEmpty() )
|
|
|
|
{
|
|
|
|
const QFontMetricsF fm( effectiveFont( Text ) );
|
|
|
|
const auto textSize = fm.size( Qt::TextShowMnemonic, m_data->text );
|
|
|
|
size += textSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2017-11-17 08:03:38 +01:00
|
|
|
QRectF QskTabButton::layoutRect() const
|
|
|
|
{
|
|
|
|
return innerBox( Panel, effectiveSkinlet()->subControlRect( this, Panel ) );
|
|
|
|
}
|
|
|
|
|
2017-10-17 17:34:00 +02:00
|
|
|
QskAspect::Placement QskTabButton::effectivePlacement() const
|
|
|
|
{
|
|
|
|
if ( m_data->tabBar )
|
|
|
|
{
|
2019-04-17 16:33:17 +02:00
|
|
|
const auto pos = m_data->tabBar->position();
|
|
|
|
|
|
|
|
switch ( pos )
|
|
|
|
{
|
|
|
|
case Qsk::Left:
|
|
|
|
return QskAspect::Left;
|
|
|
|
|
|
|
|
case Qsk::Right:
|
|
|
|
return QskAspect::Right;
|
|
|
|
|
|
|
|
case Qsk::Top:
|
|
|
|
return QskAspect::Top;
|
|
|
|
|
|
|
|
case Qsk::Bottom:
|
|
|
|
return QskAspect::Bottom;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
QskTabBar* QskTabButton::tabBar() const
|
|
|
|
{
|
|
|
|
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:
|
|
|
|
{
|
|
|
|
resolveTabBar();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Inherited::changeEvent( event );
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskTabButton::resolveTabBar()
|
|
|
|
{
|
|
|
|
auto p = parent();
|
|
|
|
while ( p )
|
|
|
|
{
|
|
|
|
if ( const auto tabBar = qobject_cast< QskTabBar* >( p ) )
|
|
|
|
{
|
|
|
|
m_data->tabBar = tabBar;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p = p->parent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "moc_QskTabButton.cpp"
|