1
/***************************************************************************
2
radiostation-listview.cpp - description
5
copyright : (C) 2003 by Martin Witte
6
email : witte@kawo1.rwth-aachen.de
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
***************************************************************************/
18
#include "include/radiostation-listview.h"
19
#include "include/stationlist.h"
20
#include "include/radiostation.h"
21
#include "include/station-drag-object.h"
30
RadioStationListView::RadioStationListView(QWidget *parent, const char *name)
31
: KListView(parent, name)
33
addColumn(i18n("No."));
34
addColumn(i18n("Icon"));
35
addColumn(i18n("Station"));
36
addColumn(i18n("Description"));
37
setAllColumnsShowFocus(true);
40
QObject::connect(this, SIGNAL(spacePressed(QListViewItem*)),
41
this, SLOT(slotStationActivation(QListViewItem* )));
42
QObject::connect(this, SIGNAL(returnPressed(QListViewItem*)),
43
this, SLOT(slotStationActivation(QListViewItem* )));
44
QObject::connect(this, SIGNAL(doubleClicked(QListViewItem*)),
45
this, SLOT(slotStationActivation(QListViewItem *)));
46
QObject::connect(this, SIGNAL(currentChanged(QListViewItem*)),
47
this, SLOT(slotCurrentStationChanged(QListViewItem *)));
53
RadioStationListView::~RadioStationListView()
58
QListViewItem *RadioStationListView::getItemForIndex(int idx) const
60
QListViewItem *item = NULL;
62
if (idx >= 0 && idx < childCount()) {
65
while (item && i < idx) {
66
item = item->nextSibling();
74
int RadioStationListView::getIndexForItem(QListViewItem *queryItem) const
79
QListViewItem *item = firstChild();
81
while (item && item != queryItem) {
82
item = item->nextSibling();
93
void RadioStationListView::setStation(int idx, const RadioStation &s, int nr)
95
QListViewItem *item = getItemForIndex(idx);
98
item = new QListViewItem(this, firstChild());
99
firstChild()->moveItem(item);
100
m_StationIDs.prepend(s.stationID());
102
} else if (idx >= childCount()) {
103
item = new QListViewItem(this, lastChild());
104
m_StationIDs.append(s.stationID());
105
idx = childCount() - 1;
109
item->setDragEnabled(true);
110
item->setDropEnabled(true);
112
item->setText(0, QString::number(nr > 0 ? nr : idx+1));
113
item->setText(2, s.name());
114
item->setText(3, s.description());
116
m_StationIDs[idx] = s.stationID();
118
QImage img(s.iconName());
120
int h = img.height();
121
float f = 0.9 * (float)(item->height()) / (h ? (float)h : 1.0);
122
item->setPixmap(1, img.smoothScale((int)(img.width()*f), (int)(h * f)));
124
item->setPixmap(1, QPixmap());
130
void RadioStationListView::appendStation(const RadioStation &st, int nr)
132
setStation(childCount(), st, nr);
136
void RadioStationListView::setStations(const StationList &stations)
139
for (RawStationList::Iterator it(stations.all()); it.current(); ++it) {
140
setStation(childCount(), *it.current());
145
void RadioStationListView::removeStation(int idx)
147
QListViewItem *item = getItemForIndex(idx);
150
m_StationIDs.remove(m_StationIDs.at(idx));
154
void RadioStationListView::takeItem(QListViewItem *item, int idx)
156
QListView::takeItem(item);
157
m_StationIDs.remove(m_StationIDs.at(idx));
160
void RadioStationListView::insertItem(QListViewItem *item, const QString &stationid, int idx_to)
162
QListView::insertItem(item);
163
m_StationIDs.insert(m_StationIDs.at(idx_to), stationid);
166
void RadioStationListView::setCurrentStation(int idx)
168
QListViewItem *item = getItemForIndex(idx);
171
setSelected(item, true);
172
setCurrentItem(item);
177
int RadioStationListView::currentStationIndex() const
179
return getIndexForItem(currentItem());
183
void RadioStationListView::slotStationActivation(QListViewItem *item)
185
emit sigStationActivated(getIndexForItem(item));
189
void RadioStationListView::slotCurrentStationChanged(QListViewItem *item)
191
emit sigCurrentStationChanged(getIndexForItem(item));
195
void RadioStationListView::saveState (KConfig *cfg) const
199
for (int i = 0; i < 4; ++i)
200
cfg->writeEntry(QString(name()) + "_radiostation_listview_col_" + QString::number(i), columnWidth(i));
204
void RadioStationListView::restoreState (KConfig *cfg)
208
for (int i = 0; i < 4; ++i)
209
setColumnWidth(i, cfg->readNumEntry(QString(name()) + "_radiostation_listview_col_" + QString::number(i), -1));
213
QDragObject *RadioStationListView::dragObject()
216
QListViewItem *item = firstChild();
217
for (int idx = 0; item; ++idx, item = item->nextSibling()) {
218
if (item->isSelected()) {
219
list.append(m_StationIDs[idx]);
222
return new StationDragObject(list, this);
225
void RadioStationListView::dragEnterEvent(QDragEnterEvent* event)
227
event->accept(StationDragObject::canDecode(event));
230
void RadioStationListView::contentsDragEnterEvent(QDragEnterEvent* event)
232
bool a = StationDragObject::canDecode(event);
234
IErrorLogClient::staticLogDebug(i18n("contentsDragEnterEvent accepted"));
236
IErrorLogClient::staticLogDebug(i18n("contentsDragEnterEvent rejected"));
240
void RadioStationListView::dropEvent(QDropEvent* event)
244
if ( StationDragObject::decode(event, list) ) {
245
emit sigStationsReceived(list);
249
void RadioStationListView::contentsDropEvent(QDropEvent* event)
254
void RadioStationListView::contentsDragMoveEvent(QDragMoveEvent* event)
259
#include "radiostation-listview.moc"