⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 command.cpp

📁 Qt/Embedded是一个多平台的C++图形用户界面应用程序框架
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/************************************************************************ Copyright (C) 2000 Trolltech AS.  All rights reserved.**** This file is part of Qt Designer.**** 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.**** 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.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "command.h"#include "formwindow.h"#include "widgetfactory.h"#include "propertyeditor.h"#include "metadatabase.h"#include <widgetdatabase.h>#include "mainwindow.h"#include "hierarchyview.h"#include "formlist.h"#include <qwidget.h>#include <qmetaobject.h>#include <qapplication.h>#include <qlayout.h>#include <qmessagebox.h>#include <qlistbox.h>#include <qiconview.h>#include <qmultilineedit.h>#include <qstack.h>#include <qheader.h>CommandHistory::CommandHistory( int s )    : current( -1 ), steps( s ), savedAt( -1 ){    history.setAutoDelete( TRUE );    modified = FALSE;    compressedCommand = 0;}void CommandHistory::addCommand( Command *cmd, bool tryCompress ){    if ( tryCompress ) {	if ( !compressedCommand ||	     compressedCommand->type() != cmd->type() ||	     !compressedCommand->canMerge( cmd ) ) {	    checkCompressedCommand();	    compressedCommand = 0;	}		if ( compressedCommand ) {	    compressedCommand->merge( cmd );	    modified = TRUE;	    modificationChanged( modified );	    return;	}	compressedCommand = cmd;    } else {	checkCompressedCommand();    }    if ( current < (int)history.count() - 1 ) {	if ( current < savedAt )	    savedAt = -2;		QList<Command> commands;	commands.setAutoDelete( FALSE );	for( int i = 0; i <= current; ++i ) {	    commands.insert( i, history.at( 0 ) );	    history.take( 0 );	}	commands.append( cmd );	history.clear();	history = commands;	history.setAutoDelete( TRUE );    } else {	history.append( cmd );    }    if ( (int)history.count() > steps ) {	savedAt--;	history.removeFirst();    } else {	++current;    }    emitUndoRedo();    modified = TRUE;    modificationChanged( modified );}void CommandHistory::undo(){    checkCompressedCommand();    compressedCommand = 0;    if ( current > -1 ) {	history.at( current )->unexecute();	--current;    }    emitUndoRedo();    modified = savedAt != current;    modificationChanged( modified );}void CommandHistory::redo(){    checkCompressedCommand();    compressedCommand = 0;    if ( current > -1 ) {	if ( current < (int)history.count() - 1 ) {	    ++current;	    history.at( current )->execute();	}    } else {	if ( history.count() > 0 ) {	    ++current;	    history.at( current )->execute();	}    }    emitUndoRedo();    modified = savedAt != current;    modificationChanged( modified );}void CommandHistory::emitUndoRedo(){    Command *undoCmd = 0;    Command *redoCmd = 0;    if ( current >= 0 && current < (int)history.count() )	undoCmd = history.at( current );    if ( current + 1 >= 0 && current + 1 < (int)history.count() )	redoCmd = history.at( current + 1 );    bool ua = (bool)undoCmd;    QString uc;    if ( ua )	uc = undoCmd->name();    bool ra = (bool)redoCmd;    QString rc;    if ( ra )	rc = redoCmd->name();    emit undoRedoChanged( ua, ra, uc, rc );}void CommandHistory::setModified( bool m ){    modified = m;    if ( !modified )	savedAt = current;    modificationChanged( modified );}bool CommandHistory::isModified() const{    return modified;}void CommandHistory::checkCompressedCommand(){    if ( compressedCommand && compressedCommand->type() == Command::SetProperty ) {	Command *c = compressedCommand;	compressedCommand = 0;	if ( !( (SetPropertyCommand*)c )->checkProperty() ) {	    history.remove( current );	    --current;	    emitUndoRedo();	}    }}// ------------------------------------------------------------Command::Command( const QString &n, FormWindow *fw )    : cmdName( n ), formWin( fw ){}Command::~Command(){}QString Command::name() const{    return cmdName;}FormWindow *Command::formWindow() const{    return formWin;}void Command::merge( Command * ){}bool Command::canMerge( Command * ){    return FALSE;}// ------------------------------------------------------------ResizeCommand::ResizeCommand( const QString &n, FormWindow *fw,			      QWidget *w, const QRect &oldr, const QRect &nr )    : Command( n, fw ), widget( w ), oldRect( oldr ), newRect( nr ){}void ResizeCommand::execute(){    widget->setGeometry( newRect );    formWindow()->updateSelection( widget );    formWindow()->emitUpdateProperties( widget );    if ( WidgetFactory::layoutType( widget ) != WidgetFactory::NoLayout )	formWindow()->updateChildSelections( widget );}void ResizeCommand::unexecute(){    widget->setGeometry( oldRect );    formWindow()->updateSelection( widget );    formWindow()->emitUpdateProperties( widget );    if ( WidgetFactory::layoutType( widget ) != WidgetFactory::NoLayout )	formWindow()->updateChildSelections( widget );}// ------------------------------------------------------------InsertCommand::InsertCommand( const QString &n, FormWindow *fw,			      QWidget *w, const QRect &g )    : Command( n, fw ), widget( w ), geometry( g ){}void InsertCommand::execute(){    if ( geometry.size() == QSize( 0, 0 ) ) {	widget->move( geometry.topLeft() );	widget->adjustSize();    } else {	QSize s = geometry.size().expandedTo( widget->minimumSize() );	s = s.expandedTo( widget->minimumSizeHint() );	QRect r( geometry.topLeft(), s );	widget->setGeometry( r );    }    widget->show();    formWindow()->widgets()->insert( widget, widget );    formWindow()->clearSelection( FALSE );    formWindow()->selectWidget( widget );    formWindow()->mainWindow()->objectHierarchy()->widgetInserted( widget );}void InsertCommand::unexecute(){    widget->hide();    formWindow()->selectWidget( widget, FALSE );    formWindow()->widgets()->remove( widget );    formWindow()->mainWindow()->objectHierarchy()->widgetRemoved( widget ); }// ------------------------------------------------------------MoveCommand::MoveCommand( const QString &n, FormWindow *fw,			  const QWidgetList &w,			  const QValueList<QPoint> op,			  const QValueList<QPoint> np,			  QWidget *opr, QWidget *npr )    : Command( n, fw ), widgets( w ), oldPos( op ), newPos( np ),      oldParent( opr ), newParent( npr ){    widgets.setAutoDelete( FALSE );}void MoveCommand::merge( Command *c ){    MoveCommand *cmd = (MoveCommand*)c;    newPos = cmd->newPos;}bool MoveCommand::canMerge( Command *c ){    MoveCommand *cmd = (MoveCommand*)c;    return widgets == cmd->widgets;}void MoveCommand::execute(){    for ( QWidget *w = widgets.first(); w; w = widgets.next() ) {	if ( !w->parentWidget() || WidgetFactory::layoutType( w->parentWidget() ) == WidgetFactory::NoLayout ) {	    if ( newParent && oldParent && newParent != oldParent ) {		QPoint pos = newParent->mapFromGlobal( w->mapToGlobal( QPoint( 0,0 ) ) );		w->reparent( newParent, pos, TRUE );		formWindow()->raiseSelection( w );		formWindow()->raiseChildSelections( w );		formWindow()->widgetChanged( w );		formWindow()->mainWindow()->objectHierarchy()->widgetRemoved( w );		formWindow()->mainWindow()->objectHierarchy()->widgetInserted( w );	    }	    w->move( newPos[ widgets.at() ] );	}	formWindow()->updateSelection( w );	formWindow()->updateChildSelections( w );	formWindow()->emitUpdateProperties( w );    }}void MoveCommand::unexecute(){    for ( QWidget *w = widgets.first(); w; w = widgets.next() ) {	if ( !w->parentWidget() || WidgetFactory::layoutType( w->parentWidget() ) == WidgetFactory::NoLayout ) {	    if ( newParent && oldParent && newParent != oldParent ) {		QPoint pos = oldParent->mapFromGlobal( w->mapToGlobal( QPoint( 0,0 ) ) );		w->reparent( oldParent, pos, TRUE );		formWindow()->raiseSelection( w );		formWindow()->raiseChildSelections( w );		formWindow()->widgetChanged( w );		formWindow()->mainWindow()->objectHierarchy()->widgetRemoved( w );		formWindow()->mainWindow()->objectHierarchy()->widgetInserted( w );	    }	    w->move( oldPos[ widgets.at() ] );	}	formWindow()->updateSelection( w );	formWindow()->updateChildSelections( w );	formWindow()->emitUpdateProperties( w );    }}// ------------------------------------------------------------DeleteCommand::DeleteCommand( const QString &n, FormWindow *fw,			      const QWidgetList &w )    : Command( n, fw ), widgets( w ){    widgets.setAutoDelete( FALSE );}void DeleteCommand::execute(){    formWindow()->setPropertyShowingBlocked( TRUE );    connections.clear();    for ( QWidget *w = widgets.first(); w; w = widgets.next() ) {	w->hide();	formWindow()->selectWidget( w, FALSE );	formWindow()->widgets()->remove( w );	QValueList<MetaDataBase::Connection> conns = MetaDataBase::connections( formWindow(), w );	connections.insert( w, conns );	QValueList<MetaDataBase::Connection>::Iterator it = conns.begin();	for ( ; it != conns.end(); ++it ) {	    MetaDataBase::removeConnection( formWindow(), (*it).sender,					    (*it).signal, (*it).receiver, (*it).slot );	}    }    formWindow()->setPropertyShowingBlocked( FALSE );    formWindow()->emitShowProperties();    formWindow()->mainWindow()->objectHierarchy()->widgetsRemoved( widgets );}void DeleteCommand::unexecute(){    formWindow()->setPropertyShowingBlocked( TRUE );    formWindow()->clearSelection( FALSE );    for ( QWidget *w = widgets.first(); w; w = widgets.next() ) {	w->show();	formWindow()->widgets()->insert( w, w );	formWindow()->selectWidget( w );	QValueList<MetaDataBase::Connection> conns = *connections.find( w );	QValueList<MetaDataBase::Connection>::Iterator it = conns.begin();	for ( ; it != conns.end(); ++it ) {	    MetaDataBase::addConnection( formWindow(), (*it).sender,					 (*it).signal, (*it).receiver, (*it).slot );	}    }    formWindow()->setPropertyShowingBlocked( FALSE );    formWindow()->emitShowProperties();    formWindow()->mainWindow()->objectHierarchy()->widgetsInserted( widgets );}// ------------------------------------------------------------SetPropertyCommand::SetPropertyCommand( const QString &n, FormWindow *fw,					QWidget *w, PropertyEditor *e,					const QString &pn, const QVariant &ov,					const QVariant &nv, const QString &ncut,					const QString &ocut, bool reset )    : Command( n, fw ), widget( w ), editor( e ), propName( pn ),      oldValue( ov ), newValue( nv ), oldCurrentItemText( ocut ), newCurrentItemText( ncut ),      wasChanged( TRUE ), isResetCommand( reset ){    wasChanged = MetaDataBase::isPropertyChanged( w, propName );}void SetPropertyCommand::execute()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -