00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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
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
00116
return lst;
00117 }