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

📄 widgetfactory.cpp

📁 Trolltech公司发布的基于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 <qvariant.h> // HP-UX compiler need this here#include "widgetfactory.h"#include <widgetdatabase.h>#include "metadatabase.h"#include "mainwindow.h"#include "formwindow.h"#include "pixmapchooser.h"#include "layout.h"#include "listboxeditorimpl.h"#include "listvieweditorimpl.h"#include "iconvieweditorimpl.h"#include "formwindow.h"#include "multilineeditorimpl.h"#include "../integration/kdevelop/kdewidgets.h"#include <qmodules.h>#include <qpixmap.h>#include <qgroupbox.h>#include <qiconview.h>#if defined(QT_MODULE_TABLE)#include <qtable.h>#endif#include <qlineedit.h>#include <qspinbox.h>#include <qmultilineedit.h>#include <qlabel.h>#include <qlayout.h>#include <qwidgetstack.h>#include <qcombobox.h>#include <qtabbar.h>#include <qlistbox.h>#include <qlistview.h>#include <qobjectlist.h>#include <qlcdnumber.h>#include <qslider.h>#include <qdial.h>#include <qprogressbar.h>#include <qtextview.h>#include <qtextbrowser.h>#include <qframe.h>#include <qmetaobject.h>#include <qwidgetstack.h>#include <qwizard.h>#include <qvaluelist.h>#include <qtimer.h>#include <globaldefs.h>void QLayoutWidget::paintEvent( QPaintEvent* ){    QPainter p ( this );    p.setPen( red );    p.drawRect( rect() );}int QDesignerTabWidget::currentPage() const{    return tabBar()->currentTab();}void QDesignerTabWidget::setCurrentPage( int i ){    tabBar()->setCurrentTab( i );}QString QDesignerTabWidget::pageTitle() const{    return ((QTabWidget*)this)->tabLabel( QTabWidget::currentPage() );}void QDesignerTabWidget::setPageTitle( const QString& title ){    changeTab( QTabWidget::currentPage(), title  );}void QDesignerTabWidget::setPageName( const QCString& name ){    if ( QTabWidget::currentPage() )	QTabWidget::currentPage()->setName( name );}QCString QDesignerTabWidget::pageName() const{    if ( !QTabWidget::currentPage() )	return 0;    return QTabWidget::currentPage()->name();}int QDesignerTabWidget::count() const{    return tabBar()->count();}int QDesignerWizard::currentPageNum() const{    for ( int i = 0; i < pageCount(); ++i ) {	if ( page( i ) == currentPage() )	    return i;    }    return 0;}void QDesignerWizard::setCurrentPage( int i ){    if ( i < currentPageNum() ) {	while ( i < currentPageNum() ) {	    if ( currentPageNum() == 0 )		break;	    back();	}	    } else {	while ( i > currentPageNum() ) {	    if ( currentPageNum() == pageCount() - 1 )		break;	    next();	}    }}QString QDesignerWizard::pageTitle() const{    return title( currentPage() );}void QDesignerWizard::setPageTitle( const QString& title ){    setTitle( currentPage(), title );}void QDesignerWizard::setPageName( const QCString& name ){    if ( QWizard::currentPage() )	QWizard::currentPage()->setName( name );}QCString QDesignerWizard::pageName() const{    if ( !QWizard::currentPage() )	return 0;    return QWizard::currentPage()->name();}int QDesignerWizard::pageNum( QWidget *p ){    for ( int i = 0; i < pageCount(); ++i ) {	if ( page( i ) == p )	    return i;    }    return -1;}void QDesignerWizard::addPage( QWidget *p, const QString &t ){    QWizard::addPage( p, t );    if ( removedPages.find( p ) )	removedPages.remove( p );}void QDesignerWizard::removePage( QWidget *p ){    QWizard::removePage( p );    removedPages.insert( p, p );}void QDesignerWizard::insertPage( QWidget *p, const QString &t, int index ){    if ( removedPages.find( p ) )	removedPages.remove( p );    if ( index == pageCount() ) {	addPage( p, t );	return;    }    QList<Page> pages;    pages.setAutoDelete( TRUE );    setCurrentPage( pageCount() - 1 );    while ( pageCount() ) {	QWidget *w = currentPage();	pages.insert( 0, new Page( w, title( w ) ) );	back();	removePage( w );    }    int i = 0;    for ( Page *pg = pages.first(); pg; pg = pages.next(), ++i ) {	if ( i == index ) {	    addPage( p, t );	    next();	}	addPage( pg->p, pg->t );	next();    }}QMap< int, QMap< QString, QVariant> > *defaultProperties = 0;QMap< int, QStringList > *changedProperties = 0;/*!  \class WidgetFactory widgetfactory.h  \brief Set of static functions for creating widgets, layouts and do other stuff  The widget factory offers functions to create widgets, create and  delete layouts find out other details - all based on the  WidgetDatabase's data. So the functions that use ids use the same  ids as in the WidgetDatabase.*/static void saveDefaultProperties( QWidget *w, int id ){    QMap< QString, QVariant> propMap;    QStrList lst = w->metaObject()->propertyNames( TRUE );    for ( uint i = 0; i < lst.count(); ++i )	propMap.insert( lst.at( i ), w->property( lst.at( i ) ) );    defaultProperties->insert( id, propMap );}static void saveChangedProperties( QWidget *w, int id ){    QStringList l = MetaDataBase::changedProperties( w );    changedProperties->insert( id, l );}/*!  Creates a widget of the type which is registered as \a id as  child of \a parent. The \a name is optional. If \a init is TRUE, the  widget is initialized with some defaults, else the plain widget is  created.*/QWidget *WidgetFactory::create( int id, QWidget *parent, const char *name, bool init, const QRect *r, Qt::Orientation orient ){    QString n = WidgetDatabase::className( id );    if ( n.isEmpty() )	return 0;    if ( !defaultProperties ) {	defaultProperties = new QMap< int, QMap< QString, QVariant> >();	changedProperties = new QMap< int, QStringList >();    }    QWidget *w = 0;    QString str = WidgetDatabase::createWidgetName( id );    const char *s = str.latin1();    if ( !WidgetDatabase::isCustomWidget( id ) )	w = createWidget( n, parent, name ? name : s, init, r, orient );    else	w = createCustomWidget( parent, name ? name : s, MetaDataBase::customWidget( id ) );    if ( !w )	return 0;    MetaDataBase::addEntry( w );    if ( !defaultProperties->contains( id ) )	saveDefaultProperties( w, id );    if ( !changedProperties->contains( id ) )	saveChangedProperties( w, id );    return w;}/*!  Creates a layout on the widget \a widget of the type \a type  which can be \c HBox, \c VBox or \c Grid.*/QLayout *WidgetFactory::createLayout( QWidget *widget, QLayout*  layout, LayoutType type ){    int spacing = BOXLAYOUT_DEFAULT_SPACING;    int margin = 0;    if ( widget && !widget->inherits( "QLayoutWidget" ) &&	 ( WidgetDatabase::isContainer( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( widget ) ) ) ||	   widget && widget->parentWidget() && widget->parentWidget()->inherits( "FormWindow" ) ) )	margin = BOXLAYOUT_DEFAULT_MARGIN;	    if ( !layout && widget && widget->inherits( "QTabWidget" ) )	widget = ((QTabWidget*)widget)->currentPage();    if ( !layout && widget && widget->inherits( "QWizard" ) )	widget = ((QWizard*)widget)->currentPage();    if ( !layout && widget && widget->inherits( "QWidgetStack" ) )	widget = ((QWidgetStack*)widget)->visibleWidget();    MetaDataBase::addEntry( widget );    if ( !layout && widget && widget->inherits( "QGroupBox" ) ) {	QGroupBox *gb = (QGroupBox*)widget;	gb->setColumnLayout( 0, Qt::Vertical );	gb->layout()->setMargin( 0 );	gb->layout()->setSpacing( 0 );	QLayout *l;	switch ( type ) {	case HBox:	    l = new QHBoxLayout( gb->layout() );	    MetaDataBase::setMargin( gb, margin );	    MetaDataBase::setSpacing( gb, spacing );	    l->setAlignment( AlignTop );	    return l;	case VBox:	    l = new QVBoxLayout( gb->layout(), spacing );	    MetaDataBase::setMargin( gb, margin );	    MetaDataBase::setSpacing( gb, spacing );	    l->setAlignment( AlignTop );	    return l;	case Grid:	    l = new QDesignerGridLayout( gb->layout() );	    MetaDataBase::setMargin( gb, margin );	    MetaDataBase::setSpacing( gb, spacing );	    l->setAlignment( AlignTop );	    return l;	default:	    return 0;	}    } else {	if ( layout ) {	    QLayout *l;	    switch ( type ) {	    case HBox:		l = new QHBoxLayout( layout );		l->setSpacing( spacing );		l->setMargin( margin );		return l;	    case VBox:		l = new QVBoxLayout( layout );		l->setSpacing( spacing );		l->setMargin( margin );		return l;	    case Grid: {		l = new QDesignerGridLayout( layout );		l->setSpacing( spacing );		l->setMargin( margin );		return l;	    }	    default:		return 0;	    }

⌨️ 快捷键说明

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