hierarchyview.cpp
来自「qt-x11-free-3.0.3.tar.gz minigui图形界面工具」· C++ 代码 · 共 1,133 行 · 第 1/3 页
CPP
1,133 行
/************************************************************************ 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 "pixmapchooser.h"#include "project.h"#include "sourceeditor.h"#include "propertyeditor.h"#include "editslotsimpl.h"#include "listeditor.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 <stdlib.h>static const char * const folder_xpm[]={ "16 16 6 1", ". c None", "b c #ffff00", "d c #000000", "* c #999999", "a c #cccccc", "c c #ffffff", "................", "................", "..*****.........", ".*ababa*........", "*abababa******..", "*cccccccccccc*d.", "*cbababababab*d.", "*cabababababa*d.", "*cbababababab*d.", "*cabababababa*d.", "*cbababababab*d.", "*cabababababa*d.", "*cbababababab*d.", "**************d.", ".dddddddddddddd.", "................"};static QPixmap *folderPixmap = 0;QListViewItem *newItem = 0;static QPluginManager<ClassBrowserInterface> *classBrowserInterfaceManager = 0;HierarchyItem::HierarchyItem( Type type, QListViewItem *parent, const QString &txt1, const QString &txt2, const QString &txt3 ) : QListViewItem( parent, txt1, txt2, txt3 ), typ( type ){}HierarchyItem::HierarchyItem( Type type, QListView *parent, const QString &txt1, const QString &txt2, const QString &txt3 ) : QListViewItem( parent, 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() == Slot && MainWindow::self->currProject()->language() == "C++" && ( 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::setWidget( QWidget *w ){ wid = w;}QWidget *HierarchyItem::widget() const{ return wid;}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( 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 );}void HierarchyList::objectClicked( QListViewItem *i ){ if ( !i ) return; QWidget *w = findWidget( i ); if ( !w ) return; if ( formWindow == w ) { if ( deselect ) formWindow->clearSelection( FALSE ); formWindow->emitShowProperties( formWindow ); return; } 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 ) ); w = (QWidget*)w->parent()->parent(); formWindow->emitUpdateProperties( formWindow->currentWidget() ); } else { return; } } if ( deselect ) formWindow->clearSelection( FALSE ); if ( w->isVisibleTo( formWindow ) ) formWindow->selectWidget( w, TRUE );}QWidget *HierarchyList::findWidget( QListViewItem *i ){ return ( (HierarchyItem*)i )->widget();}QListViewItem *HierarchyList::findItem( QWidget *w ){ QListViewItemIterator it( this ); while ( it.current() ) { if ( ( (HierarchyItem*)it.current() )->widget() == w ) return it.current(); ++it; } return 0;}QWidget *HierarchyList::current() const{ if ( currentItem() ) return ( (HierarchyItem*)currentItem() )->widget(); return 0;}void HierarchyList::changeNameOf( QWidget *w, const QString &name ){ QListViewItem *item = findItem( w ); if ( !item ) return; item->setText( 0, name );}void HierarchyList::changeDatabaseOf( QWidget *w, const QString &info ){#ifndef QT_NO_SQL if ( !formWindow->isDatabaseAware() ) return; QListViewItem *item = findItem( w ); if ( !item ) return; item->setText( 2, info );#endif}void HierarchyList::setup(){ if ( !formWindow ) 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 ( w ) insertObject( w, 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;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?