QskDialog::StandardButton renamed to QskDialog::Action

This commit is contained in:
Uwe Rathmann 2018-11-05 13:29:52 +01:00
parent 11a4c79f0f
commit b398d11310
14 changed files with 238 additions and 248 deletions

View File

@ -18,25 +18,20 @@ Window::Window( Qt::Orientation orientation )
m_layoutBox->setExtraSpacingAt( Qt::BottomEdge | Qt::RightEdge );
addBox( QskDialog::Ok );
addBox( QskDialog::StandardButtons( QskDialog::Ok | QskDialog::Cancel ) );
addBox( QskDialog::StandardButtons( QskDialog::Yes | QskDialog::No ) );
addBox( QskDialog::StandardButtons( QskDialog::Save | QskDialog::Discard
| QskDialog::RestoreDefaults | QskDialog::Help ) );
addBox( QskDialog::StandardButtons( QskDialog::Abort
| QskDialog::Retry | QskDialog::Ignore ) );
addBox( QskDialog::Ok | QskDialog::Cancel );
addBox( QskDialog::Yes | QskDialog::No );
addBox( QskDialog::Save | QskDialog::Discard |
QskDialog::RestoreDefaults | QskDialog::Help );
addBox( QskDialog::Abort | QskDialog::Retry | QskDialog::Ignore );
addActionBox();
addItem( m_layoutBox );
}
void Window::addBox( QskDialog::StandardButtons standardButtons )
void Window::addBox( QskDialog::Actions actions )
{
QskDialogButtonBox* box = new QskDialogButtonBox( m_orientation );
box->setStandardButtons( standardButtons );
box->setActions( actions );
box->setObjectName( "DialogBox" );
m_layoutBox->addItem( box );
@ -48,9 +43,9 @@ void Window::addActionBox()
QskPushButton* centerButton = new QskPushButton( "Center" );
QskDialogButtonBox* box = new QskDialogButtonBox( m_orientation );
box->addButton( flipButton, QskDialog::ActionRole );
box->addButton( centerButton, QskDialog::ActionRole );
box->setObjectName( "ActionBox" );
box->addButton( flipButton, QskDialog::UserRole );
box->addButton( centerButton, QskDialog::UserRole );
box->setObjectName( "UserBox" );
m_layoutBox->addItem( box );

View File

@ -24,7 +24,7 @@ class Window : public QskWindow
void centerButtons();
private:
void addBox( QskDialog::StandardButtons );
void addBox( QskDialog::Actions );
void addActionBox();
QVector< QskDialogButtonBox* > dialogBoxes() const;

View File

@ -278,7 +278,7 @@ void QskQml::registerTypes()
QSK_REGISTER_FLAGS( QskSizePolicy::Policy );
QMetaType::registerConverter< int, QskSetupFlagsProvider >();
QSK_REGISTER_FLAGS( QskDialog::StandardButtons );
QSK_REGISTER_FLAGS( QskDialog::Actions );
QSK_REGISTER_GADGET( QskRgbValue_Gadget, "RgbValue" );
QSK_REGISTER_GADGET( QskStandardSymbol, "StandardSymbol" );

View File

@ -49,33 +49,33 @@ static QQuickWindow* qskSomeQuickWindow()
}
static void qskSetupSubWindow(
const QString& title, QskDialog::StandardButtons buttons,
QskDialog::StandardButton defaultButton, QskInputSubWindow* subWindow )
const QString& title, QskDialog::Actions actions,
QskDialog::Action defaultAction, QskInputSubWindow* subWindow )
{
subWindow->setModal( true );
subWindow->setWindowTitle( title );
subWindow->setStandardButtons( buttons );
subWindow->setActions( actions );
if ( defaultButton == QskDialog::NoButton )
defaultButton = subWindow->buttonBox()->defaultButtonCandidate();
if ( defaultAction == QskDialog::NoAction )
defaultAction = subWindow->buttonBox()->defaultActionCandidate();
subWindow->setDefaultButton( defaultButton );
subWindow->setDefaultAction( defaultAction );
}
static void qskSetupWindow(
QWindow* transientParent, const QString& title,
QskDialog::StandardButtons buttons, QskDialog::StandardButton defaultButton,
QskDialog::Actions actions, QskDialog::Action defaultAction,
QskInputWindow* window )
{
window->setTransientParent( transientParent );
window->setTitle( title );
window->setStandardButtons( buttons );
window->setActions( actions );
if ( defaultButton == QskDialog::NoButton )
defaultButton = window->buttonBox()->defaultButtonCandidate();
if ( defaultAction == QskDialog::NoAction )
defaultAction = window->buttonBox()->defaultActionCandidate();
window->setDefaultButton( defaultButton );
window->setDefaultAction( defaultAction );
window->setModality( transientParent ? Qt::WindowModal : Qt::ApplicationModal );
@ -98,53 +98,53 @@ static void qskSetupWindow(
window->setModality( Qt::ApplicationModal );
}
static QskDialog::StandardButton qskMessageSubWindow(
static QskDialog::Action qskMessageSubWindow(
QQuickWindow* window, const QString& title,
const QString& text, int symbolType, QskDialog::StandardButtons buttons,
QskDialog::StandardButton defaultButton )
const QString& text, int symbolType, QskDialog::Actions actions,
QskDialog::Action defaultAction )
{
QskMessageSubWindow subWindow( window->contentItem() );
subWindow.setSymbolType( symbolType );
subWindow.setInfoText( text );
qskSetupSubWindow( title, buttons, defaultButton, &subWindow );
qskSetupSubWindow( title, actions, defaultAction, &subWindow );
( void ) subWindow.exec();
QskDialog::StandardButton clickedButton = subWindow.clickedButton();
if ( clickedButton == QskDialog::NoButton )
auto clickedAction = subWindow.clickedAction();
if ( clickedAction == QskDialog::NoAction )
{
// dialog might have been closed by the window menu
clickedButton = QskDialog::Cancel;
clickedAction = QskDialog::Cancel;
}
return clickedButton;
return clickedAction;
}
static QskDialog::StandardButton qskMessageWindow(
static QskDialog::Action qskMessageWindow(
QWindow* transientParent, const QString& title,
const QString& text, int symbolType, QskDialog::StandardButtons buttons,
QskDialog::StandardButton defaultButton )
const QString& text, int symbolType, QskDialog::Actions actions,
QskDialog::Action defaultAction )
{
QskMessageWindow messageWindow;
messageWindow.setSymbolType( symbolType );
messageWindow.setInfoText( text );
qskSetupWindow( transientParent, title, buttons, defaultButton, &messageWindow );
qskSetupWindow( transientParent, title, actions, defaultAction, &messageWindow );
( void ) qskExec( &messageWindow );
QskDialog::StandardButton clickedButton = messageWindow.clickedButton();
if ( clickedButton == QskDialog::NoButton )
auto clickedAction = messageWindow.clickedAction();
if ( clickedAction == QskDialog::NoAction )
{
// dialog might have been closed by the window menu
clickedButton = QskDialog::Cancel;
clickedAction = QskDialog::Cancel;
}
return clickedButton;
return clickedAction;
}
static QString qskSelectSubWindow(
QQuickWindow* window, const QString& title, const QString& text,
QskDialog::StandardButtons buttons, QskDialog::StandardButton defaultButton,
QskDialog::Actions actions, QskDialog::Action defaultAction,
const QStringList& entries, int selectedRow )
{
QskSelectionSubWindow subWindow( window->contentItem() );
@ -154,7 +154,7 @@ static QString qskSelectSubWindow(
QString selectedEntry = subWindow.selectedEntry();
qskSetupSubWindow( title, buttons, defaultButton, &subWindow );
qskSetupSubWindow( title, actions, defaultAction, &subWindow );
if ( subWindow.exec() == QskDialog::Accepted )
selectedEntry = subWindow.selectedEntry();
@ -163,7 +163,7 @@ static QString qskSelectSubWindow(
static QString qskSelectWindow(
QWindow* transientParent, const QString& title, const QString& text,
QskDialog::StandardButtons buttons, QskDialog::StandardButton defaultButton,
QskDialog::Actions actions, QskDialog::Action defaultAction,
const QStringList& entries, int selectedRow )
{
QskSelectionWindow window;
@ -173,7 +173,7 @@ static QString qskSelectWindow(
QString selectedEntry = window.selectedEntry();
qskSetupWindow( transientParent, title, buttons, defaultButton, &window );
qskSetupWindow( transientParent, title, actions, defaultAction, &window );
if ( qskExec( &window ) == QskDialog::Accepted )
selectedEntry = window.selectedEntry();
@ -238,9 +238,9 @@ QWindow* QskDialog::transientParent() const
return m_data->transientParent;
}
QskDialog::StandardButton QskDialog::message(
QskDialog::Action QskDialog::message(
const QString& title, const QString& text, int symbolType,
StandardButtons buttons, StandardButton defaultButton ) const
Actions actions, Action defaultAction ) const
{
if ( m_data->policy == EmbeddedBox )
{
@ -252,44 +252,44 @@ QskDialog::StandardButton QskDialog::message(
if ( quickWindow )
{
return qskMessageSubWindow( quickWindow,
title, text, symbolType, buttons, defaultButton );
title, text, symbolType, actions, defaultAction );
}
}
return qskMessageWindow( m_data->transientParent,
title, text, symbolType, buttons, defaultButton );
title, text, symbolType, actions, defaultAction );
}
QskDialog::StandardButton QskDialog::information(
QskDialog::Action QskDialog::information(
const QString& title, const QString& text,
StandardButtons buttons, StandardButton defaultButton ) const
Actions actions, Action defaultAction ) const
{
return QskDialog::message( title, text,
QskStandardSymbol::Information, buttons, defaultButton );
QskStandardSymbol::Information, actions, defaultAction );
}
QskDialog::StandardButton QskDialog::warning(
QskDialog::Action QskDialog::warning(
const QString& title, const QString& text,
StandardButtons buttons, StandardButton defaultButton ) const
Actions actions, Action defaultAction ) const
{
return QskDialog::message( title, text,
QskStandardSymbol::Warning, buttons, defaultButton );
QskStandardSymbol::Warning, actions, defaultAction );
}
QskDialog::StandardButton QskDialog::critical(
QskDialog::Action QskDialog::critical(
const QString& title, const QString& text,
StandardButtons buttons, StandardButton defaultButton ) const
Actions actions, Action defaultAction ) const
{
return QskDialog::message( title, text,
QskStandardSymbol::Critical, buttons, defaultButton );
QskStandardSymbol::Critical, actions, defaultAction );
}
QskDialog::StandardButton QskDialog::question(
QskDialog::Action QskDialog::question(
const QString& title, const QString& text,
StandardButtons buttons, StandardButton defaultButton ) const
Actions actions, Action defaultAction ) const
{
return QskDialog::message( title, text,
QskStandardSymbol::Question, buttons, defaultButton );
QskStandardSymbol::Question, actions, defaultAction );
}
QString QskDialog::select(
@ -298,8 +298,8 @@ QString QskDialog::select(
{
#if 1
// should be parameters
const QskDialog::StandardButtons buttons( QskDialog::Ok | QskDialog::Cancel );
const QskDialog::StandardButton defaultButton = QskDialog::Ok;
const QskDialog::Actions actions( QskDialog::Ok | QskDialog::Cancel );
const QskDialog::Action defaultAction = QskDialog::Ok;
#endif
if ( m_data->policy == EmbeddedBox )
@ -312,12 +312,12 @@ QString QskDialog::select(
if ( quickWindow )
{
return qskSelectSubWindow( quickWindow,
title, text, buttons, defaultButton, entries, selectedRow );
title, text, actions, defaultAction, entries, selectedRow );
}
}
return qskSelectWindow( m_data->transientParent, title, text,
buttons, defaultButton, entries, selectedRow );
actions, defaultAction, entries, selectedRow );
}

