2017-07-21 16:21:34 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
2023-04-06 07:23:37 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2017-07-21 16:21:34 +00:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "QskMessageSubWindow.h"
|
2018-11-06 17:54:21 +00:00
|
|
|
#include "QskGraphic.h"
|
|
|
|
#include "QskGraphicLabel.h"
|
|
|
|
#include "QskLinearBox.h"
|
2023-03-03 17:11:57 +00:00
|
|
|
#include "QskStandardSymbol.h"
|
2018-11-06 17:54:21 +00:00
|
|
|
#include "QskTextLabel.h"
|
|
|
|
|
|
|
|
#include <qfontmetrics.h>
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
class TextLabel final : public QskTextLabel
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TextLabel( QskMessageSubWindow* box )
|
|
|
|
{
|
|
|
|
setObjectName( QStringLiteral( "QskMessageSubWindowTextLabel" ) );
|
|
|
|
initSizePolicy( QskSizePolicy::Preferred, QskSizePolicy::Preferred );
|
|
|
|
|
2018-11-06 18:00:42 +00:00
|
|
|
setAlignment( Qt::AlignLeft | Qt::AlignTop );
|
2018-11-06 17:54:21 +00:00
|
|
|
setWrapMode( QskTextOptions::WordWrap );
|
|
|
|
|
|
|
|
connect( this, &QskTextLabel::textChanged,
|
2018-11-06 18:00:42 +00:00
|
|
|
box, &QskMessageSubWindow::textChanged );
|
2018-11-06 17:54:21 +00:00
|
|
|
|
|
|
|
connect( this, &QskTextLabel::textOptionsChanged,
|
2018-11-06 18:00:42 +00:00
|
|
|
box, &QskMessageSubWindow::textOptionsChanged );
|
2018-11-06 17:54:21 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class SymbolLabel final : public QskGraphicLabel
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SymbolLabel( QskMessageSubWindow* )
|
|
|
|
{
|
|
|
|
setObjectName( QStringLiteral( "QskMessageSubWindowSymbolLabel" ) );
|
|
|
|
initSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
|
|
|
|
|
|
|
|
setAlignment( Qt::AlignTop | Qt::AlignHCenter );
|
2022-07-28 09:37:14 +00:00
|
|
|
updatePreferredSize();
|
2018-11-06 17:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void changeEvent( QEvent* event ) override
|
|
|
|
{
|
|
|
|
if ( event->type() == QEvent::FontChange )
|
2022-07-28 09:37:14 +00:00
|
|
|
updatePreferredSize();
|
2018-11-06 17:54:21 +00:00
|
|
|
|
|
|
|
QskGraphicLabel::changeEvent( event );
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2022-07-28 09:37:14 +00:00
|
|
|
void updatePreferredSize()
|
2018-11-06 17:54:21 +00:00
|
|
|
{
|
|
|
|
// when there is no explicit size known,
|
|
|
|
// we always adjust the icon according to the font
|
|
|
|
|
2022-07-28 09:37:14 +00:00
|
|
|
if ( graphicStrutSize().isEmpty() )
|
2018-11-06 17:54:21 +00:00
|
|
|
{
|
|
|
|
const QFont font = effectiveFont( QskTextLabel::Text );
|
|
|
|
setPreferredSize( -1.0, 1.5 * QFontMetricsF( font ).height() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
class QskMessageSubWindow::PrivateData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QskGraphicLabel* symbolLabel;
|
2018-11-06 18:00:42 +00:00
|
|
|
QskTextLabel* textLabel;
|
2019-01-04 12:42:16 +00:00
|
|
|
};
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2018-08-03 06:15:28 +00:00
|
|
|
QskMessageSubWindow::QskMessageSubWindow( QQuickItem* parent )
|
|
|
|
: Inherited( parent )
|
2018-11-06 17:54:21 +00:00
|
|
|
, m_data( new PrivateData() )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2018-11-06 18:00:42 +00:00
|
|
|
m_data->textLabel = new TextLabel( this );
|
2018-11-06 17:54:21 +00:00
|
|
|
|
|
|
|
m_data->symbolLabel = new SymbolLabel( this );
|
|
|
|
m_data->symbolLabel->hide();
|
|
|
|
|
|
|
|
auto box = new QskLinearBox( Qt::Horizontal );
|
2019-09-05 08:46:42 +00:00
|
|
|
box->setDefaultAlignment( Qt::AlignTop | Qt::AlignHCenter );
|
2018-11-06 17:54:21 +00:00
|
|
|
box->setSpacing( 0 );
|
2019-09-05 08:46:42 +00:00
|
|
|
box->addItem( m_data->symbolLabel );
|
|
|
|
box->addItem( m_data->textLabel );
|
2018-11-06 18:00:42 +00:00
|
|
|
box->setStretchFactor( m_data->textLabel, 10 );
|
2018-11-06 17:54:21 +00:00
|
|
|
|
|
|
|
setContentItem( box );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QskMessageSubWindow::~QskMessageSubWindow()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-11-06 18:00:42 +00:00
|
|
|
void QskMessageSubWindow::setText( const QString& text )
|
2018-11-06 17:54:21 +00:00
|
|
|
{
|
2018-11-06 18:00:42 +00:00
|
|
|
m_data->textLabel->setText( text );
|
2018-11-06 17:54:21 +00:00
|
|
|
}
|
|
|
|
|
2018-11-06 18:00:42 +00:00
|
|
|
QString QskMessageSubWindow::text() const
|
2018-11-06 17:54:21 +00:00
|
|
|
{
|
2018-11-06 18:00:42 +00:00
|
|
|
return m_data->textLabel->text();
|
2018-11-06 17:54:21 +00:00
|
|
|
}
|
|
|
|
|
2018-11-06 18:00:42 +00:00
|
|
|
void QskMessageSubWindow::setTextOptions( const QskTextOptions& options )
|
2018-11-06 17:54:21 +00:00
|
|
|
{
|
2018-11-06 18:00:42 +00:00
|
|
|
m_data->textLabel->setTextOptions( options );
|
2018-11-06 17:54:21 +00:00
|
|
|
}
|
|
|
|
|
2018-11-06 18:00:42 +00:00
|
|
|
QskTextOptions QskMessageSubWindow::textOptions() const
|
2018-11-06 17:54:21 +00:00
|
|
|
{
|
2018-11-06 18:00:42 +00:00
|
|
|
return m_data->textLabel->textOptions();
|
2018-11-06 17:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QskMessageSubWindow::setSymbolSource( const QUrl& url )
|
|
|
|
{
|
|
|
|
m_data->symbolLabel->setSource( url );
|
|
|
|
m_data->symbolLabel->setVisible( !url.isEmpty() );
|
|
|
|
|
|
|
|
if ( auto box = qobject_cast< QskLinearBox* >( contentItem() ) )
|
|
|
|
box->setSpacing( m_data->symbolLabel->isVisible() ? 15 : 0 ); // metrics !!
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskMessageSubWindow::setSymbolType( int symbolType )
|
|
|
|
{
|
2023-03-03 17:11:57 +00:00
|
|
|
#if 1
|
|
|
|
const auto graphic = QskStandardSymbol::graphic(
|
|
|
|
static_cast< QskStandardSymbol::Type >( symbolType ) );
|
|
|
|
#else
|
|
|
|
const auto graphic = symbolHint( ... ); // TODO
|
|
|
|
#endif
|
|
|
|
setSymbol( graphic );
|
2018-11-06 17:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QUrl QskMessageSubWindow::symbolSource() const
|
|
|
|
{
|
|
|
|
return m_data->symbolLabel->source();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskMessageSubWindow::setSymbol( const QskGraphic& symbol )
|
|
|
|
{
|
|
|
|
m_data->symbolLabel->setVisible( !symbol.isNull() );
|
|
|
|
m_data->symbolLabel->setGraphic( symbol );
|
|
|
|
}
|
|
|
|
|
|
|
|
QskGraphic QskMessageSubWindow::symbol() const
|
|
|
|
{
|
|
|
|
return m_data->symbolLabel->graphic();
|
|
|
|
}
|
|
|
|
|
2017-07-21 16:21:34 +00:00
|
|
|
#include "moc_QskMessageSubWindow.cpp"
|