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.
322 lines
11 KiB
322 lines
11 KiB
15 years ago
|
/**********************************************************************
|
||
|
** Copyright (C) 2000-2002 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 "actioneditorimpl.h"
|
||
|
#include "formwindow.h"
|
||
|
#include "metadatabase.h"
|
||
|
#include "actionlistview.h"
|
||
|
#include "connectiondialog.h"
|
||
|
#include "mainwindow.h"
|
||
|
#include "hierarchyview.h"
|
||
|
#include "formfile.h"
|
||
|
|
||
15 years ago
|
#include <tqaction.h>
|
||
|
#include <tqlineedit.h>
|
||
|
#include <tqlabel.h>
|
||
|
#include <tqtoolbutton.h>
|
||
|
#include <tqlistview.h>
|
||
|
#include <tqcheckbox.h>
|
||
|
#include <tqpushbutton.h>
|
||
|
#include <tqpopupmenu.h>
|
||
|
#include <tqobjectlist.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
|
||
14 years ago
|
ActionEditor::ActionEditor( TQWidget* parent, const char* name, WFlags fl )
|
||
|
: ActionEditorBase( parent, name, fl ), currentAction( 0 ), formWindow( 0 ),
|
||
15 years ago
|
explicitlyClosed(false)
|
||
|
{
|
||
|
listActions->addColumn( i18n( "Actions" ) );
|
||
|
setEnabled( FALSE );
|
||
|
buttonConnect->setEnabled( FALSE );
|
||
|
|
||
15 years ago
|
TQPopupMenu *popup = new TQPopupMenu( this );
|
||
|
popup->insertItem( i18n( "New &Action" ), this, TQT_SLOT( newAction() ) );
|
||
|
popup->insertItem( i18n( "New Action &Group" ), this, TQT_SLOT( newActionGroup() ) );
|
||
|
popup->insertItem( i18n( "New &Dropdown Action Group" ), this, TQT_SLOT( newDropDownActionGroup() ) );
|
||
15 years ago
|
buttonNewAction->setPopup( popup );
|
||
|
buttonNewAction->setPopupDelay( 0 );
|
||
|
|
||
15 years ago
|
connect( listActions, TQT_SIGNAL( insertAction() ), this, TQT_SLOT( newAction() ) );
|
||
|
connect( listActions, TQT_SIGNAL( insertActionGroup() ), this, TQT_SLOT( newActionGroup() ) );
|
||
|
connect( listActions, TQT_SIGNAL( insertDropDownActionGroup() ), this, TQT_SLOT( newDropDownActionGroup() ) );
|
||
|
connect( listActions, TQT_SIGNAL( deleteAction() ), this, TQT_SLOT( deleteAction() ) );
|
||
|
connect( listActions, TQT_SIGNAL( connectAction() ), this, TQT_SLOT( connectionsClicked() ) );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void ActionEditor::closeEvent( TQCloseEvent *e )
|
||
15 years ago
|
{
|
||
|
emit hidden();
|
||
|
e->accept();
|
||
|
}
|
||
|
|
||
15 years ago
|
void ActionEditor::currentActionChanged( TQListViewItem *i )
|
||
15 years ago
|
{
|
||
|
buttonConnect->setEnabled( i != 0 );
|
||
|
if ( !i )
|
||
|
return;
|
||
|
currentAction = ( (ActionItem*)i )->action();
|
||
|
if ( !currentAction )
|
||
|
currentAction = ( (ActionItem*)i )->actionGroup();
|
||
|
if ( formWindow && currentAction )
|
||
|
formWindow->setActiveObject( currentAction );
|
||
|
MainWindow::self->objectHierarchy()->hierarchyList()->setCurrent( currentAction );
|
||
|
}
|
||
|
|
||
15 years ago
|
void ActionEditor::setCurrentAction( TQAction *a )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQListViewItemIterator it( listActions );
|
||
15 years ago
|
while ( it.current() ) {
|
||
|
if ( ( (ActionItem*)it.current() )->action() == a || ( (ActionItem*)it.current() )->actionGroup() == a ) {
|
||
|
listActions->setCurrentItem( it.current() );
|
||
|
listActions->ensureItemVisible( it.current() );
|
||
|
break;
|
||
|
}
|
||
|
++it;
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
TQAction *ActionEditor::newActionEx()
|
||
15 years ago
|
{
|
||
|
ActionItem *i = new ActionItem( listActions, (bool)FALSE );
|
||
15 years ago
|
TQAction *a = i->action();
|
||
|
TQObject::connect( a, TQT_SIGNAL( destroyed( TQObject * ) ),
|
||
|
this, TQT_SLOT( removeConnections( TQObject* ) ) );
|
||
15 years ago
|
MetaDataBase::addEntry( i->action() );
|
||
15 years ago
|
TQString n = "Action";
|
||
15 years ago
|
formWindow->unify( i->action(), n, TRUE );
|
||
|
i->setText( 0, n );
|
||
|
i->action()->setName( n );
|
||
|
i->action()->setText( i->action()->name() );
|
||
|
MetaDataBase::setPropertyChanged( i->action(), "text", TRUE );
|
||
|
MetaDataBase::setPropertyChanged( i->action(), "name", TRUE );
|
||
|
formWindow->actionList().append( i->action() );
|
||
|
if ( formWindow->formFile() )
|
||
|
formWindow->formFile()->setModified( TRUE );
|
||
|
return i->action();
|
||
|
}
|
||
|
|
||
|
void ActionEditor::deleteAction()
|
||
|
{
|
||
|
if ( !currentAction )
|
||
|
return;
|
||
|
|
||
15 years ago
|
TQListViewItemIterator it( listActions );
|
||
15 years ago
|
ActionItem *ai = 0;
|
||
|
while ( it.current() ) {
|
||
|
ai = (ActionItem*)it.current();
|
||
|
if ( ai->action() == currentAction || ai->actionGroup() == currentAction ) {
|
||
|
emit removing( currentAction );
|
||
|
formWindow->actionList().removeRef( currentAction );
|
||
|
delete currentAction;
|
||
|
currentAction = 0;
|
||
|
delete it.current();
|
||
|
break;
|
||
|
}
|
||
|
++it;
|
||
|
}
|
||
|
if ( formWindow ) {
|
||
14 years ago
|
formWindow->setActiveObject( TQT_TQOBJECT(formWindow->mainContainer()) );
|
||
15 years ago
|
if ( formWindow->formFile() )
|
||
|
formWindow->formFile()->setModified( TRUE );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void ActionEditor::newAction()
|
||
|
{
|
||
|
ActionItem *actionParent = (ActionItem*)listActions->selectedItem();
|
||
|
if ( actionParent ) {
|
||
14 years ago
|
if ( !::tqqt_cast<TQActionGroup*>(actionParent->actionGroup()) )
|
||
14 years ago
|
actionParent = (ActionItem*)actionParent->parent();
|
||
15 years ago
|
}
|
||
|
|
||
|
ActionItem *i = 0;
|
||
|
if ( actionParent )
|
||
|
i = new ActionItem( actionParent );
|
||
|
else
|
||
|
i = new ActionItem( listActions, (bool)FALSE );
|
||
15 years ago
|
TQAction *a = i->action();
|
||
|
TQObject::connect( a, TQT_SIGNAL( destroyed( TQObject * ) ),
|
||
|
this, TQT_SLOT( removeConnections( TQObject* ) ) );
|
||
15 years ago
|
MetaDataBase::addEntry( i->action() );
|
||
15 years ago
|
TQString n = "Action";
|
||
15 years ago
|
formWindow->unify( i->action(), n, TRUE );
|
||
|
i->setText( 0, n );
|
||
|
i->action()->setName( n );
|
||
|
i->action()->setText( i->action()->name() );
|
||
|
if ( actionParent && actionParent->actionGroup() &&
|
||
|
actionParent->actionGroup()->usesDropDown() ) {
|
||
|
i->action()->setToggleAction( TRUE );
|
||
|
MetaDataBase::setPropertyChanged( i->action(), "toggleAction", TRUE );
|
||
|
}
|
||
|
MetaDataBase::setPropertyChanged( i->action(), "text", TRUE );
|
||
|
MetaDataBase::setPropertyChanged( i->action(), "name", TRUE );
|
||
|
listActions->setCurrentItem( i );
|
||
|
if ( !actionParent )
|
||
|
formWindow->actionList().append( i->action() );
|
||
|
if ( formWindow->formFile() )
|
||
|
formWindow->formFile()->setModified( TRUE );
|
||
|
}
|
||
|
|
||
|
void ActionEditor::newActionGroup()
|
||
|
{
|
||
|
ActionItem *actionParent = (ActionItem*)listActions->selectedItem();
|
||
|
if ( actionParent ) {
|
||
14 years ago
|
if ( !::tqqt_cast<TQActionGroup*>(actionParent->actionGroup()) )
|
||
14 years ago
|
actionParent = (ActionItem*)actionParent->parent();
|
||
15 years ago
|
}
|
||
|
|
||
|
ActionItem *i = 0;
|
||
|
if ( actionParent )
|
||
|
i = new ActionItem( actionParent, TRUE );
|
||
|
else
|
||
|
i = new ActionItem( listActions, TRUE );
|
||
15 years ago
|
TQAction *ag = i->actionGroup();
|
||
|
TQObject::connect( ag, TQT_SIGNAL( destroyed( TQObject * ) ),
|
||
|
this, TQT_SLOT( removeConnections( TQObject* ) ) );
|
||
15 years ago
|
MetaDataBase::addEntry( i->actionGroup() );
|
||
|
MetaDataBase::setPropertyChanged( i->actionGroup(), "usesDropDown", TRUE );
|
||
15 years ago
|
TQString n = "ActionGroup";
|
||
15 years ago
|
formWindow->unify( i->action(), n, TRUE );
|
||
|
i->setText( 0, n );
|
||
|
i->actionGroup()->setName( n );
|
||
|
i->actionGroup()->setText( i->actionGroup()->name() );
|
||
|
MetaDataBase::setPropertyChanged( i->actionGroup(), "text", TRUE );
|
||
|
MetaDataBase::setPropertyChanged( i->actionGroup(), "name", TRUE );
|
||
|
listActions->setCurrentItem( i );
|
||
|
i->setOpen( TRUE );
|
||
|
if ( !actionParent )
|
||
|
formWindow->actionList().append( i->actionGroup() );
|
||
|
if ( formWindow->formFile() )
|
||
|
formWindow->formFile()->setModified( TRUE );
|
||
|
}
|
||
|
|
||
|
void ActionEditor::newDropDownActionGroup()
|
||
|
{
|
||
|
newActionGroup();
|
||
|
( (ActionItem*)listActions->currentItem() )->actionGroup()->setUsesDropDown( TRUE );
|
||
|
}
|
||
|
|
||
|
void ActionEditor::setFormWindow( FormWindow *fw )
|
||
|
{
|
||
|
listActions->clear();
|
||
|
formWindow = fw;
|
||
|
if ( !formWindow ||
|
||
14 years ago
|
!::tqqt_cast<TQMainWindow*>(formWindow->mainContainer()) ) {
|
||
15 years ago
|
setEnabled( FALSE );
|
||
|
} else {
|
||
|
setEnabled( TRUE );
|
||
15 years ago
|
for ( TQAction *a = formWindow->actionList().first(); a; a = formWindow->actionList().next() ) {
|
||
15 years ago
|
ActionItem *i = 0;
|
||
14 years ago
|
if ( ::tqqt_cast<TQAction*>(a->parent()) )
|
||
15 years ago
|
continue;
|
||
|
i = new ActionItem( listActions, a );
|
||
|
i->setText( 0, a->name() );
|
||
|
i->setPixmap( 0, a->iconSet().pixmap() );
|
||
|
// make sure we don't duplicate the connection
|
||
15 years ago
|
TQObject::disconnect( a, TQT_SIGNAL( destroyed( TQObject * ) ),
|
||
|
this, TQT_SLOT( removeConnections( TQObject * ) ) );
|
||
|
TQObject::connect( a, TQT_SIGNAL( destroyed( TQObject * ) ),
|
||
|
this, TQT_SLOT( removeConnections( TQObject* ) ) );
|
||
14 years ago
|
if ( ::tqqt_cast<TQActionGroup*>(a) ) {
|
||
15 years ago
|
insertChildActions( i );
|
||
|
}
|
||
|
}
|
||
|
if ( listActions->firstChild() ) {
|
||
|
listActions->setCurrentItem( listActions->firstChild() );
|
||
|
listActions->setSelected( listActions->firstChild(), TRUE );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void ActionEditor::insertChildActions( ActionItem *i )
|
||
|
{
|
||
14 years ago
|
TQObjectList clo = i->actionGroup()->childrenListObject();
|
||
|
if ( !i->actionGroup() || clo.isEmpty() )
|
||
15 years ago
|
return;
|
||
14 years ago
|
TQObjectListIt it( clo );
|
||
15 years ago
|
while ( it.current() ) {
|
||
15 years ago
|
TQObject *o = it.current();
|
||
15 years ago
|
++it;
|
||
14 years ago
|
if ( !::tqqt_cast<TQAction*>(o) )
|
||
15 years ago
|
continue;
|
||
15 years ago
|
TQAction *a = (TQAction*)o;
|
||
|
ActionItem *i2 = new ActionItem( (TQListViewItem*)i, a );
|
||
15 years ago
|
i->setOpen( TRUE );
|
||
|
i2->setText( 0, a->name() );
|
||
|
i2->setPixmap( 0, a->iconSet().pixmap() );
|
||
|
// make sure we don't duplicate the connection
|
||
15 years ago
|
TQObject::disconnect( o, TQT_SIGNAL( destroyed( TQObject * ) ),
|
||
|
this, TQT_SLOT( removeConnections( TQObject * ) ) );
|
||
|
TQObject::connect( o, TQT_SIGNAL( destroyed( TQObject * ) ),
|
||
|
this, TQT_SLOT( removeConnections( TQObject * ) ) );
|
||
14 years ago
|
if ( ::tqqt_cast<TQActionGroup*>(a) )
|
||
15 years ago
|
insertChildActions( i2 );
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void ActionEditor::updateActionName( TQAction *a )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQListViewItemIterator it( listActions );
|
||
15 years ago
|
while ( it.current() ) {
|
||
|
if ( ( (ActionItem*)it.current() )->action() == a )
|
||
|
( (ActionItem*)it.current() )->setText( 0, a->name() );
|
||
|
else if ( ( (ActionItem*)it.current() )->actionGroup() == a )
|
||
|
( (ActionItem*)it.current() )->setText( 0, a->name() );
|
||
|
++it;
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void ActionEditor::updateActionIcon( TQAction *a )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQListViewItemIterator it( listActions );
|
||
15 years ago
|
while ( it.current() ) {
|
||
|
if ( ( (ActionItem*)it.current() )->action() == a )
|
||
|
( (ActionItem*)it.current() )->setPixmap( 0, a->iconSet().pixmap() );
|
||
|
else if ( ( (ActionItem*)it.current() )->actionGroup() == a )
|
||
|
( (ActionItem*)it.current() )->setPixmap( 0, a->iconSet().pixmap() );
|
||
|
++it;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void ActionEditor::connectionsClicked()
|
||
|
{
|
||
|
ConnectionDialog dlg( formWindow->mainWindow() );
|
||
14 years ago
|
dlg.setDefault( TQT_TQOBJECT(currentAction), TQT_TQOBJECT(formWindow) );
|
||
15 years ago
|
dlg.addConnection();
|
||
|
dlg.exec();
|
||
|
}
|
||
|
|
||
15 years ago
|
void ActionEditor::removeConnections( TQObject *o )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQValueList<MetaDataBase::Connection> conns =
|
||
14 years ago
|
MetaDataBase::connections( TQT_TQOBJECT(formWindow), o );
|
||
15 years ago
|
for ( TQValueList<MetaDataBase::Connection>::Iterator it2 = conns.begin();
|
||
15 years ago
|
it2 != conns.end(); ++it2 )
|
||
14 years ago
|
MetaDataBase::removeConnection( TQT_TQOBJECT(formWindow), (*it2).sender, (*it2).signal,
|
||
15 years ago
|
(*it2).receiver, (*it2).slot );
|
||
|
}
|