API adjustments
This commit is contained in:
parent
c5a4a5d8fe
commit
b55e5ee00a
|
@ -68,6 +68,17 @@ QskHashValue QskLabelData::hash( QskHashValue seed ) const
|
||||||
return m_icon.hash( hash );
|
return m_icon.hash( hash );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVector< QskLabelData > qskCreateLabelData( const QVector< QString >& list )
|
||||||
|
{
|
||||||
|
QVector< QskLabelData > labelData;
|
||||||
|
labelData.reserve( list.size() );
|
||||||
|
|
||||||
|
for ( const auto& text : list )
|
||||||
|
labelData += QskLabelData( text );
|
||||||
|
|
||||||
|
return labelData;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef QT_NO_DEBUG_STREAM
|
#ifndef QT_NO_DEBUG_STREAM
|
||||||
|
|
||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "QskIcon.h"
|
#include "QskIcon.h"
|
||||||
|
|
||||||
#include <qstring.h>
|
#include <qstring.h>
|
||||||
|
#include <qvector.h>
|
||||||
#include <qmetatype.h>
|
#include <qmetatype.h>
|
||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
|
|
||||||
|
@ -69,6 +70,8 @@ inline bool QskLabelData::operator!=( const QskLabelData& other ) const noexcept
|
||||||
return ( !( *this == other ) );
|
return ( !( *this == other ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSK_EXPORT QVector< QskLabelData > qskCreateLabelData( const QVector< QString >& );
|
||||||
|
|
||||||
#ifndef QT_NO_DEBUG_STREAM
|
#ifndef QT_NO_DEBUG_STREAM
|
||||||
|
|
||||||
class QDebug;
|
class QDebug;
|
||||||
|
|
|
@ -140,6 +140,11 @@ int QskComboBox::addOption( const QskLabelData& option )
|
||||||
return count() - 1;
|
return count() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QskComboBox::setOptions( const QStringList& options )
|
||||||
|
{
|
||||||
|
setOptions( qskCreateLabelData( options ) );
|
||||||
|
}
|
||||||
|
|
||||||
void QskComboBox::setOptions( const QVector< QskLabelData >& options )
|
void QskComboBox::setOptions( const QVector< QskLabelData >& options )
|
||||||
{
|
{
|
||||||
if ( options == m_data->options )
|
if ( options == m_data->options )
|
||||||
|
|
|
@ -7,8 +7,11 @@
|
||||||
#define QSK_COMBO_BOX_H
|
#define QSK_COMBO_BOX_H
|
||||||
|
|
||||||
#include "QskControl.h"
|
#include "QskControl.h"
|
||||||
|
#include <qstringlist.h>
|
||||||
|
|
||||||
|
class QskTextOptions;
|
||||||
class QskLabelData;
|
class QskLabelData;
|
||||||
|
class QUrl;
|
||||||
|
|
||||||
class QSK_EXPORT QskComboBox : public QskControl
|
class QSK_EXPORT QskComboBox : public QskControl
|
||||||
{
|
{
|
||||||
|
@ -52,6 +55,7 @@ class QSK_EXPORT QskComboBox : public QskControl
|
||||||
int addOption( const QskLabelData& );
|
int addOption( const QskLabelData& );
|
||||||
|
|
||||||
void setOptions( const QVector< QskLabelData >& );
|
void setOptions( const QVector< QskLabelData >& );
|
||||||
|
void setOptions( const QStringList& );
|
||||||
|
|
||||||
QVector< QskLabelData > options() const;
|
QVector< QskLabelData > options() const;
|
||||||
QskLabelData optionAt( int ) const;
|
QskLabelData optionAt( int ) const;
|
||||||
|
|
|
@ -37,11 +37,8 @@ class QskMenu::PrivateData
|
||||||
// QVector< bool > enabled;
|
// QVector< bool > enabled;
|
||||||
QVector< int > separators;
|
QVector< int > separators;
|
||||||
|
|
||||||
|
int triggeredIndex = -1;
|
||||||
// current/selected are not well defined yet, TODO ...
|
|
||||||
int currentIndex = -1;
|
int currentIndex = -1;
|
||||||
int selectedIndex = -1;
|
|
||||||
|
|
||||||
bool isPressed = false;
|
bool isPressed = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -62,6 +59,9 @@ QskMenu::QskMenu( QQuickItem* parent )
|
||||||
// we hide the focus indicator while fading
|
// we hide the focus indicator while fading
|
||||||
connect( this, &QskMenu::fadingChanged, this,
|
connect( this, &QskMenu::fadingChanged, this,
|
||||||
&QskControl::focusIndicatorRectChanged );
|
&QskControl::focusIndicatorRectChanged );
|
||||||
|
|
||||||
|
connect( this, &QskMenu::opened, this,
|
||||||
|
[this]() { m_data->triggeredIndex = -1; } );
|
||||||
}
|
}
|
||||||
|
|
||||||
QskMenu::~QskMenu()
|
QskMenu::~QskMenu()
|
||||||
|
@ -137,10 +137,14 @@ int QskMenu::addOption( const QskLabelData& option )
|
||||||
return count() - 1;
|
return count() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QskMenu::setOptions( const QStringList& options )
|
||||||
|
{
|
||||||
|
setOptions( qskCreateLabelData( options ) );
|
||||||
|
}
|
||||||
|
|
||||||
void QskMenu::setOptions( const QVector< QskLabelData >& options )
|
void QskMenu::setOptions( const QVector< QskLabelData >& options )
|
||||||
{
|
{
|
||||||
m_data->options = options;
|
m_data->options = options;
|
||||||
m_data->selectedIndex = -1;
|
|
||||||
|
|
||||||
if ( m_data->currentIndex >= 0 )
|
if ( m_data->currentIndex >= 0 )
|
||||||
{
|
{
|
||||||
|
@ -159,16 +163,8 @@ void QskMenu::setOptions( const QVector< QskLabelData >& options )
|
||||||
|
|
||||||
void QskMenu::clear()
|
void QskMenu::clear()
|
||||||
{
|
{
|
||||||
m_data->selectedIndex = m_data->currentIndex = -1;
|
|
||||||
m_data->separators.clear();
|
m_data->separators.clear();
|
||||||
|
setOptions( QVector< QskLabelData >() );
|
||||||
if ( !m_data->options.isEmpty() )
|
|
||||||
{
|
|
||||||
m_data->options.clear();
|
|
||||||
|
|
||||||
if ( isComponentComplete() )
|
|
||||||
Q_EMIT optionsChanged();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector< QskLabelData > QskMenu::options() const
|
QVector< QskLabelData > QskMenu::options() const
|
||||||
|
@ -204,12 +200,9 @@ int QskMenu::separatorCount() const
|
||||||
return m_data->separators.count();
|
return m_data->separators.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QskMenu::currentText() const
|
int QskMenu::currentIndex() const
|
||||||
{
|
{
|
||||||
if ( m_data->currentIndex >= 0 )
|
return m_data->currentIndex;
|
||||||
return optionAt( m_data->currentIndex ).text();
|
|
||||||
|
|
||||||
return QString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskMenu::setCurrentIndex( int index )
|
void QskMenu::setCurrentIndex( int index )
|
||||||
|
@ -229,9 +222,19 @@ void QskMenu::setCurrentIndex( int index )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int QskMenu::currentIndex() const
|
QString QskMenu::currentText() const
|
||||||
{
|
{
|
||||||
return m_data->currentIndex;
|
return optionAt( m_data->currentIndex ).text();
|
||||||
|
}
|
||||||
|
|
||||||
|
int QskMenu::triggeredIndex() const
|
||||||
|
{
|
||||||
|
return m_data->triggeredIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString QskMenu::triggeredText() const
|
||||||
|
{
|
||||||
|
return optionAt( m_data->triggeredIndex ).text();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskMenu::keyPressEvent( QKeyEvent* event )
|
void QskMenu::keyPressEvent( QKeyEvent* event )
|
||||||
|
@ -267,28 +270,29 @@ void QskMenu::keyPressEvent( QKeyEvent* event )
|
||||||
case Qt::Key_Escape:
|
case Qt::Key_Escape:
|
||||||
case Qt::Key_Cancel:
|
case Qt::Key_Cancel:
|
||||||
{
|
{
|
||||||
setSelectedIndex( -1 );
|
close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
const int steps = qskFocusChainIncrement( event );
|
if ( const int steps = qskFocusChainIncrement( event ) )
|
||||||
|
|
||||||
if( steps != 0 )
|
|
||||||
{
|
|
||||||
traverse( steps );
|
traverse( steps );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void QskMenu::keyReleaseEvent( QKeyEvent* )
|
void QskMenu::keyReleaseEvent( QKeyEvent* )
|
||||||
{
|
{
|
||||||
if( m_data->isPressed )
|
if( m_data->isPressed )
|
||||||
{
|
{
|
||||||
m_data->isPressed = false;
|
m_data->isPressed = false;
|
||||||
setSelectedIndex( m_data->currentIndex );
|
|
||||||
|
if ( m_data->currentIndex >= 0 )
|
||||||
|
{
|
||||||
|
trigger( m_data->currentIndex );
|
||||||
|
close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,9 +363,14 @@ void QskMenu::mouseReleaseEvent( QMouseEvent* event )
|
||||||
{
|
{
|
||||||
m_data->isPressed = false;
|
m_data->isPressed = false;
|
||||||
|
|
||||||
const auto index = indexAtPosition( qskMousePosition( event ) );
|
const auto index = m_data->currentIndex;
|
||||||
if ( index == m_data->currentIndex )
|
|
||||||
setSelectedIndex( index );
|
if ( ( index >= 0 )
|
||||||
|
&& ( index == indexAtPosition( qskMousePosition( event ) ) ) )
|
||||||
|
{
|
||||||
|
trigger( m_data->currentIndex );
|
||||||
|
close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -394,20 +403,6 @@ QRectF QskMenu::focusIndicatorRect() const
|
||||||
return Inherited::focusIndicatorRect();
|
return Inherited::focusIndicatorRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskMenu::setSelectedIndex( int index )
|
|
||||||
{
|
|
||||||
if ( !isOpen() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
if ( index >= 0 )
|
|
||||||
setCurrentIndex( index );
|
|
||||||
|
|
||||||
m_data->selectedIndex = index;
|
|
||||||
Q_EMIT triggered( index );
|
|
||||||
|
|
||||||
close();
|
|
||||||
}
|
|
||||||
|
|
||||||
QRectF QskMenu::cellRect( int index ) const
|
QRectF QskMenu::cellRect( int index ) const
|
||||||
{
|
{
|
||||||
return effectiveSkinlet()->sampleRect(
|
return effectiveSkinlet()->sampleRect(
|
||||||
|
@ -420,11 +415,19 @@ int QskMenu::indexAtPosition( const QPointF& pos ) const
|
||||||
this, contentsRect(), QskMenu::Segment, pos );
|
this, contentsRect(), QskMenu::Segment, pos );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QskMenu::trigger( int index )
|
||||||
|
{
|
||||||
|
if ( index >= 0 && index < m_data->options.count() )
|
||||||
|
{
|
||||||
|
m_data->triggeredIndex = index;
|
||||||
|
Q_EMIT triggered( index );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int QskMenu::exec()
|
int QskMenu::exec()
|
||||||
{
|
{
|
||||||
m_data->selectedIndex = -1;
|
|
||||||
(void) execPopup();
|
(void) execPopup();
|
||||||
return m_data->selectedIndex;
|
return m_data->triggeredIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "moc_QskMenu.cpp"
|
#include "moc_QskMenu.cpp"
|
||||||
|
|
|
@ -7,12 +7,11 @@
|
||||||
#define QSK_MENU_H
|
#define QSK_MENU_H
|
||||||
|
|
||||||
#include "QskPopup.h"
|
#include "QskPopup.h"
|
||||||
|
#include <qstringlist.h>
|
||||||
#include <qurl.h>
|
|
||||||
#include <qstring.h>
|
|
||||||
|
|
||||||
class QskTextOptions;
|
class QskTextOptions;
|
||||||
class QskLabelData;
|
class QskLabelData;
|
||||||
|
class QUrl;
|
||||||
|
|
||||||
class QSK_EXPORT QskMenu : public QskPopup
|
class QSK_EXPORT QskMenu : public QskPopup
|
||||||
{
|
{
|
||||||
|
@ -32,7 +31,10 @@ class QSK_EXPORT QskMenu : public QskPopup
|
||||||
Q_PROPERTY( int currentIndex READ currentIndex
|
Q_PROPERTY( int currentIndex READ currentIndex
|
||||||
WRITE setCurrentIndex NOTIFY currentIndexChanged )
|
WRITE setCurrentIndex NOTIFY currentIndexChanged )
|
||||||
|
|
||||||
Q_PROPERTY( QString currentText READ currentText )
|
Q_PROPERTY( int triggeredIndex READ triggeredIndex NOTIFY triggered )
|
||||||
|
|
||||||
|
Q_PROPERTY( QString triggeredText READ triggeredText NOTIFY triggered )
|
||||||
|
Q_PROPERTY( QString currentText READ currentText NOTIFY currentIndexChanged )
|
||||||
|
|
||||||
using Inherited = QskPopup;
|
using Inherited = QskPopup;
|
||||||
|
|
||||||
|
@ -58,6 +60,7 @@ class QSK_EXPORT QskMenu : public QskPopup
|
||||||
int addOption( const QskLabelData& );
|
int addOption( const QskLabelData& );
|
||||||
|
|
||||||
void setOptions( const QVector< QskLabelData >& );
|
void setOptions( const QVector< QskLabelData >& );
|
||||||
|
void setOptions( const QStringList& );
|
||||||
|
|
||||||
QVector< QskLabelData > options() const;
|
QVector< QskLabelData > options() const;
|
||||||
QskLabelData optionAt( int ) const;
|
QskLabelData optionAt( int ) const;
|
||||||
|
@ -74,6 +77,9 @@ class QSK_EXPORT QskMenu : public QskPopup
|
||||||
int currentIndex() const;
|
int currentIndex() const;
|
||||||
QString currentText() const;
|
QString currentText() const;
|
||||||
|
|
||||||
|
int triggeredIndex() const;
|
||||||
|
QString triggeredText() const;
|
||||||
|
|
||||||
QRectF focusIndicatorRect() const override;
|
QRectF focusIndicatorRect() const override;
|
||||||
|
|
||||||
QRectF cellRect( int index ) const;
|
QRectF cellRect( int index ) const;
|
||||||
|
@ -106,10 +112,10 @@ class QSK_EXPORT QskMenu : public QskPopup
|
||||||
void mouseReleaseEvent( QMouseEvent* ) override;
|
void mouseReleaseEvent( QMouseEvent* ) override;
|
||||||
|
|
||||||
void aboutToShow() override;
|
void aboutToShow() override;
|
||||||
|
void trigger( int );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void traverse( int steps );
|
void traverse( int steps );
|
||||||
void setSelectedIndex( int index );
|
|
||||||
|
|
||||||
class PrivateData;
|
class PrivateData;
|
||||||
std::unique_ptr< PrivateData > m_data;
|
std::unique_ptr< PrivateData > m_data;
|
||||||
|
|
|
@ -124,6 +124,11 @@ QskLabelData QskSegmentedBar::optionAt( int index ) const
|
||||||
return m_data->options.value( index );
|
return m_data->options.value( index );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QskSegmentedBar::setOptions( const QStringList& options )
|
||||||
|
{
|
||||||
|
setOptions( qskCreateLabelData( options ) );
|
||||||
|
}
|
||||||
|
|
||||||
void QskSegmentedBar::setOptions( const QVector< QskLabelData >& options )
|
void QskSegmentedBar::setOptions( const QVector< QskLabelData >& options )
|
||||||
{
|
{
|
||||||
m_data->options = options;
|
m_data->options = options;
|
||||||
|
|
|
@ -7,12 +7,11 @@
|
||||||
#define QSK_SEGMENTED_BAR_H
|
#define QSK_SEGMENTED_BAR_H
|
||||||
|
|
||||||
#include "QskControl.h"
|
#include "QskControl.h"
|
||||||
|
#include <qstringlist.h>
|
||||||
#include <qurl.h>
|
|
||||||
#include <qstring.h>
|
|
||||||
|
|
||||||
class QskTextOptions;
|
class QskTextOptions;
|
||||||
class QskLabelData;
|
class QskLabelData;
|
||||||
|
class QUrl;
|
||||||
|
|
||||||
class QSK_EXPORT QskSegmentedBar : public QskControl
|
class QSK_EXPORT QskSegmentedBar : public QskControl
|
||||||
{
|
{
|
||||||
|
@ -55,6 +54,7 @@ class QSK_EXPORT QskSegmentedBar : public QskControl
|
||||||
int addOption( const QskLabelData& );
|
int addOption( const QskLabelData& );
|
||||||
|
|
||||||
void setOptions( const QVector< QskLabelData >& );
|
void setOptions( const QVector< QskLabelData >& );
|
||||||
|
void setOptions( const QStringList& );
|
||||||
|
|
||||||
QVector< QskLabelData > options() const;
|
QVector< QskLabelData > options() const;
|
||||||
QskLabelData optionAt( int ) const;
|
QskLabelData optionAt( int ) const;
|
||||||
|
|
Loading…
Reference in New Issue