168 lines
5.0 KiB
C++
Raw Permalink Normal View History

2022-07-05 15:45:06 +02:00
/******************************************************************************
2024-01-17 14:31:45 +01:00
* QSkinny - Copyright (C) The authors
2023-04-06 09:23:37 +02:00
* SPDX-License-Identifier: BSD-3-Clause
2022-07-05 15:45:06 +02:00
*****************************************************************************/
#include "DialogPage.h"
#include <QskDialog.h>
2023-02-27 12:27:57 +01:00
#include <QskLinearBox.h>
2022-07-05 15:45:06 +02:00
#include <QskPushButton.h>
#if QT_CONFIG(thread)
/*
WebAssembly without asyncify support does not allow recursive
event loops. As we did not implement QskDialog::message and friends
with callbacks yet ( TODO ) we do have some dummy code here to avoid
crashes.
*/
#define QSK_USE_EXEC
#endif
#ifndef QSK_USE_EXEC
#include <QskMessageSubWindow.h>
#include <QskSelectionSubWindow.h>
#include <qquickwindow.h>
namespace
{
void openMessageSubWindow( QQuickWindow* window, const QString& title,
const QString& text, QskDialog::Actions actions, QskDialog::Action defaultAction )
{
auto subWindow = new QskMessageSubWindow( window->contentItem() );
subWindow->setPopupFlag( QskPopup::DeleteOnClose );
subWindow->setModal( true );
subWindow->setTitle( title );
subWindow->setDialogActions( actions );
subWindow->setDefaultDialogAction( defaultAction );
subWindow->setText( text );
( void ) subWindow->open();
}
void openSelectSubWindow( QQuickWindow* window, const QString& title,
QskDialog::Actions actions, QskDialog::Action defaultAction,
const QStringList& entries, int selectedRow )
{
auto subWindow = new QskSelectionSubWindow( window->contentItem() );
subWindow->setPopupFlag( QskPopup::DeleteOnClose );
subWindow->setModal( true );
subWindow->setTitle( title );
subWindow->setDialogActions( actions );
subWindow->setDefaultDialogAction( defaultAction );
subWindow->setEntries( entries );
subWindow->setSelectedRow( selectedRow );
( void ) subWindow->open();
}
}
#endif
2022-07-05 15:45:06 +02:00
namespace
{
2023-02-27 12:27:57 +01:00
class Button : public QskPushButton
2022-07-05 15:45:06 +02:00
{
public:
Button( const QString& text, QQuickItem* parent = nullptr )
: QskPushButton( text, parent )
{
setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
}
};
2023-02-27 12:27:57 +01:00
class ButtonBox : public QskLinearBox
{
2023-02-26 17:04:47 +01:00
public:
ButtonBox( QQuickItem* parent = nullptr )
: QskLinearBox( Qt::Vertical, parent )
2022-07-05 15:45:06 +02:00
{
setObjectName( "ButtonBox" );
setDefaultAlignment( Qt::AlignCenter );
2022-07-05 15:45:06 +02:00
setMargins( 10 );
setSpacing( 20 );
2022-07-05 15:45:06 +02:00
auto messageButton = new Button( "Message", this );
connect( messageButton, &Button::clicked, this, &ButtonBox::execMessage );
2022-07-05 15:45:06 +02:00
auto questionButton = new Button( "Question", this );
connect( questionButton, &Button::clicked, this, &ButtonBox::execQuestion );
2022-07-05 15:45:06 +02:00
auto selectButton = new Button( "Selection", this );
connect( selectButton, &Button::clicked, this, &ButtonBox::execSelection );
setExtraSpacingAt( Qt::BottomEdge );
2023-02-27 12:27:57 +01:00
}
2022-07-05 15:45:06 +02:00
2023-02-27 12:27:57 +01:00
private:
void execMessage()
2023-02-27 12:27:57 +01:00
{
const QString title( "Message" );
const QString message( "Request vector, over." );
#ifndef QSK_USE_EXEC
openMessageSubWindow( window(), title, message,
QskDialog::Ok, QskDialog::Ok );
#else
qskDialog->information( title, message );
#endif
}
void execQuestion()
{
const QString title( "Question" );
const QString question( "Roger, Roger. Do we have a vector, Victor ?" );
#ifndef QSK_USE_EXEC
openMessageSubWindow( window(), title, question,
QskDialog::Yes | QskDialog::No, QskDialog::Yes );
#else
(void )qskDialog->question( title, question );
#endif
}
void execSelection()
{
const QString title( "The Teens" );
const QStringList entries =
{
"Give Me More",
"Gimme Gimme Your Love",
"1-2-3-4 Red Light",
"New York",
"If You Walk Away",
"Eloise",
"On The Radio",
"We Are The Teens",
"Never Gonna Tell No Lie To You",
"Walking On Sunshine ",
"Get Out Of My Mind",
"Cover Girl ",
"Here I Stand",
"Gypsy Caravan",
"It´s Good To Have A Friend",
"We´ll Have A Party Tonite ´nite",
"Automatic World",
"Gimme Gimme Gimme Gimme Gimme Your Love"
};
#ifndef QSK_USE_EXEC
openSelectSubWindow( window(), title,
QskDialog::Ok | QskDialog::Cancel, QskDialog::Ok, entries, 7 );
#else
(void )qskDialog->select( title, entries, 7 );
#endif
}
2022-07-05 15:45:06 +02:00
};
}
DialogPage::DialogPage( QQuickItem* parent )
: Page( Qt::Horizontal, parent )
{
( void ) new ButtonBox( this );
2022-07-05 15:45:06 +02:00
}