qskinny/examples/gallery/dialog/DialogPage.cpp

93 lines
2.4 KiB
C++
Raw Normal View History

2022-07-05 15:45:06 +02:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#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>
#include <QskStandardSymbol.h>
2023-02-27 12:27:57 +01:00
#include <QskBoxShapeMetrics.h>
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
{
2023-02-27 12:27:57 +01:00
Q_OBJECT
2023-02-26 17:04:47 +01:00
public:
2023-02-27 12:27:57 +01:00
enum ButtonType
2022-07-05 15:45:06 +02:00
{
2023-02-27 12:27:57 +01:00
Message,
Information,
Warning,
Critical,
2022-07-05 15:45:06 +02:00
2023-02-27 12:27:57 +01:00
Question,
Selection,
2022-07-05 15:45:06 +02:00
2023-02-27 12:27:57 +01:00
TypeCount
};
Q_ENUM( ButtonType );
2022-07-05 15:45:06 +02:00
2023-02-27 12:27:57 +01:00
Button( ButtonType type, QQuickItem* parent = nullptr )
: QskPushButton( parent )
, m_type( type )
{
setShape( 10 );
initSizePolicy( QskSizePolicy::Ignored, QskSizePolicy::Ignored );
2022-07-05 15:45:06 +02:00
2023-02-27 12:27:57 +01:00
const int index = metaObject()->indexOfEnumerator( "ButtonType" );
setText( metaObject()->enumerator( index ).key( m_type ) );
2022-07-05 15:45:06 +02:00
2023-02-27 12:27:57 +01:00
connect( this, &QskPushButton::clicked, this, &Button::showDialog );
}
2022-07-05 15:45:06 +02:00
2023-02-27 12:27:57 +01:00
private:
void showDialog()
{
switch( static_cast< int >( m_type ) )
{
case Message:
qskDialog->message( text(), text(), QskStandardSymbol::Ok );
break;
case Information:
qskDialog->information( text(), text() );
break;
case Warning:
qskDialog->warning( text(), text() );
break;
case Critical:
qskDialog->critical( text(), text() );
break;
case Question:
qskDialog->question( text(), text() );
break;
case Selection:
qskDialog->select( text(), text(), { "yes", "no", "maybe" } );
break;
}
2022-07-05 15:45:06 +02:00
}
2023-02-27 12:27:57 +01:00
const ButtonType m_type;
2022-07-05 15:45:06 +02:00
};
}
DialogPage::DialogPage( QQuickItem* parent )
: Page( Qt::Horizontal, parent )
{
2023-02-27 12:27:57 +01:00
auto box = new QskLinearBox( Qt::Horizontal, 2, this );
2022-07-05 15:45:06 +02:00
2023-02-27 12:27:57 +01:00
for ( int i = 0; i < Button::TypeCount; i++ )
new Button( static_cast< Button::ButtonType >( i ), box );
2022-07-05 15:45:06 +02:00
}
2023-02-27 12:27:57 +01:00
#include "DialogPage.moc"