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.
304 lines
9.1 KiB
304 lines
9.1 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Made by Tomislav Lukman (tomislav.lukman@ck.tel.hr)
|
||
|
Copyright (C) 2002, 2003 The Karbon Developers
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library 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
|
||
|
Library 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.
|
||
|
*/
|
||
|
|
||
14 years ago
|
#include <tqlabel.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
14 years ago
|
#include <tqtabwidget.h>
|
||
|
#include <tqsize.h>
|
||
|
#include <tqhbuttongroup.h>
|
||
|
#include <tqtoolbutton.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
#include <kiconloader.h>
|
||
|
#include <KoMainWindow.h>
|
||
|
#include <KoFilterManager.h>
|
||
12 years ago
|
#include <tdefiledialog.h>
|
||
15 years ago
|
|
||
|
#include "karbon_part.h"
|
||
|
#include "karbon_view.h"
|
||
|
#include "karbon_factory.h"
|
||
|
#include "karbon_resourceserver.h"
|
||
|
#include "karbon_drag.h"
|
||
|
#include "vselection.h"
|
||
|
#include "vlayer.h"
|
||
|
#include "vfill.h"
|
||
|
#include "vfillcmd.h"
|
||
|
#include "vtransformcmd.h"
|
||
|
|
||
|
#include "vstyledocker.h"
|
||
|
|
||
|
#include <unistd.h>
|
||
|
|
||
13 years ago
|
ClipartChooser::ClipartChooser( TQSize iconSize, TQWidget *parent, const char *name )
|
||
|
: KoIconChooser( iconSize, parent, name )
|
||
15 years ago
|
{
|
||
|
setDragEnabled( true );
|
||
|
}
|
||
|
|
||
|
void
|
||
|
ClipartChooser::startDrag()
|
||
|
{
|
||
|
KoIconChooser::startDrag();
|
||
|
KarbonDrag* kd = new KarbonDrag( this );
|
||
|
VObjectList objects;
|
||
|
VClipartIconItem *selectedClipart = (VClipartIconItem *)currentItem();
|
||
|
double s = kMax( selectedClipart->originalWidth(), selectedClipart->originalHeight() );
|
||
|
VObject *clipart = selectedClipart->clipart()->clone();
|
||
|
|
||
14 years ago
|
TQWMatrix mat( s, 0, 0, -s, -( s / 2 ), ( s / 2 ) );
|
||
15 years ago
|
|
||
|
VTransformCmd trafo( 0L, mat );
|
||
|
trafo.visit( *clipart );
|
||
|
|
||
|
objects.append( clipart );
|
||
|
kd->setObjectList( objects );
|
||
|
kd->dragCopy();
|
||
|
}
|
||
|
|
||
13 years ago
|
VStyleDocker::VStyleDocker( KarbonPart* part, KarbonView* parent, const char* /*name*/ )
|
||
|
: TQWidget(), m_part ( part ), m_view( parent )
|
||
15 years ago
|
{
|
||
|
setCaption( i18n( "Resources" ) );
|
||
|
|
||
14 years ago
|
mTabWidget = new TQTabWidget( this );
|
||
15 years ago
|
|
||
|
//Pattern
|
||
|
KoPatternChooser *pPatternChooser = new KoPatternChooser( KarbonFactory::rServer()->patterns(), mTabWidget );
|
||
|
pPatternChooser->setCaption( i18n( "Patterns" ) );
|
||
|
|
||
14 years ago
|
connect( pPatternChooser, TQT_SIGNAL(selected( KoIconItem * ) ), this, TQT_SLOT( slotItemSelected( KoIconItem * )));
|
||
|
connect( KarbonFactory::rServer(), TQT_SIGNAL( patternAdded( KoIconItem * )), pPatternChooser, TQT_SLOT( addPattern( KoIconItem * )));
|
||
|
connect( KarbonFactory::rServer(), TQT_SIGNAL( patternRemoved( KoIconItem * )), pPatternChooser, TQT_SLOT( removePattern( KoIconItem * )));
|
||
15 years ago
|
mTabWidget->addTab( pPatternChooser, i18n( "Patterns" ) );
|
||
|
|
||
|
//Clipart
|
||
|
ClipartWidget *pClipartWidget = new ClipartWidget( KarbonFactory::rServer()->cliparts(), part, mTabWidget );
|
||
|
mTabWidget->addTab( pClipartWidget, i18n( "Clipart" ) );
|
||
|
|
||
14 years ago
|
TQVBoxLayout *mainWidgetLayout = new TQVBoxLayout( this, 2 );
|
||
15 years ago
|
mainWidgetLayout->addWidget( mTabWidget );
|
||
|
mainWidgetLayout->activate();
|
||
|
setMinimumHeight( 174 );
|
||
|
setMinimumWidth( 194 );
|
||
|
}
|
||
|
|
||
|
VStyleDocker::~VStyleDocker()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void VStyleDocker::slotItemSelected( KoIconItem *item )
|
||
|
{
|
||
|
VPattern *pattern = (VPattern *)item;
|
||
|
if( !pattern ) return;
|
||
|
kdDebug(38000) << "loading pattern : " << pattern->tilename().latin1() << endl;
|
||
|
if( m_part && m_part->document().selection() )
|
||
|
{
|
||
|
VFill fill;
|
||
|
fill.pattern() = *pattern;//.load( pattern->tilename() );
|
||
|
//fill.setColor( *m_color );
|
||
|
fill.setType( VFill::patt );
|
||
|
m_part->addCommand( new VFillCmd( &m_part->document(), fill ), true );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VStyleDocker::mouseReleaseEvent( TQMouseEvent * )
|
||
15 years ago
|
{
|
||
|
}
|
||
|
|
||
13 years ago
|
ClipartWidget::ClipartWidget( TQPtrList<VClipartIconItem>* clipartItems, KarbonPart *part, TQWidget* parent )
|
||
|
: TQWidget( parent ), m_part( part )
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEIconLoader il;
|
||
15 years ago
|
|
||
13 years ago
|
TQVBoxLayout* layout = new TQVBoxLayout( this );
|
||
|
layout->addWidget( m_clipartChooser = new ClipartChooser( TQSize( 32, 32 ), this ) );
|
||
|
layout->addWidget( m_buttonGroup = new TQHButtonGroup( this ) );
|
||
14 years ago
|
TQToolButton* m_addClipartButton;
|
||
|
m_buttonGroup->insert( m_addClipartButton = new TQToolButton( m_buttonGroup ) );
|
||
|
m_buttonGroup->insert( m_importClipartButton = new TQToolButton( m_buttonGroup ) );
|
||
|
m_buttonGroup->insert( m_deleteClipartButton = new TQToolButton( m_buttonGroup ) );
|
||
15 years ago
|
m_addClipartButton->setIconSet( SmallIcon( "14_layer_newlayer" ) );
|
||
|
m_addClipartButton->setTextLabel( i18n( "Add" ) );
|
||
|
m_importClipartButton->setIconSet( SmallIcon( "fileimport" ) );
|
||
|
m_importClipartButton->setTextLabel( i18n( "Import" ) );
|
||
|
m_deleteClipartButton->setIconSet( SmallIcon( "14_layer_deletelayer" ) );
|
||
|
m_deleteClipartButton->setTextLabel( i18n( "Delete" ) );
|
||
|
|
||
|
m_buttonGroup->setInsideMargin( 3 );
|
||
|
|
||
|
//setFrameStyle( Box | Sunken );
|
||
13 years ago
|
layout->setMargin( 3 );
|
||
15 years ago
|
|
||
14 years ago
|
connect( m_buttonGroup, TQT_SIGNAL( clicked( int ) ), this, TQT_SLOT( slotButtonClicked( int ) ) );
|
||
|
//connect( m_deleteClipartButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( deleteClipart() ) );
|
||
|
connect( m_clipartChooser, TQT_SIGNAL( selected( KoIconItem* ) ), this, TQT_SLOT( clipartSelected( KoIconItem* ) ) );
|
||
15 years ago
|
|
||
|
m_clipartChooser->setAutoDelete( false );
|
||
|
VClipartIconItem* item = 0L;
|
||
|
|
||
|
for( item = clipartItems->first(); item; item = clipartItems->next() )
|
||
|
m_clipartChooser->addItem( item );
|
||
|
|
||
|
m_clipartItem = ( clipartItems->first() ) ? clipartItems->first()->clone() : 0;
|
||
|
if( !m_clipartItem )
|
||
|
m_deleteClipartButton->setEnabled( false );
|
||
|
}
|
||
|
|
||
|
ClipartWidget::~ClipartWidget()
|
||
|
{
|
||
|
delete m_clipartItem;
|
||
|
}
|
||
|
|
||
|
VClipartIconItem* ClipartWidget::selectedClipart()
|
||
|
{
|
||
|
return m_clipartItem;
|
||
|
}
|
||
|
|
||
|
void
|
||
|
ClipartWidget::clipartSelected( KoIconItem* item )
|
||
|
{
|
||
|
if( item )
|
||
|
{
|
||
|
delete m_clipartItem;
|
||
|
VClipartIconItem* clipartItem = ( VClipartIconItem* ) item;
|
||
|
m_deleteClipartButton->setEnabled( clipartItem->canDelete() );
|
||
|
m_selectedItem = clipartItem;
|
||
|
m_clipartItem = clipartItem->clone();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void
|
||
|
ClipartWidget::addClipart()
|
||
|
{
|
||
|
VObject* clipart = 0L;
|
||
|
VSelection* selection = m_part->document().selection();
|
||
|
|
||
|
if( selection->objects().count() == 1 )
|
||
|
{
|
||
|
clipart = selection->objects().getFirst()->clone();
|
||
|
clipart->setParent( 0L );
|
||
|
}
|
||
|
|
||
|
if( selection->objects().count() > 1 )
|
||
|
{
|
||
14 years ago
|
TQPtrVector<VObject> objects;
|
||
15 years ago
|
selection->objects().toVector( &objects );
|
||
|
VGroup* group = new VGroup( 0L );
|
||
|
|
||
|
for( unsigned int i = 0; i < objects.count(); i++ )
|
||
|
{
|
||
|
VObject *obj = objects[ i ]->clone();
|
||
|
obj->setParent( 0L );
|
||
|
group->append( obj );
|
||
|
}
|
||
|
|
||
|
clipart = group;
|
||
|
}
|
||
|
|
||
|
if( clipart )
|
||
|
{
|
||
|
KoRect clipartBox = clipart->boundingBox();
|
||
|
double scaleFactor = 1. / kMax( clipartBox.width(), clipartBox.height() );
|
||
14 years ago
|
TQWMatrix trMatrix( scaleFactor, 0, 0, scaleFactor, -clipartBox.x() * scaleFactor, -clipartBox.y() * scaleFactor );
|
||
15 years ago
|
|
||
|
VTransformCmd trafo( 0L, trMatrix );
|
||
|
trafo.visit( *clipart );
|
||
|
|
||
|
// center the clipart
|
||
|
trMatrix.reset();
|
||
|
double size = kMax( clipart->boundingBox().width(), clipart->boundingBox().height() );
|
||
|
trMatrix.translate( ( size - clipart->boundingBox().width() ) / 2, ( size - clipart->boundingBox().height() ) / 2 );
|
||
|
|
||
|
trafo.setMatrix( trMatrix );
|
||
|
trafo.visit( *clipart );
|
||
|
|
||
|
// remove Y-mirroring
|
||
|
trMatrix.reset();
|
||
|
trMatrix.scale( 1, -1 );
|
||
|
trMatrix.translate( 0, -1 );
|
||
|
|
||
|
trafo.setMatrix( trMatrix );
|
||
|
trafo.visit( *clipart );
|
||
|
|
||
|
m_clipartChooser->addItem( KarbonFactory::rServer()->addClipart( clipart, clipartBox.width(), clipartBox.height() ) );
|
||
|
}
|
||
|
|
||
|
m_clipartChooser->updateContents();
|
||
|
}
|
||
|
|
||
|
void
|
||
|
ClipartWidget::importClipart()
|
||
|
{
|
||
14 years ago
|
TQStringList filter;
|
||
15 years ago
|
filter << "application/x-karbon" << "image/svg+xml" << "image/x-wmf" << "image/x-eps" << "application/postscript";
|
||
14 years ago
|
KFileDialog *dialog = new KFileDialog( "foo", TQString(), 0L, "Choose Graphic to Add", true);
|
||
15 years ago
|
dialog->setMimeFilter( filter, "application/x-karbon" );
|
||
14 years ago
|
if( dialog->exec()!=TQDialog::Accepted )
|
||
15 years ago
|
{
|
||
|
delete dialog;
|
||
|
return;
|
||
|
}
|
||
14 years ago
|
TQString fname = dialog->selectedFile();
|
||
15 years ago
|
delete dialog;
|
||
|
if( m_part->nativeFormatMimeType() == dialog->currentMimeFilter().latin1() )
|
||
|
m_part->mergeNativeFormat( fname );
|
||
|
else
|
||
|
{
|
||
|
KoFilterManager man( m_part );
|
||
13 years ago
|
KoFilter::ConversionStatus status;
|
||
14 years ago
|
TQString importedFile = man.import( fname, status );
|
||
15 years ago
|
if( status == KoFilter::OK )
|
||
|
m_part->mergeNativeFormat( importedFile );
|
||
|
if( !importedFile.isEmpty() )
|
||
14 years ago
|
unlink( TQFile::encodeName( importedFile ) );
|
||
15 years ago
|
if( status != KoFilter::OK )
|
||
|
return;
|
||
|
}
|
||
|
m_part->document().selection()->clear();
|
||
|
m_part->document().selection()->append( m_part->document().activeLayer()->objects() );
|
||
|
addClipart();
|
||
|
m_part->document().selection()->clear();
|
||
|
m_part->document().removeLayer( m_part->document().activeLayer() );
|
||
|
}
|
||
|
|
||
|
void
|
||
|
ClipartWidget::deleteClipart()
|
||
|
{
|
||
|
VClipartIconItem* clipartItem = m_clipartItem;
|
||
|
KarbonFactory::rServer()->removeClipart( clipartItem );
|
||
|
m_clipartChooser->removeItem( m_selectedItem );
|
||
|
m_clipartChooser->updateContents();
|
||
|
}
|
||
|
|
||
|
void
|
||
|
ClipartWidget::slotButtonClicked( int id )
|
||
|
{
|
||
|
switch( id )
|
||
|
{
|
||
|
case 0: addClipart(); break;
|
||
|
case 1: importClipart(); break;
|
||
|
case 2: deleteClipart();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#include "vstyledocker.moc"
|
||
|
|