View File

@ -39,58 +39,62 @@ class QSK_EXPORT QskDialog : public QObject
TopLevelWindow
};
enum StandardButton
Q_ENUM( Policy )
// a.k.a QMessageBox::StandardButton or QPlatformDialogHelper::StandardButton
enum Action
{
NoButton = 0x00000000,
Ok = 0x00000400,
Save = 0x00000800,
SaveAll = 0x00001000,
Open = 0x00002000,
Yes = 0x00004000,
YesToAll = 0x00008000,
No = 0x00010000,
NoToAll = 0x00020000,
Abort = 0x00040000,
Retry = 0x00080000,
Ignore = 0x00100000,
Close = 0x00200000,
Cancel = 0x00400000,
Discard = 0x00800000,
Help = 0x01000000,
Apply = 0x02000000,
Reset = 0x04000000,
RestoreDefaults = 0x08000000,
NoAction = 0,
Ok = 1 << 10,
Save = 1 << 11,
SaveAll = 1 << 12,
Open = 1 << 13,
Yes = 1 << 14,
YesToAll = 1 << 15,
No = 1 << 16,
NoToAll = 1 << 17,
Abort = 1 << 18,
Retry = 1 << 19,
Ignore = 1 << 20,
Close = 1 << 21,
Cancel = 1 << 22,
Discard = 1 << 23,
Help = 1 << 24,
Apply = 1 << 25,
Reset = 1 << 26,
RestoreDefaults = 1 << 27
};
enum ButtonRole
Q_ENUM( Action )
Q_DECLARE_FLAGS( Actions, Action )
// a.k.a QMessageBox::ButtonRole
enum ActionRole
{
InvalidRole = -1,
AcceptRole,
RejectRole,
DestructiveRole,
ActionRole,
UserRole,
HelpRole,
YesRole,
NoRole,
ResetRole,
ApplyRole,
NButtonRoles
NActionRoles
};
Q_ENUM( ActionRole )
enum DialogCode
{
Rejected = 0,
Accepted
};
Q_ENUM( Policy )
Q_ENUM( DialogCode )
Q_ENUM( ButtonRole )
Q_ENUM( StandardButton )
Q_DECLARE_FLAGS( StandardButtons, StandardButton )
static QskDialog* instance();
@ -100,29 +104,26 @@ class QSK_EXPORT QskDialog : public QObject
Q_INVOKABLE void setTransientParent( QWindow* );
Q_INVOKABLE QWindow* transientParent() const;
Q_INVOKABLE StandardButton message(
const QString& title, const QString& text,
int symbolType, StandardButtons buttons = Ok,
StandardButton defaultButton = NoButton
) const;
Q_INVOKABLE Action message(
const QString& title, const QString& text, int symbolType,
Actions actions = Ok, Action defaultAction = NoAction ) const;
Q_INVOKABLE StandardButton information(
Q_INVOKABLE Action information(
const QString& title, const QString& text,
StandardButtons buttons = Ok,
StandardButton defaultButton = NoButton
) const;
Actions actions = Ok, Action defaultAction = NoAction ) const;
Q_INVOKABLE StandardButton warning(
Q_INVOKABLE Action warning(
const QString& title, const QString& text,
StandardButtons buttons = Ok, StandardButton = NoButton ) const;
Actions actions = Ok, Action defaultAction = NoAction ) const;
Q_INVOKABLE StandardButton critical(
Q_INVOKABLE Action critical(
const QString& title, const QString& text,
StandardButtons buttons = Ok, StandardButton = NoButton ) const;
Actions actions = Ok, Action defaultAction = NoAction ) const;
Q_INVOKABLE StandardButton question(
Q_INVOKABLE Action question(
const QString& title, const QString& text,
StandardButtons = StandardButtons( Yes | No ), StandardButton = NoButton ) const;
Actions actions = Actions( Yes | No ),
Action defaultAction = NoAction ) const;
Q_INVOKABLE QString select(
const QString& title, const QString& text,
@ -142,8 +143,8 @@ class QSK_EXPORT QskDialog : public QObject
std::unique_ptr< PrivateData > m_data;
};
Q_DECLARE_METATYPE( QskDialog::StandardButton )
Q_DECLARE_METATYPE( QskDialog::StandardButtons )
Q_DECLARE_OPERATORS_FOR_FLAGS( QskDialog::StandardButtons )
Q_DECLARE_METATYPE( QskDialog::Action )
Q_DECLARE_METATYPE( QskDialog::Actions )
Q_DECLARE_OPERATORS_FOR_FLAGS( QskDialog::Actions )
#endif

