6#include "QskDialogWindow.h"
7#include "QskDialogButtonBox.h"
8#include "QskLinearBox.h"
9#include "QskPushButton.h"
13#include <qeventloop.h>
16class QskDialogWindow::PrivateData
25 QskDialog::Actions actions = QskDialog::NoAction;
27 QPointer< QQuickItem > dialogContentItem;
31 QskDialog::DialogCode result : 1;
35QskDialogWindow::QskDialogWindow( QWindow* parent )
37 , m_data( new PrivateData() )
39 setFlags( Qt::Dialog | Qt::WindowTitleHint | Qt::WindowCloseButtonHint |
40 Qt::WindowSystemMenuHint | Qt::WindowContextHelpButtonHint );
43 setAutoLayoutChildren(
true );
44 m_data->layoutBox =
new QskLinearBox( Qt::Vertical, contentItem() );
45 m_data->layoutBox->setPadding( 5 );
46 m_data->layoutBox->setPanel(
true );
49QskDialogWindow::~QskDialogWindow()
53void QskDialogWindow::setDialogActions( QskDialog::Actions actions )
55 if ( m_data->actions == actions )
58 m_data->actions = actions;
60 if ( actions == QskDialog::NoAction )
62 delete m_data->buttonBox;
63 m_data->buttonBox =
nullptr;
67 if ( m_data->buttonBox ==
nullptr )
69 m_data->buttonBox = createButtonBox();
71 if ( m_data->buttonBox )
73 m_data->layoutBox->addItem( m_data->buttonBox );
75 connect( m_data->buttonBox, &QskDialogButtonBox::accepted,
76 this, &QskDialogWindow::accept, Qt::UniqueConnection );
78 connect( m_data->buttonBox, &QskDialogButtonBox::rejected,
79 this, &QskDialogWindow::reject, Qt::UniqueConnection );
83 if ( m_data->buttonBox )
84 m_data->buttonBox->setActions( actions );
88QskDialog::Actions QskDialogWindow::dialogActions()
const
90 if ( m_data->buttonBox )
91 return m_data->buttonBox->actions();
93 return QskDialog::NoAction;
96void QskDialogWindow::setDialogContentItem( QQuickItem* item )
98 if ( item == m_data->dialogContentItem )
101 if ( m_data->dialogContentItem )
103 m_data->layoutBox->removeAt( 0 );
104 if ( m_data->dialogContentItem->parent() == m_data->layoutBox )
105 delete m_data->dialogContentItem;
108 m_data->dialogContentItem = item;
111 m_data->layoutBox->insertItem( 0, item );
114QQuickItem* QskDialogWindow::dialogContentItem()
const
116 return m_data->dialogContentItem;
119void QskDialogWindow::setDefaultButton(
QskPushButton* button )
121 if ( !qskIsAncestorOf( m_data->buttonBox, button ) )
123#if defined( QT_DEBUG )
124 qWarning(
"Only buttons of the QskDialogButtonBox can be the default button." );
129 m_data->buttonBox->setDefaultButton( button );
134 if ( m_data->buttonBox ==
nullptr )
137 return m_data->buttonBox->defaultButton();
140void QskDialogWindow::setDefaultDialogAction( QskDialog::Action action )
144 if ( m_data->buttonBox )
145 button = m_data->buttonBox->button( action );
147 setDefaultButton( button );
152 return m_data->buttonBox;
157 return m_data->buttonBox;
160QskDialog::Action QskDialogWindow::clickedAction()
const
162 if ( m_data->buttonBox )
163 return m_data->buttonBox->clickedAction();
165 return QskDialog::NoAction;
168void QskDialogWindow::setResult( QskDialog::DialogCode result )
170 m_data->result = result;
173QskDialog::DialogCode QskDialogWindow::result()
const
175 return m_data->result;
178QskDialog::DialogCode QskDialogWindow::exec()
180 const bool deleteOnClose = this->deleteOnClose();
181 setDeleteOnClose(
false );
185 QEventLoop eventLoop;
187 connect(
this, &QskDialogWindow::finished, &eventLoop, &QEventLoop::quit );
188 ( void ) eventLoop.exec( QEventLoop::DialogExec );
190 const auto result =
static_cast< QskDialog::DialogCode
>( m_data->result );
198void QskDialogWindow::done( QskDialog::DialogCode result )
200 m_data->result = result;
202 Q_EMIT finished( result );
204 if ( result == QskDialog::Accepted )
209 const QPointer< QObject > that =
this;
211 m_data->inDone =
true;
218 m_data->inDone =
false;
222void QskDialogWindow::accept()
224 done( QskDialog::Accepted );
227void QskDialogWindow::reject()
229 done( QskDialog::Rejected );
232bool QskDialogWindow::event( QEvent* event )
234 if ( event->type() == QEvent::Close )
236 if ( !m_data->inDone )
237 done( QskDialog::Rejected );
240 return Inherited::event( event );
243void QskDialogWindow::keyPressEvent( QKeyEvent* event )
245 if ( m_data->buttonBox &&
246 QskDialogButtonBox::isDefaultButtonKeyEvent( event ) )
248 auto button = m_data->buttonBox->defaultButton();
249 if ( button && button->isEnabled() )
253 if ( qskIsStandardKeyInput( event, QKeySequence::Cancel ) )
261 Inherited::keyPressEvent( event );
269#include "moc_QskDialogWindow.cpp"
Layout stringing items in rows and columns.