QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskSelectionWindow.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskSelectionWindow.h"
7#include "QskSimpleListBox.h"
8
9/*
10 QInputDialog uses a combo box instead of a list widget
11 Guess we should do the same TODO ...
12 */
13static inline QskSimpleListBox* qskListBox(
14 QskSelectionWindow* window )
15{
16 return qobject_cast< QskSimpleListBox* >( window->dialogContentItem() );
17}
18
19static inline const QskSimpleListBox* qskListBox(
20 const QskSelectionWindow* window )
21{
22 return qobject_cast< QskSimpleListBox* >( window->dialogContentItem() );
23}
24
25namespace
26{
27 class ListBox final : public QskSimpleListBox
28 {
29 public:
30 ListBox( QskSelectionWindow* window )
31 {
32 setObjectName( QStringLiteral( "QskSelectionWindowListBox" ) );
33
34 connect( this, &QskSimpleListBox::selectedRowChanged,
35 window, &QskSelectionWindow::selectedRowChanged );
36
37 connect( this, &QskSimpleListBox::selectedEntryChanged,
38 window, &QskSelectionWindow::selectedEntryChanged );
39
40 connect( this, &QskSimpleListBox::entriesChanged,
41 window, &QskSelectionWindow::entriesChanged );
42 }
43 };
44}
45
46QskSelectionWindow::QskSelectionWindow( QWindow* parent )
47 : Inherited( parent )
48{
49 setFlags( Qt::Dialog | Qt::WindowTitleHint |
50 Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint );
51
52 auto listBox = new ListBox( this );
53#if 1
54 listBox->setPreferredSize( 500, 500 );
55#endif
56
57 setDialogContentItem( listBox );
58 setDialogActions( QskDialog::Ok | QskDialog::Cancel );
59}
60
61QskSelectionWindow::~QskSelectionWindow()
62{
63}
64
65void QskSelectionWindow::setEntries( const QStringList& entries )
66{
67 if ( auto listBox = qskListBox( this ) )
68 listBox->setEntries( entries );
69}
70
71QStringList QskSelectionWindow::entries() const
72{
73 if ( auto listBox = qskListBox( this ) )
74 return listBox->entries();
75
76 return QStringList();
77}
78
79void QskSelectionWindow::setSelectedRow( int row )
80{
81 if ( auto listBox = qskListBox( this ) )
82 listBox->setSelectedRow( row );
83}
84
85int QskSelectionWindow::selectedRow() const
86{
87 if ( auto listBox = qskListBox( this ) )
88 return listBox->selectedRow();
89
90 return -1;
91}
92
93QString QskSelectionWindow::selectedEntry() const
94{
95 if ( auto listBox = qskListBox( this ) )
96 return listBox->selectedEntry();
97
98 return QString();
99}
100
101#include "moc_QskSelectionWindow.cpp"