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 "QskSubWindow.h"
|
|
|
|
#include "QskAspect.h"
|
|
|
|
#include "QskFunctions.h"
|
2018-10-29 20:11:48 +01:00
|
|
|
#include "QskGraphic.h"
|
|
|
|
#include "QskGraphicProvider.h"
|
|
|
|
#include "QskTextOptions.h"
|
2018-08-03 08:15:28 +02:00
|
|
|
#include "QskQuick.h"
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2018-10-29 20:11:48 +01:00
|
|
|
#include <qurl.h>
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
QSK_SUBCONTROL( QskSubWindow, Panel )
|
|
|
|
QSK_SUBCONTROL( QskSubWindow, TitleBar )
|
2018-10-29 20:11:48 +01:00
|
|
|
QSK_SUBCONTROL( QskSubWindow, TitleBarSymbol )
|
|
|
|
QSK_SUBCONTROL( QskSubWindow, TitleBarText )
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
class QskSubWindow::PrivateData
|
|
|
|
{
|
2018-08-03 08:15:28 +02:00
|
|
|
public:
|
2017-07-21 18:21:34 +02:00
|
|
|
PrivateData()
|
2018-10-29 20:11:48 +01:00
|
|
|
: isWindowIconSourceDirty( false )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
// should be available from the platform somehow. TODO ...
|
|
|
|
|
|
|
|
windowButtons = QskSubWindow::WindowButtons( QskSubWindow::MinimizeButton |
|
|
|
|
QskSubWindow::MaximizeButton | QskSubWindow::CloseButton );
|
2018-10-29 20:11:48 +01:00
|
|
|
|
|
|
|
windowTitleTextOptions.setElideMode( Qt::ElideRight );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QskSubWindow::WindowButtons windowButtons;
|
2018-10-29 20:11:48 +01:00
|
|
|
|
|
|
|
QString windowTitle;
|
|
|
|
QskTextOptions windowTitleTextOptions;
|
|
|
|
|
|
|
|
QUrl windowIconSource;
|
|
|
|
QskGraphic windowIcon;
|
|
|
|
|
|
|
|
bool isWindowIconSourceDirty : 1;
|
2017-07-21 18:21:34 +02:00
|
|
|
};
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
QskSubWindow::QskSubWindow( QQuickItem* parent )
|
|
|
|
: Inherited( parent )
|
|
|
|
, m_data( new PrivateData() )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
setMargins( 0 );
|
2017-08-31 09:09:05 +02:00
|
|
|
initSizePolicy( QskSizePolicy::MinimumExpanding, QskSizePolicy::MinimumExpanding );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
setAutoLayoutChildren( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
QskSubWindow::~QskSubWindow()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskSubWindow::setDecorated( bool on )
|
|
|
|
{
|
|
|
|
if ( on == isDecorated() )
|
|
|
|
return;
|
|
|
|
|
2020-12-21 09:57:57 +01:00
|
|
|
setFlagHint( Panel | QskAspect::Decoration, on );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
resetImplicitSize(); // in case some parent wants to layout
|
|
|
|
|
|
|
|
polish();
|
|
|
|
update();
|
|
|
|
|
|
|
|
Q_EMIT decoratedChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QskSubWindow::isDecorated() const
|
|
|
|
{
|
2018-10-29 20:11:48 +01:00
|
|
|
return flagHint< bool >( Panel | QskAspect::Decoration, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskSubWindow::setWindowTitle( const QString& title )
|
|
|
|
{
|
|
|
|
if ( m_data->windowTitle != title )
|
|
|
|
{
|
|
|
|
m_data->windowTitle = title;
|
2019-03-26 16:10:15 +01:00
|
|
|
|
2019-03-26 16:11:50 +01:00
|
|
|
update();
|
2018-10-29 20:11:48 +01:00
|
|
|
Q_EMIT windowTitleChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString QskSubWindow::windowTitle() const
|
|
|
|
{
|
|
|
|
return m_data->windowTitle;
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
2018-10-29 20:11:48 +01:00
|
|
|
void QskSubWindow::setWindowTitleTextOptions( const QskTextOptions& options )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2018-10-29 20:11:48 +01:00
|
|
|
if ( options != m_data->windowTitleTextOptions )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2018-10-29 20:11:48 +01:00
|
|
|
m_data->windowTitleTextOptions = options;
|
|
|
|
|
|
|
|
update();
|
|
|
|
Q_EMIT windowTitleTextOptionsChanged();
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-29 20:11:48 +01:00
|
|
|
QskTextOptions QskSubWindow::windowTitleTextOptions() const
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2018-10-29 20:11:48 +01:00
|
|
|
return m_data->windowTitleTextOptions;
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
2018-11-05 13:50:41 +01:00
|
|
|
void QskSubWindow::setWindowIconSource( const QString& url )
|
|
|
|
{
|
|
|
|
setWindowIconSource( QUrl( url ) );
|
|
|
|
}
|
|
|
|
|
2018-10-29 20:11:48 +01: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 13:42:16 +01:00
|
|
|
}
|
2018-10-29 20:11:48 +01:00
|
|
|
|
|
|
|
QskGraphic QskSubWindow::windowIcon() const
|
|
|
|
{
|
|
|
|
return m_data->windowIcon;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QskSubWindow::hasWindowIcon() const
|
|
|
|
{
|
|
|
|
return !( windowIcon().isEmpty() && windowIconSource().isEmpty() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
void QskSubWindow::setWindowButtons( WindowButtons buttons )
|
|
|
|
{
|
|
|
|
if ( buttons != m_data->windowButtons )
|
|
|
|
{
|
|
|
|
m_data->windowButtons = buttons;
|
|
|
|
update();
|
|
|
|
|
|
|
|
Q_EMIT windowButtonsChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QskSubWindow::WindowButtons QskSubWindow::windowButtons() const
|
|
|
|
{
|
|
|
|
return m_data->windowButtons;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskSubWindow::setWindowButton( WindowButton button, bool on )
|
|
|
|
{
|
|
|
|
if ( on == bool( button & m_data->windowButtons ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( on )
|
|
|
|
m_data->windowButtons |= button;
|
|
|
|
else
|
|
|
|
m_data->windowButtons &= ~button;
|
|
|
|
|
|
|
|
Q_EMIT windowButtonsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QskSubWindow::testWindowButton( WindowButton button ) const
|
|
|
|
{
|
|
|
|
return m_data->windowButtons & button;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF QskSubWindow::titleBarRect() const
|
|
|
|
{
|
2017-10-17 17:34:00 +02:00
|
|
|
return subControlRect( TitleBar );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool QskSubWindow::event( QEvent* event )
|
|
|
|
{
|
|
|
|
if ( event->type() == QEvent::LayoutRequest )
|
|
|
|
resetImplicitSize();
|
|
|
|
|
|
|
|
return Inherited::event( event );
|
|
|
|
}
|
|
|
|
|
2018-10-29 20:11:48 +01: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 18:09:59 +02:00
|
|
|
QRectF QskSubWindow::layoutRectForSize( const QSizeF& size ) const
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2019-04-30 09:05:08 +02:00
|
|
|
QRectF rect;
|
|
|
|
rect.setSize( size );
|
|
|
|
rect.setTop( subControlRect( size, TitleBar ).bottom() );
|
2017-10-17 17:34:00 +02:00
|
|
|
|
|
|
|
return innerBox( Panel, rect );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
2019-09-10 17:01:47 +02:00
|
|
|
QSizeF QskSubWindow::layoutSizeHint(
|
|
|
|
Qt::SizeHint which, const QSizeF& constraint ) const
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2018-10-29 20:11:48 +01:00
|
|
|
// the size we get from the children
|
2019-09-10 17:01:47 +02:00
|
|
|
auto hint = Inherited::layoutSizeHint( which, constraint );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2019-09-10 17:01:47 +02:00
|
|
|
if ( which == Qt::PreferredSize )
|
|
|
|
{
|
|
|
|
// should be Minimum Width/Height from the skin hints
|
|
|
|
if ( hint.width() < 0.0 )
|
|
|
|
hint.setWidth( qskDpiScaled( 100 ) );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2019-09-10 17:01:47 +02:00
|
|
|
if ( hint.height() < 0.0 )
|
|
|
|
hint.setHeight( qskDpiScaled( 80 ) );
|
|
|
|
}
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
return hint;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskSubWindow::itemChange( QQuickItem::ItemChange change,
|
|
|
|
const QQuickItem::ItemChangeData& value )
|
|
|
|
{
|
|
|
|
Inherited::itemChange( change, value );
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
switch ( change )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
case QQuickItem::ItemChildAddedChange:
|
|
|
|
case QQuickItem::ItemChildRemovedChange:
|
|
|
|
{
|
2018-01-19 10:07:05 +01:00
|
|
|
if ( !qskIsTransparentForPositioner( value.item ) )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
resetImplicitSize();
|
|
|
|
polish();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "moc_QskSubWindow.cpp"
|