1
/* This file is part of the KDE project
2
Copyright (C) 2002 Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
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.
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.
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.
20
#include <qcheckbox.h>
24
#include <qlineedit.h>
25
#include <qpaintdevice.h>
27
#include <qvbuttongroup.h>
30
#include <kapplication.h>
33
#include <kmessagebox.h>
34
#include <knuminput.h>
36
#include "pngexportdia.h"
39
PNGExportDia::PNGExportDia( int width, int height,
40
QWidget *parent, const char *name )
41
: KDialogBase( parent, name, true,
42
i18n("PNG Export Filter Parameters" ), Ok|Cancel )
44
kapp->restoreOverrideCursor();
49
m_realHeight = height;
50
m_widthEdit ->setValue( m_realWidth );
51
m_heightEdit->setValue( m_realHeight );
52
m_percWidthEdit->setValue( 100 );
53
m_percHeightEdit->setValue( 100 );
56
connect( m_proportional, SIGNAL( clicked() ),
57
this, SLOT( proportionalClicked() ) );
61
PNGExportDia::~PNGExportDia()
66
void PNGExportDia::setupGUI()
69
QWidget *page = new QWidget( this );
73
QBoxLayout* mainLayout = new QVBoxLayout( page,
74
KDialog::marginHint(),
75
KDialog::spacingHint() );
77
QGridLayout *mainLayout = new QGridLayout( page, 5, 2,
78
KDialog::marginHint(),
79
KDialog::spacingHint() );
81
m_proportional = new QCheckBox( page, "proportional" );
82
m_proportional->setText( i18n( "Keep ratio" ) );
83
m_proportional->setChecked( true );
84
mainLayout->addWidget( m_proportional, 0, 0 );
86
QLabel* width = new QLabel( page, "width" );
87
width->setText( i18n( "Width:" ) );
88
m_widthEdit = new KIntNumInput( page, "widthEdit" );
89
QLabel* height = new QLabel( page, "height" );
90
height->setText( i18n( "Height:" ) );
91
m_heightEdit = new KIntNumInput( page, "heightEdit" );
93
mainLayout->addWidget( width, 1, 0 );
94
mainLayout->addWidget( m_widthEdit, 1, 1 );
95
mainLayout->addWidget( height, 2, 0 );
96
mainLayout->addWidget( m_heightEdit, 2, 1 );
98
QLabel* percentWidth = new QLabel( page, "PercentWidth" );
99
percentWidth->setText( i18n( "Width (%):" ) );
100
m_percWidthEdit = new KDoubleNumInput( page, "percWidthEdit" );
101
QLabel* percentHeight = new QLabel( page, "PercentHeight" );
102
percentHeight->setText( i18n( "Height (%):" ) );
103
m_percHeightEdit = new KDoubleNumInput( page, "percHeightEdit" );
105
mainLayout->addWidget( percentWidth, 3, 0 );
106
mainLayout->addWidget( m_percHeightEdit, 3, 1 );
107
mainLayout->addWidget( percentHeight, 4, 0 );
108
mainLayout->addWidget( m_percWidthEdit, 4, 1 );
110
/* Display the main layout */
111
//mainLayout->addStretch( 5 );
112
mainLayout->activate();
116
// ----------------------------------------------------------------
119
int PNGExportDia::width()
121
return m_widthEdit->value();
125
int PNGExportDia::height()
127
return m_heightEdit->value();
131
// ----------------------------------------------------------------
135
void PNGExportDia::widthChanged( int width )
138
width = QMIN( width, m_realWidth * 10 );
139
width = QMAX( width, m_realWidth / 10 );
140
double percent = (100.0 * static_cast<double>( width )
141
/ static_cast<double>( m_realWidth ));
142
m_percWidthEdit->setValue( percent );
143
if ( m_proportional->isChecked() ) {
144
m_percHeightEdit->setValue( percent );
145
int height = static_cast<int>( m_realHeight * percent / 100.0 );
146
m_heightEdit->setValue( height );
152
void PNGExportDia::heightChanged( int height )
155
height = QMIN( height, m_realHeight * 10 );
156
height = QMAX( height, m_realHeight / 10 );
157
double percent = (100.0 * static_cast<double>( height )
158
/ static_cast<double>( m_realHeight ));
159
m_percHeightEdit->setValue( percent );
160
if ( m_proportional->isChecked() ) {
161
m_percWidthEdit->setValue( percent );
162
int width = static_cast<int>( m_realWidth * percent / 100.0 );
163
m_widthEdit->setValue( width );
169
void PNGExportDia::percentWidthChanged( double percent )
172
percent = QMIN( percent, 1000 );
173
percent = QMAX( percent, 10 );
174
int width = static_cast<int>( m_realWidth * percent / 100. );
175
m_widthEdit->setValue( width );
176
if ( m_proportional->isChecked() ) {
177
int height = static_cast<int>( m_realHeight * percent / 100. );
178
m_heightEdit->setValue( height );
179
m_percHeightEdit->setValue( percent );
185
void PNGExportDia::percentHeightChanged( double percent )
188
percent = QMIN( percent, 1000 );
189
percent = QMAX( percent, 10 );
190
if ( m_proportional->isChecked() ) {
191
int width = static_cast<int>( m_realWidth * percent / 100. );
192
m_widthEdit->setValue( width );
193
m_percWidthEdit->setValue( percent );
195
int height = static_cast<int>( m_realHeight * percent / 100. );
196
m_heightEdit->setValue( height );
201
void PNGExportDia::proportionalClicked()
203
if ( m_proportional->isChecked() ) {
205
int width = m_widthEdit->value( );
206
width = QMIN( width, m_realWidth * 10 );
207
width = QMAX( width, m_realWidth / 10 );
208
double percent = (100.0 * static_cast<double>( width )
209
/ static_cast<double>( m_realWidth ));
210
m_percHeightEdit->setValue( percent );
211
int height = static_cast<int>( m_realHeight * percent / 100. );
212
m_heightEdit->setValue( height );
218
// ----------------------------------------------------------------
222
void PNGExportDia::connectAll()
224
connect( m_widthEdit, SIGNAL( valueChanged(int) ),
225
this, SLOT( widthChanged( int ) ) );
226
connect( m_heightEdit, SIGNAL( valueChanged(int) ),
227
this, SLOT( heightChanged( int ) ) );
228
connect( m_percWidthEdit, SIGNAL( valueChanged(double) ),
229
this, SLOT( percentWidthChanged( double ) ) );
230
connect( m_percHeightEdit, SIGNAL( valueChanged(double) ),
231
this, SLOT( percentHeightChanged(double ) ) );
235
void PNGExportDia::disconnectAll()
237
disconnect( m_widthEdit, SIGNAL( valueChanged(int) ),
238
this, SLOT( widthChanged( int ) ) );
239
disconnect( m_heightEdit, SIGNAL( valueChanged(int) ),
240
this, SLOT( heightChanged( int ) ) );
241
disconnect( m_percWidthEdit, SIGNAL( valueChanged(double) ),
242
this, SLOT( percentWidthChanged( double ) ) );
243
disconnect( m_percHeightEdit, SIGNAL( valueChanged(double) ),
244
this, SLOT( percentHeightChanged(double ) ) );
249
void PNGExportDia::slotOk()
252
//doc->setZoomAndResolution( 100, 600, 600 );
253
//doc->setZoomAndResolution( 1000, QPaintDevice::x11AppDpiX(), QPaintDevice::x11AppDpiY() );
254
//doc->newZoomAndResolution( false, false );
255
int width = widthEdit->value();
256
int height = heightEdit->value();
257
// kdDebug( KFormula::DEBUGID ) << k_funcinfo
258
// << "(" << width << " " << height << ")"
260
// width = realWidth;
261
// height = realHeight;
262
QImage image = formula->drawImage( width, height );
263
if ( !image.save( _fileOut, "PNG" ) ) {
264
KMessageBox::error( 0, i18n( "Failed to write file." ), i18n( "PNG Export Error" ) );
270
#include "pngexportdia.moc"