You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
260 lines
7.1 KiB
260 lines
7.1 KiB
15 years ago
|
/***************************************************************************
|
||
|
radiostation-listview.cpp - description
|
||
|
-------------------
|
||
|
begin : Mi Feb 3 2004
|
||
|
copyright : (C) 2003 by Martin Witte
|
||
|
email : witte@kawo1.rwth-aachen.de
|
||
|
***************************************************************************/
|
||
|
|
||
|
/***************************************************************************
|
||
|
* *
|
||
|
* This program is free software; you can redistribute it and/or modify *
|
||
|
* it under the terms of the GNU General Public License as published by *
|
||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||
|
* (at your option) any later version. *
|
||
|
* *
|
||
|
***************************************************************************/
|
||
|
|
||
|
#include "include/radiostation-listview.h"
|
||
|
#include "include/stationlist.h"
|
||
|
#include "include/radiostation.h"
|
||
|
#include "include/station-drag-object.h"
|
||
|
|
||
12 years ago
|
#include <tdelocale.h>
|
||
14 years ago
|
#include <tqfile.h>
|
||
|
#include <tqimage.h>
|
||
|
#include <tqpixmap.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdeconfig.h>
|
||
15 years ago
|
|
||
13 years ago
|
RadioStationListView::RadioStationListView(TQWidget *parent, const char *name)
|
||
12 years ago
|
: TDEListView(parent, name)
|
||
15 years ago
|
{
|
||
|
addColumn(i18n("No."));
|
||
|
addColumn(i18n("Icon"));
|
||
|
addColumn(i18n("Station"));
|
||
|
addColumn(i18n("Description"));
|
||
|
setAllColumnsShowFocus(true);
|
||
|
setSorting(-1);
|
||
|
|
||
14 years ago
|
TQObject::connect(this, TQT_SIGNAL(spacePressed(TQListViewItem*)),
|
||
|
this, TQT_SLOT(slotStationActivation(TQListViewItem* )));
|
||
|
TQObject::connect(this, TQT_SIGNAL(returnPressed(TQListViewItem*)),
|
||
|
this, TQT_SLOT(slotStationActivation(TQListViewItem* )));
|
||
|
TQObject::connect(this, TQT_SIGNAL(doubleClicked(TQListViewItem*)),
|
||
|
this, TQT_SLOT(slotStationActivation(TQListViewItem *)));
|
||
|
TQObject::connect(this, TQT_SIGNAL(currentChanged(TQListViewItem*)),
|
||
|
this, TQT_SLOT(slotCurrentStationChanged(TQListViewItem *)));
|
||
15 years ago
|
|
||
|
setAcceptDrops(true);
|
||
|
}
|
||
|
|
||
|
|
||
|
RadioStationListView::~RadioStationListView()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
TQListViewItem *RadioStationListView::getItemForIndex(int idx) const
|
||
15 years ago
|
{
|
||
14 years ago
|
TQListViewItem *item = NULL;
|
||
15 years ago
|
|
||
|
if (idx >= 0 && idx < childCount()) {
|
||
|
item = firstChild();
|
||
|
int i = 0;
|
||
|
while (item && i < idx) {
|
||
|
item = item->nextSibling();
|
||
|
++i;
|
||
|
}
|
||
|
}
|
||
|
return item;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
int RadioStationListView::getIndexForItem(TQListViewItem *queryItem) const
|
||
15 years ago
|
{
|
||
|
int idx = -1;
|
||
|
|
||
|
if (queryItem) {
|
||
14 years ago
|
TQListViewItem *item = firstChild();
|
||
15 years ago
|
++idx;
|
||
|
while (item && item != queryItem) {
|
||
|
item = item->nextSibling();
|
||
|
++idx;
|
||
|
}
|
||
|
if (!item)
|
||
|
idx = -1;
|
||
|
}
|
||
|
|
||
|
return idx;
|
||
|
}
|
||
|
|
||
|
|
||
|
void RadioStationListView::setStation(int idx, const RadioStation &s, int nr)
|
||
|
{
|
||
14 years ago
|
TQListViewItem *item = getItemForIndex(idx);
|
||
15 years ago
|
|
||
|
if (idx < 0) {
|
||
14 years ago
|
item = new TQListViewItem(this, firstChild());
|
||
15 years ago
|
firstChild()->moveItem(item);
|
||
|
m_StationIDs.prepend(s.stationID());
|
||
|
idx = 0;
|
||
|
} else if (idx >= childCount()) {
|
||
14 years ago
|
item = new TQListViewItem(this, lastChild());
|
||
15 years ago
|
m_StationIDs.append(s.stationID());
|
||
|
idx = childCount() - 1;
|
||
|
}
|
||
|
|
||
|
if (item) {
|
||
|
item->setDragEnabled(true);
|
||
|
item->setDropEnabled(true);
|
||
|
|
||
14 years ago
|
item->setText(0, TQString::number(nr > 0 ? nr : idx+1));
|
||
15 years ago
|
item->setText(2, s.name());
|
||
|
item->setText(3, s.description());
|
||
|
|
||
|
m_StationIDs[idx] = s.stationID();
|
||
|
|
||
14 years ago
|
TQImage img(s.iconName());
|
||
15 years ago
|
if (!img.isNull()) {
|
||
|
int h = img.height();
|
||
|
float f = 0.9 * (float)(item->height()) / (h ? (float)h : 1.0);
|
||
|
item->setPixmap(1, img.smoothScale((int)(img.width()*f), (int)(h * f)));
|
||
|
} else {
|
||
14 years ago
|
item->setPixmap(1, TQPixmap());
|
||
15 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void RadioStationListView::appendStation(const RadioStation &st, int nr)
|
||
|
{
|
||
|
setStation(childCount(), st, nr);
|
||
|
}
|
||
|
|
||
|
|
||
|
void RadioStationListView::setStations(const StationList &stations)
|
||
|
{
|
||
|
clear();
|
||
|
for (RawStationList::Iterator it(stations.all()); it.current(); ++it) {
|
||
|
setStation(childCount(), *it.current());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void RadioStationListView::removeStation(int idx)
|
||
|
{
|
||
14 years ago
|
TQListViewItem *item = getItemForIndex(idx);
|
||
15 years ago
|
if (item) {
|
||
|
delete item;
|
||
|
m_StationIDs.remove(m_StationIDs.at(idx));
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void RadioStationListView::takeItem(TQListViewItem *item, int idx)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQListView::takeItem(item);
|
||
15 years ago
|
m_StationIDs.remove(m_StationIDs.at(idx));
|
||
|
}
|
||
|
|
||
14 years ago
|
void RadioStationListView::insertItem(TQListViewItem *item, const TQString &stationid, int idx_to)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQListView::insertItem(item);
|
||
15 years ago
|
m_StationIDs.insert(m_StationIDs.at(idx_to), stationid);
|
||
|
}
|
||
|
|
||
|
void RadioStationListView::setCurrentStation(int idx)
|
||
|
{
|
||
14 years ago
|
TQListViewItem *item = getItemForIndex(idx);
|
||
15 years ago
|
if (item) {
|
||
|
clearSelection();
|
||
|
setSelected(item, true);
|
||
|
setCurrentItem(item);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
int RadioStationListView::currentStationIndex() const
|
||
|
{
|
||
|
return getIndexForItem(currentItem());
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void RadioStationListView::slotStationActivation(TQListViewItem *item)
|
||
15 years ago
|
{
|
||
|
emit sigStationActivated(getIndexForItem(item));
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void RadioStationListView::slotCurrentStationChanged(TQListViewItem *item)
|
||
15 years ago
|
{
|
||
|
emit sigCurrentStationChanged(getIndexForItem(item));
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void RadioStationListView::saveState (TDEConfig *cfg) const
|
||
15 years ago
|
{
|
||
|
if (!cfg)
|
||
|
return;
|
||
|
for (int i = 0; i < 4; ++i)
|
||
14 years ago
|
cfg->writeEntry(TQString(name()) + "_radiostation_listview_col_" + TQString::number(i), columnWidth(i));
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void RadioStationListView::restoreState (TDEConfig *cfg)
|
||
15 years ago
|
{
|
||
|
if (!cfg)
|
||
|
return;
|
||
|
for (int i = 0; i < 4; ++i)
|
||
14 years ago
|
setColumnWidth(i, cfg->readNumEntry(TQString(name()) + "_radiostation_listview_col_" + TQString::number(i), -1));
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
14 years ago
|
TQDragObject *RadioStationListView::dragObject()
|
||
15 years ago
|
{
|
||
14 years ago
|
TQStringList list;
|
||
|
TQListViewItem *item = firstChild();
|
||
15 years ago
|
for (int idx = 0; item; ++idx, item = item->nextSibling()) {
|
||
|
if (item->isSelected()) {
|
||
|
list.append(m_StationIDs[idx]);
|
||
|
}
|
||
|
}
|
||
|
return new StationDragObject(list, this);
|
||
|
}
|
||
|
|
||
14 years ago
|
void RadioStationListView::dragEnterEvent(TQDragEnterEvent* event)
|
||
15 years ago
|
{
|
||
|
event->accept(StationDragObject::canDecode(event));
|
||
|
}
|
||
|
|
||
14 years ago
|
void RadioStationListView::contentsDragEnterEvent(TQDragEnterEvent* event)
|
||
15 years ago
|
{
|
||
|
bool a = StationDragObject::canDecode(event);
|
||
|
if (a)
|
||
|
IErrorLogClient::staticLogDebug(i18n("contentsDragEnterEvent accepted"));
|
||
|
else
|
||
|
IErrorLogClient::staticLogDebug(i18n("contentsDragEnterEvent rejected"));
|
||
|
event->accept(a);
|
||
|
}
|
||
|
|
||
14 years ago
|
void RadioStationListView::dropEvent(TQDropEvent* event)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQStringList list;
|
||
15 years ago
|
|
||
|
if ( StationDragObject::decode(event, list) ) {
|
||
|
emit sigStationsReceived(list);
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void RadioStationListView::contentsDropEvent(TQDropEvent* event)
|
||
15 years ago
|
{
|
||
|
dropEvent(event);
|
||
|
}
|
||
|
|
||
14 years ago
|
void RadioStationListView::contentsDragMoveEvent(TQDragMoveEvent* event)
|
||
15 years ago
|
{
|
||
|
event->accept();
|
||
|
}
|
||
|
|
||
|
#include "radiostation-listview.moc"
|