2017-07-21 16:21:34 +00:00
|
|
|
/******************************************************************************
|
2024-01-17 13:31:45 +00:00
|
|
|
* QSkinny - Copyright (C) The authors
|
2023-04-06 07:23:37 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2017-07-21 16:21:34 +00:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "QskSubWindow.h"
|
|
|
|
#include "QskAspect.h"
|
2018-10-29 19:11:48 +00:00
|
|
|
#include "QskGraphic.h"
|
|
|
|
#include "QskGraphicProvider.h"
|
|
|
|
#include "QskTextOptions.h"
|
2018-08-03 06:15:28 +00:00
|
|
|
#include "QskQuick.h"
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2018-10-29 19:11:48 +00:00
|
|
|
#include <qurl.h>
|
|
|
|
|
2017-07-21 16:21:34 +00:00
|
|
|
QSK_SUBCONTROL( QskSubWindow, Panel )
|
2021-04-28 07:32:49 +00:00
|
|
|
QSK_SUBCONTROL( QskSubWindow, TitleBarPanel )
|
2018-10-29 19:11:48 +00:00
|
|
|
QSK_SUBCONTROL( QskSubWindow, TitleBarSymbol )
|
|
|
|
QSK_SUBCONTROL( QskSubWindow, TitleBarText )
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2021-04-28 07:32:49 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
inline QskAspect aspectDecoration()
|
|
|
|
{
|
2024-02-06 14:41:50 +00:00
|
|
|
return QskSubWindow::TitleBarPanel | QskAspect::Style;
|
2021-04-28 07:32:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-21 16:21:34 +00:00
|
|
|
class QskSubWindow::PrivateData
|
|
|
|
{
|
2018-08-03 06:15:28 +00:00
|
|
|
public:
|
2017-07-21 16:21:34 +00:00
|
|
|
PrivateData()
|
2018-10-29 19:11:48 +00:00
|
|
|
: isWindowIconSourceDirty( false )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-10-29 19:11:48 +00:00
|
|
|
QString windowTitle;
|
|
|
|
|
|
|
|
QUrl windowIconSource;
|
|
|
|
QskGraphic windowIcon;
|
|
|
|
|
|
|
|
bool isWindowIconSourceDirty : 1;
|
2017-07-21 16:21:34 +00:00
|
|
|
};
|
|
|
|
|
2018-08-03 06:15:28 +00:00
|
|
|
QskSubWindow::QskSubWindow( QQuickItem* parent )
|
|
|
|
: Inherited( parent )
|
|
|
|
, m_data( new PrivateData() )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
|
|
|
setMargins( 0 );
|
2017-08-31 07:09:05 +00:00
|
|
|
initSizePolicy( QskSizePolicy::MinimumExpanding, QskSizePolicy::MinimumExpanding );
|
2017-07-21 16:21:34 +00:00
|
|
|
|
|
|
|
setAutoLayoutChildren( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
QskSubWindow::~QskSubWindow()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-04-28 07:32:49 +00:00
|
|
|
void QskSubWindow::setDecorations( Decorations decorations )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2021-04-28 07:32:49 +00:00
|
|
|
if ( setFlagHint( aspectDecoration(), decorations ) )
|
|
|
|
Q_EMIT decorationsChanged( decorations );
|
|
|
|
}
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2021-04-28 07:32:49 +00:00
|
|
|
QskSubWindow::Decorations QskSubWindow::decorations() const
|
|
|
|
{
|
|
|
|
return flagHint< QskSubWindow::Decorations >( aspectDecoration() );
|
|
|
|
}
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2021-04-28 07:32:49 +00:00
|
|
|
void QskSubWindow::setDecoration( Decoration decoration, bool on )
|
|
|
|
{
|
|
|
|
auto d = decorations();
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2021-04-28 07:32:49 +00:00
|
|
|
if ( on )
|
|
|
|
d |= decoration;
|
|
|
|
else
|
|
|
|
d &= ~decoration;
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2021-04-28 07:32:49 +00:00
|
|
|
setDecorations( d );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2021-04-28 07:32:49 +00:00
|
|
|
void QskSubWindow::resetDecorations()
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2023-03-02 11:19:32 +00:00
|
|
|
if ( resetSkinHint( aspectDecoration() ) )
|
2021-04-28 07:32:49 +00:00
|
|
|
Q_EMIT decorationsChanged( decorations() );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QskSubWindow::hasDecoration( Decoration decoration ) const
|
|
|
|
{
|
|
|
|
return decorations() & decoration;
|
2018-10-29 19:11:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QskSubWindow::setWindowTitle( const QString& title )
|
|
|
|
{
|
|
|
|
if ( m_data->windowTitle != title )
|
|
|
|
{
|
|
|
|
m_data->windowTitle = title;
|
2019-03-26 15:10:15 +00:00
|
|
|
|
2019-03-26 15:11:50 +00:00
|
|
|
update();
|
2018-10-29 19:11:48 +00:00
|
|
|
Q_EMIT windowTitleChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString QskSubWindow::windowTitle() const
|
|
|
|
{
|
|
|
|
return m_data->windowTitle;
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2018-10-29 19:11:48 +00:00
|
|
|
void QskSubWindow::setWindowTitleTextOptions( const QskTextOptions& options )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2022-08-25 07:39:33 +00:00
|
|
|
if ( setTextOptionsHint( TitleBarText, options ) )
|
2018-10-29 19:11:48 +00:00
|
|
|
Q_EMIT windowTitleTextOptionsChanged();
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2018-10-29 19:11:48 +00:00
|
|
|
QskTextOptions QskSubWindow::windowTitleTextOptions() const
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2022-08-25 07:39:33 +00:00
|
|
|
return textOptionsHint( TitleBarText );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2018-11-05 12:50:41 +00:00
|
|
|
void QskSubWindow::setWindowIconSource( const QString& url )
|
|
|
|
{
|
|
|
|
setWindowIconSource( QUrl( url ) );
|
|
|
|
}
|
|
|
|
|
2018-10-29 19:11:48 +00:00
|
|
|
void QskSubWindow::setWindowIconSource( const QUrl& url )
|
|
|
|
{
|
|
|
|
if ( m_data->windowIconSource == url )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_data->windowIconSource = url;
|
|
|
|
m_data->windowIcon.reset();
|
|
|
|
|
|
|
|
m_data->isWindowIconSourceDirty = true;
|
|
|
|
|
|
|
|
polish();
|
|
|
|
update();
|
|
|
|
|
|
|
|
Q_EMIT windowIconSourceChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
QUrl QskSubWindow::windowIconSource() const
|
|
|
|
{
|
|
|
|
return m_data->windowIconSource;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskSubWindow::setWindowIcon( const QskGraphic& graphic )
|
|
|
|
{
|
|
|
|
if ( graphic != m_data->windowIcon )
|
|
|
|
{
|
|
|
|
m_data->windowIcon = graphic;
|
|
|
|
|
|
|
|
if ( !m_data->windowIconSource.isEmpty() )
|
|
|
|
{
|
|
|
|
m_data->windowIconSource = QString();
|
|
|
|
m_data->isWindowIconSourceDirty = false;
|
|
|
|
|
|
|
|
Q_EMIT windowIconSourceChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
polish();
|
|
|
|
update();
|
|
|
|
|
|
|
|
Q_EMIT windowIconChanged();
|
|
|
|
}
|
2019-01-04 12:42:16 +00:00
|
|
|
}
|
2018-10-29 19:11:48 +00:00
|
|
|
|
|
|
|
QskGraphic QskSubWindow::windowIcon() const
|
|
|
|
{
|
|
|
|
return m_data->windowIcon;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QskSubWindow::hasWindowIcon() const
|
|
|
|
{
|
|
|
|
return !( windowIcon().isEmpty() && windowIconSource().isEmpty() );
|
|
|
|
}
|
|
|
|
|
2017-07-21 16:21:34 +00:00
|
|
|
QRectF QskSubWindow::titleBarRect() const
|
|
|
|
{
|
2021-04-28 07:32:49 +00:00
|
|
|
return subControlRect( TitleBarPanel );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool QskSubWindow::event( QEvent* event )
|
|
|
|
{
|
|
|
|
if ( event->type() == QEvent::LayoutRequest )
|
|
|
|
resetImplicitSize();
|
|
|
|
|
|
|
|
return Inherited::event( event );
|
|
|
|
}
|
|
|
|
|
2018-10-29 19:11:48 +00:00
|
|
|
void QskSubWindow::updateLayout()
|
|
|
|
{
|
|
|
|
if ( m_data->isWindowIconSourceDirty )
|
|
|
|
{
|
|
|
|
if ( !m_data->windowIconSource.isEmpty() )
|
|
|
|
{
|
|
|
|
m_data->windowIcon = Qsk::loadGraphic( m_data->windowIconSource );
|
|
|
|
Q_EMIT windowIconChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_data->isWindowIconSourceDirty = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Inherited::updateLayout();
|
|
|
|
}
|
|
|
|
|
2019-04-26 16:09:59 +00:00
|
|
|
QRectF QskSubWindow::layoutRectForSize( const QSizeF& size ) const
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-04-30 07:05:08 +00:00
|
|
|
QRectF rect;
|
|
|
|
rect.setSize( size );
|
2021-04-28 07:32:49 +00:00
|
|
|
rect.setTop( subControlRect( size, TitleBarPanel ).bottom() );
|
2017-10-17 15:34:00 +00:00
|
|
|
|
|
|
|
return innerBox( Panel, rect );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-09-10 15:01:47 +00:00
|
|
|
QSizeF QskSubWindow::layoutSizeHint(
|
|
|
|
Qt::SizeHint which, const QSizeF& constraint ) const
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2018-10-29 19:11:48 +00:00
|
|
|
// the size we get from the children
|
2019-09-10 15:01:47 +00:00
|
|
|
auto hint = Inherited::layoutSizeHint( which, constraint );
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-09-10 15:01:47 +00:00
|
|
|
if ( which == Qt::PreferredSize )
|
|
|
|
{
|
|
|
|
// should be Minimum Width/Height from the skin hints
|
|
|
|
if ( hint.width() < 0.0 )
|
2024-10-30 11:51:17 +00:00
|
|
|
hint.setWidth( 100 );
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-09-10 15:01:47 +00:00
|
|
|
if ( hint.height() < 0.0 )
|
2024-10-30 11:51:17 +00:00
|
|
|
hint.setHeight( 80 );
|
2019-09-10 15:01:47 +00:00
|
|
|
}
|
2017-07-21 16:21:34 +00:00
|
|
|
|
|
|
|
return hint;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskSubWindow::itemChange( QQuickItem::ItemChange change,
|
|
|
|
const QQuickItem::ItemChangeData& value )
|
|
|
|
{
|
|
|
|
Inherited::itemChange( change, value );
|
|
|
|
|
2018-08-03 06:15:28 +00:00
|
|
|
switch ( change )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
|
|
|
case QQuickItem::ItemChildAddedChange:
|
|
|
|
case QQuickItem::ItemChildRemovedChange:
|
|
|
|
{
|
2022-04-07 15:19:59 +00:00
|
|
|
if ( qskIsVisibleToLayout( value.item ) )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
|
|
|
resetImplicitSize();
|
|
|
|
polish();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-21 14:26:23 +00:00
|
|
|
void QskSubWindow::geometryChange(
|
|
|
|
const QRectF& newGeometry, const QRectF& oldGeometry )
|
|
|
|
{
|
|
|
|
Inherited::geometryChange( newGeometry, oldGeometry );
|
|
|
|
}
|
|
|
|
|
2023-11-03 17:13:24 +00:00
|
|
|
void QskSubWindow::updateResources()
|
|
|
|
{
|
|
|
|
setOpacity( fadingFactor() );
|
|
|
|
Inherited::updateResources();
|
|
|
|
}
|
|
|
|
|
|
|
|
QskAspect QskSubWindow::fadingAspect() const
|
|
|
|
{
|
|
|
|
return QskSubWindow::Panel | QskAspect::Position;
|
|
|
|
}
|
|
|
|
|
2017-07-21 16:21:34 +00:00
|
|
|
#include "moc_QskSubWindow.cpp"
|