lib Library API Documentation

koPictureFilePreview.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
00003    Copyright (C) 2002 Nicolas GOUTTE <goutte@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #include "koPictureFilePreview.h"
00022 #include "koPictureFilePreview.moc"
00023 #include <kdialog.h>
00024 #include <klocale.h>
00025 #include <kurl.h>
00026 #include <qbitmap.h>
00027 #include <qlayout.h>
00028 #include <qfileinfo.h>
00029 #include <qpainter.h>
00030 #include <qscrollview.h>
00031 
00032 #include <kdebug.h>
00033 
00034 #include <koPicture.h>
00035 
00041 class KoPictureFilePreviewWidget : public QScrollView
00042 {
00043 public:
00044     KoPictureFilePreviewWidget( QWidget *parent )
00045         : QScrollView( parent ) { viewport()->setBackgroundMode( PaletteBase ); }
00046 
00047     bool setPicture( const QString & filename )
00048     {
00049         KoPicture picture;
00050         if (picture.loadFromFile( filename ))
00051         {
00052             m_size = picture.getOriginalSize();
00053             m_picture = picture;
00054             resizeContents( m_size.width(), m_size.height() );
00055             repaintContents();
00056             return true;
00057         }
00058         else
00059             return false;
00060     }
00061 
00062     void setNullPicture(void)
00063     {
00064         m_picture=KoPicture();
00065         m_size=QSize();
00066     }
00067 
00068     void drawContents( QPainter *p, int, int, int, int )
00069     {
00070         p->setBackgroundColor( Qt::white );
00071         // Be sure that the background is white (for transparency)
00072         p->fillRect(0, 0, m_size.width(), m_size.height(), QBrush( Qt::white ));
00073         m_picture.draw( *p, 0 ,0, m_size.width(), m_size.height());
00074     }
00075 
00076 private:
00077     KoPicture m_picture;
00078     QSize m_size;
00079 };
00080 
00081 KoPictureFilePreview::KoPictureFilePreview( QWidget *parent )
00082     : KPreviewWidgetBase( parent )
00083 {
00084     QVBoxLayout *vb = new QVBoxLayout( this, KDialog::marginHint() );
00085     m_widget = new KoPictureFilePreviewWidget( this );
00086     vb->addWidget( m_widget, 1 );
00087 }
00088 
00089 void KoPictureFilePreview::showPreview( const KURL &u )
00090 {
00091     if ( u.isLocalFile() ) {
00092         QString path = u.path();
00093         m_widget->setPicture( path );
00094     } else {
00095         // ## TODO support for remote URLs
00096         m_widget->setNullPicture();
00097     }
00098 }
00099 
00100 void KoPictureFilePreview::clearPreview()
00101 {
00102     m_widget->setNullPicture();
00103 }
00104 
00105 QString KoPictureFilePreview::clipartPattern()
00106 {
00107     return i18n( "*.svg *.wmf|Clipart (*.svg *.wmf)" );
00108 }
00109 
00110 QStringList KoPictureFilePreview::clipartMimeTypes()
00111 {
00112     QStringList lst;
00113     lst << "image/svg+xml";
00114     lst << "image/x-wmf";
00115     // TODO; image/x-qpicture
00116     return lst;
00117 }
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Mar 20 14:25:26 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003