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.
158 lines
4.1 KiB
158 lines
4.1 KiB
/***************************************************************************
|
|
imageslistview.cpp - description
|
|
-------------------
|
|
begin : Weg Feb 26 2003
|
|
copyright : (C) 2003 by Jan Schäfer
|
|
email : janschaefer@users.sourceforge.net
|
|
***************************************************************************/
|
|
|
|
/***************************************************************************
|
|
* *
|
|
* 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. *
|
|
* *
|
|
***************************************************************************/
|
|
|
|
// QT
|
|
#include <tqptrlist.h>
|
|
|
|
|
|
// KDE
|
|
#include <klocale.h>
|
|
#include <kdebug.h>
|
|
|
|
// locale
|
|
#include "imageslistview.h"
|
|
|
|
ImagesListViewItem::ImagesListViewItem(ImagesListView* tqparent, ImageTag* tag)
|
|
: TQListViewItem(tqparent)
|
|
{
|
|
_imageTag = tag;
|
|
update();
|
|
}
|
|
|
|
|
|
void ImagesListViewItem::update() {
|
|
TQString src="";
|
|
TQString usemap="";
|
|
if (_imageTag->tqfind("src"))
|
|
src=*_imageTag->tqfind("src");
|
|
if (_imageTag->tqfind("usemap"))
|
|
usemap=*_imageTag->tqfind("usemap");
|
|
|
|
setText(0,src);
|
|
setText(1,usemap);
|
|
}
|
|
|
|
ImageTag* ImagesListViewItem::imageTag() {
|
|
return _imageTag;
|
|
}
|
|
|
|
|
|
ImagesListView::ImagesListView(TQWidget *tqparent, const char *name)
|
|
: KListView(tqparent, name)
|
|
{
|
|
addColumn(i18n("Images"));
|
|
addColumn(i18n("Usemap"));
|
|
//addColumn(i18n("Preview"));
|
|
setFullWidth(true);
|
|
|
|
|
|
connect( this, TQT_SIGNAL( selectionChanged(TQListViewItem*)),
|
|
this, TQT_SLOT( slotSelectionChanged(TQListViewItem*)));
|
|
}
|
|
|
|
|
|
ImagesListView::~ImagesListView()
|
|
{
|
|
}
|
|
|
|
void ImagesListView::addImage(ImageTag* tag)
|
|
{
|
|
if (!tag) {
|
|
kdDebug() << "ImageListView::addImage: Parameter is null !" << endl;
|
|
return;
|
|
}
|
|
|
|
new ImagesListViewItem(this, tag);
|
|
}
|
|
|
|
void ImagesListView::addImages(TQPtrList<ImageTag> * images)
|
|
{
|
|
for (ImageTag *tag = images->first(); tag!=0L; tag=images->next()) {
|
|
addImage(tag);
|
|
}
|
|
}
|
|
|
|
void ImagesListView::clear() {
|
|
TQListView::clear();
|
|
}
|
|
|
|
void ImagesListView::removeImage(ImageTag* tag) {
|
|
ImagesListViewItem *item = findListViewItem(tag);
|
|
if (item) {
|
|
takeItem(item);
|
|
setSelected(currentItem(),true);
|
|
}
|
|
else {
|
|
kdDebug() << "ImageListView::removeImage: ListViewItem was not found !" << endl;
|
|
}
|
|
}
|
|
|
|
void ImagesListView::updateImage(ImageTag* tag) {
|
|
ImagesListViewItem *item = findListViewItem(tag);
|
|
if (item)
|
|
item->update();
|
|
else {
|
|
kdDebug() << "ImageListView::updateImage: ListViewItem was not found !" << endl;
|
|
}
|
|
}
|
|
|
|
ImagesListViewItem* ImagesListView::findListViewItem(ImageTag* tag) {
|
|
|
|
kdDebug() << "ImageListView::findListViewItem: start searching ... " << endl;
|
|
|
|
for (TQListViewItem* item = firstChild(); item ; item = item->nextSibling()) {
|
|
ImagesListViewItem *imageItem = static_cast<ImagesListViewItem*>(item);
|
|
if (imageItem->imageTag() == tag) {
|
|
kdDebug() << "ImageListView::findListViewItem: found it " << endl;
|
|
|
|
return imageItem;
|
|
}
|
|
}
|
|
|
|
kdDebug() << "ImageListView::findListViewItem: found nothing " << endl;
|
|
return 0L;
|
|
|
|
}
|
|
|
|
void ImagesListView::slotSelectionChanged(TQListViewItem* item) {
|
|
TQString src = item->text(0);
|
|
|
|
emit imageSelected(KURL(_baseUrl,src));
|
|
}
|
|
|
|
ImageTag* ImagesListView::selectedImage() {
|
|
ImagesListViewItem* item = static_cast<ImagesListViewItem*>(selectedItem());
|
|
if ( ! item) {
|
|
kdDebug() << "ImagesListView::selectedImage: No Image is selected !" << endl;
|
|
return 0L;
|
|
}
|
|
|
|
return item->imageTag();
|
|
|
|
|
|
}
|
|
|
|
void ImagesListView::selectImage(ImageTag* tag) {
|
|
ImagesListViewItem* item = findListViewItem(tag);
|
|
if (item) {
|
|
setSelected(item, true);
|
|
}
|
|
}
|
|
|
|
#include "imageslistview.moc"
|
|
|