20#include <tqcheckbox.h>
24#include <tqlineedit.h>
25#include <tqpaintdevice.h>
27#include <tqvbuttongroup.h>
30#include <tdeapplication.h>
33#include <tdemessagebox.h>
35#include <kformulacontainer.h>
36#include <kformuladocument.h>
37#include <kformulamimesource.h>
39#include "pngexportdia.h"
42PNGExportDia::PNGExportDia(
const TQDomDocument &dom,
const TQString &outFile, TQWidget *parent,
const char *name )
43 : KDialogBase( parent, name, true, i18n(
"PNG Export Filter Parameters" ), Ok|Cancel ),
46 kapp->restoreOverrideCursor();
47 wrapper =
new KFormula::DocumentWrapper( kapp->config(), 0 );
48 KFormula::Document* doc =
new KFormula::Document;
49 wrapper->document( doc );
50 formula = doc->createFormula();
51 if ( !doc->loadXML( dom ) ) {
52 kdError() <<
"Failed." << endl;
57 TQRect rect = formula->boundingRect();
58 realWidth = rect.width();
59 realHeight = rect.height();
60 widthEdit->setValue( realWidth );
61 heightEdit->setValue( realHeight );
62 percWidthEdit->setValue( 100 );
63 percHeightEdit->setValue( 100 );
66 connect( proportional, TQ_SIGNAL( clicked() ),
67 this, TQ_SLOT( proportionalClicked() ) );
70PNGExportDia::~PNGExportDia()
75void PNGExportDia::connectAll()
77 connect( widthEdit, TQ_SIGNAL( valueChanged(
int) ),
78 this, TQ_SLOT( widthChanged(
int ) ) );
79 connect( heightEdit, TQ_SIGNAL( valueChanged(
int) ),
80 this, TQ_SLOT( heightChanged(
int ) ) );
81 connect( percWidthEdit, TQ_SIGNAL( valueChanged(
double) ),
82 this, TQ_SLOT( percentWidthChanged(
double ) ) );
83 connect( percHeightEdit, TQ_SIGNAL( valueChanged(
double) ),
84 this, TQ_SLOT( percentHeightChanged(
double ) ) );
87void PNGExportDia::disconnectAll()
89 disconnect( widthEdit, TQ_SIGNAL( valueChanged(
int) ),
90 this, TQ_SLOT( widthChanged(
int ) ) );
91 disconnect( heightEdit, TQ_SIGNAL( valueChanged(
int) ),
92 this, TQ_SLOT( heightChanged(
int ) ) );
93 disconnect( percWidthEdit, TQ_SIGNAL( valueChanged(
double) ),
94 this, TQ_SLOT( percentWidthChanged(
double ) ) );
95 disconnect( percHeightEdit, TQ_SIGNAL( valueChanged(
double) ),
96 this, TQ_SLOT( percentHeightChanged(
double ) ) );
99void PNGExportDia::widthChanged(
int width )
102 width = TQMIN( width, realWidth*10 );
103 width = TQMAX( width, realWidth/10 );
104 double percent = 100.*
static_cast<double>( width )/
static_cast<double>( realWidth );
105 percWidthEdit->setValue( percent );
106 if ( proportional->isChecked() ) {
107 percHeightEdit->setValue( percent );
108 int height =
static_cast<int>( realHeight*percent/100. );
109 heightEdit->setValue( height );
114void PNGExportDia::heightChanged(
int height )
117 height = TQMIN( height, realHeight*10 );
118 height = TQMAX( height, realHeight/10 );
119 double percent = 100.*
static_cast<double>( height )/
static_cast<double>( realHeight );
120 percHeightEdit->setValue( percent );
121 if ( proportional->isChecked() ) {
122 percWidthEdit->setValue( percent );
123 int width =
static_cast<int>( realWidth*percent/100. );
124 widthEdit->setValue( width );
129void PNGExportDia::percentWidthChanged(
double percent )
132 percent = TQMIN( percent, 1000 );
133 percent = TQMAX( percent, 10 );
134 int width =
static_cast<int>( realWidth*percent/100. );
135 widthEdit->setValue( width );
136 if ( proportional->isChecked() ) {
137 int height =
static_cast<int>( realHeight*percent/100. );
138 heightEdit->setValue( height );
139 percHeightEdit->setValue( percent );
144void PNGExportDia::percentHeightChanged(
double percent )
147 percent = TQMIN( percent, 1000 );
148 percent = TQMAX( percent, 10 );
149 if ( proportional->isChecked() ) {
150 int width =
static_cast<int>( realWidth*percent/100. );
151 widthEdit->setValue( width );
152 percWidthEdit->setValue( percent );
154 int height =
static_cast<int>( realHeight*percent/100. );
155 heightEdit->setValue( height );
159void PNGExportDia::proportionalClicked()
161 if ( proportional->isChecked() ) {
163 int width = widthEdit->value( );
164 width = TQMIN( width, realWidth*10 );
165 width = TQMAX( width, realWidth/10 );
166 double percent = 100.*
static_cast<double>( width )/
static_cast<double>( realWidth );
167 percHeightEdit->setValue( percent );
168 int height =
static_cast<int>( realHeight*percent/100. );
169 heightEdit->setValue( height );
174void PNGExportDia::setupGUI()
176 TQWidget *page =
new TQWidget(
this );
179 TQBoxLayout* mainLayout =
new TQVBoxLayout( page, KDialog::marginHint(), KDialog::spacingHint() );
181 proportional =
new TQCheckBox( page,
"proportional" );
182 proportional->setText( i18n(
"Keep ratio" ) );
183 proportional->setChecked(
true );
184 mainLayout->addWidget( proportional );
186 TQLabel* height =
new TQLabel( page,
"Height" );
187 height->setText( i18n(
"Height" ) );
188 widthEdit =
new KIntNumInput( page,
"widthEdit" );
189 TQLabel* width =
new TQLabel( page,
"Width" );
190 width->setText( i18n(
"Width" ) );
191 heightEdit =
new KIntNumInput( page,
"heightEdit" );
193 TQGridLayout* layout1 =
new TQGridLayout;
194 layout1->addWidget( height, 1, 0 );
195 layout1->addWidget( widthEdit, 0, 1 );
196 layout1->addWidget( width, 0, 0 );
197 layout1->addWidget( heightEdit, 1, 1 );
199 mainLayout->addLayout( layout1 );
201 TQLabel* percentHeight =
new TQLabel( page,
"PercentHeight" );
202 percentHeight->setText( i18n(
"Height (%)" ) );
203 TQLabel* percentWidth =
new TQLabel( page,
"PercentWidth" );
204 percentWidth->setText( i18n(
"Width (%)" ) );
205 percWidthEdit =
new KDoubleNumInput( page,
"percWidthEdit" );
206 percHeightEdit =
new KDoubleNumInput( page,
"percHeightEdit" );
208 TQGridLayout* layout2 =
new TQGridLayout;
209 layout2->addWidget( percWidthEdit, 0, 1 );
210 layout2->addWidget( percHeightEdit, 1, 1 );
211 layout2->addWidget( percentHeight, 1, 0 );
212 layout2->addWidget( percentWidth, 0, 0 );
214 mainLayout->addLayout( layout2 );
217 mainLayout->addStretch( 5 );
218 mainLayout->activate();
222void PNGExportDia::slotOk()
228 int width = widthEdit->value();
229 int height = heightEdit->value();
235 TQImage image = formula->drawImage( width, height );
236 if ( !image.save( _fileOut,
"PNG" ) ) {
237 KMessageBox::error( 0, i18n(
"Failed to write file." ), i18n(
"PNG Export Error" ) );
242#include "pngexportdia.moc"