You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
415 lines
13 KiB
415 lines
13 KiB
15 years ago
|
/**********************************************************************
|
||
|
** Copyright (C) 2000-2001 Trolltech AS. All rights reserved.
|
||
|
**
|
||
14 years ago
|
** This file is part of TQt Designer.
|
||
15 years ago
|
**
|
||
|
** 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.
|
||
|
**
|
||
14 years ago
|
** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition
|
||
|
** licenses may use this file in accordance with the TQt Commercial License
|
||
15 years ago
|
** 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
|
||
14 years ago
|
** information about TQt Commercial License Agreements.
|
||
15 years ago
|
**
|
||
|
** Contact info@trolltech.com if any conditions of this licensing are
|
||
|
** not clear to you.
|
||
|
**
|
||
|
**********************************************************************/
|
||
|
|
||
|
#include "newformimpl.h"
|
||
|
#include "mainwindow.h"
|
||
|
#include "metadatabase.h"
|
||
|
#include "project.h"
|
||
|
#include "formwindow.h"
|
||
|
#include "widgetfactory.h"
|
||
|
#include "widgetdatabase.h"
|
||
|
#include "actioneditorimpl.h"
|
||
|
#include "hierarchyview.h"
|
||
|
#include "resource.h"
|
||
|
#include "projectsettingsimpl.h"
|
||
|
#include "sourcefile.h"
|
||
|
|
||
|
#include <kiconloader.h>
|
||
11 years ago
|
#include "tdevdesigner_part.h"
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
|
||
15 years ago
|
#include <tqiconview.h>
|
||
|
#include <tqlabel.h>
|
||
|
#include <tqfileinfo.h>
|
||
|
#include <tqdir.h>
|
||
|
#include <tqpushbutton.h>
|
||
15 years ago
|
#include <stdlib.h>
|
||
15 years ago
|
#include <tqcombobox.h>
|
||
|
#include <tqworkspace.h>
|
||
|
#include <tqmessagebox.h>
|
||
15 years ago
|
|
||
|
static int forms = 0;
|
||
|
|
||
15 years ago
|
ProjectItem::ProjectItem( TQIconView *view, const TQString &text )
|
||
15 years ago
|
: NewItem( view, text )
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void ProjectItem::insert( Project * )
|
||
|
{
|
||
|
MainWindow::self->createNewProject( lang );
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
15 years ago
|
FormItem::FormItem( TQIconView *view, const TQString &text )
|
||
15 years ago
|
: NewItem( view, text )
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void FormItem::insert( Project *pro )
|
||
|
{
|
||
15 years ago
|
TQString n = "Form" + TQString::number( ++forms );
|
||
15 years ago
|
FormWindow *fw = 0;
|
||
|
FormFile *ff = new FormFile( FormFile::createUnnamedFileName(), TRUE, pro );
|
||
|
fw = new FormWindow( ff, MainWindow::self, MainWindow::self->qWorkspace(), n );
|
||
|
fw->setProject( pro );
|
||
14 years ago
|
MetaDataBase::addEntry( TQT_TQOBJECT(fw) );
|
||
15 years ago
|
if ( fType == Widget ) {
|
||
14 years ago
|
TQWidget *w = WidgetFactory::create( WidgetDatabase::idFromClassName( TQWIDGET_OBJECT_NAME_STRING ),
|
||
15 years ago
|
fw, n.latin1() );
|
||
|
fw->setMainContainer( w );
|
||
|
} else if ( fType == Dialog ) {
|
||
14 years ago
|
TQWidget *w = WidgetFactory::create( WidgetDatabase::idFromClassName( TQDIALOG_OBJECT_NAME_STRING ), fw, n.latin1() );
|
||
15 years ago
|
fw->setMainContainer( w );
|
||
|
} else if ( fType == Wizard ) {
|
||
14 years ago
|
TQWidget *w = WidgetFactory::create( WidgetDatabase::idFromClassName( TQWIZARD_OBJECT_NAME_STRING ),
|
||
15 years ago
|
fw, n.latin1() );
|
||
|
fw->setMainContainer( w );
|
||
|
} else if ( fType == MainWindow ) {
|
||
14 years ago
|
TQWidget *w = WidgetFactory::create( WidgetDatabase::idFromClassName( TQMAINWINDOW_OBJECT_NAME_STRING ),
|
||
15 years ago
|
fw, n.latin1() );
|
||
|
fw->setMainContainer( w );
|
||
|
}
|
||
|
|
||
|
fw->setCaption( n );
|
||
|
fw->resize( 600, 480 );
|
||
|
MainWindow::self->insertFormWindow( fw );
|
||
|
|
||
|
TemplateWizardInterface *iface =
|
||
|
MainWindow::self->templateWizardInterface( fw->mainContainer()->className() );
|
||
|
if ( iface ) {
|
||
|
iface->setup( fw->mainContainer()->className(), fw->mainContainer(),
|
||
|
fw->iFace(), MainWindow::self->designerInterface() );
|
||
|
iface->release();
|
||
|
}
|
||
|
|
||
|
// the wizard might have changed a lot, lets update everything
|
||
|
MainWindow::self->actioneditor()->setFormWindow( fw );
|
||
14 years ago
|
MainWindow::self->objectHierarchy()->setFormWindow( fw, TQT_TQOBJECT(fw) );
|
||
15 years ago
|
MainWindow::self->objectHierarchy()->formDefinitionView()->refresh();
|
||
|
MainWindow::self->objectHierarchy()->rebuild();
|
||
14 years ago
|
fw->killAccels( TQT_TQOBJECT(fw) );
|
||
15 years ago
|
fw->project()->setModified( TRUE );
|
||
|
fw->setFocus();
|
||
|
if ( !pro->isDummy() ) {
|
||
|
fw->setSavePixmapInProject( TRUE );
|
||
|
fw->setSavePixmapInline( FALSE );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
15 years ago
|
CustomFormItem::CustomFormItem( TQIconView *view, const TQString &text )
|
||
15 years ago
|
: NewItem( view, text )
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
static void unifyFormName( FormWindow *fw, TQWorkspace *qworkspace )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQStringList lst;
|
||
|
TQWidgetList windows = qworkspace->windowList();
|
||
|
for ( TQWidget *w =windows.first(); w; w = windows.next() ) {
|
||
15 years ago
|
if ( w == fw )
|
||
|
continue;
|
||
|
lst << w->name();
|
||
|
}
|
||
|
|
||
14 years ago
|
if ( lst.findIndex( fw->name() ) == -1 )
|
||
15 years ago
|
return;
|
||
15 years ago
|
TQString origName = fw->name();
|
||
|
TQString n = origName;
|
||
15 years ago
|
int i = 1;
|
||
14 years ago
|
while ( lst.findIndex( n ) != -1 ) {
|
||
15 years ago
|
n = origName + TQString::number( i++ );
|
||
15 years ago
|
}
|
||
|
fw->setName( n );
|
||
|
fw->setCaption( n );
|
||
|
}
|
||
|
|
||
|
void CustomFormItem::insert( Project *pro )
|
||
|
{
|
||
15 years ago
|
TQString filename = templateFileName();
|
||
|
if ( !filename.isEmpty() && TQFile::exists( filename ) ) {
|
||
15 years ago
|
Resource resource( MainWindow::self );
|
||
|
FormFile *ff = new FormFile( filename, TRUE, pro );
|
||
|
if ( !resource.load( ff ) ) {
|
||
15 years ago
|
TQMessageBox::information( MainWindow::self, i18n("Load Template"),
|
||
13 years ago
|
i18n("Could not load form description from template '%1'" ).arg( filename ) );
|
||
15 years ago
|
delete ff;
|
||
|
return;
|
||
|
}
|
||
14 years ago
|
ff->setFileName( TQString() );
|
||
15 years ago
|
if ( MainWindow::self->formWindow() ) {
|
||
14 years ago
|
MainWindow::self->formWindow()->setFileName( TQString() );
|
||
15 years ago
|
unifyFormName( MainWindow::self->formWindow(), MainWindow::self->qWorkspace() );
|
||
|
if ( !pro->isDummy() ) {
|
||
|
MainWindow::self->formWindow()->setSavePixmapInProject( TRUE );
|
||
|
MainWindow::self->formWindow()->setSavePixmapInline( FALSE );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
15 years ago
|
SourceFileItem::SourceFileItem( TQIconView *view, const TQString &text )
|
||
15 years ago
|
: NewItem( view, text ), visible( TRUE )
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void SourceFileItem::insert( Project *pro )
|
||
|
{
|
||
|
SourceFile *f = new SourceFile( SourceFile::createUnnamedFileName( ext ), TRUE, pro );
|
||
|
MainWindow::self->editSource( f );
|
||
|
}
|
||
|
|
||
|
void SourceFileItem::setProject( Project *pro )
|
||
|
{
|
||
15 years ago
|
TQIconView *iv = iconView();
|
||
15 years ago
|
bool v = lang == pro->language();
|
||
|
if ( !iv || v == visible )
|
||
|
return;
|
||
|
visible = v;
|
||
|
if ( !visible )
|
||
|
iv->takeItem( this );
|
||
|
else
|
||
|
iv->insertItem( this );
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
15 years ago
|
SourceTemplateItem::SourceTemplateItem( TQIconView *view, const TQString &text )
|
||
15 years ago
|
: NewItem( view, text ), visible( TRUE )
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void SourceTemplateItem::insert( Project *pro )
|
||
|
{
|
||
|
SourceTemplateInterface *siface = MainWindow::self->sourceTemplateInterface( text() );
|
||
|
if ( !siface )
|
||
|
return;
|
||
|
SourceTemplateInterface::Source src = siface->create( text(), MainWindow::self->designerInterface() );
|
||
|
SourceFile *f = 0;
|
||
|
if ( src.type == SourceTemplateInterface::Source::Invalid )
|
||
|
return;
|
||
|
if ( src.type == SourceTemplateInterface::Source::FileName )
|
||
|
f = new SourceFile( src.filename, FALSE, pro );
|
||
|
else
|
||
|
f = new SourceFile( SourceFile::createUnnamedFileName( src.extension ), TRUE, pro );
|
||
|
if ( f->isAccepted()) {
|
||
|
f->setText( src.code );
|
||
|
MainWindow::self->editSource( f );
|
||
|
f->setModified( TRUE );
|
||
|
} else {
|
||
|
delete f;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void SourceTemplateItem::setProject( Project *pro )
|
||
|
{
|
||
15 years ago
|
TQIconView *iv = iconView();
|
||
15 years ago
|
bool v = !pro->isDummy() && lang == pro->language();
|
||
|
if ( !iv || v == visible )
|
||
|
return;
|
||
|
visible = v;
|
||
|
if ( !visible )
|
||
|
iv->takeItem( this );
|
||
|
else
|
||
|
iv->insertItem( this );
|
||
|
}
|
||
|
|
||
15 years ago
|
void NewForm::insertTemplates( TQIconView *tView,
|
||
|
const TQString &templatePath )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQStringList::Iterator it;
|
||
|
TQStringList languages = MetaDataBase::languages();
|
||
15 years ago
|
if ( !MainWindow::self->singleProjectMode() ) {
|
||
|
for ( it = languages.begin(); it != languages.end(); ++it ) {
|
||
13 years ago
|
ProjectItem *pi = new ProjectItem( tView, i18n("%1 Project" ).arg( *it ) );
|
||
15 years ago
|
allItems.append( pi );
|
||
|
pi->setLanguage( *it );
|
||
11 years ago
|
pi->setPixmap( BarIcon( "designer_project.png" , TDevDesignerPartFactory::instance()) );
|
||
15 years ago
|
pi->setDragEnabled( FALSE );
|
||
|
}
|
||
|
}
|
||
15 years ago
|
TQIconViewItem *cur = 0;
|
||
15 years ago
|
FormItem *fi = new FormItem( tView,i18n( "Dialog" ) );
|
||
|
allItems.append( fi );
|
||
|
fi->setFormType( FormItem::Dialog );
|
||
11 years ago
|
fi->setPixmap( BarIcon( "designer_newform.png" , TDevDesignerPartFactory::instance()) );
|
||
15 years ago
|
fi->setDragEnabled( FALSE );
|
||
|
cur = fi;
|
||
|
if ( !MainWindow::self->singleProjectMode() ) {
|
||
|
fi = new FormItem( tView,i18n( "Wizard" ) );
|
||
|
allItems.append( fi );
|
||
|
fi->setFormType( FormItem::Wizard );
|
||
11 years ago
|
fi->setPixmap( BarIcon( "designer_newform.png" , TDevDesignerPartFactory::instance()) );
|
||
15 years ago
|
fi->setDragEnabled( FALSE );
|
||
|
fi = new FormItem( tView, i18n( "Widget" ) );
|
||
|
allItems.append( fi );
|
||
|
fi->setFormType( FormItem::Widget );
|
||
11 years ago
|
fi->setPixmap( BarIcon( "designer_newform.png" , TDevDesignerPartFactory::instance()) );
|
||
15 years ago
|
fi->setDragEnabled( FALSE );
|
||
|
fi = new FormItem( tView, i18n( "Main Window" ) );
|
||
|
allItems.append( fi );
|
||
|
fi->setFormType( FormItem::MainWindow );
|
||
11 years ago
|
fi->setPixmap( BarIcon( "designer_newform.png" , TDevDesignerPartFactory::instance()) );
|
||
15 years ago
|
fi->setDragEnabled( FALSE );
|
||
|
|
||
15 years ago
|
TQString templPath = templatePath;
|
||
|
TQStringList templRoots;
|
||
13 years ago
|
const char *qtdir = getenv( "QTDIR" );
|
||
15 years ago
|
if(qtdir)
|
||
|
templRoots << qtdir;
|
||
13 years ago
|
templRoots << tqInstallPathData();
|
||
15 years ago
|
if(qtdir) //try the tools/designer directory last!
|
||
15 years ago
|
templRoots << (TQString(qtdir) + "/tools/designer");
|
||
|
for ( TQStringList::Iterator it = templRoots.begin(); it != templRoots.end(); ++it ) {
|
||
|
TQString path = (*it) + "/templates";
|
||
|
if ( TQFile::exists( path )) {
|
||
15 years ago
|
templPath = path;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if ( !templPath.isEmpty() ) {
|
||
15 years ago
|
TQDir dir( templPath );
|
||
14 years ago
|
const TQFileInfoList *filist = dir.entryInfoList( TQDir::DefaultFilter, TQDir::DirsFirst | TQDir::Name );
|
||
15 years ago
|
if ( filist ) {
|
||
14 years ago
|
TQFileInfoListIterator it( *filist );
|
||
15 years ago
|
TQFileInfo *fi;
|
||
15 years ago
|
while ( ( fi = it.current() ) != 0 ) {
|
||
|
++it;
|
||
|
if ( !fi->isFile() || fi->extension() != "ui" )
|
||
|
continue;
|
||
15 years ago
|
TQString name = fi->baseName();
|
||
14 years ago
|
name = name.replace( '_', ' ' );
|
||
15 years ago
|
CustomFormItem *ci = new CustomFormItem( tView, name );
|
||
|
allItems.append( ci );
|
||
|
ci->setDragEnabled( FALSE );
|
||
11 years ago
|
ci->setPixmap( BarIcon( "designer_newform.png" , TDevDesignerPartFactory::instance()) );
|
||
15 years ago
|
ci->setTemplateFile( fi->absFilePath() );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
for ( it = languages.begin(); it != languages.end(); ++it ) {
|
||
|
LanguageInterface *iface = MetaDataBase::languageInterface( *it );
|
||
|
if ( iface ) {
|
||
15 years ago
|
TQMap<TQString, TQString> extensionMap;
|
||
15 years ago
|
iface->preferedExtensions( extensionMap );
|
||
15 years ago
|
for ( TQMap<TQString, TQString>::Iterator eit = extensionMap.begin();
|
||
15 years ago
|
eit != extensionMap.end(); ++eit ) {
|
||
|
SourceFileItem * si = new SourceFileItem( tView, *eit );
|
||
|
allItems.append( si );
|
||
|
si->setExtension( eit.key() );
|
||
|
si->setLanguage( *it );
|
||
11 years ago
|
si->setPixmap( BarIcon( "designer_filenew.png", TDevDesignerPartFactory::instance() ) );
|
||
15 years ago
|
si->setDragEnabled( FALSE );
|
||
|
}
|
||
|
iface->release();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ( !MainWindow::self->singleProjectMode() ) {
|
||
15 years ago
|
TQStringList sourceTemplates = MainWindow::self->sourceTemplates();
|
||
|
for ( TQStringList::Iterator sit = sourceTemplates.begin(); sit != sourceTemplates.end(); ++sit ) {
|
||
15 years ago
|
SourceTemplateInterface *siface = MainWindow::self->sourceTemplateInterface( *sit );
|
||
|
if ( !siface )
|
||
|
continue;
|
||
|
SourceTemplateItem * si = new SourceTemplateItem( tView, *sit );
|
||
|
allItems.append( si );
|
||
|
si->setTemplate( *sit );
|
||
|
si->setLanguage( siface->language( *sit ) );
|
||
11 years ago
|
si->setPixmap( BarIcon( "designer_filenew.png", TDevDesignerPartFactory::instance() ) );
|
||
15 years ago
|
si->setDragEnabled( FALSE );
|
||
|
siface->release();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
tView->viewport()->setFocus();
|
||
|
tView->setCurrentItem( cur );
|
||
|
|
||
|
if ( MainWindow::self->singleProjectMode() )
|
||
|
adjustSize();
|
||
|
}
|
||
|
|
||
15 years ago
|
NewForm::NewForm( TQIconView *templateView, const TQString &templatePath )
|
||
15 years ago
|
{
|
||
|
insertTemplates( templateView, templatePath );
|
||
|
projectChanged( i18n( "<No Project>" ) );
|
||
|
}
|
||
|
|
||
14 years ago
|
NewForm::NewForm( TQWidget *parent, const TQStringList& projects,
|
||
15 years ago
|
const TQString& currentProject, const TQString &templatePath )
|
||
14 years ago
|
: NewFormBase( parent, 0, TRUE )
|
||
15 years ago
|
{
|
||
15 years ago
|
connect( helpButton, TQT_SIGNAL( clicked() ), MainWindow::self, TQT_SLOT( showDialogHelp() ) );
|
||
15 years ago
|
|
||
|
projectCombo->insertStringList( projects );
|
||
|
projectCombo->setCurrentText( currentProject );
|
||
|
|
||
|
insertTemplates( templateView, templatePath );
|
||
|
|
||
|
projectChanged( projectCombo->currentText() );
|
||
|
}
|
||
|
|
||
|
void NewForm::accept()
|
||
|
{
|
||
|
if ( !templateView->currentItem() )
|
||
|
return;
|
||
|
Project *pro = MainWindow::self->findProject( projectCombo->currentText() );
|
||
|
if ( !pro )
|
||
|
return;
|
||
|
MainWindow::self->setCurrentProject( pro );
|
||
|
NewFormBase::accept();
|
||
|
( (NewItem*)templateView->currentItem() )->insert( pro );
|
||
|
}
|
||
|
|
||
15 years ago
|
void NewForm::projectChanged( const TQString &project )
|
||
15 years ago
|
{
|
||
|
Project *pro = MainWindow::self->findProject( project );
|
||
|
if ( !pro )
|
||
|
return;
|
||
15 years ago
|
TQIconViewItem *i;
|
||
15 years ago
|
for ( i = allItems.first(); i; i = allItems.next() )
|
||
|
( (NewItem*)i )->setProject( pro );
|
||
|
templateView->setCurrentItem( templateView->firstItem() );
|
||
|
templateView->arrangeItemsInGrid( TRUE );
|
||
|
}
|
||
|
|
||
15 years ago
|
void NewForm::itemChanged( TQIconViewItem *item )
|
||
15 years ago
|
{
|
||
|
labelProject->setEnabled( item->rtti() != NewItem::ProjectType );
|
||
|
projectCombo->setEnabled( item->rtti() != NewItem::ProjectType );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQPtrList<TQIconViewItem> NewForm::allViewItems()
|
||
15 years ago
|
{
|
||
|
return allItems;
|
||
|
}
|