📄 hierarchyview.cpp
字号:
/************************************************************************ 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.**** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition** licenses may use this file in accordance with the Qt Commercial License** 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** information about Qt Commercial License Agreements.**** 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 "popupmenueditor.h"#include "menubareditor.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 ( ::qt_cast<QWidgetStack*>(w->parent()) ) { if (::qt_cast<QTabWidget*>(w->parent()->parent()) ) { ((QTabWidget*)w->parent()->parent())->showPage( w ); o = (QWidget*)w->parent()->parent(); formWindow->emitUpdateProperties( formWindow->currentWidget() ); } else if ( ::qt_cast<QWizard*>(w->parent()->parent()) ) { ((QDesignerWizard*)w->parent()->parent())-> setCurrentPage( ( (QDesignerWizard*)w->parent()->parent() )->pageNum( w ) ); o = (QWidget*)w->parent()->parent(); formWindow->emitUpdateProperties( formWindow->currentWidget() ); } else { ( (QWidgetStack*)w->parent() )->raiseWidget( w ); if ( (QWidgetStack*)w->parent()->isA( "QDesignerWidgetStack" ) ) ( (QDesignerWidgetStack*)w->parent() )->updateButtons(); } } else if ( ::qt_cast<QMenuBar*>(w) || ::qt_cast<QDockWindow*>(w) ) { formWindow->setActiveObject( w ); } else if ( ::qt_cast<QPopupMenu*>(w) ) { return 0; // ### we could try to find our menu bar and change the currentMenu to our index } else { return 0; } } } else if ( ::qt_cast<QAction*>(o) ) { 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 QPtrList<QWidgetStack> *widgetStacks = 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 if ( !widgetStacks ) widgetStacks = new QPtrList<QWidgetStack>; if ( w ) insertObject( w, 0 ); widgetStacks->clear();}void HierarchyList::setOpen( QListViewItem *i, bool b ){ QListView::setOpen( i, b );}void HierarchyList::insertObject( QObject *o, QListViewItem *parent ){ if ( QString( o->name() ).startsWith( "qt_dead_widget_" ) ) return; bool fakeMainWindow = FALSE; if ( ::qt_cast<QMainWindow*>(o) ) { QObject *cw = ( (QMainWindow*)o )->centralWidget(); if ( cw ) { o = cw; fakeMainWindow = TRUE; } } QListViewItem *item = 0; QString className = WidgetFactory::classNameOf( o ); if ( ::qt_cast<QLayoutWidget*>(o) ) { 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 ( ::qt_cast<QWidgetStack*>(o->parent()) ) { if ( ::qt_cast<QTabWidget*>(o->parent()->parent()) ) name = ( (QTabWidget*)o->parent()->parent() )->tabLabel( (QWidget*)o ); else if ( ::qt_cast<QWizard*>(o->parent()->parent()) ) name = ( (QWizard*)o->parent()->parent() )->title( (QWidget*)o ); } QToolBox *tb; if ( o->parent() && o->parent()->parent() && (tb = ::qt_cast<QToolBox*>(o->parent()->parent()->parent())) ) name = tb->itemLabel( tb->indexOf((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 ); item->setOpen( TRUE ); if ( !parent ) item->setPixmap( 0, QPixmap::fromMimeSource( "designer_form.png" ) ); else if ( ::qt_cast<QLayoutWidget*>(o) ) item->setPixmap( 0, QPixmap::fromMimeSource( "designer_layout.png" )); else item->setPixmap( 0, WidgetDatabase::iconSet( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( o ) ) ). pixmap( QIconSet::Small, QIconSet::Normal ) ); if ( ::qt_cast<QAction*>(o) ) item->setPixmap( 0, ( (QAction*)o )->iconSet().pixmap() ); ( (HierarchyItem*)item )->setObject( o ); const QObjectList *l = o->children(); if ( ::qt_cast<QDesignerToolBar*>(o) ) l = 0; 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 ( ::qt_cast<QWidgetStack*>(it.current()->parent()) || ::qt_cast<QWidgetStack*>(it.current()) ) { QObject *obj = it.current(); QDesignerTabWidget *tw = ::qt_cast<QDesignerTabWidget*>(it.current()->parent()); QDesignerWizard *dw = ::qt_cast<QDesignerWizard*>(it.current()->parent()); QWidgetStack *stack = 0; if ( dw || tw || ::qt_cast<QWidgetStack*>(obj) ) stack = (QWidgetStack*)obj; else stack = (QWidgetStack*)obj->parent(); if ( widgetStacks->findRef( stack ) != -1 ) continue; widgetStacks->append( 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -