summaryrefslogtreecommitdiffstats
path: root/lib/kofficeui/KoPictureFilePreview.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
commit8362bf63dea22bbf6736609b0f49c152f975eb63 (patch)
tree0eea3928e39e50fae91d4e68b21b1e6cbae25604 /lib/kofficeui/KoPictureFilePreview.cpp
downloadkoffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz
koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'lib/kofficeui/KoPictureFilePreview.cpp')
-rw-r--r--lib/kofficeui/KoPictureFilePreview.cpp121
1 files changed, 121 insertions, 0 deletions
diff --git a/lib/kofficeui/KoPictureFilePreview.cpp b/lib/kofficeui/KoPictureFilePreview.cpp
new file mode 100644
index 00000000..7f27b940
--- /dev/null
+++ b/lib/kofficeui/KoPictureFilePreview.cpp
@@ -0,0 +1,121 @@
+/* This file is part of the KDE project
+ Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
+ Copyright (C) 2002 Nicolas GOUTTE <goutte@kde.org>
+
+ 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.
+*/
+
+#include "KoPictureFilePreview.h"
+#include "KoPictureFilePreview.moc"
+#include <kdialog.h>
+#include <klocale.h>
+#include <kurl.h>
+#include <qbitmap.h>
+#include <qlayout.h>
+#include <qfileinfo.h>
+#include <qpainter.h>
+#include <qscrollview.h>
+
+#include <kdebug.h>
+
+#include <KoPicture.h>
+
+/**
+ * This class implements the actual widget that shows the image.
+ * It is a scrollview, to have scrollbars if the image is big,
+ * and it supports both pixmaps and cliparts
+ */
+class KoPictureFilePreviewWidget : public QScrollView
+{
+public:
+ KoPictureFilePreviewWidget( QWidget *parent )
+ : QScrollView( parent ) { viewport()->setBackgroundMode( PaletteBase ); }
+
+ bool setPicture( const KURL& url )
+ {
+ KoPicture picture;
+ if ( url.isLocalFile() )
+ {
+ if ( !picture.loadFromFile( url.path() ) )
+ {
+ return false;
+ }
+ }
+ else
+ {
+ // ### TODO: find a way to avoid to download the file again later
+ if ( !picture.setKeyAndDownloadPicture( url, this ) )
+ {
+ return false;
+ }
+ }
+ m_size = picture.getOriginalSize();
+ m_picture = picture;
+ resizeContents( m_size.width(), m_size.height() );
+ repaintContents();
+ return true;
+ }
+
+ void setNullPicture(void)
+ {
+ m_picture=KoPicture();
+ m_size=QSize();
+ }
+
+ void drawContents( QPainter *p, int, int, int, int )
+ {
+ p->setBackgroundColor( Qt::white );
+ // Be sure that the background is white (for transparency)
+ p->fillRect(0, 0, m_size.width(), m_size.height(), QBrush( Qt::white ));
+ m_picture.draw( *p, 0 ,0, m_size.width(), m_size.height());
+ }
+
+private:
+ KoPicture m_picture;
+ QSize m_size;
+};
+
+KoPictureFilePreview::KoPictureFilePreview( QWidget *parent )
+ : KPreviewWidgetBase( parent )
+{
+ QVBoxLayout *vb = new QVBoxLayout( this, KDialog::marginHint() );
+ m_widget = new KoPictureFilePreviewWidget( this );
+ vb->addWidget( m_widget, 1 );
+}
+
+void KoPictureFilePreview::showPreview( const KURL &u )
+{
+ m_widget->setPicture( u );
+}
+
+void KoPictureFilePreview::clearPreview()
+{
+ m_widget->setNullPicture();
+}
+
+QString KoPictureFilePreview::clipartPattern()
+{
+ return i18n( "*.svg *.wmf *.qpic|Clipart (*.svg *.wmf *.qpic)" );
+}
+
+QStringList KoPictureFilePreview::clipartMimeTypes()
+{
+ QStringList lst;
+ lst << "image/svg+xml";
+ lst << "image/x-wmf";
+ lst << "image/x-vnd.trolltech.qpicture";
+ return lst;
+}