exportsizedia.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002 Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
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., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include <tqcheckbox.h>
21#include <tqimage.h>
22#include <tqlabel.h>
23#include <tqlayout.h>
24#include <tqlineedit.h>
25#include <tqpaintdevice.h>
26#include <tqrect.h>
27#include <tqvbuttongroup.h>
28#include <tqwidget.h>
29
30#include <tdeapplication.h>
31#include <kdebug.h>
32#include <tdelocale.h>
33#include <tdemessagebox.h>
34#include <knuminput.h>
35
36#include "exportsizedia.h"
37
38
39ExportSizeDia::ExportSizeDia( int width, int height,
40 TQWidget *parent, const char *name )
41 : KDialogBase( parent, name, true,
42 i18n("Export Filter Parameters" ), Ok|Cancel )
43{
44 kapp->restoreOverrideCursor();
45
46 setupGUI();
47
48 m_realWidth = width;
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 );
54
55 connectAll();
56 connect( m_proportional, TQ_SIGNAL( clicked() ),
57 this, TQ_SLOT( proportionalClicked() ) );
58}
59
60
61ExportSizeDia::~ExportSizeDia()
62{
63}
64
65
66void ExportSizeDia::setupGUI()
67{
68 //resize( size() );
69 TQWidget *page = new TQWidget( this );
70 setMainWidget(page);
71
72#if 0
73 TQBoxLayout* mainLayout = new TQVBoxLayout( page,
74 KDialog::marginHint(),
75 KDialog::spacingHint() );
76#else
77 TQGridLayout *mainLayout = new TQGridLayout( page, 5, 2,
78 KDialog::marginHint(),
79 KDialog::spacingHint() );
80#endif
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 );
85
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" );
92
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 );
97
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" );
104
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 );
109
110 /* Display the main layout */
111 //mainLayout->addStretch( 5 );
112 mainLayout->activate();
113}
114
115
116// ----------------------------------------------------------------
117// public methods
118
119int ExportSizeDia::width() const
120{
121 return m_widthEdit->value();
122}
123
124
125int ExportSizeDia::height() const
126{
127 return m_heightEdit->value();
128}
129
130
131// ----------------------------------------------------------------
132// slots
133
134
135void ExportSizeDia::widthChanged( int width )
136{
137 disconnectAll();
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 );
147 }
148 connectAll();
149}
150
151
152void ExportSizeDia::heightChanged( int height )
153{
154 disconnectAll();
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 );
164 }
165 connectAll();
166}
167
168
169void ExportSizeDia::percentWidthChanged( double percent )
170{
171 disconnectAll();
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 );
180 }
181 connectAll();
182}
183
184
185void ExportSizeDia::percentHeightChanged( double percent )
186{
187 disconnectAll();
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 );
194 }
195 int height = static_cast<int>( m_realHeight * percent / 100. );
196 m_heightEdit->setValue( height );
197 connectAll();
198}
199
200
201void ExportSizeDia::proportionalClicked()
202{
203 if ( m_proportional->isChecked() ) {
204 disconnectAll();
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 );
213 connectAll();
214 }
215}
216
217
218// ----------------------------------------------------------------
219// private methods
220
221
222void ExportSizeDia::connectAll()
223{
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 ) ) );
232}
233
234
235void ExportSizeDia::disconnectAll()
236{
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 ) ) );
245}
246
247
248#if 0
249void ExportSizeDia::slotOk()
250{
251 hide();
252 //doc->setZoomAndResolution( 100, 600, 600 );
253 //doc->setZoomAndResolution( 1000, TQPaintDevice::x11AppDpiX(), TQPaintDevice::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 << ")"
259// << endl;
260// width = realWidth;
261// height = realHeight;
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" ) );
265 }
266 reject();
267}
268#endif
269
270#include "exportsizedia.moc"
271