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

📄 hierarchyview.cpp

📁 Linux下的基于X11的图形开发环境。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/************************************************************************ Copyright (C) 2000-2001 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 "hierarchyview.h"#include "formwindow.h"#include "globaldefs.h"#include "mainwindow.h"#include "command.h"#include "widgetfactory.h"#include "widgetdatabase.h"#include "project.h"#include "sourceeditor.h"#include "propertyeditor.h"#include "editfunctionsimpl.h"#include "listeditor.h"#include "actiondnd.h"#include "actioneditorimpl.h"#include "variabledialogimpl.h"#include <qpalette.h>#include <qobjectlist.h>#include <qheader.h>#include <qpopupmenu.h>#include <qtabwidget.h>#include <qwizard.h>#include <qwidgetstack.h>#include <qtabbar.h>#include <qfeatures.h>#include <qapplication.h>#include <qtimer.h>#include "../interfaces/languageinterface.h"#include <qworkspace.h>#include <qaccel.h>#include <qmessagebox.h>#include <stdlib.h>QListViewItem *newItem = 0;static QPluginManager<ClassBrowserInterface> *classBrowserInterfaceManager = 0;HierarchyItem::HierarchyItem( Type type, QListViewItem *parent, QListViewItem *after,			      const QString &txt1, const QString &txt2, const QString &txt3 )    : QListViewItem( parent, after, txt1, txt2, txt3 ), typ( type ){}HierarchyItem::HierarchyItem( Type type, QListView *parent, QListViewItem *after,			      const QString &txt1, const QString &txt2, const QString &txt3 )    : QListViewItem( parent, after, txt1, txt2, txt3 ), typ( type ){}void HierarchyItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int align ){    QColorGroup g( cg );    g.setColor( QColorGroup::Base, backgroundColor() );    g.setColor( QColorGroup::Foreground, Qt::black );    g.setColor( QColorGroup::Text, Qt::black );    QString txt = text( 0 );    if ( rtti() == Function &&	 MainWindow::self->currProject()->isCpp() &&	 ( txt == "init()" || txt == "destroy()" ) ) {	listView()->setUpdatesEnabled( FALSE );	if ( txt == "init()" )	    setText( 0, txt + " " + "(Constructor)" );	else	    setText( 0, txt + " " + "(Destructor)" );	QListViewItem::paintCell( p, g, column, width, align );	setText( 0, txt );	listView()->setUpdatesEnabled( TRUE );    } else {	QListViewItem::paintCell( p, g, column, width, align );    }    p->save();    p->setPen( QPen( cg.dark(), 1 ) );    if ( column == 0 )	p->drawLine( 0, 0, 0, height() - 1 );    if ( listView()->firstChild() != this ) {	if ( nextSibling() != itemBelow() && itemBelow()->depth() < depth() ) {	    int d = depth() - itemBelow()->depth();	    p->drawLine( -listView()->treeStepSize() * d, height() - 1, 0, height() - 1 );	}    }    p->drawLine( 0, height() - 1, width, height() - 1 );    p->drawLine( width - 1, 0, width - 1, height() );    p->restore();}QColor HierarchyItem::backgroundColor(){    updateBackColor();    return backColor;}void HierarchyItem::updateBackColor(){    if ( listView()->firstChild() == this ) {	backColor = *backColor1;	return;    }    QListViewItemIterator it( this );    --it;    if ( it.current() ) {	if ( ( ( HierarchyItem*)it.current() )->backColor == *backColor1 )	    backColor = *backColor2;	else	    backColor = *backColor1;    } else {	backColor = *backColor1;    }}void HierarchyItem::setObject( QObject *o ){    obj = o;}QObject *HierarchyItem::object() const{    return obj;}void HierarchyItem::okRename( int col ){    if ( newItem == this )	newItem = 0;    QListViewItem::okRename( col );}void HierarchyItem::cancelRename( int col ){    if ( newItem == this ) {	newItem = 0;	QListViewItem::cancelRename( col );	delete this;	return;    }    QListViewItem::cancelRename( col );}HierarchyList::HierarchyList( QWidget *parent, FormWindow *fw, bool doConnects )    : QListView( parent ), formWindow( fw ){    init_colors();    setDefaultRenameAction( Accept );    header()->setMovingEnabled( FALSE );    header()->setStretchEnabled( TRUE );    normalMenu = 0;    tabWidgetMenu = 0;    addColumn( tr( "Name" ) );    addColumn( tr( "Class" ) );    QPalette p( palette() );    p.setColor( QColorGroup::Base, QColor( *backColor2 ) );    (void)*selectedBack; // hack    setPalette( p );    disconnect( header(), SIGNAL( sectionClicked( int ) ),		this, SLOT( changeSortColumn( int ) ) );    setSorting( -1 );    setHScrollBarMode( AlwaysOff );    setVScrollBarMode( AlwaysOn );    if ( doConnects ) {	connect( this, SIGNAL( clicked( QListViewItem * ) ),		 this, SLOT( objectClicked( QListViewItem * ) ) );	connect( this, SIGNAL( doubleClicked( QListViewItem * ) ),		 this, SLOT( objectDoubleClicked( QListViewItem * ) ) );	connect( this, SIGNAL( returnPressed( QListViewItem * ) ),		 this, SLOT( objectClicked( QListViewItem * ) ) );	connect( this, SIGNAL( contextMenuRequested( QListViewItem *, const QPoint&, int ) ),		 this, SLOT( showRMBMenu( QListViewItem *, const QPoint & ) ) );    }    deselect = TRUE;    setColumnWidthMode( 1, Manual );}void HierarchyList::keyPressEvent( QKeyEvent *e ){    if ( e->key() == Key_Shift || e->key() == Key_Control )	deselect = FALSE;    else	deselect = TRUE;    QListView::keyPressEvent( e );}void HierarchyList::keyReleaseEvent( QKeyEvent *e ){    deselect = TRUE;    QListView::keyReleaseEvent( e );}void HierarchyList::viewportMousePressEvent( QMouseEvent *e ){    if ( e->state() & ShiftButton || e->state() & ControlButton )	deselect = FALSE;    else	deselect = TRUE;    QListView::viewportMousePressEvent( e );}void HierarchyList::viewportMouseReleaseEvent( QMouseEvent *e ){    QListView::viewportMouseReleaseEvent( e );}QObject *HierarchyList::handleObjectClick( QListViewItem *i ){    if ( !i )	return 0;    QObject *o = findObject( i );    if ( !o )	return 0;    if ( formWindow == o ) {	if ( deselect )	    formWindow->clearSelection( FALSE );	formWindow->emitShowProperties( formWindow );	return 0;    }    if ( o->isWidgetType() ) {	QWidget *w = (QWidget*)o;	if ( !formWindow->widgets()->find( w ) ) {	    if ( w->parent() && w->parent()->inherits( "QWidgetStack" ) &&		 w->parent()->parent() &&		 ( w->parent()->parent()->inherits( "QTabWidget" ) ||		   w->parent()->parent()->inherits( "QWizard" ) ) ) {		if ( w->parent()->parent()->inherits( "QTabWidget" ) )		    ( (QTabWidget*)w->parent()->parent() )->showPage( w );		else		    ( (QDesignerWizard*)w->parent()->parent() )->			setCurrentPage( ( (QDesignerWizard*)w->parent()->parent() )->					pageNum( w ) );		o = (QWidget*)w->parent()->parent();		formWindow->emitUpdateProperties( formWindow->currentWidget() );	    } else if ( w->parent() && w->parent()->inherits( "QWidgetStack" ) ) {		( (QDesignerWidgetStack*)w->parent() )->raiseWidget( w );		( (QDesignerWidgetStack*)w->parent() )->updateButtons();	    } else if ( w->inherits( "QMenuBar" ) || w->inherits( "QDockWindow" ) ) {		formWindow->setActiveObject( w );	    } else if ( w->inherits( "QPopupMenu" ) ) {		return 0; // ### we could try to find our menu bar and change the currentMenu to our index	    } else {		return 0;	    }	}    } else if ( o->inherits( "QAction" ) ) {	MainWindow::self->actioneditor()->setCurrentAction( (QAction*)o );	deselect = TRUE;    }    if ( deselect )	formWindow->clearSelection( FALSE );    return o;}void HierarchyList::objectDoubleClicked( QListViewItem *i ){    QObject *o = handleObjectClick( i );    if ( !o )	return;    if ( o->isWidgetType() && ( (QWidget*)o )->isVisibleTo( formWindow ) ) {	QWidget *w = (QWidget*)o;	if ( !w->parentWidget() ||	     WidgetFactory::layoutType( w->parentWidget() ) == WidgetFactory::NoLayout )	    w->raise();	formWindow->selectWidget( w, TRUE );    }}void HierarchyList::objectClicked( QListViewItem *i ){    QObject *o = handleObjectClick( i );    if ( !o )	return;    if ( o->isWidgetType() && ( (QWidget*)o )->isVisibleTo( formWindow ) ) {	QWidget *w = (QWidget*)o;	formWindow->selectWidget( w, TRUE );    }}QObject *HierarchyList::findObject( QListViewItem *i ){    return ( (HierarchyItem*)i )->object();}QListViewItem *HierarchyList::findItem( QObject *o ){    QListViewItemIterator it( this );    while ( it.current() ) {	if ( ( (HierarchyItem*)it.current() )->object() == o )	    return it.current();	++it;    }    return 0;}QObject *HierarchyList::current() const{    if ( currentItem() )	return ( (HierarchyItem*)currentItem() )->object();    return 0;}void HierarchyList::changeNameOf( QObject *o, const QString &name ){    QListViewItem *item = findItem( o );    if ( !item )	return;    item->setText( 0, name );}void HierarchyList::changeDatabaseOf( QObject *o, const QString &info ){#ifndef QT_NO_SQL    if ( !formWindow->isDatabaseAware() )	return;    QListViewItem *item = findItem( o );    if ( !item )	return;    item->setText( 2, info );#endif}static QWidgetStack *lastWidgetStack = 0;void HierarchyList::setup(){    if ( !formWindow || formWindow->isFake() )	return;    clear();    QWidget *w = formWindow->mainContainer();#ifndef QT_NO_SQL    if ( formWindow->isDatabaseAware() ) {	if ( columns() == 2 ) {	    addColumn( tr( "Database" ) );	    header()->resizeSection( 0, 1 );	    header()->resizeSection( 1, 1 );	    header()->resizeSection( 2, 1 );	    header()->adjustHeaderSize();	}    } else {	if ( columns() == 3 ) {	    removeColumn( 2 );	}    }#endif    lastWidgetStack = 0;    if ( w )	insertObject( w, 0 );    lastWidgetStack = 0;}void HierarchyList::setOpen( QListViewItem *i, bool b ){    QListView::setOpen( i, b );}void HierarchyList::insertObject( QObject *o, QListViewItem *parent ){    bool fakeMainWindow = FALSE;    if ( o && o->inherits( "QMainWindow" ) ) {	QObject *cw = ( (QMainWindow*)o )->centralWidget();	if ( cw ) {	    o = cw;	    fakeMainWindow = TRUE;	}    }    QListViewItem *item = 0;    QString className = WidgetFactory::classNameOf( o );    if ( o->inherits( "QLayoutWidget" ) ) {	switch ( WidgetFactory::layoutType( (QWidget*)o ) ) {	case WidgetFactory::HBox:	    className = "HBox";	    break;	case WidgetFactory::VBox:	    className = "VBox";	    break;	case WidgetFactory::Grid:	    className = "Grid";	    break;	default:	    break;	}    }    QString dbInfo;#ifndef QT_NO_SQL    dbInfo = MetaDataBase::fakeProperty( o, "database" ).toStringList().join(".");#endif    QString name = o->name();    if ( o->parent() && o->parent()->inherits( "QWidgetStack" ) &&	 o->parent()->parent() ) {	if ( o->parent()->parent()->inherits( "QTabWidget" ) )	    name = ( (QTabWidget*)o->parent()->parent() )->tabLabel( (QWidget*)o );	else if ( o->parent()->parent()->inherits( "QWizard" ) )	    name = ( (QWizard*)o->parent()->parent() )->title( (QWidget*)o );    }    if ( fakeMainWindow ) {	name = o->parent()->name();	className = "QMainWindow";    }    if ( !parent )	item = new HierarchyItem( HierarchyItem::Widget, this, 0, name, className, dbInfo );    else	item = new HierarchyItem( HierarchyItem::Widget, parent, 0, name, className, dbInfo );    if ( !parent )	item->setPixmap( 0, QPixmap::fromMimeSource( "form.png" ) );    else if ( o->inherits( "QLayoutWidget") )	item->setPixmap( 0, QPixmap::fromMimeSource( "layout.png" ));    else	item->setPixmap( 0, WidgetDatabase::iconSet(		    WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( o ) ) ).			 pixmap( QIconSet::Small, QIconSet::Normal ) );    if ( o->inherits( "QAction" ) )	item->setPixmap( 0, ( (QAction*)o )->iconSet().pixmap() );    ( (HierarchyItem*)item )->setObject( o );    const QObjectList *l = o->children();    if ( l ) {	QObjectListIt it( *l );	it.toLast();	for ( ; it.current(); --it ) {	    if ( !it.current()->isWidgetType() || ( (QWidget*)it.current() )->isHidden() )		continue;	    if (  !formWindow->widgets()->find( (QWidget*)it.current() ) ) {		if ( it.current()->parent() &&		     it.current()->inherits( "QWidgetStack" ) ||		     it.current()->parent()->inherits( "QWidgetStack" ) ) {		    QObject *obj = it.current();		    QDesignerTabWidget *tw = 0;		    QDesignerWizard *dw = 0;		    if ( it.current()->parent()->inherits( "QTabWidget" ) )			tw = (QDesignerTabWidget*)it.current()->parent();		    if ( it.current()->parent()->inherits( "QWizard" ) )			dw = (QDesignerWizard*)it.current()->parent();		    QWidgetStack *stack = 0;		    if ( dw || tw )			stack = (QWidgetStack*)obj;		    else			stack = (QWidgetStack*)obj->parent();		    if ( lastWidgetStack == stack )			continue;		    lastWidgetStack = stack;		    QObjectList *l2 = stack->queryList( "QWidget", 0, TRUE, FALSE );		    for ( obj = l2->last(); obj; obj = l2->prev() ) {			if ( qstrcmp( obj->className(),				      "QWidgetStackPrivate::Invisible" ) == 0 ||			     ( tw && !tw->tabBar()->tab( stack->id( (QWidget*)obj ) ) ) ||			     ( dw && dw->isPageRemoved( (QWidget*)obj ) ) )			    continue;			if ( qstrcmp( obj->name(), "designer_wizardstack_button" ) == 0 )			    continue;			if ( stack->id( (QWidget*)obj ) == -1 )			    continue;			insertObject( obj, item );		    }		    delete l2;		}		continue;	    }

⌨️ 快捷键说明

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