raDIYo 0.4
swlistcontrol.cpp
1/***************************************************************************
2
3 source::worx raDIYo
4 Copyright © 2020-2022 c.holzheuer
5 c.holzheuer@sourceworx.org
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12***************************************************************************/
13
14
15#include <QDebug>
16#include <QPainter>
17#include <QStandardPaths>
18#include <QDir>
19#include <QTextStream>
20
21#include <swlistcontrol.h>
22#include <swradiyomainwidget.h>
23
24
25SWListControl::SWListControl( SWRaDIYoMainWidget* parent )
26 : SWAbstractControl( parent ),
27 _idx( -1 )
28
29{
30
31 _acceptDial = true;
32
33 setupUi( this );
34
35 _itemList->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
36
37 // TOTALER QUARK! zu allererst: der Back-Link
38 //_itemList->addItem( new QListWidgetItem( raDIYo::BackLink ) );
39
40 // 'innere' SIGNALS einsammeln ...
41
42 // click
43 connect( _itemList, SIGNAL( itemClicked(QListWidgetItem*) ), this, SLOT( onItemActivated(QListWidgetItem*) ) );
44 // doublelcick, 'enter'
45 connect( _itemList, SIGNAL( itemActivated(QListWidgetItem*) ), this, SLOT( onItemActivated(QListWidgetItem*) ) );
46
47 // ...und weiterschicken
48 connect( this, SIGNAL( entryActivated( const SWPlayableItem&) ), parent, SLOT( onEntryActivated(const SWPlayableItem&) ) );
49
50}
51
52
53SWListControl::~SWListControl()
54{
55
56}
57
58
59
60
61
62/*
63 * kommt von aussen
64 */
65
66void SWListControl::onDialClicked()
67{
68
69 // Backlink geklickt? dann machet mir nix
70 //if( _idx == 0 )
71 // return false;
72
73 QListWidgetItem* item = _itemList->item( _idx );
74 // das schickt ein SIGNAL, wann kommt das zurück?
75 onItemActivated( item );
76 qDebug() << "nach EMIT: onDialClicked() " << _idx;
77
78
79}
80
81
82/*
83 * kommt von aussen
84 */
85
86void SWListControl::onDialValueChanged( int value )
87{
88 _itemList->setFocus();
89 _idx = value % _itemList->count();
90 _itemList->setCurrentRow( _idx, QItemSelectionModel::ClearAndSelect );
91
92 qDebug() << "on Value: " << value << ": " << _idx;
93
94
95}
96
97/*
98 * kommt von innen
99 * setM
100 */
101
102void SWListControl::onItemActivated( QListWidgetItem* item )
103{
104
105 // Backlink geklickt? ?? KLAPPT das so?
106 //if(item->text() == raDIYo::BackLink )
107 // return;
108
109 QString urltext = item->data( SWListControlRole ).toString();
110 qDebug() << "EMIT on entry activated: " << item->text() << ": " << urltext;
111 SWPlayableItem entry( _sourceType, item->text(), urltext );
112 emit entryActivated( entry );
113
114}
115
116
117
118bool SWListControl::getCurrentEntry( SWPlayableItem& entry )
119{
120
121 // liste noch nicht geladen oder gar leer?
122 if( _idx < 0 || _itemList->count() == 0)
123 {
124 entry.title = raDIYo::NoMedia;
125 return false;
126 }
127
128 QListWidgetItem* item = _itemList->currentItem();
129
130 QString urltext = item->data( SWListControlRole ).toString();
131
132 entry.title = item->text();
133 entry.urlText = urltext;
134
135 return true;
136
137}
138