20#include <tqcheckbox.h>
24#include <tqlineedit.h>
25#include <tqpaintdevice.h>
27#include <tqvbuttongroup.h>
30#include <tdeapplication.h>
33#include <tdemessagebox.h>
36#include "exportsizedia.h"
39ExportSizeDia::ExportSizeDia(
int width,
int height,
40 TQWidget *parent,
const char *name )
41 : KDialogBase( parent, name, true,
42 i18n(
"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, TQ_SIGNAL( clicked() ),
57 this, TQ_SLOT( proportionalClicked() ) );
61ExportSizeDia::~ExportSizeDia()
66void ExportSizeDia::setupGUI()
69 TQWidget *page =
new TQWidget(
this );
73 TQBoxLayout* mainLayout =
new TQVBoxLayout( page,
74 KDialog::marginHint(),
75 KDialog::spacingHint() );
77 TQGridLayout *mainLayout =
new TQGridLayout( page, 5, 2,
78 KDialog::marginHint(),
79 KDialog::spacingHint() );
81 m_proportional =
new TQCheckBox( page,
"proportional" );
82 m_proportional->setText( i18n(
"Keep ratio" ) );
83 m_proportional->setChecked(
true );
84 mainLayout->addWidget( m_proportional, 0, 0 );
86 TQLabel* width =
new TQLabel( page,
"width" );
87 width->setText( i18n(
"Width:" ) );
88 m_widthEdit =
new KIntNumInput( page,
"widthEdit" );
89 TQLabel* height =
new TQLabel( 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 TQLabel* percentWidth =
new TQLabel( page,
"PercentWidth" );
99 percentWidth->setText( i18n(
"Width (%):" ) );
100 m_percWidthEdit =
new KDoubleNumInput( page,
"percWidthEdit" );
101 TQLabel* percentHeight =
new TQLabel( 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 );
112 mainLayout->activate();
119int ExportSizeDia::width()
const
121 return m_widthEdit->value();
125int ExportSizeDia::height()
const
127 return m_heightEdit->value();
135void ExportSizeDia::widthChanged(
int width )
138 width = TQMIN( width, m_realWidth * 10 );
139 width = TQMAX( 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 );
152void ExportSizeDia::heightChanged(
int height )
155 height = TQMIN( height, m_realHeight * 10 );
156 height = TQMAX( 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 );
169void ExportSizeDia::percentWidthChanged(
double percent )
172 percent = TQMIN( percent, 1000 );
173 percent = TQMAX( 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 );
185void ExportSizeDia::percentHeightChanged(
double percent )
188 percent = TQMIN( percent, 1000 );
189 percent = TQMAX( 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 );
201void ExportSizeDia::proportionalClicked()
203 if ( m_proportional->isChecked() ) {
205 int width = m_widthEdit->value( );
206 width = TQMIN( width, m_realWidth * 10 );
207 width = TQMAX( 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 );
222void ExportSizeDia::connectAll()
224 connect( m_widthEdit, TQ_SIGNAL( valueChanged(
int) ),
225 this, TQ_SLOT( widthChanged(
int ) ) );
226 connect( m_heightEdit, TQ_SIGNAL( valueChanged(
int) ),
227 this, TQ_SLOT( heightChanged(
int ) ) );
228 connect( m_percWidthEdit, TQ_SIGNAL( valueChanged(
double) ),
229 this, TQ_SLOT( percentWidthChanged(
double ) ) );
230 connect( m_percHeightEdit, TQ_SIGNAL( valueChanged(
double) ),
231 this, TQ_SLOT( percentHeightChanged(
double ) ) );
235void ExportSizeDia::disconnectAll()
237 disconnect( m_widthEdit, TQ_SIGNAL( valueChanged(
int) ),
238 this, TQ_SLOT( widthChanged(
int ) ) );
239 disconnect( m_heightEdit, TQ_SIGNAL( valueChanged(
int) ),
240 this, TQ_SLOT( heightChanged(
int ) ) );
241 disconnect( m_percWidthEdit, TQ_SIGNAL( valueChanged(
double) ),
242 this, TQ_SLOT( percentWidthChanged(
double ) ) );
243 disconnect( m_percHeightEdit, TQ_SIGNAL( valueChanged(
double) ),
244 this, TQ_SLOT( percentHeightChanged(
double ) ) );
249void ExportSizeDia::slotOk()
255 int width = widthEdit->value();
256 int height = heightEdit->value();
262 TQImage 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 "exportsizedia.moc"