qskinny/src/dialogs/QskSelectionWindow.cpp

102 lines
2.6 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 "QskSelectionWindow.h"
2018-11-06 17:54:21 +00:00
#include "QskSimpleListBox.h"
/*
QInputDialog uses a combo box instead of a list widget
Guess we should do the same TODO ...
*/
static inline QskSimpleListBox* qskListBox(
QskSelectionWindow* window )
2019-01-04 12:42:16 +00:00
{
return qobject_cast< QskSimpleListBox* >( window->dialogContentItem() );
}
2018-11-06 17:54:21 +00:00
static inline const QskSimpleListBox* qskListBox(
const QskSelectionWindow* window )
{
return qobject_cast< QskSimpleListBox* >( window->dialogContentItem() );
}
2018-11-06 17:54:21 +00:00
namespace
{
2018-11-06 17:54:21 +00:00
class ListBox final : public QskSimpleListBox
{
public:
ListBox( QskSelectionWindow* window )
{
setObjectName( QStringLiteral( "QskSelectionWindowListBox" ) );
connect( this, &QskSimpleListBox::selectedRowChanged,
window, &QskSelectionWindow::selectedRowChanged );
connect( this, &QskSimpleListBox::selectedEntryChanged,
window, &QskSelectionWindow::selectedEntryChanged );
connect( this, &QskSimpleListBox::entriesChanged,
window, &QskSelectionWindow::entriesChanged );
}
};
}
2018-08-03 06:15:28 +00:00
QskSelectionWindow::QskSelectionWindow( QWindow* parent )
: Inherited( parent )
2017-07-21 16:21:34 +00:00
{
2018-11-06 17:54:21 +00:00
setFlags( Qt::Dialog | Qt::WindowTitleHint |
Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint );
2017-07-21 16:21:34 +00:00
auto listBox = new ListBox( this );
#if 1
listBox->setPreferredSize( 500, 500 );
#endif
2017-07-21 16:21:34 +00:00
setDialogContentItem( listBox );
2018-11-06 17:54:21 +00:00
setDialogActions( QskDialog::Ok | QskDialog::Cancel );
2017-07-21 16:21:34 +00:00
}
QskSelectionWindow::~QskSelectionWindow()
{
}
void QskSelectionWindow::setEntries( const QStringList& entries )
{
if ( auto listBox = qskListBox( this ) )
listBox->setEntries( entries );
2017-07-21 16:21:34 +00:00
}
QStringList QskSelectionWindow::entries() const
{
if ( auto listBox = qskListBox( this ) )
return listBox->entries();
return QStringList();
2017-07-21 16:21:34 +00:00
}
void QskSelectionWindow::setSelectedRow( int row )
{
if ( auto listBox = qskListBox( this ) )
listBox->setSelectedRow( row );
2017-07-21 16:21:34 +00:00
}
int QskSelectionWindow::selectedRow() const
{
if ( auto listBox = qskListBox( this ) )
return listBox->selectedRow();
return -1;
2017-07-21 16:21:34 +00:00
}
QString QskSelectionWindow::selectedEntry() const
{
if ( auto listBox = qskListBox( this ) )
listBox->selectedEntry();
return QString();
2017-07-21 16:21:34 +00:00
}
#include "moc_QskSelectionWindow.cpp"