1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
/* This file is part of the KDE project
Copyright (C) 1999 Simon Hausmann <hausmann@kde.org>
2001 Matthias Kretz <kretz@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kviewkonqextension.h"
#include "kviewviewer.h"
#include "kimageviewer/canvas.h"
#include "imagesettings.h"
#include <qpainter.h>
#include <qimage.h>
#include <qpaintdevicemetrics.h>
#include <kprinter.h>
#include <kdebug.h>
#include <kglobal.h>
#include <klocale.h>
KViewKonqExtension::KViewKonqExtension( KImageViewer::Canvas * canvas,
KViewViewer *parent, const char *name )
: KParts::BrowserExtension( parent, name ),
m_pViewer( parent ),
m_pCanvas( canvas )
{
KGlobal::locale()->insertCatalogue("kview");
}
void KViewKonqExtension::setXYOffset( int x, int y )
{
m_pCanvas->setXYOffset( x, y );
}
int KViewKonqExtension::xOffset()
{
return m_pCanvas->xOffset();
}
int KViewKonqExtension::yOffset()
{
return m_pCanvas->yOffset();
}
void KViewKonqExtension::print()
{
if( ! m_pCanvas->image() )
{
kdError( 4610 ) << "No image to print" << endl;
return;
}
KPrinter printer;//( true, QPrinter::ScreenResolution );
printer.addDialogPage( new ImageSettings );
printer.setDocName( "KView: " + m_pViewer->url().fileName( false ) );
if ( !printer.setup( ((KViewViewer *)parent())->widget(), i18n("Print %1").arg(m_pViewer->url().fileName( false )) ) )
return;
QPainter painter;
painter.begin( &printer );
QPaintDeviceMetrics metrics( painter.device() );
kdDebug( 4610 ) << "metrics: " << metrics.width() << "x" << metrics.height() << endl;
QPoint pos( 0, 0 );
QImage imagetoprint;
if( printer.option( "app-kviewviewer-fitimage" ) == "1" )
imagetoprint = m_pCanvas->image()->smoothScale( metrics.width(), metrics.height(), QImage::ScaleMin );
else
imagetoprint = *m_pCanvas->image();
if( printer.option( "app-kviewviewer-center" ) == "1" )
{
pos.setX( ( metrics.width() - imagetoprint.width() ) / 2 );
pos.setY( ( metrics.height() - imagetoprint.height() ) / 2 );
}
painter.drawImage( pos, imagetoprint );
painter.end();
}
void KViewKonqExtension::del()
{
m_pViewer->slotDel();
}
// vim:sw=4:ts=4
#include "kviewkonqextension.moc"
|