KoPictureBase.cpp
1/* This file is part of the KDE project
2 Copyright (c) 2001 Simon Hausmann <hausmann@kde.org>
3 Copyright (C) 2002, 2003 Nicolas GOUTTE <goutte@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include "KoPictureBase.h"
22
23#include <KoXmlWriter.h>
24
25#include <kdebug.h>
26#include <tdeconfig.h>
27#include <tdeglobal.h>
28
29#include <kmdcodec.h>
30#include <tqpainter.h>
31#include <tqpicture.h>
32#include <tqpixmap.h>
33#include <tqdragobject.h>
34
35static int s_useSlowResizeMode = -1; // unset
36
37KoPictureBase::KoPictureBase(void)
38{
39 // Slow mode can be very slow, especially at high zoom levels -> configurable
40 if ( s_useSlowResizeMode == -1 )
41 {
42 TDEConfigGroup group( TDEGlobal::config(), "KOfficeImage" );
43 s_useSlowResizeMode = group.readNumEntry( "HighResolution", 1 );
44 kdDebug(30003) << "HighResolution = " << s_useSlowResizeMode << endl;
45 }
46}
47
48KoPictureBase::~KoPictureBase(void)
49{
50}
51
52KoPictureBase* KoPictureBase::newCopy(void) const
53{
54 return new KoPictureBase(*this);
55}
56
57KoPictureType::Type KoPictureBase::getType(void) const
58{
59 return KoPictureType::TypeUnknown;
60}
61
62bool KoPictureBase::isNull(void) const
63{
64 return true; // A KoPictureBase is always null.
65}
66
67void KoPictureBase::draw(TQPainter& painter, int x, int y, int width, int height, int, int, int, int, bool /*fastMode*/)
68{
69 // Draw a light red box (easier DEBUG)
70 kdWarning(30003) << "Drawing light red rectangle! (KoPictureBase::draw)" << endl;
71 painter.save();
72 painter.setBrush(TQColor(128,0,0));
73 painter.drawRect(x,y,width,height);
74 painter.restore();
75}
76
77bool KoPictureBase::load(TQIODevice* io, const TQString& extension)
78{
79 return loadData(io->readAll(), extension);
80}
81
82bool KoPictureBase::loadData(const TQByteArray&, const TQString&)
83{
84 // Nothing to load!
85 return false;
86}
87
88bool KoPictureBase::save(TQIODevice*) const
89{
90 // Nothing to save!
91 return false;
92}
93
94bool KoPictureBase::saveAsBase64( KoXmlWriter& writer ) const
95{
96 TQBuffer buffer;
97 buffer.open(IO_ReadWrite);
98 if ( !save( &buffer ) )
99 return false;
100 TQCString encoded = KCodecs::base64Encode( buffer.buffer() );
101 writer.addTextNode( encoded );
102 return true;
103}
104
105TQSize KoPictureBase::getOriginalSize(void) const
106{
107 return TQSize(0,0);
108}
109
110TQPixmap KoPictureBase::generatePixmap(const TQSize&, bool /*smoothScale*/)
111{
112 return TQPixmap();
113}
114
115TQString KoPictureBase::getMimeType(const TQString&) const
116{
117 return TQString(NULL_MIME_TYPE);
118}
119
120bool KoPictureBase::isSlowResizeModeAllowed(void) const
121{
122 return s_useSlowResizeMode != 0;
123}
124
125TQDragObject* KoPictureBase::dragObject( TQWidget * dragSource, const char * name )
126{
127 TQImage image (generateImage(getOriginalSize()));
128 if (image.isNull())
129 return 0L;
130 else
131 return new TQImageDrag( image, dragSource, name );
132}
133
134TQImage KoPictureBase::generateImage(const TQSize& size)
135{
136 return generatePixmap(size,true).convertToImage();
137}
138
139void KoPictureBase::clearCache(void)
140{
141 // Nothign to do!
142}
A class for writing out XML (to any TQIODevice), with a special attention on performance.
Definition KoXmlWriter.h:37
void addTextNode(const TQString &str)
Overloaded version of addTextNode( const char* ), which is a bit slower because it needs to convert s...
TDEAction * save(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)