qskinny/src/dialogs/QskSelectionSubWindow.cpp

99 lines
2.5 KiB
C++
Raw Normal View History

2017-07-21 16:21:34 +00:00
/******************************************************************************
2024-01-17 13:31:45 +00:00
* QSkinny - Copyright (C) The authors
2023-04-06 07:23:37 +00:00
* SPDX-License-Identifier: BSD-3-Clause
2017-07-21 16:21:34 +00:00
*****************************************************************************/
#include "QskSelectionSubWindow.h"
#include "QskSimpleListBox.h"
/*
QInputDialog uses a combo box instead of a list widget
Guess we should do the same TODO ...
*/
static inline QskSimpleListBox* qskListBox(
QskSelectionSubWindow* subWindow )
2017-07-21 16:21:34 +00:00
{
return qobject_cast< QskSimpleListBox* >( subWindow->contentItem() );
}
2018-11-06 17:54:21 +00:00
static inline const QskSimpleListBox* qskListBox(
const QskSelectionSubWindow* subWindow )
{
return qobject_cast< QskSimpleListBox* >( subWindow->contentItem() );
}
2018-11-06 17:54:21 +00:00
namespace
{
2017-07-21 16:21:34 +00:00
class ListBox final : public QskSimpleListBox
{
2018-08-03 06:15:28 +00:00
public:
ListBox( QskSelectionSubWindow* subWindow )
2017-07-21 16:21:34 +00:00
{
setObjectName( QStringLiteral( "QskSelectionSubWindowListBox" ) );
2018-08-03 06:15:28 +00:00
connect( this, &QskSimpleListBox::selectedRowChanged,
subWindow, &QskSelectionSubWindow::selectedRowChanged );
2017-07-21 16:21:34 +00:00
2018-08-03 06:15:28 +00:00
connect( this, &QskSimpleListBox::selectedEntryChanged,
subWindow, &QskSelectionSubWindow::selectedEntryChanged );
2017-07-21 16:21:34 +00:00
2018-08-03 06:15:28 +00:00
connect( this, &QskSimpleListBox::entriesChanged,
subWindow, &QskSelectionSubWindow::entriesChanged );
2017-07-21 16:21:34 +00:00
}
};
}
2018-08-03 06:15:28 +00:00
QskSelectionSubWindow::QskSelectionSubWindow( QQuickItem* parent )
: Inherited( parent )
2017-07-21 16:21:34 +00:00
{
auto listBox = new ListBox( this );
#if 1
listBox->setPreferredSize( 500, 500 );
#endif
2018-11-06 17:54:21 +00:00
setContentItem( listBox );
2018-11-05 12:50:41 +00:00
setDialogActions( QskDialog::Ok | QskDialog::Cancel );
2017-07-21 16:21:34 +00:00
}
QskSelectionSubWindow::~QskSelectionSubWindow()
{
}
void QskSelectionSubWindow::setEntries( const QStringList& entries )
{
if ( auto listBox = qskListBox( this ) )
listBox->setEntries( entries );
2017-07-21 16:21:34 +00:00
}
QStringList QskSelectionSubWindow::entries() const
{
if ( auto listBox = qskListBox( this ) )
return listBox->entries();
return QStringList();
2017-07-21 16:21:34 +00:00
}
void QskSelectionSubWindow::setSelectedRow( int row )
{
if ( auto listBox = qskListBox( this ) )
listBox->setSelectedRow( row );
2017-07-21 16:21:34 +00:00
}
int QskSelectionSubWindow::selectedRow() const
{
if ( auto listBox = qskListBox( this ) )
return listBox->selectedRow();
return -1;
2017-07-21 16:21:34 +00:00
}
QString QskSelectionSubWindow::selectedEntry() const
{
if ( auto listBox = qskListBox( this ) )
2024-09-25 11:52:12 +00:00
return listBox->selectedEntry();
return QString();
2017-07-21 16:21:34 +00:00
}
#include "moc_QskSelectionSubWindow.cpp"