View File

@ -11,15 +11,15 @@ QSK_SUBCONTROL( QskDialogButton, Text )
QSK_SUBCONTROL( QskDialogButton, Graphic )
QskDialogButton::QskDialogButton(
QskDialog::StandardButton standardButton, QQuickItem* parent )
QskDialog::Action action, QQuickItem* parent )
: QskPushButton( parent )
, m_buttonType( standardButton )
, m_action( action )
{
setText( QskDialogButtonBox::buttonText( m_buttonType ) );
setText( QskDialogButtonBox::buttonText( m_action ) );
}
QskDialogButton::QskDialogButton( QQuickItem* parent )
: QskDialogButton( QskDialog::NoButton, parent )
: QskDialogButton( QskDialog::NoAction, parent )
{
}
@ -42,26 +42,26 @@ QskAspect::Subcontrol QskDialogButton::effectiveSubcontrol(
return Inherited::effectiveSubcontrol( subControl );
}
void QskDialogButton::setStandardButton( QskDialog::StandardButton button )
void QskDialogButton::setAction( QskDialog::Action action )
{
if ( button != m_buttonType )
if ( action != m_action )
{
m_buttonType = button;
setText( QskDialogButtonBox::buttonText( m_buttonType ) );
m_action = action;
setText( QskDialogButtonBox::buttonText( m_action ) );
Q_EMIT standardButtonChanged();
Q_EMIT actionChanged();
}
}
QskDialog::StandardButton QskDialogButton::standardButton() const
QskDialog::Action QskDialogButton::action() const
{
return m_buttonType;
return m_action;
}
void QskDialogButton::changeEvent( QEvent* event )
{
if ( event->type() == QEvent::LocaleChange )
setText( QskDialogButtonBox::buttonText( m_buttonType ) );
setText( QskDialogButtonBox::buttonText( m_action ) );
Inherited::changeEvent( event );
}

