workspace.cpp
来自「qt-x11-free-3.0.3.tar.gz minigui图形界面工具」· C++ 代码 · 共 674 行 · 第 1/2 页
CPP
674 行
/************************************************************************ 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 <qvariant.h> // HP-UX compiler needs this here#include "workspace.h"#include "formwindow.h"#include "mainwindow.h"#include "pixmapchooser.h"#include "globaldefs.h"#include "command.h"#include "project.h"#include "pixmapcollection.h"#include "sourcefile.h"#include "sourceeditor.h"#include <qheader.h>#include <qdragobject.h>#include <qfileinfo.h>#include <qapplication.h>#include <qpainter.h>#include <qpen.h>#include <qobjectlist.h>#include <qworkspace.h>#include <qpopupmenu.h>#include <qtextstream.h>#include "qcompletionedit.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 const char * const file_xpm[]={ "16 16 5 1", ". c #7f7f7f", "# c None", "c c #000000", "b c #bfbfbf", "a c #ffffff", "################", "..........######", ".aaaaaaaab.#####", ".aaaaaaaaba.####", ".aaaaaaaacccc###", ".aaaaaaaaaabc###", ".aaaaaaaaaabc###", ".aaaaaaaaaabc###", ".aaaaaaaaaabc###", ".aaaaaaaaaabc###", ".aaaaaaaaaabc###", ".aaaaaaaaaabc###", ".aaaaaaaaaabc###", ".aaaaaaaaaabc###", ".bbbbbbbbbbbc###", "ccccccccccccc###"};static QPixmap *folderPixmap = 0;static QPixmap *filePixmap = 0;static QPixmap* formPixmap = 0;WorkspaceItem::WorkspaceItem( QListView *parent, Project* p ) : QListViewItem( parent ){ init(); project = p; t = ProjectType; setPixmap( 0, *folderPixmap ); setExpandable( FALSE );}WorkspaceItem::WorkspaceItem( QListViewItem *parent, SourceFile* sf ) : QListViewItem( parent ){ init(); sourceFile = sf; t = SourceFileType; setPixmap( 0, *filePixmap );}WorkspaceItem::WorkspaceItem( QListViewItem *parent, FormFile* ff, Type type ) : QListViewItem( parent ){ init(); formFile = ff; t = type; if ( type == FormFileType ) { setPixmap( 0, *formPixmap ); QObject::connect( ff, SIGNAL( somethingChanged(FormFile*) ), listView(), SLOT( update(FormFile*) ) ); if ( formFile->supportsCodeFile() ) (void) new WorkspaceItem( this, formFile, FormSourceType ); } else if ( type == FormSourceType ) { setPixmap( 0, *filePixmap ); }}void WorkspaceItem::init(){ autoOpen = FALSE; useOddColor = FALSE; project = 0; sourceFile = 0; formFile = 0;}void WorkspaceItem::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 ); if ( type() == FormSourceType && !formFile->hasFormCode() ) { g.setColor( QColorGroup::Text, listView()->palette().disabled().color( QColorGroup::Text) ); g.setColor( QColorGroup::HighlightedText, listView()->palette().disabled().color( QColorGroup::Text) ); } else { g.setColor( QColorGroup::Text, Qt::black ); } p->save(); if ( isModified() ) { QFont f = p->font(); f.setBold( TRUE ); p->setFont( f ); } QListViewItem::paintCell( p, g, column, width, align ); 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();}QString WorkspaceItem::text( int column ) const{ if ( column != 0 ) return QListViewItem::text( column ); switch( t ) { case ProjectType: if ( project->isDummy() ) return Project::tr("<No Project>" ); return project->makeRelative( project->fileName() ); case FormFileType: return formFile->formName() + ": " + formFile->fileName(); case FormSourceType: return formFile->codeFile(); case SourceFileType: return sourceFile->fileName(); } return QString::null; // shut up compiler}void WorkspaceItem::fillCompletionList( QStringList& completion ){ switch( t ) { case ProjectType: break; case FormFileType: completion += formFile->formName(); completion += formFile->fileName(); break; case FormSourceType: completion += formFile->codeFile(); break; case SourceFileType: completion += sourceFile->fileName(); break; }}bool WorkspaceItem::checkCompletion( const QString& completion ){ switch( t ) { case ProjectType: break; case FormFileType: return completion == formFile->formName() || completion == formFile->fileName(); case FormSourceType: return completion == formFile->codeFile(); case SourceFileType: return completion == sourceFile->fileName(); } return FALSE;}bool WorkspaceItem::isModified() const{ switch( t ) { case ProjectType: return project->isModified(); case FormFileType: return formFile->isModified( FormFile::WFormWindow ); case FormSourceType: return formFile->isModified( FormFile::WFormCode ); case SourceFileType: return sourceFile->isModified(); } return FALSE; // shut up compiler}QString WorkspaceItem::key( int column, bool ) const{ QString key = text( column ); if ( t == FormFileType ) key.prepend( "0" ); else key.prepend( "a" ); return key;}QColor WorkspaceItem::backgroundColor(){ bool b = useOddColor; if ( t == FormSourceType && parent() ) b = ( ( WorkspaceItem*)parent() )->useOddColor; return b ? *backColor2 : *backColor1;}void WorkspaceItem::setOpen( bool b ){ QListViewItem::setOpen( b ); autoOpen = FALSE;}void WorkspaceItem::setAutoOpen( bool b ){ QListViewItem::setOpen( b ); autoOpen = b;}Workspace::Workspace( QWidget *parent, MainWindow *mw ) : QListView( parent, 0, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_Tool | WStyle_MinMax | WStyle_SysMenu ), mainWindow( mw ), project( 0 ), completionDirty( FALSE ){ init_colors(); setDefaultRenameAction( Accept ); blockNewForms = FALSE; bufferEdit = 0; header()->setStretchEnabled( TRUE ); header()->hide(); setSorting( 0 ); setResizePolicy( QScrollView::Manual ); setIcon( PixmapChooser::loadPixmap( "logo" ) ); QPalette p( palette() ); p.setColor( QColorGroup::Base, QColor( *backColor2 ) ); (void)*selectedBack; // hack setPalette( p ); addColumn( tr( "Files" ) ); setAllColumnsShowFocus( TRUE ); connect( this, SIGNAL( mouseButtonClicked( int, QListViewItem *, const QPoint &, int ) ), this, SLOT( itemClicked( int, QListViewItem *, const QPoint& ) ) ), connect( this, SIGNAL( doubleClicked( QListViewItem * ) ), this, SLOT( itemDoubleClicked( QListViewItem * ) ) ), connect( this, SIGNAL( contextMenuRequested( QListViewItem *, const QPoint &, int ) ), this, SLOT( rmbClicked( QListViewItem *, const QPoint& ) ) ), setHScrollBarMode( AlwaysOff ); setVScrollBarMode( AlwaysOn ); viewport()->setAcceptDrops( TRUE ); setAcceptDrops( TRUE ); setColumnWidthMode( 1, Manual ); if ( !folderPixmap ) { folderPixmap = new QPixmap( folder_xpm ); filePixmap = new QPixmap( file_xpm ); formPixmap = new QPixmap( PixmapChooser::loadPixmap( "form.xpm", PixmapChooser::Mini ) ); }}void Workspace::projectDestroyed( QObject* o ){ if ( o == project ) { project = 0; clear(); }}void Workspace::setCurrentProject( Project *pro ){ if ( project == pro ) return; if ( project ) { disconnect( project, SIGNAL( sourceFileAdded(SourceFile*) ), this, SLOT( sourceFileAdded(SourceFile*) ) ); disconnect( project, SIGNAL( sourceFileRemoved(SourceFile*) ), this, SLOT( sourceFileRemoved(SourceFile*) ) ); disconnect( project, SIGNAL( formFileAdded(FormFile*) ), this, SLOT( formFileAdded(FormFile*) ) ); disconnect( project, SIGNAL( formFileRemoved(FormFile*) ), this, SLOT( formFileRemoved(FormFile*) ) ); disconnect( project, SIGNAL( projectModified() ), this, SLOT( update() ) );
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?