~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to kounavail/kounavail.cc

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2001 David Faure <david@mandrakesoft.com>
 
3
 
 
4
   This library is free software; you can redistribute it and/or
 
5
   modify it under the terms of the GNU Library General Public
 
6
   License as published by the Free Software Foundation; either
 
7
   version 2 of the License, or (at your option) any later version.
 
8
 
 
9
   This library is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
   Library General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU Library General Public License
 
15
   along with this library; see the file COPYING.LIB.  If not, write to
 
16
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
   Boston, MA 02111-1307, USA.
 
18
*/
 
19
 
 
20
#include "kounavail.h"
 
21
 
 
22
#include <qpainter.h>
 
23
#include <qiconset.h>
 
24
#include <kaction.h>
 
25
#include <kinstance.h>
 
26
#include <kstdaction.h>
 
27
#include <klocale.h>
 
28
#include <kaboutdata.h>
 
29
#include <kdebug.h>
 
30
#include <kglobalsettings.h>
 
31
#include <qapplication.h>
 
32
 
 
33
KoUnavailPart::KoUnavailPart( QWidget *parentWidget, const char *widgetName, QObject* parent, const char* name )
 
34
    : KoDocument( parentWidget, widgetName, parent, name, false /*singleViewMode*/ )
 
35
{
 
36
    setReadWrite( false );
 
37
}
 
38
 
 
39
KoView* KoUnavailPart::createViewInstance( QWidget* parent, const char* name )
 
40
{
 
41
    return new KoUnavailView( this, parent, name );
 
42
}
 
43
 
 
44
bool KoUnavailPart::loadXML( QIODevice *, const QDomDocument &doc )
 
45
{
 
46
    // Simply keep a copy of the whole document ;)
 
47
    m_doc = doc;
 
48
    return true;
 
49
}
 
50
 
 
51
bool KoUnavailPart::saveFile()
 
52
{
 
53
    kdDebug() << "KoUnavailPart::saveFile m_url=" << m_url.prettyURL() << endl;
 
54
    // This is called if the part points to an external file
 
55
    // In that case we have nothing to save, the file was unavailable !
 
56
    return true;
 
57
}
 
58
 
 
59
QDomDocument KoUnavailPart::saveXML()
 
60
{
 
61
    kdDebug() << "KoUnavailPart::saveXML" << endl;
 
62
    return m_doc;
 
63
}
 
64
 
 
65
void KoUnavailPart::setMimeType( const QCString& mime )
 
66
{
 
67
    kdDebug() << "KoUnavailPart::setMimeType " << mime << endl;
 
68
    m_mimetype = mime;
 
69
}
 
70
 
 
71
void KoUnavailPart::paintContent( QPainter& painter, const QRect& rect, bool /*transparent*/,
 
72
                                double /*zoomX*/, double /*zoomY*/ )
 
73
{
 
74
    painter.save();
 
75
    painter.setPen( QApplication::palette().color( QPalette::Active, QColorGroup::Text ) );
 
76
    // Need to draw only the document rectangle described in the parameter rect.
 
77
    int left = rect.left() / 20;
 
78
    int right = rect.right() / 20 + 1;
 
79
    int top = rect.top() / 20;
 
80
    int bottom = rect.bottom() / 20 + 1;
 
81
 
 
82
    for( int x = left; x < right; ++x )
 
83
        painter.drawLine( x * 20, top * 20, x * 20, bottom * 20 );
 
84
    for( int y = left; y < right; ++y )
 
85
        painter.drawLine( left * 20, y * 20, right * 20, y * 20 );
 
86
 
 
87
    QFont defaultFont = KGlobalSettings::generalFont();
 
88
    defaultFont.setPointSize( 16 ); // ###
 
89
    painter.setFont( defaultFont );
 
90
    //painter.drawText( 20, 20, m_reason );
 
91
    painter.drawText( rect, Qt::AlignCenter | Qt::WordBreak, m_reason );
 
92
    painter.restore();
 
93
}
 
94
 
 
95
KoUnavailView::KoUnavailView( KoUnavailPart* part, QWidget* parent, const char* name )
 
96
    : KoView( part, parent, name )
 
97
{
 
98
    setInstance( KoUnavailFactory::global() );
 
99
    //setXMLFile( "kounavail.rc" );
 
100
}
 
101
 
 
102
void KoUnavailView::paintEvent( QPaintEvent* ev )
 
103
{
 
104
    QPainter painter;
 
105
    painter.begin( this );
 
106
 
 
107
    // ### TODO: Scaling
 
108
 
 
109
    // Let the document do the drawing
 
110
    koDocument()->paintEverything( painter, ev->rect(), FALSE, this );
 
111
 
 
112
    painter.end();
 
113
}
 
114
 
 
115
extern "C"
 
116
{
 
117
    void* init_libkounavailpart()
 
118
    {
 
119
        return new KoUnavailFactory;
 
120
    }
 
121
}
 
122
 
 
123
KInstance* KoUnavailFactory::s_global = 0L;
 
124
KAboutData* KoUnavailFactory::s_aboutData = 0L;
 
125
 
 
126
KoUnavailFactory::KoUnavailFactory( QObject* parent, const char* name )
 
127
    : KoFactory( parent, name )
 
128
{
 
129
    global();
 
130
}
 
131
 
 
132
KoUnavailFactory::~KoUnavailFactory()
 
133
{
 
134
    delete s_aboutData;
 
135
    s_aboutData = 0L;
 
136
    delete s_global;
 
137
    s_global = 0L;
 
138
}
 
139
 
 
140
KParts::Part* KoUnavailFactory::createPartObject( QWidget *parentWidget, const char *widgetName, QObject* parent, const char* name, const char*, const QStringList & )
 
141
{
 
142
    return new KoUnavailPart( parentWidget, widgetName, parent, name );
 
143
}
 
144
 
 
145
KAboutData* KoUnavailFactory::aboutData()
 
146
{
 
147
    if ( !s_aboutData )
 
148
    {
 
149
        static const char* description=I18N_NOOP("KoUnavail KOffice Program");
 
150
        static const char* version="0.1";
 
151
        s_aboutData=new KAboutData( "kounavail", I18N_NOOP("KoUnavail"),
 
152
                                    version, description, KAboutData::License_LGPL,
 
153
                                    "(c) 2001, David Faure");
 
154
        s_aboutData->addAuthor("David Faure",0, "david@mandrakesoft.com");
 
155
    }
 
156
    return s_aboutData;
 
157
}
 
158
 
 
159
KInstance* KoUnavailFactory::global()
 
160
{
 
161
    if ( !s_global )
 
162
    {
 
163
        s_global = new KInstance( aboutData() );
 
164
        // Tell the iconloader about share/apps/koffice/icons
 
165
        //s_global->iconLoader()->addAppDir("koffice");
 
166
    }
 
167
    return s_global;
 
168
}
 
169
 
 
170
#include "kounavail.moc"