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.
327 lines
8.2 KiB
327 lines
8.2 KiB
15 years ago
|
/*
|
||
|
KDE Draw - a small graphics drawing program for the KDE
|
||
|
Copyright (C) 1998 Thomas Tanghus (tanghus@kde.org)
|
||
|
|
||
|
This program is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This program is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
13 years ago
|
#include <tqlayout.h>
|
||
15 years ago
|
#include <tqpainter.h>
|
||
|
#include <tqbuttongroup.h>
|
||
|
#include <tqradiobutton.h>
|
||
|
#include <tqpushbutton.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdeconfig.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
|
#include <tdeglobal.h>
|
||
15 years ago
|
#include <kiconloader.h>
|
||
|
#include <kdebug.h>
|
||
12 years ago
|
#include <tdeapplication.h>
|
||
15 years ago
|
|
||
|
#include "knew.h"
|
||
|
|
||
12 years ago
|
TDEIconTemplateContainer* TDEIconTemplateContainer::instance = 0;
|
||
15 years ago
|
|
||
12 years ago
|
void createStandardTemplates(TDEIconTemplateContainer *list)
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEIconLoader *kil = TDEGlobal::iconLoader();
|
||
15 years ago
|
|
||
12 years ago
|
TDEIconTemplate it;
|
||
|
it.path = kil->iconPath("standard", TDEIcon::User);
|
||
15 years ago
|
it.title = i18n("Standard File");
|
||
|
list->append(it);
|
||
|
|
||
12 years ago
|
it.path = kil->iconPath("source", TDEIcon::User);
|
||
15 years ago
|
it.title = i18n("Source File");
|
||
|
list->append(it);
|
||
|
|
||
12 years ago
|
it.path = kil->iconPath("compressed", TDEIcon::User);
|
||
15 years ago
|
it.title = i18n("Compressed File");
|
||
|
list->append(it);
|
||
|
|
||
12 years ago
|
it.path = kil->iconPath("folder", TDEIcon::User);
|
||
15 years ago
|
it.title = i18n("Standard Folder");
|
||
|
list->append(it);
|
||
|
|
||
12 years ago
|
it.path = kil->iconPath("package", TDEIcon::User);
|
||
15 years ago
|
it.title = i18n("Standard Package");
|
||
|
list->append(it);
|
||
|
|
||
12 years ago
|
it.path = kil->iconPath("mini-folder", TDEIcon::User);
|
||
15 years ago
|
it.title = i18n("Mini Folder");
|
||
|
list->append(it);
|
||
|
|
||
12 years ago
|
it.path = kil->iconPath("mini-package", TDEIcon::User);
|
||
15 years ago
|
it.title = i18n("Mini Package");
|
||
|
list->append(it);
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconTemplateContainer::save()
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEConfig *k = kapp->config();
|
||
15 years ago
|
k->setGroup("Templates");
|
||
|
|
||
15 years ago
|
TQStringList names;
|
||
12 years ago
|
for (TQValueListIterator<TDEIconTemplate> iter = begin(); iter != end(); iter++)
|
||
15 years ago
|
{
|
||
|
names.append((*iter).title);
|
||
|
}
|
||
|
|
||
|
k->writeEntry("Names", names);
|
||
|
|
||
|
for(unsigned int i = 0; i < names.count(); i++)
|
||
|
{
|
||
|
k->writePathEntry(names[i], (*this)[i].path);
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEIconTemplateContainer::TDEIconTemplateContainer() : TQValueList<TDEIconTemplate>()
|
||
15 years ago
|
{
|
||
15 years ago
|
TQStrList names;
|
||
12 years ago
|
TDEConfig *k = kapp->config();
|
||
15 years ago
|
k->setGroup("Templates");
|
||
|
k->readListEntry("Names", names);
|
||
|
for(int i = 0; i < (int)names.count(); i++)
|
||
|
{
|
||
12 years ago
|
TDEIconTemplate it;
|
||
15 years ago
|
it.path = k->readPathEntry(names.at(i));
|
||
|
it.title = names.at(i);
|
||
|
//kdDebug(4640) << "Template: " << names.at(i) << "\n" << path.data() << endl;
|
||
|
append(it);
|
||
|
}
|
||
|
|
||
|
if(count() == 0)
|
||
|
{
|
||
|
createStandardTemplates(this);
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEIconTemplateContainer::~TDEIconTemplateContainer()
|
||
15 years ago
|
{
|
||
|
clear();
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEIconListBoxItem::TDEIconListBoxItem( TDEIconTemplate t )
|
||
15 years ago
|
: TQListBoxItem(), icontemplate(t)
|
||
15 years ago
|
{
|
||
12 years ago
|
//kdDebug(4640) << "TDEIconListBoxItem - " << t->path.data() << ", " << t->title.data() << endl;
|
||
15 years ago
|
|
||
|
pm.load(t.path);
|
||
|
setText( t.title );
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconListBoxItem::reloadIcon()
|
||
15 years ago
|
{
|
||
|
pm.load(icontemplate.path);
|
||
|
setText( icontemplate.title );
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
12 years ago
|
void TDEIconListBoxItem::paint( TQPainter *p )
|
||
15 years ago
|
{
|
||
|
p->drawPixmap( 3, 0, pm );
|
||
15 years ago
|
TQFontMetrics fm = p->fontMetrics();
|
||
15 years ago
|
int yPos; // vertical text position
|
||
|
if ( pm.height() < fm.height() )
|
||
|
yPos = fm.ascent() + fm.leading()/2;
|
||
|
else
|
||
|
yPos = pm.height()/2 - fm.height()/2 + fm.ascent();
|
||
|
p->drawText( pm.width() + 5, yPos, text() );
|
||
|
}
|
||
|
|
||
12 years ago
|
int TDEIconListBoxItem::height(const TQListBox *lb ) const
|
||
15 years ago
|
{
|
||
14 years ago
|
return TQMAX( pm.height(), lb->fontMetrics().lineSpacing() + 1 );
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
int TDEIconListBoxItem::width(const TQListBox *lb ) const
|
||
15 years ago
|
{
|
||
|
return pm.width() + lb->fontMetrics().width( text() ) + 6;
|
||
|
}
|
||
|
|
||
14 years ago
|
NewSelect::NewSelect(TQWidget *parent) : TQWidget( parent )
|
||
15 years ago
|
{
|
||
14 years ago
|
wiz = (KWizard*) parent;
|
||
15 years ago
|
grp = new TQButtonGroup( this );
|
||
|
connect( grp, TQT_SIGNAL( clicked( int ) ), TQT_SLOT( buttonClicked( int ) ) );
|
||
15 years ago
|
grp->setExclusive( true );
|
||
|
|
||
15 years ago
|
TQVBoxLayout* ml = new TQVBoxLayout( this );
|
||
15 years ago
|
ml->addWidget( grp, 1 );
|
||
|
//ml->addWidget(grp, 10, AlignLeft);
|
||
15 years ago
|
TQVBoxLayout* l = new TQVBoxLayout( grp, 10 );
|
||
15 years ago
|
|
||
15 years ago
|
rbscratch = new TQRadioButton( i18n( "Create from scratch" ), grp );
|
||
15 years ago
|
l->addWidget( rbscratch, 1 );
|
||
|
//l->addWidget(rbscratch, 5, AlignLeft);
|
||
|
|
||
15 years ago
|
rbtempl = new TQRadioButton( i18n( "Create from template" ), grp );
|
||
15 years ago
|
l->addWidget( rbtempl, 1 );
|
||
|
//l->addWidget(rbtempl, 5, AlignLeft);
|
||
|
|
||
13 years ago
|
//grp->setMinimumSize(grp->childrenRect().size());
|
||
15 years ago
|
|
||
|
grp->setButton( 0 );
|
||
|
}
|
||
|
|
||
|
NewSelect::~NewSelect()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void NewSelect::buttonClicked(int id)
|
||
|
{
|
||
|
//kdDebug(4640) << "Button: " << id << endl;
|
||
|
|
||
|
emit iconopenstyle(id);
|
||
|
}
|
||
|
|
||
14 years ago
|
NewFromTemplate::NewFromTemplate( TQWidget* parent )
|
||
|
: TQWidget( parent )
|
||
15 years ago
|
{
|
||
14 years ago
|
wiz = (KWizard*) parent;
|
||
15 years ago
|
|
||
15 years ago
|
TQVBoxLayout* ml = new TQVBoxLayout(this);
|
||
15 years ago
|
|
||
15 years ago
|
grp = new TQGroupBox( i18n( "Templates" ), this );
|
||
15 years ago
|
ml->addWidget( grp, 1 );
|
||
|
//ml->addWidget(grp, 10, AlignLeft);
|
||
|
|
||
15 years ago
|
TQHBoxLayout* l = new TQHBoxLayout( grp, 15 );
|
||
15 years ago
|
|
||
12 years ago
|
templates = new TDEIconListBox( grp );
|
||
15 years ago
|
connect( templates, TQT_SIGNAL( highlighted( int ) ), TQT_SLOT( checkSelection( int ) ) );
|
||
15 years ago
|
l->addWidget( templates );
|
||
|
|
||
12 years ago
|
for( int i = 0; i < (int) TDEIconTemplateContainer::self()->count(); i++ )
|
||
|
templates->insertItem( new TDEIconListBoxItem( *TDEIconTemplateContainer::self()->at( i ) ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
NewFromTemplate::~NewFromTemplate()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void NewFromTemplate::checkSelection( int )
|
||
|
{
|
||
|
//kdDebug(4640) << "checkSelection(int) " << templates->currentItem() << endl;
|
||
|
if( templates->currentItem() != -1 )
|
||
|
wiz->finishButton()->setEnabled( true );
|
||
|
else
|
||
|
wiz->finishButton()->setEnabled( false );
|
||
|
}
|
||
|
|
||
14 years ago
|
KNewIcon::KNewIcon( TQWidget* parent )
|
||
|
: KWizard( parent, 0, true )
|
||
15 years ago
|
{
|
||
|
//kdDebug(4640) << "KNewIcon" << endl;
|
||
|
setCaption( i18n( "Create New Icon" ) );
|
||
|
resize( 400, 250 );
|
||
|
|
||
|
openstyle = 0;
|
||
|
|
||
|
finishButton()->setEnabled( true );
|
||
|
cancelButton()->setEnabled( true );
|
||
|
nextButton()->setEnabled( false );
|
||
|
|
||
|
select = new NewSelect( this );
|
||
15 years ago
|
connect( select, TQT_SIGNAL( iconopenstyle( int ) ), TQT_SLOT( iconOpenStyle( int ) ) );
|
||
15 years ago
|
|
||
15 years ago
|
scratch = new KResizeWidget( this, 0, TQSize( 32, 32 ) );
|
||
15 years ago
|
// this doesn't accept default valid size, besides spin buttons won't allow
|
||
|
// an invalid size to be set by the user - forces user to change valid default
|
||
|
// size to create the new icon object -
|
||
15 years ago
|
connect( scratch, TQT_SIGNAL( validSize( bool ) ), TQT_SLOT( checkPage( bool ) ) );
|
||
|
connect(this, TQT_SIGNAL(selected(const TQString &)), this, TQT_SLOT(checkPage(const TQString &)));
|
||
15 years ago
|
templ = new NewFromTemplate(this);
|
||
|
templ->hide();
|
||
|
|
||
|
addPage(select, i18n("Select Icon Type"));
|
||
|
addPage(scratch, i18n("Create From Scratch"));
|
||
|
act = scratch;
|
||
|
//addPage(templ, i18n("Create From Template"));
|
||
|
}
|
||
|
|
||
|
KNewIcon::~KNewIcon()
|
||
|
{
|
||
|
delete select;
|
||
|
delete scratch;
|
||
|
delete templ;
|
||
|
}
|
||
|
|
||
|
void KNewIcon::okClicked()
|
||
|
{
|
||
|
if(openstyle == Blank)
|
||
|
emit newicon(scratch->getSize());
|
||
|
else
|
||
|
emit newicon(templ->path());
|
||
|
hide();
|
||
|
setResult(1);
|
||
|
accept();
|
||
|
}
|
||
|
|
||
|
void KNewIcon::cancelClicked()
|
||
|
{
|
||
|
hide();
|
||
|
setResult(0);
|
||
|
reject();
|
||
|
}
|
||
|
|
||
|
void KNewIcon::iconOpenStyle(int style)
|
||
|
{
|
||
|
openstyle = style;
|
||
|
|
||
|
if( act )
|
||
|
removePage( act );
|
||
|
|
||
|
if(openstyle == Blank)
|
||
|
{
|
||
|
act = scratch;
|
||
|
setNextEnabled( act, true );
|
||
|
addPage( scratch, i18n( "Create From Scratch" ) );
|
||
|
}
|
||
|
else if( openstyle == Template )
|
||
|
{
|
||
|
act = templ;
|
||
|
setNextEnabled( act, true );
|
||
|
addPage( templ, i18n( "Create From Template" ) );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KNewIcon::checkPage( bool b)
|
||
|
{
|
||
|
//kdDebug(4640) << "checkPage(int) " << openstyle << " " << p << endl;
|
||
|
if(openstyle == Blank)
|
||
|
finishButton()->setEnabled(true);
|
||
|
else if( !b )
|
||
|
finishButton()->setEnabled(false);
|
||
|
else
|
||
|
templ->checkSelection(0);
|
||
|
}
|
||
|
|
||
15 years ago
|
void KNewIcon::checkPage(const TQString &)
|
||
15 years ago
|
{
|
||
|
if(currentPage() == select || openstyle == Blank)
|
||
|
finishButton()->setEnabled(true);
|
||
|
else
|
||
|
finishButton()->setEnabled(false);
|
||
|
}
|
||
|
#include "knew.moc"
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|