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.
246 lines
7.1 KiB
246 lines
7.1 KiB
15 years ago
|
/**********************************************************************
|
||
|
** Copyright (C) 2000 Trolltech AS. All rights reserved.
|
||
|
**
|
||
14 years ago
|
** This file is part of TQt Designer.
|
||
15 years ago
|
**
|
||
|
** This file may be distributed and/or modified under the terms of the
|
||
|
** GNU General Public License version 2 as published by the Free Software
|
||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||
|
** packaging of this file.
|
||
|
**
|
||
14 years ago
|
** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition
|
||
|
** licenses may use this file in accordance with the TQt Commercial License
|
||
15 years ago
|
** Agreement provided with the Software.
|
||
|
**
|
||
|
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||
|
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||
|
**
|
||
|
** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
||
|
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
||
14 years ago
|
** information about TQt Commercial License Agreements.
|
||
15 years ago
|
**
|
||
|
** Contact info@trolltech.com if any conditions of this licensing are
|
||
|
** not clear to you.
|
||
|
**
|
||
|
**********************************************************************/
|
||
|
|
||
|
#include "listboxeditorimpl.h"
|
||
|
#include "formwindow.h"
|
||
|
#include "mainwindow.h"
|
||
|
#include "pixmapchooser.h"
|
||
|
#include "command.h"
|
||
|
#include "listboxdnd.h"
|
||
|
#include "listboxrename.h"
|
||
|
|
||
|
#include <klineedit.h>
|
||
15 years ago
|
#include <tqlabel.h>
|
||
|
#include <tqlistbox.h>
|
||
|
#include <tqpushbutton.h>
|
||
|
#include <tqcheckbox.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
|
||
14 years ago
|
ListBoxEditor::ListBoxEditor( TQWidget *parent, TQWidget *editWidget, FormWindow *fw )
|
||
|
: ListBoxEditorBase( parent, 0, TRUE ), formwindow( fw )
|
||
15 years ago
|
{
|
||
15 years ago
|
connect( helpButton, TQT_SIGNAL( clicked() ), MainWindow::self, TQT_SLOT( showDialogHelp() ) );
|
||
|
listbox = (TQListBox*)editWidget;
|
||
15 years ago
|
|
||
|
itemText->setText( "" );
|
||
|
itemText->setEnabled( FALSE );
|
||
|
itemPixmap->setText( "" );
|
||
|
itemChoosePixmap->setEnabled( FALSE );
|
||
|
itemDeletePixmap->setEnabled( FALSE );
|
||
|
|
||
15 years ago
|
TQListBoxItem *i = 0;
|
||
15 years ago
|
for ( i = listbox->firstItem(); i; i = i->next() ) {
|
||
|
if ( i->pixmap() )
|
||
15 years ago
|
(void)new TQListBoxPixmap( preview, *i->pixmap(), i->text() );
|
||
15 years ago
|
else
|
||
15 years ago
|
(void)new TQListBoxText( preview, i->text() );
|
||
15 years ago
|
}
|
||
|
|
||
|
if ( preview->firstItem() )
|
||
|
preview->setCurrentItem( preview->firstItem() );
|
||
|
|
||
|
ListBoxDnd *editorDnd = new ListBoxDnd( preview );
|
||
|
editorDnd->setDragMode( ListBoxDnd::Internal | ListBoxDnd::Move );
|
||
15 years ago
|
TQObject::connect( editorDnd, TQT_SIGNAL( dropped( TQListBoxItem * ) ),
|
||
|
editorDnd, TQT_SLOT( confirmDrop( TQListBoxItem * ) ) );
|
||
15 years ago
|
|
||
|
ListBoxRename *editorRename = new ListBoxRename( preview );
|
||
|
|
||
14 years ago
|
TQObjectList *l = parent->queryList( TQLINEEDIT_OBJECT_NAME_STRING, "itemText" );
|
||
15 years ago
|
TQObjectListIt it( *l );
|
||
|
TQObject *obj;
|
||
15 years ago
|
while ( (obj = it.current()) != 0 ) {
|
||
|
++it;
|
||
15 years ago
|
TQObject::connect( editorRename,
|
||
|
TQT_SIGNAL( itemTextChanged( const TQString & ) ),
|
||
15 years ago
|
obj,
|
||
15 years ago
|
TQT_SLOT( setText( const TQString & ) ) );
|
||
15 years ago
|
}
|
||
|
delete l;
|
||
|
|
||
|
}
|
||
|
|
||
|
void ListBoxEditor::insertNewItem()
|
||
|
{
|
||
15 years ago
|
TQListBoxItem *i = new TQListBoxText( preview, i18n("New Item") );
|
||
15 years ago
|
preview->setCurrentItem( i );
|
||
|
preview->setSelected( i, TRUE );
|
||
|
itemText->setFocus();
|
||
|
itemText->selectAll();
|
||
|
}
|
||
|
|
||
|
void ListBoxEditor::deleteCurrentItem()
|
||
|
{
|
||
|
delete preview->item( preview->currentItem() );
|
||
|
if ( preview->currentItem() != -1 )
|
||
|
preview->setSelected( preview->currentItem(), TRUE );
|
||
|
}
|
||
|
|
||
15 years ago
|
void ListBoxEditor::currentItemChanged( TQListBoxItem *i )
|
||
15 years ago
|
{
|
||
|
itemText->blockSignals( TRUE );
|
||
|
itemText->setText( "" );
|
||
|
itemPixmap->setText( "" );
|
||
|
itemText->blockSignals( FALSE );
|
||
|
|
||
|
if ( !i ) {
|
||
|
itemText->setEnabled( FALSE );
|
||
|
itemChoosePixmap->setEnabled( FALSE );
|
||
|
itemDeletePixmap->setEnabled( FALSE );
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
itemText->blockSignals( TRUE );
|
||
|
itemText->setEnabled( TRUE );
|
||
|
itemChoosePixmap->setEnabled( TRUE );
|
||
|
itemDeletePixmap->setEnabled( i->pixmap() && !i->pixmap()->isNull() );
|
||
|
|
||
|
itemText->setText( i->text() );
|
||
|
if ( i->pixmap() )
|
||
|
itemPixmap->setPixmap( *i->pixmap() );
|
||
|
itemText->blockSignals( FALSE );
|
||
|
}
|
||
|
|
||
15 years ago
|
void ListBoxEditor::currentTextChanged( const TQString &txt )
|
||
15 years ago
|
{
|
||
|
if ( preview->currentItem() == -1 )
|
||
|
return;
|
||
|
|
||
|
preview->blockSignals( TRUE );
|
||
|
if ( preview->item( preview->currentItem() )->pixmap() )
|
||
|
preview->changeItem( *preview->item( preview->currentItem() )->pixmap(), txt, preview->currentItem() );
|
||
|
else
|
||
|
preview->changeItem( txt, preview->currentItem() );
|
||
|
preview->blockSignals( FALSE );
|
||
|
}
|
||
|
|
||
|
void ListBoxEditor::okClicked()
|
||
|
{
|
||
|
applyClicked();
|
||
|
accept();
|
||
|
}
|
||
|
|
||
|
void ListBoxEditor::cancelClicked()
|
||
|
{
|
||
|
reject();
|
||
|
}
|
||
|
|
||
|
void ListBoxEditor::applyClicked()
|
||
|
{
|
||
15 years ago
|
TQListBoxItem *i = 0;
|
||
|
TQValueList<PopulateListBoxCommand::Item> items;
|
||
15 years ago
|
for ( i = preview->firstItem(); i; i = i->next() ) {
|
||
|
PopulateListBoxCommand::Item item;
|
||
|
if ( i->pixmap() )
|
||
|
item.pix = *i->pixmap();
|
||
|
item.text = i->text();
|
||
|
items.append( item );
|
||
|
}
|
||
|
|
||
13 years ago
|
PopulateListBoxCommand *cmd = new PopulateListBoxCommand( i18n( "Edit the Items of '%1'" ).arg( listbox->name() ),
|
||
15 years ago
|
formwindow, listbox, items );
|
||
|
cmd->execute();
|
||
|
formwindow->commandHistory()->addCommand( cmd );
|
||
|
}
|
||
|
|
||
|
void ListBoxEditor::choosePixmap()
|
||
|
{
|
||
|
if ( preview->currentItem() == -1 )
|
||
|
return;
|
||
|
|
||
15 years ago
|
TQPixmap pix;
|
||
15 years ago
|
if ( preview->item( preview->currentItem() )->pixmap() )
|
||
|
pix = qChoosePixmap( this, formwindow, *preview->item( preview->currentItem() )->pixmap() );
|
||
|
else
|
||
15 years ago
|
pix = qChoosePixmap( this, formwindow, TQPixmap() );
|
||
15 years ago
|
|
||
|
if ( pix.isNull() )
|
||
|
return;
|
||
|
|
||
15 years ago
|
TQString txt = preview->item( preview->currentItem() )->text();
|
||
15 years ago
|
preview->changeItem( pix, txt, preview->currentItem() );
|
||
|
itemDeletePixmap->setEnabled( TRUE );
|
||
|
}
|
||
|
|
||
|
void ListBoxEditor::moveItemUp()
|
||
|
{
|
||
|
if ( preview->currentItem() < 1 )
|
||
|
return;
|
||
|
|
||
15 years ago
|
TQListBoxItem *i = preview->item( preview->currentItem() );
|
||
15 years ago
|
bool hasPix = (i->pixmap() != 0);
|
||
15 years ago
|
TQPixmap pix;
|
||
15 years ago
|
if ( hasPix )
|
||
|
pix = *i->pixmap();
|
||
15 years ago
|
TQString txt = i->text();
|
||
15 years ago
|
|
||
15 years ago
|
TQListBoxItem *p = i->prev();
|
||
15 years ago
|
if ( p->pixmap() )
|
||
|
preview->changeItem( *p->pixmap(), p->text(), preview->currentItem() );
|
||
|
else
|
||
|
preview->changeItem( p->text(), preview->currentItem() );
|
||
|
|
||
|
if ( hasPix )
|
||
|
preview->changeItem( pix, txt, preview->currentItem() - 1 );
|
||
|
else
|
||
|
preview->changeItem( txt, preview->currentItem() - 1 );
|
||
|
}
|
||
|
|
||
|
void ListBoxEditor::moveItemDown()
|
||
|
{
|
||
|
if ( preview->currentItem() == -1 || preview->currentItem() > (int)preview->count() - 2 )
|
||
|
return;
|
||
|
|
||
15 years ago
|
TQListBoxItem *i = preview->item( preview->currentItem() );
|
||
15 years ago
|
bool hasPix = (i->pixmap() != 0);
|
||
15 years ago
|
TQPixmap pix;
|
||
15 years ago
|
if ( hasPix )
|
||
|
pix = *i->pixmap();
|
||
15 years ago
|
TQString txt = i->text();
|
||
15 years ago
|
|
||
15 years ago
|
TQListBoxItem *n = i->next();
|
||
15 years ago
|
if ( n->pixmap() )
|
||
|
preview->changeItem( *n->pixmap(), n->text(), preview->currentItem() );
|
||
|
else
|
||
|
preview->changeItem( n->text(), preview->currentItem() );
|
||
|
|
||
|
if ( hasPix )
|
||
|
preview->changeItem( pix, txt, preview->currentItem() + 1 );
|
||
|
else
|
||
|
preview->changeItem( txt, preview->currentItem() + 1 );
|
||
|
}
|
||
|
|
||
|
void ListBoxEditor::deletePixmap()
|
||
|
{
|
||
|
if ( preview->currentItem() == -1 )
|
||
|
return;
|
||
|
|
||
15 years ago
|
TQListBoxItem *i = preview->item( preview->currentItem() );
|
||
15 years ago
|
preview->changeItem( i->text(), preview->currentItem() );
|
||
|
itemDeletePixmap->setEnabled( FALSE );
|
||
|
}
|