Compare commits
35 Commits
master
...
features/m
Author | SHA1 | Date |
---|---|---|
|
f4b7aa33fe | |
|
ed584af5c1 | |
|
7f67014bef | |
|
607939a4dc | |
|
aa2a76996d | |
|
a40170159c | |
|
87ae5efd67 | |
|
714e47a74c | |
|
0408c70442 | |
|
8e81db43f1 | |
|
e56c1fae9d | |
|
e620b56d4e | |
|
beec40af06 | |
|
130bd3f9d2 | |
|
606de9080a | |
|
b273264629 | |
|
f67ff13f93 | |
|
ee7896e2d4 | |
|
9060f7cf75 | |
|
51fd38eb01 | |
|
78d3a9af9c | |
|
dbe1fad7ec | |
|
99151186fb | |
|
260c35f2a4 | |
|
ea36b7da8e | |
|
b7e4f10f91 | |
|
a0df814121 | |
|
defb193387 | |
|
b7fe24602c | |
|
b25852ff6f | |
|
b3ed7f90e4 | |
|
329efbb242 | |
|
b1a816e61e | |
|
a5a28bebc2 | |
|
2a7a68e915 |
|
@ -25,7 +25,7 @@
|
||||||
#include <QskPushButton.h>
|
#include <QskPushButton.h>
|
||||||
#include <QskPageIndicator.h>
|
#include <QskPageIndicator.h>
|
||||||
#include <QskScrollArea.h>
|
#include <QskScrollArea.h>
|
||||||
#include <QskMenu.h>
|
#include <QskMenuButton.h>
|
||||||
#include <QskWindow.h>
|
#include <QskWindow.h>
|
||||||
#include <QskDialog.h>
|
#include <QskDialog.h>
|
||||||
#include <QskSkinManager.h>
|
#include <QskSkinManager.h>
|
||||||
|
@ -37,6 +37,8 @@
|
||||||
#include <QskGraphicProvider.h>
|
#include <QskGraphicProvider.h>
|
||||||
#include <QskGraphicIO.h>
|
#include <QskGraphicIO.h>
|
||||||
#include <QskGraphic.h>
|
#include <QskGraphic.h>
|
||||||
|
#include <QskLabelData.h>
|
||||||
|
#include <QskSetup.h>
|
||||||
|
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
|
|
||||||
|
@ -118,49 +120,29 @@ namespace
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class MenuButton : public QskPushButton
|
class SkinButton final : public QskMenuButton
|
||||||
{
|
|
||||||
public:
|
|
||||||
MenuButton( const QString& text, QQuickItem* parent = nullptr )
|
|
||||||
: QskPushButton( text, parent )
|
|
||||||
{
|
|
||||||
connect( this, &QskPushButton::pressed, this, &MenuButton::openMenu );
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void openMenu()
|
|
||||||
{
|
|
||||||
auto menu = new QskMenu( window()->contentItem() );
|
|
||||||
|
|
||||||
populateMenu( menu );
|
|
||||||
|
|
||||||
menu->setOrigin( geometry().bottomLeft() );
|
|
||||||
menu->open();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void populateMenu( QskMenu* ) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class SkinButton final : public MenuButton
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SkinButton( const QString& text, QQuickItem* parent = nullptr )
|
SkinButton( const QString& text, QQuickItem* parent = nullptr )
|
||||||
: MenuButton( text, parent )
|
: QskMenuButton( text, parent )
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void populateMenu( QskMenu* menu ) override
|
|
||||||
{
|
{
|
||||||
const auto names = qskSkinManager->skinNames();
|
const auto names = qskSkinManager->skinNames();
|
||||||
|
|
||||||
for ( const auto& name : names )
|
setOptions( names );
|
||||||
menu->addOption( QUrl(), name );
|
|
||||||
|
|
||||||
if ( const auto index = names.indexOf( qskSkinManager->skinName() ) )
|
if ( const auto index = names.indexOf( qskSkinManager->skinName() ) )
|
||||||
menu->setCurrentIndex( index );
|
setStartIndex( index );
|
||||||
|
|
||||||
connect( menu, &QskMenu::triggered, this, &SkinButton::changeSkin );
|
connect( this, &QskMenuButton::triggered,
|
||||||
|
this, &SkinButton::changeSkin );
|
||||||
|
}
|
||||||
|
|
||||||
|
void openMenu() override
|
||||||
|
{
|
||||||
|
const auto names = qskSkinManager->skinNames();
|
||||||
|
setStartIndex( names.indexOf( qskSkinManager->skinName() ) );
|
||||||
|
|
||||||
|
QskMenuButton::openMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
void changeSkin( int index )
|
void changeSkin( int index )
|
||||||
|
@ -175,26 +157,27 @@ namespace
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileButton final : public MenuButton
|
class FileButton final : public QskMenuButton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileButton( const QString& text, QQuickItem* parent = nullptr )
|
FileButton( const QString& text, QQuickItem* parent = nullptr )
|
||||||
: MenuButton( text, parent )
|
: QskMenuButton( text, parent )
|
||||||
{
|
{
|
||||||
}
|
addOption( "image://shapes/Rectangle/White", "Print" );
|
||||||
|
addOption( "image://shapes/Diamond/Yellow", "Save As" );
|
||||||
private:
|
addOption( "image://shapes/Ellipse/Red", "Setup" );
|
||||||
void populateMenu( QskMenu* menu ) override
|
addSeparator();
|
||||||
{
|
addOption( "image://shapes/Hexagon/PapayaWhip", "Quit" );
|
||||||
menu->addOption( "image://shapes/Rectangle/White", "Print" );
|
|
||||||
menu->addOption( "image://shapes/Diamond/Yellow", "Save As" );
|
|
||||||
menu->addOption( "image://shapes/Ellipse/Red", "Setup" );
|
|
||||||
menu->addSeparator();
|
|
||||||
menu->addOption( "image://shapes/Hexagon/PapayaWhip", "Quit" );
|
|
||||||
|
|
||||||
// see https://github.com/uwerat/qskinny/issues/192
|
// see https://github.com/uwerat/qskinny/issues/192
|
||||||
connect( menu, &QskMenu::triggered,
|
connect( this, &QskMenuButton::triggered,
|
||||||
[]( int index ) { if ( index == 4 ) qApp->quit(); } );
|
this, &FileButton::activate );
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
void activate( int index )
|
||||||
|
{
|
||||||
|
if ( optionAt( index ).text() == "Quit" )
|
||||||
|
qApp->quit();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -233,6 +233,7 @@ list(APPEND HEADERS
|
||||||
controls/QskListViewSkinlet.h
|
controls/QskListViewSkinlet.h
|
||||||
controls/QskMenu.h
|
controls/QskMenu.h
|
||||||
controls/QskMenuSkinlet.h
|
controls/QskMenuSkinlet.h
|
||||||
|
controls/QskMenuButton.h
|
||||||
controls/QskObjectTree.h
|
controls/QskObjectTree.h
|
||||||
controls/QskPageIndicator.h
|
controls/QskPageIndicator.h
|
||||||
controls/QskPageIndicatorSkinlet.h
|
controls/QskPageIndicatorSkinlet.h
|
||||||
|
@ -343,8 +344,9 @@ list(APPEND SOURCES
|
||||||
controls/QskItemAnchors.cpp
|
controls/QskItemAnchors.cpp
|
||||||
controls/QskListView.cpp
|
controls/QskListView.cpp
|
||||||
controls/QskListViewSkinlet.cpp
|
controls/QskListViewSkinlet.cpp
|
||||||
controls/QskMenuSkinlet.cpp
|
|
||||||
controls/QskMenu.cpp
|
controls/QskMenu.cpp
|
||||||
|
controls/QskMenuSkinlet.cpp
|
||||||
|
controls/QskMenuButton.cpp
|
||||||
controls/QskObjectTree.cpp
|
controls/QskObjectTree.cpp
|
||||||
controls/QskPageIndicator.cpp
|
controls/QskPageIndicator.cpp
|
||||||
controls/QskPageIndicatorSkinlet.cpp
|
controls/QskPageIndicatorSkinlet.cpp
|
||||||
|
|
|
@ -0,0 +1,153 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* QSkinny - Copyright (C) The authors
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#include "QskMenuButton.h"
|
||||||
|
#include "QskMenu.h"
|
||||||
|
#include "QskLabelData.h"
|
||||||
|
|
||||||
|
#include <qpointer.h>
|
||||||
|
#include <qquickwindow.h>
|
||||||
|
|
||||||
|
class QskMenuButton::PrivateData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int triggeredIndex = -1;
|
||||||
|
int startIndex = -1;
|
||||||
|
|
||||||
|
QPointer< QskMenu > menu;
|
||||||
|
QVector< QskLabelData > options;
|
||||||
|
};
|
||||||
|
|
||||||
|
QskMenuButton::QskMenuButton( QQuickItem* parent )
|
||||||
|
: QskMenuButton( QString(), parent )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QskMenuButton::QskMenuButton( const QString& text, QQuickItem* parent )
|
||||||
|
: QskPushButton( text, parent )
|
||||||
|
, m_data( new PrivateData )
|
||||||
|
{
|
||||||
|
connect( this, &QskPushButton::pressed,
|
||||||
|
this, &QskMenuButton::openMenu );
|
||||||
|
}
|
||||||
|
|
||||||
|
QskMenuButton::~QskMenuButton()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int QskMenuButton::addOption( const QString& graphicSource, const QString& text )
|
||||||
|
{
|
||||||
|
return addOption( QskLabelData( text, graphicSource ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
int QskMenuButton::addOption( const QUrl& graphicSource, const QString& text )
|
||||||
|
{
|
||||||
|
return addOption( QskLabelData( text, graphicSource ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
int QskMenuButton::addOption( const QskLabelData& option )
|
||||||
|
{
|
||||||
|
const int index = m_data->options.count();
|
||||||
|
m_data->options += option;
|
||||||
|
|
||||||
|
if ( m_data->menu )
|
||||||
|
m_data->menu->setOptions( m_data->options );
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QskMenuButton::addSeparator()
|
||||||
|
{
|
||||||
|
addOption( QskLabelData() );
|
||||||
|
}
|
||||||
|
|
||||||
|
void QskMenuButton::setOptions( const QStringList& options )
|
||||||
|
{
|
||||||
|
setOptions( qskCreateLabelData( options ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void QskMenuButton::setOptions( const QVector< QskLabelData >& options )
|
||||||
|
{
|
||||||
|
m_data->options = options;
|
||||||
|
|
||||||
|
if ( m_data->menu )
|
||||||
|
m_data->menu->setOptions( m_data->options );
|
||||||
|
}
|
||||||
|
|
||||||
|
void QskMenuButton::clear()
|
||||||
|
{
|
||||||
|
m_data->options.clear();
|
||||||
|
|
||||||
|
if ( m_data->menu )
|
||||||
|
m_data->menu->clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector< QskLabelData > QskMenuButton::options() const
|
||||||
|
{
|
||||||
|
return m_data->options;
|
||||||
|
}
|
||||||
|
|
||||||
|
QskLabelData QskMenuButton::optionAt( int index ) const
|
||||||
|
{
|
||||||
|
return m_data->options.value( index );
|
||||||
|
}
|
||||||
|
|
||||||
|
int QskMenuButton::optionsCount() const
|
||||||
|
{
|
||||||
|
return m_data->options.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QskMenuButton::setStartIndex( int index )
|
||||||
|
{
|
||||||
|
m_data->startIndex = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
int QskMenuButton::triggeredIndex() const
|
||||||
|
{
|
||||||
|
return m_data->triggeredIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString QskMenuButton::triggeredText() const
|
||||||
|
{
|
||||||
|
return optionAt( m_data->triggeredIndex ).text();
|
||||||
|
}
|
||||||
|
|
||||||
|
const QskMenu* QskMenuButton::menu() const
|
||||||
|
{
|
||||||
|
return m_data->menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QskMenuButton::openMenu()
|
||||||
|
{
|
||||||
|
if ( m_data->menu || window() == nullptr || m_data->options.isEmpty() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_data->triggeredIndex = -1;
|
||||||
|
|
||||||
|
auto menu = new QskMenu( window()->contentItem() );
|
||||||
|
m_data->menu = menu;
|
||||||
|
|
||||||
|
menu->setOptions( m_data->options );
|
||||||
|
if ( m_data->startIndex >= 0 )
|
||||||
|
menu->setCurrentIndex( m_data->startIndex );
|
||||||
|
|
||||||
|
menu->setOrigin( geometry().bottomLeft() );
|
||||||
|
|
||||||
|
connect( menu, &QskMenu::triggered,
|
||||||
|
this, &QskMenuButton::updateTriggeredIndex );
|
||||||
|
|
||||||
|
menu->open();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QskMenuButton::updateTriggeredIndex( int index )
|
||||||
|
{
|
||||||
|
if ( m_data->triggeredIndex != index )
|
||||||
|
{
|
||||||
|
m_data->triggeredIndex = index;
|
||||||
|
Q_EMIT triggered( index );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "moc_QskMenuButton.cpp"
|
|
@ -0,0 +1,67 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* QSkinny - Copyright (C) The authors
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef QSK_MENU_BUTTON_H
|
||||||
|
#define QSK_MENU_BUTTON_H
|
||||||
|
|
||||||
|
#include "QskPushButton.h"
|
||||||
|
|
||||||
|
class QskMenu;
|
||||||
|
class QskLabelData;
|
||||||
|
|
||||||
|
class QSK_EXPORT QskMenuButton : public QskPushButton
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY( QVector< QskLabelData > options READ options
|
||||||
|
WRITE setOptions NOTIFY optionsChanged )
|
||||||
|
|
||||||
|
Q_PROPERTY( int optionsCount READ optionsCount )
|
||||||
|
Q_PROPERTY( int triggeredIndex READ triggeredIndex NOTIFY triggered )
|
||||||
|
Q_PROPERTY( QString triggeredText READ triggeredText NOTIFY triggered )
|
||||||
|
|
||||||
|
public:
|
||||||
|
QskMenuButton( QQuickItem* parent = nullptr );
|
||||||
|
QskMenuButton( const QString& text, QQuickItem* parent = nullptr );
|
||||||
|
|
||||||
|
~QskMenuButton() override;
|
||||||
|
|
||||||
|
int addOption( const QString&, const QString& );
|
||||||
|
int addOption( const QUrl&, const QString& );
|
||||||
|
int addOption( const QskLabelData& );
|
||||||
|
void addSeparator();
|
||||||
|
|
||||||
|
void setOptions( const QVector< QskLabelData >& );
|
||||||
|
void setOptions( const QStringList& );
|
||||||
|
|
||||||
|
QVector< QskLabelData > options() const;
|
||||||
|
QskLabelData optionAt( int ) const;
|
||||||
|
|
||||||
|
int optionsCount() const;
|
||||||
|
|
||||||
|
const QskMenu* menu() const;
|
||||||
|
|
||||||
|
int triggeredIndex() const;
|
||||||
|
QString triggeredText() const;
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
void setStartIndex( int );
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void triggered( int index );
|
||||||
|
void optionsChanged();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void openMenu();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void updateTriggeredIndex( int );
|
||||||
|
|
||||||
|
class PrivateData;
|
||||||
|
std::unique_ptr< PrivateData > m_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue