/***************************************************************************
 *   Copyright (C) 2004 by Tasuku Suzuki                                   *
 *   tasuku@linux-life.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.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "kkpropertyitemtext.h"

KKPropertyItemText::KKPropertyItemText( KKProperty* parent, const QString &text )
	: KKPropertyItemBase( parent, text )
{
	setViewPortHeight( 4 );
	txtEdit = new KTextEdit( viewport() );
	txtEdit->setWordWrap( QTextEdit::NoWrap );
	setVisible( false );
}

KKPropertyItemText::~KKPropertyItemText()
{
}

void KKPropertyItemText::start()
{
	KKPropertyItemBase::start();
	txtEdit->setText( text( 1 ) );
	txtEdit->setFocus();
}

void KKPropertyItemText::accept()
{
	if( !txtEdit->isVisible() ) return;
	document()->setText( txtEdit->text() );
	KKPropertyItemBase::accept();
}

void KKPropertyItemText::reset()
{
	KKPropertyItemBase::reset();
	QPtrList<QListViewItem> selectedItems = document()->selectedItems();
	if( selectedItems.isEmpty() )
	{
		setVisible( false );
		return;
	}
	else
	{
		setVisible( ((KKItem*)selectedItems.first())->parent() != NULL );
	}
	QString text = ((KKItem*)selectedItems.first())->text();
	for( KKItem* item = (KKItem*)selectedItems.next(); item; item = (KKItem*)selectedItems.next() )
	{
		if( text != QString::null && text != item->text() )
		{
			text = QString::null;
			break;
		}
	}
	setText( 1, text );
}
