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.
729 lines
21 KiB
729 lines
21 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 "actiondnd.h"
|
||
|
#include "command.h"
|
||
|
#include "defs.h"
|
||
|
#include "formwindow.h"
|
||
|
#include "mainwindow.h"
|
||
|
#include "metadatabase.h"
|
||
|
#include "widgetfactory.h"
|
||
|
#include "hierarchyview.h"
|
||
|
|
||
15 years ago
|
#include <tqaction.h>
|
||
|
#include <tqapplication.h>
|
||
|
#include <tqbitmap.h>
|
||
|
#include <tqdragobject.h>
|
||
|
#include <tqinputdialog.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
15 years ago
|
#include <tqmainwindow.h>
|
||
|
#include <tqmenudata.h>
|
||
|
#include <tqmessagebox.h>
|
||
|
#include <tqobjectlist.h>
|
||
|
#include <tqpainter.h>
|
||
|
#include <tqstyle.h>
|
||
|
#include <tqtimer.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
|
||
15 years ago
|
TQAction *ActionDrag::the_action = 0;
|
||
15 years ago
|
|
||
15 years ago
|
ActionDrag::ActionDrag(TQAction *action, TQWidget *source)
|
||
|
: TQStoredDrag("application/x-designer-actions", source)
|
||
15 years ago
|
{
|
||
|
Q_ASSERT(the_action == 0);
|
||
|
the_action = action;
|
||
|
}
|
||
|
|
||
15 years ago
|
ActionDrag::ActionDrag(TQActionGroup *group, TQWidget *source)
|
||
|
: TQStoredDrag("application/x-designer-actiongroup", source)
|
||
15 years ago
|
{
|
||
|
Q_ASSERT(the_action == 0);
|
||
|
the_action = group;
|
||
|
}
|
||
|
|
||
15 years ago
|
ActionDrag::ActionDrag(const TQString &type, TQAction *action, TQWidget *source)
|
||
|
: TQStoredDrag(type, source)
|
||
15 years ago
|
{
|
||
|
Q_ASSERT(the_action == 0);
|
||
|
the_action = action;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool ActionDrag::canDecode(TQDropEvent *e)
|
||
15 years ago
|
{
|
||
|
return e->provides( "application/x-designer-actions" ) ||
|
||
|
e->provides( "application/x-designer-actiongroup" ) ||
|
||
|
e->provides( "application/x-designer-separator" );
|
||
|
}
|
||
|
|
||
|
ActionDrag::~ActionDrag()
|
||
|
{
|
||
|
the_action = 0;
|
||
|
}
|
||
|
|
||
14 years ago
|
void QDesignerAction::init()
|
||
15 years ago
|
{
|
||
|
MetaDataBase::addEntry( this );
|
||
|
int id = WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( this ) );
|
||
|
WidgetFactory::saveDefaultProperties( this, id );
|
||
|
WidgetFactory::saveChangedProperties( this, id );
|
||
|
}
|
||
|
|
||
14 years ago
|
void QDesignerActionGroup::init()
|
||
15 years ago
|
{
|
||
|
MetaDataBase::addEntry( this );
|
||
|
int id = WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( this ) );
|
||
|
WidgetFactory::saveDefaultProperties( this, id );
|
||
|
WidgetFactory::saveChangedProperties( this, id );
|
||
|
}
|
||
|
|
||
14 years ago
|
bool QDesignerAction::addTo( TQWidget *w )
|
||
15 years ago
|
{
|
||
|
if ( !widgetToInsert )
|
||
15 years ago
|
return TQAction::addTo( w );
|
||
15 years ago
|
|
||
14 years ago
|
if ( ::tqqt_cast<TQPopupMenu*>(w) )
|
||
15 years ago
|
return FALSE;
|
||
|
|
||
15 years ago
|
widgetToInsert->reparent( w, TQPoint( 0, 0 ), FALSE );
|
||
15 years ago
|
widgetToInsert->show();
|
||
|
addedTo( widgetToInsert, w );
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
14 years ago
|
bool QDesignerAction::removeFrom( TQWidget *w )
|
||
15 years ago
|
{
|
||
|
if ( !widgetToInsert )
|
||
15 years ago
|
return TQAction::removeFrom( w );
|
||
15 years ago
|
|
||
|
remove();
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
14 years ago
|
void QDesignerAction::remove()
|
||
15 years ago
|
{
|
||
|
if ( !widgetToInsert )
|
||
|
return;
|
||
14 years ago
|
MainWindow::self->formWindow()->selectWidget( TQT_TQOBJECT(widgetToInsert), FALSE );
|
||
15 years ago
|
widgetToInsert->reparent( 0, TQPoint( 0, 0 ), FALSE );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
QDesignerToolBarSeparator::QDesignerToolBarSeparator(Qt::Orientation o , TQToolBar *parent,
|
||
15 years ago
|
const char* name )
|
||
14 years ago
|
: TQWidget( parent, name )
|
||
15 years ago
|
{
|
||
14 years ago
|
connect( parent, TQT_SIGNAL(orientationChanged(Qt::Orientation)),
|
||
14 years ago
|
this, TQT_SLOT(setOrientation(Qt::Orientation)) );
|
||
15 years ago
|
setOrientation( o );
|
||
14 years ago
|
setBackgroundMode( parent->backgroundMode() );
|
||
15 years ago
|
setBackgroundOrigin( ParentOrigin );
|
||
13 years ago
|
setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Minimum ) );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
void QDesignerToolBarSeparator::setOrientation( Qt::Orientation o )
|
||
15 years ago
|
{
|
||
|
orient = o;
|
||
|
}
|
||
|
|
||
14 years ago
|
void QDesignerToolBarSeparator::styleChange( TQStyle& )
|
||
15 years ago
|
{
|
||
|
setOrientation( orient );
|
||
|
}
|
||
|
|
||
13 years ago
|
TQSize QDesignerToolBarSeparator::sizeHint() const
|
||
15 years ago
|
{
|
||
13 years ago
|
int extent = style().pixelMetric( TQStyle::PM_DockWindowSeparatorExtent,
|
||
15 years ago
|
this );
|
||
14 years ago
|
if ( orient ==Qt::Horizontal )
|
||
15 years ago
|
return TQSize( extent, 0 );
|
||
15 years ago
|
else
|
||
15 years ago
|
return TQSize( 0, extent );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
void QDesignerToolBarSeparator::paintEvent( TQPaintEvent * )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQPainter p( this );
|
||
|
TQStyle::SFlags flags = TQStyle::Style_Default;
|
||
15 years ago
|
|
||
14 years ago
|
if ( orientation() ==Qt::Horizontal )
|
||
15 years ago
|
flags |= TQStyle::Style_Horizontal;
|
||
15 years ago
|
|
||
13 years ago
|
style().tqdrawPrimitive( TQStyle::PE_DockWindowSeparator, &p, rect(),
|
||
13 years ago
|
colorGroup(), flags );
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
|
||
14 years ago
|
QSeparatorAction::QSeparatorAction( TQObject *parent )
|
||
|
: TQAction( parent, "qt_designer_separator" ), wid( 0 )
|
||
15 years ago
|
{
|
||
|
}
|
||
|
|
||
14 years ago
|
bool QSeparatorAction::addTo( TQWidget *w )
|
||
15 years ago
|
{
|
||
14 years ago
|
if ( ::tqqt_cast<TQToolBar*>(w) ) {
|
||
15 years ago
|
TQToolBar *tb = (TQToolBar*)w;
|
||
14 years ago
|
wid = new QDesignerToolBarSeparator( tb->orientation(), tb );
|
||
15 years ago
|
return TRUE;
|
||
14 years ago
|
} else if ( ::tqqt_cast<TQPopupMenu*>(w) ) {
|
||
15 years ago
|
idx = ( (TQPopupMenu*)w )->count();
|
||
|
( (TQPopupMenu*)w )->insertSeparator( idx );
|
||
15 years ago
|
return TRUE;
|
||
|
}
|
||
|
return FALSE;
|
||
|
}
|
||
|
|
||
14 years ago
|
bool QSeparatorAction::removeFrom( TQWidget *w )
|
||
15 years ago
|
{
|
||
14 years ago
|
if ( ::tqqt_cast<TQToolBar*>(w) ) {
|
||
15 years ago
|
delete wid;
|
||
|
return TRUE;
|
||
14 years ago
|
} else if ( ::tqqt_cast<TQPopupMenu*>(w) ) {
|
||
15 years ago
|
( (TQPopupMenu*)w )->removeItemAt( idx );
|
||
15 years ago
|
return TRUE;
|
||
|
}
|
||
|
return FALSE;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQWidget *QSeparatorAction::widget() const
|
||
15 years ago
|
{
|
||
|
return wid;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
14 years ago
|
QDesignerToolBar::QDesignerToolBar( TQMainWindow *mw )
|
||
15 years ago
|
: TQToolBar( mw ), lastIndicatorPos( -1, -1 )
|
||
15 years ago
|
{
|
||
|
insertAnchor = 0;
|
||
|
afterAnchor = TRUE;
|
||
|
setAcceptDrops( TRUE );
|
||
14 years ago
|
MetaDataBase::addEntry( TQT_TQOBJECT(this) );
|
||
15 years ago
|
lastIndicatorPos = TQPoint( -1, -1 );
|
||
14 years ago
|
indicator = new QDesignerIndicatorWidget( this );
|
||
15 years ago
|
indicator->hide();
|
||
|
installEventFilter( this );
|
||
|
widgetInserting = FALSE;
|
||
|
findFormWindow();
|
||
|
mw->setDockEnabled( DockTornOff, FALSE );
|
||
|
}
|
||
|
|
||
14 years ago
|
QDesignerToolBar::QDesignerToolBar( TQMainWindow *mw, Dock dock )
|
||
14 years ago
|
: TQToolBar( TQString(), mw, dock), lastIndicatorPos( -1, -1 )
|
||
15 years ago
|
{
|
||
|
insertAnchor = 0;
|
||
|
afterAnchor = TRUE;
|
||
|
setAcceptDrops( TRUE );
|
||
14 years ago
|
indicator = new QDesignerIndicatorWidget( this );
|
||
15 years ago
|
indicator->hide();
|
||
14 years ago
|
MetaDataBase::addEntry( TQT_TQOBJECT(this) );
|
||
15 years ago
|
installEventFilter( this );
|
||
|
widgetInserting = FALSE;
|
||
|
findFormWindow();
|
||
|
mw->setDockEnabled( DockTornOff, FALSE );
|
||
|
}
|
||
|
|
||
14 years ago
|
void QDesignerToolBar::findFormWindow()
|
||
15 years ago
|
{
|
||
15 years ago
|
TQWidget *w = this;
|
||
15 years ago
|
while ( w ) {
|
||
14 years ago
|
formWindow = ::tqqt_cast<FormWindow*>(w);
|
||
15 years ago
|
if ( formWindow )
|
||
|
break;
|
||
14 years ago
|
w = w->parentWidget();
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void QDesignerToolBar::addAction( TQAction *a )
|
||
15 years ago
|
{
|
||
|
actionList.append( a );
|
||
15 years ago
|
connect( a, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( actionRemoved() ) );
|
||
14 years ago
|
if ( ::tqqt_cast<TQActionGroup*>(a) ) {
|
||
14 years ago
|
( (QDesignerActionGroup*)a )->widget()->installEventFilter( this );
|
||
|
actionMap.insert( ( (QDesignerActionGroup*)a )->widget(), a );
|
||
|
} else if ( ::tqqt_cast<QSeparatorAction*>(a) ) {
|
||
|
( (QSeparatorAction*)a )->widget()->installEventFilter( this );
|
||
|
actionMap.insert( ( (QSeparatorAction*)a )->widget(), a );
|
||
15 years ago
|
} else {
|
||
14 years ago
|
( (QDesignerAction*)a )->widget()->installEventFilter( this );
|
||
|
actionMap.insert( ( (QDesignerAction*)a )->widget(), a );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
static void fixObject( TQObject *&o )
|
||
15 years ago
|
{
|
||
14 years ago
|
while ( o && o->parent() && !::tqqt_cast<QDesignerToolBar*>(o->parent()) )
|
||
|
o = o->parent();
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
bool QDesignerToolBar::eventFilter( TQObject *o, TQEvent *e )
|
||
15 years ago
|
{
|
||
14 years ago
|
if ( !o || !e || o->inherits( TQDOCKWINDOWHANDLE_OBJECT_NAME_STRING ) || o->inherits( "TQDockWindowTitleBar" ) )
|
||
15 years ago
|
return TQToolBar::eventFilter( o, e );
|
||
15 years ago
|
|
||
14 years ago
|
if ( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(this) && e->type() == TQEvent::MouseButtonPress &&
|
||
|
( ( TQMouseEvent*)e )->button() == Qt::LeftButton ) {
|
||
15 years ago
|
mousePressEvent( (TQMouseEvent*)e );
|
||
15 years ago
|
return TRUE;
|
||
|
}
|
||
|
|
||
14 years ago
|
if ( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(this) )
|
||
15 years ago
|
return TQToolBar::eventFilter( o, e );
|
||
15 years ago
|
|
||
15 years ago
|
if ( e->type() == TQEvent::MouseButtonPress ) {
|
||
|
TQMouseEvent *ke = (TQMouseEvent*)e;
|
||
15 years ago
|
fixObject( o );
|
||
|
if ( !o )
|
||
|
return FALSE;
|
||
|
buttonMousePressEvent( ke, o );
|
||
|
return TRUE;
|
||
15 years ago
|
} else if(e->type() == TQEvent::ContextMenu ) {
|
||
|
TQContextMenuEvent *ce = (TQContextMenuEvent*)e;
|
||
15 years ago
|
fixObject( o );
|
||
|
if( !o )
|
||
|
return FALSE;
|
||
|
buttonContextMenuEvent( ce, o );
|
||
|
return TRUE;
|
||
15 years ago
|
} else if ( e->type() == TQEvent::MouseMove ) {
|
||
|
TQMouseEvent *ke = (TQMouseEvent*)e;
|
||
15 years ago
|
fixObject( o );
|
||
|
if ( !o )
|
||
|
return FALSE;
|
||
|
buttonMouseMoveEvent( ke, o );
|
||
|
return TRUE;
|
||
15 years ago
|
} else if ( e->type() == TQEvent::MouseButtonRelease ) {
|
||
|
TQMouseEvent *ke = (TQMouseEvent*)e;
|
||
15 years ago
|
fixObject( o );
|
||
|
if ( !o )
|
||
|
return FALSE;
|
||
|
buttonMouseReleaseEvent( ke, o );
|
||
|
return TRUE;
|
||
15 years ago
|
} else if ( e->type() == TQEvent::DragEnter ) {
|
||
|
TQDragEnterEvent *de = (TQDragEnterEvent*)e;
|
||
15 years ago
|
if (ActionDrag::canDecode(de))
|
||
|
de->accept();
|
||
15 years ago
|
} else if ( e->type() == TQEvent::DragMove ) {
|
||
|
TQDragMoveEvent *de = (TQDragMoveEvent*)e;
|
||
15 years ago
|
if (ActionDrag::canDecode(de))
|
||
|
de->accept();
|
||
|
}
|
||
|
|
||
15 years ago
|
return TQToolBar::eventFilter( o, e );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
void QDesignerToolBar::paintEvent( TQPaintEvent *e )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQToolBar::paintEvent( e );
|
||
15 years ago
|
if ( e->rect() != rect() )
|
||
|
return;
|
||
15 years ago
|
lastIndicatorPos = TQPoint( -1, -1 );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
void QDesignerToolBar::contextMenuEvent( TQContextMenuEvent *e )
|
||
15 years ago
|
{
|
||
|
e->accept();
|
||
15 years ago
|
TQPopupMenu menu( 0 );
|
||
15 years ago
|
menu.insertItem( i18n( "Delete Toolbar" ), 1 );
|
||
|
int res = menu.exec( e->globalPos() );
|
||
|
if ( res != -1 ) {
|
||
13 years ago
|
RemoveToolBarCommand *cmd = new RemoveToolBarCommand( i18n( "Delete Toolbar '%1'" ).arg( name() ),
|
||
15 years ago
|
formWindow, 0, this );
|
||
|
formWindow->commandHistory()->addCommand( cmd );
|
||
|
cmd->execute();
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void QDesignerToolBar::mousePressEvent( TQMouseEvent *e )
|
||
15 years ago
|
{
|
||
|
widgetInserting = FALSE;
|
||
14 years ago
|
if ( e->button() == Qt::LeftButton &&
|
||
15 years ago
|
MainWindow::self->currentTool() != POINTER_TOOL &&
|
||
|
MainWindow::self->currentTool() != ORDER_TOOL &&
|
||
|
MainWindow::self->currentTool() != CONNECT_TOOL &&
|
||
|
MainWindow::self->currentTool() != BUDDY_TOOL )
|
||
|
widgetInserting = TRUE;
|
||
|
}
|
||
|
|
||
14 years ago
|
void QDesignerToolBar::mouseReleaseEvent( TQMouseEvent *e )
|
||
15 years ago
|
{
|
||
|
if ( widgetInserting )
|
||
|
doInsertWidget( mapFromGlobal( e->globalPos() ) );
|
||
|
widgetInserting = FALSE;
|
||
|
}
|
||
|
|
||
14 years ago
|
void QDesignerToolBar::buttonMouseReleaseEvent( TQMouseEvent *e, TQObject *w )
|
||
15 years ago
|
{
|
||
|
if ( widgetInserting )
|
||
|
doInsertWidget( mapFromGlobal( e->globalPos() ) );
|
||
14 years ago
|
else if ( w->isWidgetType() && formWindow->widgets()->find( w ) ) {
|
||
15 years ago
|
formWindow->clearSelection( FALSE );
|
||
|
formWindow->selectWidget( w );
|
||
|
}
|
||
|
widgetInserting = FALSE;
|
||
|
}
|
||
|
|
||
14 years ago
|
void QDesignerToolBar::buttonContextMenuEvent( TQContextMenuEvent *e, TQObject *o )
|
||
15 years ago
|
{
|
||
|
e->accept();
|
||
15 years ago
|
TQPopupMenu menu( 0 );
|
||
15 years ago
|
const int ID_DELETE = 1;
|
||
|
const int ID_SEP = 2;
|
||
|
const int ID_DELTOOLBAR = 3;
|
||
14 years ago
|
TQMap<TQWidget*, TQAction*>::Iterator it = actionMap.find( (TQWidget*)o );
|
||
14 years ago
|
if ( it != actionMap.end() && ::tqqt_cast<QSeparatorAction*>(*it) )
|
||
15 years ago
|
menu.insertItem( i18n( "Delete Separator" ), ID_DELETE );
|
||
|
else
|
||
|
menu.insertItem( i18n( "Delete Item" ), ID_DELETE );
|
||
|
menu.insertItem( i18n( "Insert Separator" ), ID_SEP );
|
||
|
menu.insertSeparator();
|
||
|
menu.insertItem( i18n( "Delete Toolbar" ), ID_DELTOOLBAR );
|
||
|
int res = menu.exec( e->globalPos() );
|
||
|
if ( res == ID_DELETE ) {
|
||
14 years ago
|
TQMap<TQWidget*, TQAction*>::Iterator it = actionMap.find( (TQWidget*)o );
|
||
15 years ago
|
if ( it == actionMap.end() )
|
||
|
return;
|
||
15 years ago
|
TQAction *a = *it;
|
||
14 years ago
|
int index = actionList.find( a );
|
||
15 years ago
|
RemoveActionFromToolBarCommand *cmd = new RemoveActionFromToolBarCommand(
|
||
|
i18n( "Delete Action '%1' From Toolbar '%2'" ).
|
||
13 years ago
|
arg( a->name() ).arg( caption() ),
|
||
15 years ago
|
formWindow, a, this, index );
|
||
|
formWindow->commandHistory()->addCommand( cmd );
|
||
|
cmd->execute();
|
||
|
} else if ( res == ID_SEP ) {
|
||
|
calcIndicatorPos( mapFromGlobal( e->globalPos() ) );
|
||
14 years ago
|
TQAction *a = new QSeparatorAction( 0 );
|
||
14 years ago
|
int index = actionList.findRef( *actionMap.find( insertAnchor ) );
|
||
15 years ago
|
if ( index != -1 && afterAnchor )
|
||
|
++index;
|
||
|
if ( !insertAnchor )
|
||
|
index = 0;
|
||
|
|
||
|
AddActionToToolBarCommand *cmd = new AddActionToToolBarCommand(
|
||
|
i18n( "Add Separator to Toolbar '%1'" ).
|
||
|
arg( a->name() ),
|
||
|
formWindow, a, this, index );
|
||
|
formWindow->commandHistory()->addCommand( cmd );
|
||
|
cmd->execute();
|
||
|
} else if ( res == ID_DELTOOLBAR ) {
|
||
13 years ago
|
RemoveToolBarCommand *cmd = new RemoveToolBarCommand( i18n( "Delete Toolbar '%1'" ).arg( name() ),
|
||
15 years ago
|
formWindow, 0, this );
|
||
|
formWindow->commandHistory()->addCommand( cmd );
|
||
|
cmd->execute();
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void QDesignerToolBar::buttonMousePressEvent( TQMouseEvent *e, TQObject * )
|
||
15 years ago
|
{
|
||
|
widgetInserting = FALSE;
|
||
|
|
||
14 years ago
|
if ( e->button() == Qt::MidButton )
|
||
15 years ago
|
return;
|
||
|
|
||
14 years ago
|
if ( e->button() == Qt::LeftButton &&
|
||
15 years ago
|
MainWindow::self->currentTool() != POINTER_TOOL &&
|
||
|
MainWindow::self->currentTool() != ORDER_TOOL &&
|
||
|
MainWindow::self->currentTool() != CONNECT_TOOL &&
|
||
|
MainWindow::self->currentTool() != BUDDY_TOOL ) {
|
||
|
widgetInserting = TRUE;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
dragStartPos = e->pos();
|
||
|
}
|
||
|
|
||
14 years ago
|
void QDesignerToolBar::removeWidget( TQWidget *w )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQMap<TQWidget*, TQAction*>::Iterator it = actionMap.find( w );
|
||
15 years ago
|
if ( it == actionMap.end() )
|
||
|
return;
|
||
15 years ago
|
TQAction *a = *it;
|
||
14 years ago
|
int index = actionList.find( a );
|
||
15 years ago
|
RemoveActionFromToolBarCommand *cmd =
|
||
|
new RemoveActionFromToolBarCommand( i18n( "Delete Action '%1' From Toolbar '%2'" ).
|
||
13 years ago
|
arg( a->name() ).arg( caption() ),
|
||
15 years ago
|
formWindow, a, this, index );
|
||
|
formWindow->commandHistory()->addCommand( cmd );
|
||
|
cmd->execute();
|
||
15 years ago
|
TQApplication::sendPostedEvents();
|
||
15 years ago
|
adjustSize();
|
||
|
}
|
||
|
|
||
14 years ago
|
void QDesignerToolBar::buttonMouseMoveEvent( TQMouseEvent *e, TQObject *o )
|
||
15 years ago
|
{
|
||
14 years ago
|
if ( widgetInserting || ( e->state() & Qt::LeftButton ) == 0 )
|
||
15 years ago
|
return;
|
||
14 years ago
|
if ( TQABS( TQPoint( dragStartPos - e->pos() ).manhattanLength() ) < TQApplication::startDragDistance() )
|
||
15 years ago
|
return;
|
||
14 years ago
|
TQMap<TQWidget*, TQAction*>::Iterator it = actionMap.find( (TQWidget*)o );
|
||
15 years ago
|
if ( it == actionMap.end() )
|
||
|
return;
|
||
15 years ago
|
TQAction *a = *it;
|
||
15 years ago
|
if ( !a )
|
||
|
return;
|
||
14 years ago
|
int index = actionList.find( a );
|
||
15 years ago
|
RemoveActionFromToolBarCommand *cmd =
|
||
|
new RemoveActionFromToolBarCommand( i18n( "Delete Action '%1' From Toolbar '%2'" ).
|
||
13 years ago
|
arg( a->name() ).arg( caption() ),
|
||
15 years ago
|
formWindow, a, this, index );
|
||
|
formWindow->commandHistory()->addCommand( cmd );
|
||
|
cmd->execute();
|
||
15 years ago
|
TQApplication::sendPostedEvents();
|
||
15 years ago
|
adjustSize();
|
||
|
|
||
14 years ago
|
TQString type = ::tqqt_cast<TQActionGroup*>(a) ? TQString( "application/x-designer-actiongroup" ) :
|
||
14 years ago
|
::tqqt_cast<QSeparatorAction*>(a) ? TQString( "application/x-designer-separator" ) : TQString( "application/x-designer-actions" );
|
||
15 years ago
|
TQStoredDrag *drag = new ActionDrag( type, a, this );
|
||
15 years ago
|
drag->setPixmap( a->iconSet().pixmap() );
|
||
14 years ago
|
if ( ::tqqt_cast<QDesignerAction*>(a) ) {
|
||
14 years ago
|
if ( formWindow->widgets()->find( ( (QDesignerAction*)a )->widget() ) )
|
||
14 years ago
|
formWindow->selectWidget( ( TQT_TQOBJECT(( (QDesignerAction*)a )->widget())), FALSE );
|
||
15 years ago
|
}
|
||
|
if ( !drag->drag() ) {
|
||
|
AddActionToToolBarCommand *cmd = new AddActionToToolBarCommand( i18n( "Add Action '%1' to Toolbar '%2'" ).
|
||
13 years ago
|
arg( a->name() ).arg( caption() ),
|
||
15 years ago
|
formWindow, a, this, index );
|
||
|
formWindow->commandHistory()->addCommand( cmd );
|
||
|
cmd->execute();
|
||
|
}
|
||
15 years ago
|
lastIndicatorPos = TQPoint( -1, -1 );
|
||
15 years ago
|
indicator->hide();
|
||
|
}
|
||
|
|
||
14 years ago
|
#ifndef TQT_NO_DRAGANDDROP
|
||
15 years ago
|
|
||
14 years ago
|
void QDesignerToolBar::dragEnterEvent( TQDragEnterEvent *e )
|
||
15 years ago
|
{
|
||
|
widgetInserting = FALSE;
|
||
15 years ago
|
lastIndicatorPos = TQPoint( -1, -1 );
|
||
15 years ago
|
if (ActionDrag::canDecode(e))
|
||
|
e->accept();
|
||
|
}
|
||
|
|
||
14 years ago
|
void QDesignerToolBar::dragMoveEvent( TQDragMoveEvent *e )
|
||
15 years ago
|
{
|
||
|
if (ActionDrag::canDecode(e)) {
|
||
|
e->accept();
|
||
|
drawIndicator( calcIndicatorPos( e->pos() ) );
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void QDesignerToolBar::dragLeaveEvent( TQDragLeaveEvent * )
|
||
15 years ago
|
{
|
||
|
indicator->hide();
|
||
|
insertAnchor = 0;
|
||
|
afterAnchor = TRUE;
|
||
|
}
|
||
|
|
||
14 years ago
|
void QDesignerToolBar::dropEvent( TQDropEvent *e )
|
||
15 years ago
|
{
|
||
|
if (!ActionDrag::canDecode(e))
|
||
|
return;
|
||
|
|
||
|
e->accept();
|
||
|
|
||
|
indicator->hide();
|
||
15 years ago
|
TQAction *a = 0;
|
||
14 years ago
|
int index = actionList.findRef( *actionMap.find( insertAnchor ) );
|
||
15 years ago
|
if ( index != -1 && afterAnchor )
|
||
|
++index;
|
||
|
if ( !insertAnchor )
|
||
|
index = 0;
|
||
|
if ( e->provides( "application/x-designer-actions" ) ||
|
||
|
e->provides( "application/x-designer-separator" ) ) {
|
||
|
if ( e->provides( "application/x-designer-actions" ) )
|
||
14 years ago
|
a = ::tqqt_cast<QDesignerAction*>(ActionDrag::action());
|
||
15 years ago
|
else
|
||
14 years ago
|
a = ::tqqt_cast<QSeparatorAction*>(ActionDrag::action());
|
||
15 years ago
|
} else {
|
||
14 years ago
|
a = ::tqqt_cast<QDesignerActionGroup*>(ActionDrag::action());
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
if ( actionList.findRef( a ) != -1 ) {
|
||
15 years ago
|
TQMessageBox::warning( MainWindow::self, i18n( "Insert/Move Action" ),
|
||
15 years ago
|
i18n( "Action '%1' has already been added to this toolbar.\n"
|
||
|
"An Action may only occur once in a given toolbar." ).
|
||
|
arg( a->name() ) );
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
AddActionToToolBarCommand *cmd = new AddActionToToolBarCommand( i18n( "Add Action '%1' to Toolbar '%2'" ).
|
||
13 years ago
|
arg( a->name() ).arg( caption() ),
|
||
15 years ago
|
formWindow, a, this, index );
|
||
|
formWindow->commandHistory()->addCommand( cmd );
|
||
|
cmd->execute();
|
||
|
|
||
15 years ago
|
lastIndicatorPos = TQPoint( -1, -1 );
|
||
15 years ago
|
}
|
||
|
|
||
|
#endif
|
||
|
|
||
14 years ago
|
void QDesignerToolBar::reInsert()
|
||
15 years ago
|
{
|
||
15 years ago
|
TQAction *a = 0;
|
||
15 years ago
|
actionMap.clear();
|
||
|
clear();
|
||
|
for ( a = actionList.first(); a; a = actionList.next() ) {
|
||
|
a->addTo( this );
|
||
14 years ago
|
if ( ::tqqt_cast<TQActionGroup*>(a) ) {
|
||
14 years ago
|
actionMap.insert( ( (QDesignerActionGroup*)a )->widget(), a );
|
||
|
if ( ( (QDesignerActionGroup*)a )->widget() )
|
||
|
( (QDesignerActionGroup*)a )->widget()->installEventFilter( this );
|
||
|
} else if ( ::tqqt_cast<QDesignerAction*>(a) ) {
|
||
|
actionMap.insert( ( (QDesignerAction*)a )->widget(), a );
|
||
|
( (QDesignerAction*)a )->widget()->installEventFilter( this );
|
||
|
} else if ( ::tqqt_cast<QSeparatorAction*>(a) ) {
|
||
|
actionMap.insert( ( (QSeparatorAction*)a )->widget(), a );
|
||
|
( (QSeparatorAction*)a )->widget()->installEventFilter( this );
|
||
15 years ago
|
}
|
||
|
}
|
||
15 years ago
|
TQApplication::sendPostedEvents();
|
||
15 years ago
|
adjustSize();
|
||
|
}
|
||
|
|
||
14 years ago
|
void QDesignerToolBar::actionRemoved()
|
||
15 years ago
|
{
|
||
15 years ago
|
actionList.removeRef( (TQAction*)sender() );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
TQPoint QDesignerToolBar::calcIndicatorPos( const TQPoint &pos )
|
||
15 years ago
|
{
|
||
14 years ago
|
if ( orientation() ==Qt::Horizontal ) {
|
||
15 years ago
|
TQPoint pnt( width() - 2, 0 );
|
||
15 years ago
|
insertAnchor = 0;
|
||
|
afterAnchor = TRUE;
|
||
14 years ago
|
TQObjectList clo = childrenListObject();
|
||
|
if ( clo.isEmpty() )
|
||
15 years ago
|
return pnt;
|
||
15 years ago
|
pnt = TQPoint( 13, 0 );
|
||
14 years ago
|
TQObjectListIt it( clo );
|
||
15 years ago
|
TQObject * obj;
|
||
15 years ago
|
while( (obj=it.current()) != 0 ) {
|
||
|
++it;
|
||
|
if ( obj->isWidgetType() &&
|
||
|
qstrcmp( "qt_dockwidget_internal", obj->name() ) != 0 ) {
|
||
15 years ago
|
TQWidget *w = (TQWidget*)obj;
|
||
15 years ago
|
if ( w->x() < pos.x() ) {
|
||
|
pnt.setX( w->x() + w->width() + 1 );
|
||
|
insertAnchor = w;
|
||
|
afterAnchor = TRUE;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return pnt;
|
||
|
} else {
|
||
15 years ago
|
TQPoint pnt( 0, height() - 2 );
|
||
15 years ago
|
insertAnchor = 0;
|
||
|
afterAnchor = TRUE;
|
||
14 years ago
|
TQObjectList clo = childrenListObject();
|
||
|
if ( clo.isEmpty() )
|
||
15 years ago
|
return pnt;
|
||
15 years ago
|
pnt = TQPoint( 0, 13 );
|
||
14 years ago
|
TQObjectListIt it( clo );
|
||
15 years ago
|
TQObject * obj;
|
||
15 years ago
|
while( (obj=it.current()) != 0 ) {
|
||
|
++it;
|
||
|
if ( obj->isWidgetType() &&
|
||
|
qstrcmp( "qt_dockwidget_internal", obj->name() ) != 0 ) {
|
||
15 years ago
|
TQWidget *w = (TQWidget*)obj;
|
||
15 years ago
|
if ( w->y() < pos.y() ) {
|
||
|
pnt.setY( w->y() + w->height() + 1 );
|
||
|
insertAnchor = w;
|
||
|
afterAnchor = TRUE;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return pnt;
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void QDesignerToolBar::drawIndicator( const TQPoint &pos )
|
||
15 years ago
|
{
|
||
|
if ( lastIndicatorPos == pos )
|
||
|
return;
|
||
|
bool wasVsisible = indicator->isVisible();
|
||
14 years ago
|
if ( orientation() ==Qt::Horizontal ) {
|
||
15 years ago
|
indicator->resize( 3, height() );
|
||
15 years ago
|
if ( pos != TQPoint( -1, -1 ) )
|
||
15 years ago
|
indicator->move( pos.x() - 1, 0 );
|
||
|
indicator->show();
|
||
|
indicator->raise();
|
||
|
lastIndicatorPos = pos;
|
||
|
} else {
|
||
|
indicator->resize( width(), 3 );
|
||
15 years ago
|
if ( pos != TQPoint( -1, -1 ) )
|
||
15 years ago
|
indicator->move( 0, pos.y() - 1 );
|
||
|
indicator->show();
|
||
|
indicator->raise();
|
||
|
lastIndicatorPos = pos;
|
||
|
}
|
||
|
if ( !wasVsisible )
|
||
15 years ago
|
TQApplication::sendPostedEvents();
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
void QDesignerToolBar::doInsertWidget( const TQPoint &p )
|
||
15 years ago
|
{
|
||
|
if ( formWindow != MainWindow::self->formWindow() )
|
||
|
return;
|
||
|
calcIndicatorPos( p );
|
||
15 years ago
|
TQWidget *w = WidgetFactory::create( MainWindow::self->currentTool(), this, 0, TRUE );
|
||
15 years ago
|
installEventFilters( w );
|
||
|
MainWindow::self->formWindow()->insertWidget( w, TRUE );
|
||
14 years ago
|
QDesignerAction *a = new QDesignerAction( w, parent() );
|
||
14 years ago
|
int index = actionList.findRef( *actionMap.find( insertAnchor ) );
|
||
15 years ago
|
if ( index != -1 && afterAnchor )
|
||
|
++index;
|
||
|
if ( !insertAnchor )
|
||
|
index = 0;
|
||
|
AddActionToToolBarCommand *cmd = new AddActionToToolBarCommand( i18n( "Add Widget '%1' to Toolbar '%2'" ).
|
||
13 years ago
|
arg( w->name() ).arg( caption() ),
|
||
15 years ago
|
formWindow, a, this, index );
|
||
|
formWindow->commandHistory()->addCommand( cmd );
|
||
|
cmd->execute();
|
||
|
MainWindow::self->resetTool();
|
||
|
}
|
||
|
|
||
14 years ago
|
void QDesignerToolBar::clear()
|
||
15 years ago
|
{
|
||
15 years ago
|
for ( TQAction *a = actionList.first(); a; a = actionList.next() ) {
|
||
14 years ago
|
if ( ::tqqt_cast<QDesignerAction*>(a) )
|
||
|
( (QDesignerAction*)a )->remove();
|
||
15 years ago
|
}
|
||
15 years ago
|
TQToolBar::clear();
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
void QDesignerToolBar::installEventFilters( TQWidget *w )
|
||
15 years ago
|
{
|
||
|
if ( !w )
|
||
|
return;
|
||
14 years ago
|
TQObjectList *l = w->queryList( TQWIDGET_OBJECT_NAME_STRING );
|
||
15 years ago
|
for ( TQObject *o = l->first(); o; o = l->next() )
|
||
15 years ago
|
o->installEventFilter( this );
|
||
|
delete l;
|
||
|
}
|
||
|
|
||
|
//#include "actiondnd.moc"
|