/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions respectively slots use
** Qt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/


void FormMulticlip::init()
{
    lengthLCDNumber->setBackgroundColor( darkBlue );
    currentLineEdit->setFocus();
    cb = qApp->clipboard();
    connect( cb, SIGNAL( dataChanged() ), SLOT( dataChanged() ) );
    if ( cb->supportsSelection() )
	connect( cb, SIGNAL( selectionChanged() ), SLOT( selectionChanged() ) );
    dataChanged();
}


void FormMulticlip::dataChanged()
{
    QString text;
    text = cb->text();
    clippingChanged( text );
    if ( autoCheckBox->isChecked() )
	addClipping();
}


void FormMulticlip::selectionChanged()
{
    cb->setSelectionMode( TRUE );
    dataChanged();
    cb->setSelectionMode( FALSE );
}


void FormMulticlip::clippingChanged( QString clipping)
{
    currentLineEdit->setText( clipping );
    lengthLCDNumber->display( (int)clipping.length() );
}


void FormMulticlip::addClipping()
{
    QString text = currentLineEdit->text();
    if ( ! text.isEmpty() ) {
	lengthLCDNumber->display( (int)text.length() );
	int i;
	for (i=0 ; i < (int)clippingsListBox->count(); i++ ) {
	    if ( clippingsListBox->text( i ) == text ) {
		i = -1; // Do not add duplicates
		break;
	    }
	}
	if ( i != -1 )
	    clippingsListBox->insertItem( text, 0 );
    }
}


void FormMulticlip::copyPrevious()
{
    if ( clippingsListBox->currentItem() != -1 ) {
	cb->setText( clippingsListBox->currentText() );
	if ( cb->supportsSelection() ) {
	    cb->setSelectionMode( TRUE );
	    cb->setText( clippingsListBox->currentText() );
	    cb->setSelectionMode( FALSE );
	}
    }
}


void FormMulticlip::deleteClipping()
{
    clippingChanged( "" );
    clippingsListBox->removeItem( clippingsListBox->currentItem() );
}