View File

@ -13,33 +13,33 @@ class QSK_EXPORT QskDialogButton : public QskPushButton
{
Q_OBJECT
Q_PROPERTY( QskDialog::StandardButton standardButton READ standardButton()
WRITE setStandardButton NOTIFY standardButtonChanged() FINAL )
Q_PROPERTY( QskDialog::Action action READ action()
WRITE setAction NOTIFY actionChanged() FINAL )
using Inherited = QskPushButton;
public:
QSK_SUBCONTROLS( Panel, Text, Graphic )
QskDialogButton( QskDialog::StandardButton, QQuickItem* parent = nullptr );
QskDialogButton( QskDialog::Action, QQuickItem* parent = nullptr );
QskDialogButton( QQuickItem* parent = nullptr );
~QskDialogButton() override;
void setStandardButton( QskDialog::StandardButton );
QskDialog::StandardButton standardButton() const;
void setAction( QskDialog::Action );
QskDialog::Action action() const;
QskAspect::Subcontrol effectiveSubcontrol(
QskAspect::Subcontrol ) const override;
Q_SIGNALS:
void standardButtonChanged();
void actionChanged();
protected:
void changeEvent( QEvent* ) override;
private:
QskDialog::StandardButton m_buttonType;
QskDialog::Action m_action;
};
#endif

View File

