6#include "QskDialogSubWindow.h"
7#include "QskDialogButtonBox.h"
8#include "QskTextLabel.h"
9#include "QskPushButton.h"
10#include "QskLinearBox.h"
14#include <qquickwindow.h>
23 QObject::connect( subWindow, &QskPopup::closed,
24 subWindow, &QskDialogSubWindow::reject );
28 QObject::disconnect( subWindow, &QskPopup::closed,
29 subWindow, &QskDialogSubWindow::reject );
41 if ( subControl == QskTextLabel::Text )
42 return QskDialogSubWindow::DialogTitle;
44 return QskTextLabel::substitutedSubcontrol( subControl );
49class QskDialogSubWindow::PrivateData
52 QskDialog::Actions actions = QskDialog::NoAction;
57 QPointer< QQuickItem > contentItem;
61 QskDialog::DialogCode result = QskDialog::Rejected;
64QskDialogSubWindow::QskDialogSubWindow( QQuickItem* parent )
66 , m_data( new PrivateData() )
68 qskSetRejectOnClose(
this,
true );
71 m_data->layout->setSizePolicy(
72 QskSizePolicy::MinimumExpanding, QskSizePolicy::Constrained );
74 setPolishOnResize(
true );
75 setPolishOnParentResize(
true );
78QskDialogSubWindow::~QskDialogSubWindow()
82void QskDialogSubWindow::addDialogAction( QskDialog::Action action )
84 if ( action != QskDialog::NoAction )
86 if ( m_data->buttonBox ==
nullptr )
89 m_data->buttonBox->addAction( action );
93void QskDialogSubWindow::addDialogButton(
98 if ( m_data->buttonBox ==
nullptr )
101 m_data->buttonBox->addButton( button, actionRole );
105void QskDialogSubWindow::setDialogActions( QskDialog::Actions actions )
107 if ( m_data->actions == actions )
110 m_data->actions = actions;
112 if ( actions == QskDialog::NoAction )
114 delete m_data->buttonBox;
115 m_data->buttonBox =
nullptr;
119 if ( m_data->buttonBox ==
nullptr )
122 if ( m_data->buttonBox )
123 m_data->buttonBox->setActions( actions );
127QskDialog::Actions QskDialogSubWindow::dialogActions()
const
129 if ( m_data->buttonBox )
130 return m_data->buttonBox->actions();
132 return QskDialog::NoAction;
135void QskDialogSubWindow::setTitle(
const QString& title )
137 bool changed =
false;
138 auto& titleLabel = m_data->titleLabel;
140 if ( title.isEmpty() )
142 changed = ( titleLabel != nullptr );
145 titleLabel =
nullptr;
149 if ( titleLabel ==
nullptr )
151 titleLabel =
new TitleLabel();
152 m_data->layout->insertItem( 0, titleLabel );
157 changed = ( titleLabel->text() != title );
161 titleLabel->setText( title );
169 Q_EMIT titleChanged( title );
173QString QskDialogSubWindow::title()
const
175 if (
auto label = m_data->titleLabel )
176 return label->text();
183 return m_data->titleLabel;
186const QskTextLabel* QskDialogSubWindow::titleLabel()
const
188 return m_data->titleLabel;
191void QskDialogSubWindow::setContentItem( QQuickItem* item )
193 if ( item == m_data->contentItem )
196 if ( m_data->contentItem )
198 if ( m_data->contentItem->parent() == m_data->layout )
199 delete m_data->contentItem;
201 m_data->layout->removeItem( m_data->contentItem );
204 m_data->contentItem = item;
208 const int index = m_data->titleLabel ? 1 : 0;
209 m_data->layout->insertItem( index, m_data->contentItem );
213QQuickItem* QskDialogSubWindow::contentItem()
const
215 return m_data->contentItem;
218void QskDialogSubWindow::setContentPadding(
const QMarginsF& padding )
221 m_data->layout->setMargins( padding );
224QMarginsF QskDialogSubWindow::contentPadding()
const
226 return m_data->layout->margins();
229void QskDialogSubWindow::setDefaultDialogAction( QskDialog::Action action )
233 if ( m_data->buttonBox )
234 button = m_data->buttonBox->button( action );
236 setDefaultButton( button );
239void QskDialogSubWindow::setDefaultButton(
QskPushButton* button )
241 if ( !qskIsAncestorOf( m_data->buttonBox, button ) )
243#if defined( QT_DEBUG )
244 qWarning(
"Only buttons of the QskDialogButtonBox can be the default button." );
249 m_data->buttonBox->setDefaultButton( button );
254 if ( m_data->buttonBox ==
nullptr )
257 return m_data->buttonBox->defaultButton();
262 return m_data->buttonBox;
267 return m_data->buttonBox;
270QskDialog::Action QskDialogSubWindow::clickedAction()
const
272 if ( m_data->buttonBox )
273 return m_data->buttonBox->clickedAction();
275 return QskDialog::NoAction;
278void QskDialogSubWindow::setResult( QskDialog::DialogCode result )
280 m_data->result = result;
283QskDialog::DialogCode QskDialogSubWindow::result()
const
285 return m_data->result;
288QskDialog::DialogCode QskDialogSubWindow::exec()
290 m_data->result = QskDialog::Rejected;
291 ( void ) execPopup();
292 return m_data->result;
295void QskDialogSubWindow::done( QskDialog::DialogCode result )
297 m_data->result = result;
301 qskSetRejectOnClose(
this,
false );
303 qskSetRejectOnClose(
this,
true );
306 Q_EMIT finished( result );
308 if ( result == QskDialog::Accepted )
314void QskDialogSubWindow::accept()
316 done( QskDialog::Accepted );
319void QskDialogSubWindow::reject()
321 done( QskDialog::Rejected );
324void QskDialogSubWindow::keyPressEvent( QKeyEvent* event )
326 if ( m_data->buttonBox &&
327 QskDialogButtonBox::isDefaultButtonKeyEvent( event ) )
329 auto button = m_data->buttonBox->defaultButton();
330 if ( button && button->isEnabled() )
337 Inherited::keyPressEvent( event );
340void QskDialogSubWindow::initButtonBox()
343 m_data->layout->addItem( buttonBox );
345 connect( buttonBox, &QskDialogButtonBox::accepted,
346 this, &QskDialogSubWindow::accept );
348 connect( buttonBox, &QskDialogButtonBox::rejected,
349 this, &QskDialogSubWindow::reject );
351 m_data->buttonBox = buttonBox;
354void QskDialogSubWindow::updateLayout()
360void QskDialogSubWindow::updateGeometry()
370 width = qMin( width, maxSize.width() );
371 width = qMax( width, minSize.width() );
374 height = qMin( height, maxSize.height() );
375 height = qMax( height, minSize.height() );
377 QRectF
rect( 0.0, 0.0, width, height );
378 rect.moveCenter( qskItemRect( parentItem() ).center() );
383QSizeF QskDialogSubWindow::layoutSizeHint(
384 Qt::SizeHint which,
const QSizeF& constraint )
const
386 if ( which == Qt::MaximumSize && polishOnParentResize() )
387 return 0.9 * parentItem()->size();
389 auto size = m_data->layout->effectiveSizeHint( which, constraint );
391 if ( which == Qt::MinimumSize )
393 const auto w = qMax( 300.0, size.width() );
400#include "moc_QskDialogSubWindow.cpp"
Subcontrol
For use within the rendering or lay-outing of a specific QskSkinnable.
qreal heightForWidth(qreal width) const
QRectF layoutRect() const
void setGeometry(qreal x, qreal y, qreal width, qreal height)
Layout stringing items in rows and columns.