F:/KPlato/koffice/libs/kofficeui/KoPictureFilePreview.cpp

Aller à la documentation de ce fichier.
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., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, 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>
00027 #include <QLayout>
00028 #include <QFileInfo>
00029 #include <QPainter>
00030 #include <q3scrollview.h>
00031 #include <QPalette>
00032 #include <QVBoxLayout>
00033 
00034 #include <kdebug.h>
00035 
00036 #include <KoPicture.h>
00037 
00043 class KoPictureFilePreviewWidget : public Q3ScrollView
00044 {
00045 public:
00046     KoPictureFilePreviewWidget( QWidget *parent )
00047         : Q3ScrollView( parent ) {
00048         viewport()->setBackgroundRole( QPalette::Base );
00049     }
00050 
00051     bool setPicture( const KUrl& url )
00052     {
00053         KoPicture picture;
00054         if ( url.isLocalFile() )
00055         {
00056             if ( !picture.loadFromFile( url.path() ) )
00057             {
00058                 return false;
00059             }
00060         }
00061         else
00062         {
00063             // ### TODO: find a way to avoid to download the file again later
00064             if ( !picture.setKeyAndDownloadPicture( url, this ) )
00065             {
00066                 return false;
00067             }
00068         }
00069         m_size = picture.getOriginalSize();
00070         m_picture = picture;
00071         resizeContents( m_size.width(), m_size.height() );
00072         repaintContents();
00073         return true;
00074     }
00075 
00076     void setNullPicture(void)
00077     {
00078         m_picture=KoPicture();
00079         m_size=QSize();
00080     }
00081 
00082     void drawContents( QPainter *p, int, int, int, int )
00083     {
00084         p->setBackground( QBrush( Qt::white ) );
00085         // Be sure that the background is white (for transparency)
00086         p->fillRect(0, 0, m_size.width(), m_size.height(), QBrush( Qt::white ));
00087         m_picture.draw( *p, 0 ,0, m_size.width(), m_size.height());
00088     }
00089 
00090 private:
00091     KoPicture m_picture;
00092     QSize m_size;
00093 };
00094 
00095 KoPictureFilePreview::KoPictureFilePreview( QWidget *parent )
00096     : KPreviewWidgetBase( parent )
00097 {
00098     QVBoxLayout *vb = new QVBoxLayout( this );
00099     vb->setMargin(KDialog::marginHint());
00100     m_widget = new KoPictureFilePreviewWidget( this );
00101     vb->addWidget( m_widget, 1 );
00102 }
00103 
00104 void KoPictureFilePreview::showPreview( const KUrl &u )
00105 {
00106     m_widget->setPicture( u );
00107 }
00108 
00109 void KoPictureFilePreview::clearPreview()
00110 {
00111     m_widget->setNullPicture();
00112 }
00113 
00114 QString KoPictureFilePreview::clipartPattern()
00115 {
00116     return i18n( "*.svg *.wmf *.qpic|Clipart (*.svg *.wmf *.qpic)" );
00117 }
00118 
00119 QStringList KoPictureFilePreview::clipartMimeTypes()
00120 {
00121     QStringList lst;
00122     lst << "image/svg+xml";
00123     lst << "image/x-wmf";
00124     lst << "image/x-vnd.trolltech.qpicture";
00125     return lst;
00126 }

Généré le Wed Nov 22 23:41:05 2006 pour KPlato par  doxygen 1.5.1-p1