@ -25,13 +25,12 @@ static void qskSendEventTo( QObject* object, QEvent::Type type )
QCoreApplication::sendEvent( object, &event );
}
static inline QskDialog::ButtonRole qskButtonRole(
QskDialog::StandardButton standardButton )
static inline QskDialog::ActionRole qskActionRole( QskDialog::Action action )
{
const auto role = QPlatformDialogHelper::buttonRole(
static_cast< QPlatformDialogHelper::StandardButton >( standardButton ) );
static_cast< QPlatformDialogHelper::StandardButton >( action ) );
return static_cast< QskDialog::ButtonRole >( role );
return static_cast< QskDialog::ActionRole >( role );
}
static void qskAddToLayout( const QVector< QskPushButton* >& buttons,
@ -59,9 +58,9 @@ class QskDialogButtonBox::PrivateData
}
QskLinearBox* layoutBox = nullptr;
QVector< QskPushButton* > buttons[ QskDialog::NButtonRoles ];
QVector< QskPushButton* > buttons[ QskDialog::NActionRoles ];
QskDialog::StandardButton clickedButton = QskDialog::NoButton;
QskDialog::Action clickedAction = QskDialog::NoAction;
bool centeredButtons : 1;
bool dirtyLayout : 1;
@ -245,9 +244,10 @@ bool QskDialogButtonBox::centeredButtons() const
return m_data->centeredButtons;
}
void QskDialogButtonBox::addButton( QskPushButton* button, QskDialog::ButtonRole role )
void QskDialogButtonBox::addButton(
QskPushButton* button, QskDialog::ActionRole role )
{
if ( role < 0 || role >= QskDialog::NButtonRoles )
if ( role < 0 || role >= QskDialog::NActionRoles )
return;
if ( button )
@ -263,11 +263,11 @@ void QskDialogButtonBox::addButton( QskPushButton* button, QskDialog::ButtonRole
}
}
void QskDialogButtonBox::addButton( QskDialog::StandardButton standardButton )
void QskDialogButtonBox::addButton( QskDialog::Action action )
{
QskPushButton* button = createButton( standardButton );
QskPushButton* button = createButton( action );
if ( button )
addButton( button, qskButtonRole( standardButton ) );
addButton( button, qskActionRole( action ) );
}
void QskDialogButtonBox::removeButton( QskPushButton* button )
@ -277,7 +277,7 @@ void QskDialogButtonBox::removeButton( QskPushButton* button )
if ( button == nullptr )
return;
for ( int i = 0; i < QskDialog::NButtonRoles; i++ )
for ( int i = 0; i < QskDialog::NActionRoles; i++ )
{
auto& buttons = m_data->buttons[ i ];
if ( buttons.removeOne( button ) )
@ -292,14 +292,14 @@ void QskDialogButtonBox::removeButton( QskPushButton* button )
}
QskPushButton* QskDialogButtonBox::createButton(
QskDialog::StandardButton standardButton ) const
QskDialog::Action action ) const
{
return new QskDialogButton( standardButton );
return new QskDialogButton( action );
}
void QskDialogButtonBox::clear()
{
for ( int i = 0; i < QskDialog::NButtonRoles; i++ )
for ( int i = 0; i < QskDialog::NActionRoles; i++ )
{
qDeleteAll( m_data->buttons[ i ] );
m_data->buttons[ i ].clear();
@ -308,9 +308,9 @@ void QskDialogButtonBox::clear()
invalidateLayout();
}
void QskDialogButtonBox::setStandardButtons( QskDialog::StandardButtons standardButton )
void QskDialogButtonBox::setActions( QskDialog::Actions actions )
{
for ( int i = 0; i < QskDialog::NButtonRoles; i++ )
for ( int i = 0; i < QskDialog::NActionRoles; i++ )
{
qDeleteAll( m_data->buttons[ i ] );
m_data->buttons[ i ].clear();
@ -318,9 +318,9 @@ void QskDialogButtonBox::setStandardButtons( QskDialog::StandardButtons standard
for ( int i = QskDialog::Ok; i <= QskDialog::RestoreDefaults; i <<= 1 )
{
const QskDialog::StandardButton id = static_cast< QskDialog::StandardButton >( i );
if ( id & standardButton )
addButton( id );
const auto action = static_cast< QskDialog::Action >( i );
if ( action & actions )
addButton( action );
}
invalidateLayout();
@ -330,49 +330,50 @@ QVector< QskPushButton* > QskDialogButtonBox::buttons() const
{
QVector< QskPushButton* > buttons;
for ( int i = 0; i < QskDialog::NButtonRoles; i++ )
for ( int i = 0; i < QskDialog::NActionRoles; i++ )
buttons += m_data->buttons[ i ];
return buttons;
}
QskDialog::ButtonRole QskDialogButtonBox::buttonRole( const QskPushButton* button ) const
QskDialog::ActionRole QskDialogButtonBox::actionRole(
const QskPushButton* button ) const
{
for ( int i = 0; i < QskDialog::NButtonRoles; i++ )
for ( int i = 0; i < QskDialog::NActionRoles; i++ )
{
const auto& buttons = m_data->buttons[ i ];
for ( const auto btn : buttons )
{
if ( button == btn )
return static_cast< QskDialog::ButtonRole >( i );
return static_cast< QskDialog::ActionRole >( i );
}
}
return QskDialog::InvalidRole;
}
QskDialog::StandardButton QskDialogButtonBox::defaultButtonCandidate() const
QskDialog::Action QskDialogButtonBox::defaultActionCandidate() const
{
// not the fastest code ever, but usually we always
// have a AcceptRole or YesRole button
static const QVector< QskDialog::ButtonRole > fallBackRoles =
static const QVector< QskDialog::ActionRole > fallBackRoles =
{
QskDialog::AcceptRole, QskDialog::YesRole,
QskDialog::RejectRole, QskDialog::NoRole, QskDialog::DestructiveRole,
QskDialog::ActionRole, QskDialog::ResetRole,
QskDialog::UserRole, QskDialog::ResetRole,
QskDialog::ApplyRole, QskDialog::HelpRole
};
for ( auto role : fallBackRoles )
{
const auto defaultButton = standardButton( buttonFromRole( role ) );
if ( defaultButton != QskDialog::NoButton )
return defaultButton;
const auto defaultAction = action( buttonFromRole( role ) );
if ( defaultAction != QskDialog::NoAction )
return defaultAction;
}
return QskDialog::NoButton;
return QskDialog::NoAction;
}
void QskDialogButtonBox::onButtonClicked()
@ -381,12 +382,12 @@ void QskDialogButtonBox::onButtonClicked()
if ( button == nullptr )
return;
switch ( buttonRole( button ) )
switch ( actionRole( button ) )
{
case QskDialog::AcceptRole:
case QskDialog::YesRole:
{
m_data->clickedButton = standardButton( button );
m_data->clickedAction = action( button );
Q_EMIT clicked( button );
Q_EMIT accepted();
@ -396,7 +397,7 @@ void QskDialogButtonBox::onButtonClicked()
case QskDialog::NoRole:
case QskDialog::DestructiveRole:
{
m_data->clickedButton = standardButton( button );
m_data->clickedAction = action( button );
Q_EMIT clicked( button );
Q_EMIT rejected();
@ -404,7 +405,7 @@ void QskDialogButtonBox::onButtonClicked()
}
default:
{
m_data->clickedButton = QskDialog::NoButton;
m_data->clickedAction = QskDialog::NoAction;
Q_EMIT clicked( button );
break;
@ -412,44 +413,44 @@ void QskDialogButtonBox::onButtonClicked()
}
}
QskDialog::StandardButtons QskDialogButtonBox::standardButtons() const
QskDialog::Actions QskDialogButtonBox::actions() const
{
QskDialog::StandardButtons standardButtons;
QskDialog::Actions actions;
for ( int i = 0; i < QskDialog::NButtonRoles; i++ )
for ( int i = 0; i < QskDialog::NActionRoles; i++ )
{
const auto& buttons = m_data->buttons[ i ];
for ( const auto btn : buttons )
standardButtons |= this->standardButton( btn );
actions |= action( btn );
}
return standardButtons;
return actions;
}
QskDialog::StandardButton QskDialogButtonBox::standardButton( const QskPushButton* button ) const
QskDialog::Action QskDialogButtonBox::action( const QskPushButton* button ) const
{
if ( button )
{
if ( auto dialogButton = qobject_cast< const QskDialogButton* >( button ) )
return dialogButton->standardButton();
return dialogButton->action();
const QVariant value = button->property( "standardButton" );
if ( value.canConvert< int >() )
return static_cast< QskDialog::StandardButton >( value.toInt() );
return static_cast< QskDialog::Action >( value.toInt() );
}
return QskDialog::NoButton;
return QskDialog::NoAction;
}
QskPushButton* QskDialogButtonBox::button( QskDialog::StandardButton standardButton ) const
QskPushButton* QskDialogButtonBox::button( QskDialog::Action action ) const
{
for ( int i = 0; i < QskDialog::NButtonRoles; i++ )
for ( int i = 0; i < QskDialog::NActionRoles; i++ )
{
const auto& buttons = m_data->buttons[ i ];
for ( auto btn : buttons )
{
if ( this->standardButton( btn ) == standardButton )
if ( this->action( btn ) == action )
return btn;
}
}
@ -457,18 +458,18 @@ QskPushButton* QskDialogButtonBox::button( QskDialog::StandardButton standardBut
return nullptr;
}
QskPushButton* QskDialogButtonBox::buttonFromRole( QskDialog::ButtonRole role ) const
QskPushButton* QskDialogButtonBox::buttonFromRole( QskDialog::ActionRole role ) const
{
if ( role < 0 || role >= QskDialog::NButtonRoles )
if ( role < 0 || role >= QskDialog::NActionRoles )
return nullptr;
const auto& buttons = m_data->buttons[ role ];
return buttons.isEmpty() ? nullptr : buttons.first();
}
QskDialog::StandardButton QskDialogButtonBox::clickedButton() const
QskDialog::Action QskDialogButtonBox::clickedAction() const
{
return m_data->clickedButton;
return m_data->clickedAction;
}
bool QskDialogButtonBox::event( QEvent* event )
@ -493,12 +494,12 @@ bool QskDialogButtonBox::isDefaultButtonKeyEvent( const QKeyEvent* event )
}
}
QString QskDialogButtonBox::buttonText( QskDialog::StandardButton standardButton )
QString QskDialogButtonBox::buttonText( QskDialog::Action action )
{
// should be redirected through the skin !
const QPlatformTheme* theme = QGuiApplicationPrivate::platformTheme();
QString text = theme->standardButtonText( standardButton );
QString text = theme->standardButtonText( action );
#if QT_VERSION < QT_VERSION_CHECK( 5, 7, 0 )
text.remove( '&' );

View File

@ -38,24 +38,24 @@ class QSK_EXPORT QskDialogButtonBox : public QskBox
void setCenteredButtons( bool center );
bool centeredButtons() const;
void addButton( QskPushButton* button, QskDialog::ButtonRole role );
void addButton( QskDialog::StandardButton button );
void removeButton( QskPushButton* button );
void addButton( QskPushButton*, QskDialog::ActionRole );
void addButton( QskDialog::Action );
void removeButton( QskPushButton* );
void clear();
QVector< QskPushButton* > buttons() const;
QskDialog::ButtonRole buttonRole( const QskPushButton* ) const;
QskDialog::ActionRole actionRole( const QskPushButton* ) const;
void setStandardButtons( QskDialog::StandardButtons buttons );
QskDialog::StandardButtons standardButtons() const;
QskDialog::StandardButton standardButton( const QskPushButton* ) const;
void setActions( QskDialog::Actions );
QskDialog::Actions actions() const;
QskDialog::Action action( const QskPushButton* ) const;
QskDialog::StandardButton defaultButtonCandidate() const;
QskDialog::Action defaultActionCandidate() const;
QskPushButton* button( QskDialog::StandardButton ) const;
QskPushButton* buttonFromRole( QskDialog::ButtonRole ) const;
QskPushButton* button( QskDialog::Action ) const;
QskPushButton* buttonFromRole( QskDialog::ActionRole ) const;
QskDialog::StandardButton clickedButton() const;
QskDialog::Action clickedAction() const;
QSizeF contentsSizeHint() const override;
@ -63,7 +63,7 @@ class QSK_EXPORT QskDialogButtonBox : public QskBox
QskAspect::Subcontrol ) const override;
static bool isDefaultButtonKeyEvent( const QKeyEvent* );
static QString buttonText( QskDialog::StandardButton );
static QString buttonText( QskDialog::Action );
Q_SIGNALS:
void clicked( QskPushButton* button );
@ -77,7 +77,7 @@ class QSK_EXPORT QskDialogButtonBox : public QskBox
bool event( QEvent* event ) override;
void updateLayout() override;
virtual QskPushButton* createButton( QskDialog::StandardButton ) const;
virtual QskPushButton* createButton( QskDialog::Action ) const;
void invalidateLayout();

View File

@ -70,15 +70,8 @@ namespace
class QskInputSubWindow::PrivateData
{
public:
PrivateData()
: standardButtons( QskDialog::NoButton )
, defaultButton( QskDialog::NoButton )
, inputControl( nullptr )
{
}
QskDialog::StandardButtons standardButtons;
QskDialog::StandardButton defaultButton;
QskDialog::Actions actions = QskDialog::NoAction;
QskDialog::Action defaultAction = QskDialog::NoAction;
QskTextLabel* infoTextLabel;
QskGraphicLabel* symbolLabel;
@ -129,36 +122,36 @@ QskInputSubWindow::~QskInputSubWindow()
{
}
void QskInputSubWindow::setStandardButtons( QskDialog::StandardButtons buttons )
void QskInputSubWindow::setActions( QskDialog::Actions actions )
{
if ( m_data->standardButtons == buttons )
if ( m_data->actions == actions )
return;
m_data->standardButtons = buttons;
m_data->actions = actions;
m_data->buttonBox->setStandardButtons( buttons );
m_data->buttonBox->setVisible( buttons != QskDialog::NoButton );
m_data->buttonBox->setActions( actions );
m_data->buttonBox->setVisible( actions != QskDialog::NoAction );
#if 1
const auto btns = m_data->buttonBox->buttons();
if ( !btns.isEmpty() )
btns[ 0 ]->setFocus( true );
const auto buttons = m_data->buttonBox->buttons();
if ( !buttons.isEmpty() )
buttons[ 0 ]->setFocus( true );
#endif
}
QskDialog::StandardButtons QskInputSubWindow::standardButtons() const
QskDialog::Actions QskInputSubWindow::actions() const
{
return m_data->buttonBox->standardButtons();
return m_data->buttonBox->actions();
}
QskDialog::StandardButton QskInputSubWindow::defaultButton() const
QskDialog::Action QskInputSubWindow::defaultAction() const
{
return m_data->defaultButton;
return m_data->defaultAction;
}
void QskInputSubWindow::setDefaultButton( QskDialog::StandardButton button )
void QskInputSubWindow::setDefaultAction( QskDialog::Action action )
{
m_data->defaultButton = button;
m_data->defaultAction = action;
}
void QskInputSubWindow::setInfoText( const QString& text )
@ -243,16 +236,16 @@ const QskDialogButtonBox* QskInputSubWindow::buttonBox() const
return m_data->buttonBox;
}
QskDialog::StandardButton QskInputSubWindow::clickedButton() const
QskDialog::Action QskInputSubWindow::clickedAction() const
{
return m_data->buttonBox->clickedButton();
return m_data->buttonBox->clickedAction();
}
void QskInputSubWindow::keyPressEvent( QKeyEvent* event )
{
if ( QskDialogButtonBox::isDefaultButtonKeyEvent( event ) )
{
QskPushButton* button = m_data->buttonBox->button( defaultButton() );
QskPushButton* button = m_data->buttonBox->button( defaultAction() );
if ( button && button->isEnabled() )
button->click();
}

View File

@ -31,11 +31,11 @@ class QSK_EXPORT QskInputSubWindow : public QskDialogSubWindow
QskInputSubWindow( QQuickItem* parent = nullptr );
~QskInputSubWindow() override;
QskDialog::StandardButtons standardButtons() const;
void setStandardButtons( QskDialog::StandardButtons );
QskDialog::Actions actions() const;
void setActions( QskDialog::Actions );
QskDialog::StandardButton defaultButton() const;
void setDefaultButton( QskDialog::StandardButton );
QskDialog::Action defaultAction() const;
void setDefaultAction( QskDialog::Action );
void setInfoTextOptions( const QskTextOptions& );
QskTextOptions infoTextOptions() const;
@ -50,7 +50,7 @@ class QSK_EXPORT QskInputSubWindow : public QskDialogSubWindow
void setSymbol( const QskGraphic& );
QskGraphic symbol() const;
QskDialog::StandardButton clickedButton() const;
QskDialog::Action clickedAction() const;
QskDialogButtonBox* buttonBox();
const QskDialogButtonBox* buttonBox() const;

View File

@ -55,26 +55,26 @@ QskInputSubWindow* QskInputWindow::subWindow() const
return m_subWindow;
}
QskDialog::StandardButtons QskInputWindow::standardButtons() const
QskDialog::Actions QskInputWindow::actions() const
{
return m_subWindow ? m_subWindow->standardButtons() : QskDialog::NoButton;
return m_subWindow ? m_subWindow->actions() : QskDialog::NoAction;
}
void QskInputWindow::setStandardButtons( QskDialog::StandardButtons buttons )
void QskInputWindow::setActions( QskDialog::Actions actions )
{
if ( m_subWindow )
m_subWindow->setStandardButtons( buttons );
m_subWindow->setActions( actions );
}
QskDialog::StandardButton QskInputWindow::defaultButton() const
QskDialog::Action QskInputWindow::defaultAction() const
{
return m_subWindow ? m_subWindow->defaultButton() : QskDialog::NoButton;
return m_subWindow ? m_subWindow->defaultAction() : QskDialog::NoAction;
}
void QskInputWindow::setDefaultButton( QskDialog::StandardButton button )
void QskInputWindow::setDefaultAction( QskDialog::Action action )
{
if ( m_subWindow )
m_subWindow->setDefaultButton( button );
m_subWindow->setDefaultAction( action );
}
void QskInputWindow::setInfoText( const QString& text )
@ -136,9 +136,9 @@ QskGraphic QskInputWindow::symbol() const
return m_subWindow ? m_subWindow->symbol() : QskGraphic();
}
QskDialog::StandardButton QskInputWindow::clickedButton() const
QskDialog::Action QskInputWindow::clickedAction() const
{
return m_subWindow->clickedButton();
return m_subWindow->clickedAction();
}
QskDialogButtonBox* QskInputWindow::buttonBox()

View File

@ -33,26 +33,26 @@ class QSK_EXPORT QskInputWindow : public QskDialogWindow
QskInputWindow( QWindow* parent = nullptr );
~QskInputWindow() override;
QskDialog::StandardButtons standardButtons() const;
void setStandardButtons( QskDialog::StandardButtons );
QskDialog::Actions actions() const;
void setActions( QskDialog::Actions );
QskDialog::StandardButton defaultButton() const;
void setDefaultButton( QskDialog::StandardButton );
QskDialog::Action defaultAction() const;
void setDefaultAction( QskDialog::Action );
void setInfoTextOptions( const QskTextOptions& );
QskTextOptions infoTextOptions() const;
QString infoText() const;
void setSymbolType( int symbolType );
void setSymbolType( int );
void setSymbolSource( const QUrl& url );
void setSymbolSource( const QUrl& );
QUrl symbolSource() const;
void setSymbol( const QskGraphic& );
QskGraphic symbol() const;
QskDialog::StandardButton clickedButton() const;
QskDialog::Action clickedAction() const;
QskDialogButtonBox* buttonBox();
const QskDialogButtonBox* buttonBox() const;

View File

@ -39,7 +39,7 @@ QskSelectionSubWindow::QskSelectionSubWindow( QQuickItem* parent )
: Inherited( parent )
{
setInputControl( new ListBox( this ) );
setStandardButtons( QskDialog::Ok | QskDialog::Cancel );
setActions( QskDialog::Ok | QskDialog::Cancel );
}
QskSelectionSubWindow::~QskSelectionSubWindow()