filters

exportsizedia.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002 Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include <qcheckbox.h>
00021 #include <qimage.h>
00022 #include <qlabel.h>
00023 #include <qlayout.h>
00024 #include <qlineedit.h>
00025 #include <qpaintdevice.h>
00026 #include <qrect.h>
00027 #include <qvbuttongroup.h>
00028 #include <qwidget.h>
00029 
00030 #include <kapplication.h>
00031 #include <kdebug.h>
00032 #include <klocale.h>
00033 #include <kmessagebox.h>
00034 #include <knuminput.h>
00035 
00036 #include "exportsizedia.h"
00037 
00038 
00039 ExportSizeDia::ExportSizeDia( int width, int height, 
00040                 QWidget *parent, const char *name )
00041     : KDialogBase( parent, name, true,
00042            i18n("Export Filter Parameters" ), Ok|Cancel )
00043 {
00044     kapp->restoreOverrideCursor();
00045 
00046     setupGUI();
00047 
00048     m_realWidth  = width;
00049     m_realHeight = height;
00050     m_widthEdit ->setValue( m_realWidth );
00051     m_heightEdit->setValue( m_realHeight  );
00052     m_percWidthEdit->setValue( 100 );
00053     m_percHeightEdit->setValue( 100 );
00054 
00055     connectAll();
00056     connect( m_proportional, SIGNAL( clicked() ),
00057              this,         SLOT( proportionalClicked() ) );
00058 }
00059 
00060 
00061 ExportSizeDia::~ExportSizeDia()
00062 {
00063 }
00064 
00065 
00066 void ExportSizeDia::setupGUI()
00067 {
00068     //resize( size() );
00069     QWidget *page = new QWidget( this );
00070     setMainWidget(page);
00071 
00072 #if 0
00073     QBoxLayout* mainLayout = new QVBoxLayout( page, 
00074                           KDialog::marginHint(), 
00075                           KDialog::spacingHint() );
00076 #else
00077     QGridLayout *mainLayout = new QGridLayout( page, 5, 2,
00078                            KDialog::marginHint(), 
00079                            KDialog::spacingHint() );
00080 #endif
00081     m_proportional = new QCheckBox( page, "proportional" );
00082     m_proportional->setText( i18n( "Keep ratio" ) );
00083     m_proportional->setChecked( true );
00084     mainLayout->addWidget( m_proportional, 0, 0 );
00085 
00086     QLabel* width = new QLabel( page, "width" );
00087     width->setText( i18n( "Width:" ) );
00088     m_widthEdit = new KIntNumInput( page, "widthEdit" );
00089     QLabel* height = new QLabel( page, "height" );
00090     height->setText( i18n( "Height:" ) );
00091     m_heightEdit = new KIntNumInput( page, "heightEdit" );
00092 
00093     mainLayout->addWidget( width,      1, 0 );
00094     mainLayout->addWidget( m_widthEdit,  1, 1 );
00095     mainLayout->addWidget( height,     2, 0 );
00096     mainLayout->addWidget( m_heightEdit, 2, 1 );
00097 
00098     QLabel* percentWidth = new QLabel( page, "PercentWidth" );
00099     percentWidth->setText( i18n( "Width (%):" ) );
00100     m_percWidthEdit = new KDoubleNumInput( page, "percWidthEdit" );
00101     QLabel* percentHeight = new QLabel( page, "PercentHeight" );
00102     percentHeight->setText( i18n( "Height (%):" ) );
00103     m_percHeightEdit = new KDoubleNumInput( page, "percHeightEdit" );
00104 
00105     mainLayout->addWidget( percentWidth,   3, 0 );
00106     mainLayout->addWidget( m_percHeightEdit, 3, 1 );
00107     mainLayout->addWidget( percentHeight,  4, 0 );
00108     mainLayout->addWidget( m_percWidthEdit,  4, 1 );
00109 
00110     /* Display the main layout */
00111     //mainLayout->addStretch( 5 );
00112     mainLayout->activate();
00113 }
00114 
00115 
00116 // ----------------------------------------------------------------
00117 //                          public methods
00118 
00119 int ExportSizeDia::width() const
00120 {
00121     return m_widthEdit->value();
00122 }
00123 
00124 
00125 int ExportSizeDia::height() const
00126 {
00127     return m_heightEdit->value();
00128 }
00129 
00130 
00131 // ----------------------------------------------------------------
00132 //                            slots
00133 
00134 
00135 void ExportSizeDia::widthChanged( int width )
00136 {
00137     disconnectAll();
00138     width = QMIN( width, m_realWidth * 10 );
00139     width = QMAX( width, m_realWidth / 10 );
00140     double percent = (100.0 * static_cast<double>( width ) 
00141               / static_cast<double>( m_realWidth ));
00142     m_percWidthEdit->setValue(  percent  );
00143     if ( m_proportional->isChecked() ) {
00144         m_percHeightEdit->setValue( percent );
00145         int height = static_cast<int>( m_realHeight * percent / 100.0 );
00146         m_heightEdit->setValue(  height );
00147     }
00148     connectAll();
00149 }
00150 
00151 
00152 void ExportSizeDia::heightChanged( int height )
00153 {
00154     disconnectAll();
00155     height = QMIN( height, m_realHeight * 10 );
00156     height = QMAX( height, m_realHeight / 10 );
00157     double percent = (100.0 * static_cast<double>( height )
00158               / static_cast<double>( m_realHeight ));
00159     m_percHeightEdit->setValue( percent  );
00160     if ( m_proportional->isChecked() ) {
00161         m_percWidthEdit->setValue(  percent  );
00162         int width = static_cast<int>( m_realWidth * percent / 100.0 );
00163         m_widthEdit->setValue( width );
00164     }
00165     connectAll();
00166 }
00167 
00168 
00169 void ExportSizeDia::percentWidthChanged( double percent )
00170 {
00171     disconnectAll();
00172     percent = QMIN( percent, 1000 );
00173     percent = QMAX( percent, 10 );
00174     int width = static_cast<int>( m_realWidth * percent / 100. );
00175     m_widthEdit->setValue(  width  );
00176     if ( m_proportional->isChecked() ) {
00177         int height = static_cast<int>( m_realHeight * percent / 100. );
00178         m_heightEdit->setValue(  height  );
00179         m_percHeightEdit->setValue(  percent );
00180     }
00181     connectAll();
00182 }
00183 
00184 
00185 void ExportSizeDia::percentHeightChanged( double percent )
00186 {
00187     disconnectAll();
00188     percent = QMIN( percent, 1000 );
00189     percent = QMAX( percent, 10 );
00190     if ( m_proportional->isChecked() ) {
00191         int width = static_cast<int>( m_realWidth * percent / 100. );
00192         m_widthEdit->setValue(  width  );
00193         m_percWidthEdit->setValue(  percent  );
00194     }
00195     int height = static_cast<int>( m_realHeight * percent / 100. );
00196     m_heightEdit->setValue(  height  );
00197     connectAll();
00198 }
00199 
00200 
00201 void ExportSizeDia::proportionalClicked()
00202 {
00203     if ( m_proportional->isChecked() ) {
00204         disconnectAll();
00205         int width = m_widthEdit->value( );
00206         width = QMIN( width, m_realWidth * 10 );
00207         width = QMAX( width, m_realWidth / 10 );
00208         double percent = (100.0 * static_cast<double>( width )
00209               / static_cast<double>( m_realWidth ));
00210         m_percHeightEdit->setValue(  percent  );
00211         int height = static_cast<int>( m_realHeight * percent / 100. );
00212         m_heightEdit->setValue(  height  );
00213         connectAll();
00214     }
00215 }
00216 
00217 
00218 // ----------------------------------------------------------------
00219 //                          private methods
00220 
00221 
00222 void ExportSizeDia::connectAll()
00223 {
00224     connect( m_widthEdit,      SIGNAL( valueChanged(int) ),
00225              this,             SLOT( widthChanged( int ) ) );
00226     connect( m_heightEdit,     SIGNAL( valueChanged(int) ),
00227              this,             SLOT( heightChanged( int ) ) );
00228     connect( m_percWidthEdit,  SIGNAL( valueChanged(double) ),
00229              this,             SLOT( percentWidthChanged( double ) ) );
00230     connect( m_percHeightEdit, SIGNAL( valueChanged(double) ),
00231              this,             SLOT( percentHeightChanged(double ) ) );
00232 }
00233 
00234 
00235 void ExportSizeDia::disconnectAll()
00236 {
00237     disconnect( m_widthEdit,      SIGNAL( valueChanged(int) ),
00238         this,             SLOT( widthChanged( int ) ) );
00239     disconnect( m_heightEdit,     SIGNAL( valueChanged(int) ),
00240         this,             SLOT( heightChanged( int ) ) );
00241     disconnect( m_percWidthEdit,  SIGNAL( valueChanged(double) ),
00242         this,             SLOT( percentWidthChanged( double ) ) );
00243     disconnect( m_percHeightEdit, SIGNAL( valueChanged(double) ),
00244         this,             SLOT( percentHeightChanged(double ) ) );
00245 }
00246 
00247 
00248 #if 0
00249 void ExportSizeDia::slotOk()
00250 {
00251     hide();
00252     //doc->setZoomAndResolution( 100, 600, 600 );
00253     //doc->setZoomAndResolution( 1000, QPaintDevice::x11AppDpiX(), QPaintDevice::x11AppDpiY() );
00254     //doc->newZoomAndResolution( false, false );
00255     int width = widthEdit->value();
00256     int height = heightEdit->value();
00257 //     kdDebug( KFormula::DEBUGID ) << k_funcinfo
00258 //                                  << "(" << width << " " << height << ")"
00259 //                                  << endl;
00260 //     width = realWidth;
00261 //     height = realHeight;
00262     QImage image = formula->drawImage( width, height );
00263     if ( !image.save( _fileOut, "PNG" ) ) {
00264         KMessageBox::error( 0, i18n( "Failed to write file." ), i18n( "PNG Export Error" ) );
00265     }
00266     reject();
00267 }
00268 #endif
00269 
00270 #include "exportsizedia.moc"
00271 
KDE Home | KDE Accessibility Home | Description of Access Keys