diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 47d455dd55be855e4cc691c32f687f723d9247ee (patch) | |
tree | 52e236aaa2576bdb3840ebede26619692fed6d7d /kview/modules/scale | |
download | tdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.tar.gz tdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegraphics@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kview/modules/scale')
-rw-r--r-- | kview/modules/scale/Makefile.am | 15 | ||||
-rw-r--r-- | kview/modules/scale/kfloatspinbox.cpp | 116 | ||||
-rw-r--r-- | kview/modules/scale/kfloatspinbox.h | 64 | ||||
-rw-r--r-- | kview/modules/scale/kview_scale.cpp | 180 | ||||
-rw-r--r-- | kview/modules/scale/kview_scale.desktop | 127 | ||||
-rw-r--r-- | kview/modules/scale/kview_scale.h | 48 | ||||
-rw-r--r-- | kview/modules/scale/kview_scale.rc | 14 | ||||
-rw-r--r-- | kview/modules/scale/scaledlg.cpp | 311 | ||||
-rw-r--r-- | kview/modules/scale/scaledlg.h | 78 |
9 files changed, 953 insertions, 0 deletions
diff --git a/kview/modules/scale/Makefile.am b/kview/modules/scale/Makefile.am new file mode 100644 index 00000000..39442781 --- /dev/null +++ b/kview/modules/scale/Makefile.am @@ -0,0 +1,15 @@ +INCLUDES = -I$(top_srcdir)/kview $(all_includes) + +kde_module_LTLIBRARIES = kview_scale.la + +kview_scale_la_SOURCES = kfloatspinbox.cpp scaledlg.cpp kview_scale.cpp +kview_scale_la_LIBADD = $(LIB_KFILE) $(LIB_KPARTS) -lkdeprint +kview_scale_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) + +plugdir = $(kde_datadir)/kviewviewer/kpartplugins +plug_DATA = kview_scale.rc kview_scale.desktop + +METASOURCES = AUTO + +messages: rc.cpp + $(XGETTEXT) *.cpp *.h -o $(podir)/kview_scale.pot diff --git a/kview/modules/scale/kfloatspinbox.cpp b/kview/modules/scale/kfloatspinbox.cpp new file mode 100644 index 00000000..e5ce8465 --- /dev/null +++ b/kview/modules/scale/kfloatspinbox.cpp @@ -0,0 +1,116 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Matthias Kretz <kretz@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +// $Id$ + +#include "kfloatspinbox.h" + +#if defined(QT_ACCESSIBILITY_SUPPORT) +#include <qaccessible.h> +#endif + +#include <knumvalidator.h> +#include <klocale.h> +#include <kglobal.h> +#include <kdebug.h> + +int pow( int a, int b ) +{ + int ret = 1; + for( int i = 0; i < b; ++i ) + ret *= a; + return ret; +} + +KFloatSpinBox::KFloatSpinBox( float minValue, float maxValue, float step, unsigned int precision, QWidget * parent, const char * name ) + : QSpinBox( parent, name ) + , m_doselection( true ) +{ + setRange( minValue, maxValue, step, precision ); + connect( this, SIGNAL( valueChanged( int ) ), this, SLOT( slotValueChanged( int ) ) ); +} + +KFloatSpinBox::~KFloatSpinBox() +{ +} + +void KFloatSpinBox::setRange( float minValue, float maxValue, float step, unsigned int precision ) +{ + m_factor = pow( 10, precision ); + m_min = (int)( minValue * m_factor ); + m_max = (int)( maxValue * m_factor ); + m_step = (int)( step * m_factor ); + QSpinBox::setRange( m_min, m_max ); + setSteps( m_step, m_step * 10 ); + if( precision == 0 ) + setValidator( new KIntValidator( m_min, m_max, this, 10, "KFloatValidator::KIntValidator" ) ); + else + setValidator( new KFloatValidator( minValue, maxValue, true, this, "KFloatSpinBox::KFloatValidator" ) ); +} + +float KFloatSpinBox::value() const +{ + float ret = (float)QSpinBox::value() / m_factor; + kdDebug( 4630 ) << ret << endl; + return ret; +} + +void KFloatSpinBox::setValue( float value ) +{ + QSpinBox::setValue( (int)( value * m_factor ) ); +} + +void KFloatSpinBox::setValueBlocking( float value ) +{ + m_doselection = false; + blockSignals( true ); + KFloatSpinBox::setValue( value ); + blockSignals( false ); + m_doselection = true; +} + +QString KFloatSpinBox::mapValueToText( int value ) +{ + return KGlobal::locale()->formatNumber( (float)value / (float)m_factor, 4 ); +} + +int KFloatSpinBox::mapTextToValue( bool * ok ) +{ + return (int)( m_factor * KGlobal::locale()->readNumber( text(), ok ) ); +} + +void KFloatSpinBox::valueChange() +{ + if( m_doselection ) + QSpinBox::valueChange(); + else + { + updateDisplay(); + emit valueChanged( value() ); +#if defined(QT_ACCESSIBILITY_SUPPORT) + QAccessible::updateAccessibility( this, 0, QAccessible::ValueChanged ); +#endif + } +} + +void KFloatSpinBox::slotValueChanged( int ) +{ + emit valueChanged( value() ); +} + +#include "kfloatspinbox.moc" diff --git a/kview/modules/scale/kfloatspinbox.h b/kview/modules/scale/kfloatspinbox.h new file mode 100644 index 00000000..9407a0f1 --- /dev/null +++ b/kview/modules/scale/kfloatspinbox.h @@ -0,0 +1,64 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Matthias Kretz <kretz@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +// $Id$ + +#ifndef __kfloatspinbox_h_ +#define __kfloatspinbox_h_ + +#include <qspinbox.h> + +class KFloatSpinBox : public QSpinBox +{ + Q_OBJECT + public: + KFloatSpinBox( float minValue, float maxValue, float step, unsigned int precision, QWidget * parent = 0, const char * name = 0 ); + virtual ~KFloatSpinBox(); + + void setRange( float minValue, float maxValue, float step, unsigned int precision ); + void setRangeBlocking( float minValue, float maxValue, float step, unsigned int precision ); + + float value() const; + + public slots: + virtual void setValue( float value ); + /** + * differs from the above in that it will block all signals + */ + virtual void setValueBlocking( float value ); + + protected: + virtual QString mapValueToText( int value ); + virtual int mapTextToValue( bool * ok ); + virtual void valueChange(); + + signals: + void valueChanged( float value ); + + private slots: + void slotValueChanged( int value ); + + private: + int m_factor; + int m_min; + int m_max; + int m_step; + bool m_doselection; +}; + +#endif diff --git a/kview/modules/scale/kview_scale.cpp b/kview/modules/scale/kview_scale.cpp new file mode 100644 index 00000000..aa8dec82 --- /dev/null +++ b/kview/modules/scale/kview_scale.cpp @@ -0,0 +1,180 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Matthias Kretz <kretz@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +/* $Id$ */ + +#include "kview_scale.h" +#include "scaledlg.h" + +#include <qimage.h> +#include <qvbox.h> + +#include <kaction.h> +#include <klocale.h> +#include <kgenericfactory.h> +#include <kdebug.h> +#include <kimageviewer/viewer.h> +#include <kimageviewer/canvas.h> +#include <kdialogbase.h> + +typedef KGenericFactory<KViewScale> KViewScaleFactory; +K_EXPORT_COMPONENT_FACTORY( kview_scale, KViewScaleFactory( "kview_scale" ) ) + +KViewScale::KViewScale( QObject* parent, const char* name, const QStringList & ) + : Plugin( parent, name ) + , m_pViewer( 0 ) + , m_pCanvas( 0 ) +{ + m_pViewer = static_cast<KImageViewer::Viewer *>( parent ); + if( m_pViewer ) + { + kdDebug( 4630 ) << "m_pViewer->canvas() = " << m_pViewer->canvas() << endl; + m_pCanvas = m_pViewer->canvas(); + + (void) new KAction( i18n( "&Scale Image..." ), 0, 0, + this, SLOT( slotScaleDlg() ), + actionCollection(), "plugin_scale" ); + } + else + kdWarning( 4630 ) << "no KImageViewer interface found - the scale plugin won't work" << endl; +} + +KViewScale::~KViewScale() +{ +} + +void KViewScale::slotScaleDlg() +{ + kdDebug( 4630 ) << k_funcinfo << endl; + KDialogBase dlg( m_pViewer->widget(), "KView scale dialog", true, i18n( "Scale Image" ), KDialogBase::Ok|KDialogBase::Cancel ); + ScaleDlg widget( m_pCanvas->imageSize(), dlg.makeVBoxMainWidget() ); +#if 0 + QVBox * layout = dlg.makeVBoxMainWidget(); + + QGroupBox * pixelgroup = new QGroupBox( i18n( "Pixel Dimensions" ), layout ); + QGridLayout * pixelgroupgrid = new QGridLayout( pixelgroup, 1, 1, 0, KDialog::spacingHint() ); + pixelgroupgrid->setSpacing( KDialog::spacingHint() ); + pixelgroupgrid->setMargin( KDialog::marginHint() ); + QLabel * label; + QSize imagesize = m_pCanvas->imageSize(); + + // show original width + label = new QLabel( i18n( "Original width:" ), pixelgroup ); + label->setAlignment( QLabel::AlignRight ); + pixelgroupgrid->addWidget( label, 0, 0 ); + pixelgroupgrid->addWidget( new QLabel( QString::number( imagesize.width() ), pixelgroup ), 0, 1 ); + label = new QLabel( i18n( "Height:" ), pixelgroup ); + label->setAlignment( QLabel::AlignRight ); + pixelgroupgrid->addWidget( label, 1, 0 ); + pixelgroupgrid->addWidget( new QLabel( QString::number( imagesize.height() ), pixelgroup ), 1, 1 ); + + pixelgroupgrid->addRowSpacing( 2, KDialog::spacingHint() ); + + label = new QLabel( i18n( "New width:" ), pixelgroup ); + label->setAlignment( QLabel::AlignRight ); + pixelgroupgrid->addWidget( label, 3, 0 ); + label = new QLabel( i18n( "Height:" ), pixelgroup ); + label->setAlignment( QLabel::AlignRight ); + pixelgroupgrid->addWidget( label, 4, 0 ); + QSpinBox * newwidth = new QSpinBox( 1, 100000, 1, pixelgroup ); + pixelgroupgrid->addWidget( newwidth, 3, 1 ); + QSpinBox * newheight = new QSpinBox( 1, 100000, 1, pixelgroup ); + pixelgroupgrid->addWidget( newheight, 4, 1 ); + KComboBox * newsizeunit = new KComboBox( pixelgroup ); + newsizeunit->insertItem( i18n( "px" ) ); + newsizeunit->insertItem( i18n( "%" ) ); + pixelgroupgrid->addMultiCellWidget( newsizeunit, 3, 4, 2, 2, Qt::AlignVCenter ); + + pixelgroupgrid->addRowSpacing( 5, KDialog::spacingHint() ); + + label = new QLabel( i18n( "Ratio X:" ), pixelgroup ); + label->setAlignment( QLabel::AlignRight ); + pixelgroupgrid->addWidget( label, 6, 0 ); + label = new QLabel( i18n( "Y:" ), pixelgroup ); + label->setAlignment( QLabel::AlignRight ); + pixelgroupgrid->addWidget( label, 7, 0 ); + QSpinBox * ratiox = new QSpinBox( pixelgroup ); + ratiox->setValidator( new QDoubleValidator( 0.0001, 10000, 4, ratiox ) ); + pixelgroupgrid->addWidget( ratiox, 6, 1 ); + QSpinBox * ratioy = new QSpinBox( pixelgroup ); + ratioy->setValidator( new QDoubleValidator( 0.0001, 10000, 4, ratioy ) ); + pixelgroupgrid->addWidget( ratioy, 7, 1 ); + pixelgroupgrid->addMultiCellWidget( new QCheckBox( i18n( "Link" ), pixelgroup ), 6, 7, 2, 2, Qt::AlignVCenter ); + + QGroupBox * printgroup = new QGroupBox( i18n( "Print Size && Display Units" ), layout ); + QGridLayout * printgroupgrid = new QGridLayout( printgroup, 1, 1, 0, KDialog::spacingHint() ); + printgroupgrid->setSpacing( KDialog::spacingHint() ); + printgroupgrid->setMargin( KDialog::marginHint() ); + + label = new QLabel( i18n( "New width:" ), printgroup ); + label->setAlignment( QLabel::AlignRight ); + printgroupgrid->addWidget( label, 0, 0 ); + label = new QLabel( i18n( "Height:" ), printgroup ); + label->setAlignment( QLabel::AlignRight ); + printgroupgrid->addWidget( label, 1, 0 ); + QSpinBox * newwidth2 = new QSpinBox( printgroup ); + printgroupgrid->addWidget( newwidth2, 0, 1 ); + QSpinBox * newheight2 = new QSpinBox( printgroup ); + printgroupgrid->addWidget( newheight2, 1, 1 ); + KComboBox * newsizeunit2 = new KComboBox( printgroup ); + newsizeunit2->insertItem( i18n( "in" ) ); + newsizeunit2->insertItem( i18n( "mm" ) ); + printgroupgrid->addMultiCellWidget( newsizeunit2, 0, 1, 2, 2, Qt::AlignVCenter ); + + printgroupgrid->addRowSpacing( 2, KDialog::spacingHint() ); + + label = new QLabel( i18n( "Resolution X:" ), printgroup ); + label->setAlignment( QLabel::AlignRight ); + printgroupgrid->addWidget( label, 3, 0 ); + label = new QLabel( i18n( "Y:" ), printgroup ); + label->setAlignment( QLabel::AlignRight ); + printgroupgrid->addWidget( label, 4, 0 ); + QSpinBox * resx = new QSpinBox( printgroup ); + printgroupgrid->addWidget( resx, 3, 1 ); + QSpinBox * resy = new QSpinBox( printgroup ); + printgroupgrid->addWidget( resy, 4, 1 ); + printgroupgrid->addMultiCellWidget( new QCheckBox( i18n( "Link" ), printgroup ), 3, 4, 2, 2, Qt::AlignVCenter ); + //KComboBox * newsizeunit2 = new KComboBox( printgroup ); + //newsizeunit2->insertItem( i18n( "in" ) ); + //newsizeunit2->insertItem( i18n( "mm" ) ); + //printgroupgrid->addMultiCellWidget( newsizeunit2, 0, 1, 2, 2, Qt::AlignVCenter ); +#endif + + dlg.exec(); +} + +void KViewScale::slotScale() +{ + // retrieve current image + kdDebug( 4630 ) << "m_pCanvas = " << m_pCanvas << endl; + const QImage * image = m_pCanvas->image(); + kdDebug( 4630 ) << "image pointer retrieved" << endl; + if( image ) + { + // scale + QImage newimage = image->smoothScale( 50, 50 ); + // put back (modified) + m_pCanvas->setImage( newimage ); + m_pViewer->setModified( true ); + } + else + kdDebug( 4630 ) << "no image to scale" << endl; +} + +// vim:sw=4:ts=4:cindent +#include "kview_scale.moc" diff --git a/kview/modules/scale/kview_scale.desktop b/kview/modules/scale/kview_scale.desktop new file mode 100644 index 00000000..6dd11c40 --- /dev/null +++ b/kview/modules/scale/kview_scale.desktop @@ -0,0 +1,127 @@ +[Desktop Entry] +Name=Scale +Name[af]=Skaal +Name[ar]=تكبير أو تصغير +Name[bg]=Мащабиране +Name[br]=Skeulaet +Name[bs]=Skaliraj +Name[ca]=Escala +Name[cs]=Změna měřítka +Name[cy]=Graddfa +Name[da]=Skala +Name[de]=Skalierer +Name[el]=Κλιμάκωση +Name[eo]=Grandecŝanĝo +Name[et]=Skaleerija +Name[eu]=Eskalatu +Name[fa]=مقیاس +Name[fi]=Skaalaa +Name[fr]=Échelle +Name[ga]=Scála +Name[gl]=Redimensionar +Name[he]=קנה מידה +Name[hi]=स्केल +Name[hr]=Skala +Name[hu]=Nagyítás +Name[is]=Skala +Name[it]=Riscala +Name[ja]=スケール +Name[kk]=Масштабтау +Name[km]=ធ្វើមាត្រដ្ឋាន +Name[lt]=Mąstelis +Name[ms]=Skala +Name[nb]=Skaler +Name[nds]=Grött-Topasser +Name[ne]=स्केल +Name[nl]=Schaalprogramma +Name[nn]=Skaler +Name[nso]=Sekala +Name[pa]=ਸਕੇਲ +Name[pl]=Skala +Name[pt]=Redimensionamento +Name[pt_BR]=Escala +Name[ro]=Scalare +Name[ru]=Масштабирование +Name[se]=Skále +Name[sk]=Škálovač +Name[sl]=Raztegni +Name[sr]=Скалирање +Name[sr@Latn]=Skaliranje +Name[sv]=Skala +Name[ta]=அளவுக்கோல் +Name[tg]=Масштабонӣ +Name[tr]=Oranla +Name[uk]=Масштаб +Name[ven]=Tshikeili +Name[wa]=Al schåle +Name[xh]=Isikali +Name[zh_CN]=缩放 +Name[zh_HK]=縮放 +Name[zh_TW]=縮放 +Name[zu]=Isikali +Comment=Filter to scale the image +Comment[af]=Filter na skaal die beeld +Comment[ar]=فلتر لتكبير أو تصغير الصورة +Comment[bg]=Филтър за мащабиране на изображения +Comment[bs]=Filter za skaliranje slike +Comment[ca]=Filtre per escalar la imatge +Comment[cs]=Filtr ke změně měřítka obrázku +Comment[cy]=Hidl i raddio'r ddelwedd +Comment[da]=Filter til at skalere billedet +Comment[de]=Ein Filter zum Skalieren von Bildern +Comment[el]=Φίλτρο για την κλιμάκωση της εικόνας +Comment[eo]=por ŝanĝi la grandecon de la bildo +Comment[es]=Filtro para cambiar la escala de una imagen +Comment[et]=Filter piltide skaleerimiseks +Comment[eu]=Eskalatu irudia +Comment[fa]=پالایه برای مقیاس کردن تصویر +Comment[fi]=Suodatin kuvan skaalaamiseen +Comment[fr]=Filtre pour zoomer une image +Comment[gl]=Filtro para redimensionar a imaxe +Comment[he]=מסנן לשינוי קנה המידה של התמונה +Comment[hi]=छवि का आकार बदलने का फ़िल्टर +Comment[hr]=Filter za promjenu veličine slike +Comment[hu]=Képméretező szűrő +Comment[is]=Sía sem skalar myndina +Comment[it]=Filtro per ridimensionare l'immagine +Comment[ja]=画像をスケールするフィルタ +Comment[kk]=Кескідерді масштабтау сүзгісі +Comment[km]=តម្រងធ្វើមាត្រដ្ឋានរូបភាព +Comment[lt]=Filtras paveikslėliui didinti ar mažinti +Comment[ms]=Tapis untuk menskalakan imej +Comment[nb]=Filter for skalering av bildet +Comment[nds]=En Filter för't Topassen vun de Bildgrött +Comment[ne]=छवि मापन गर्न फिल्टर +Comment[nl]=Filter om de afbeelding te schalen +Comment[nn]=Filter for skalering av biletet +Comment[nso]=Sesekodi sago kala ponagalo +Comment[pl]=Filtr do skalowania obrazków +Comment[pt]=Um filtro para escalar a imagem +Comment[pt_BR]=Filtro para escalar a imagem +Comment[ro]=Filtru de scalat imaginea +Comment[ru]=Фильтр для масштабирования изображений +Comment[se]=Silli mii skálere govaid +Comment[sk]=Filter pre zväčšenie obrázku +Comment[sl]=Filter za raztegovanje slike +Comment[sr]=Филтер за промену величине слике +Comment[sr@Latn]=Filter za promenu veličine slike +Comment[sv]=Filter för att skala bilden +Comment[ta]=பிம்பத்தை மாற்றும் வடிகட்டி +Comment[tg]=Филтр барои масштабонии тасвирот +Comment[tr]=Resmi oranlamak için filtre +Comment[uk]=Фільтр для масштабування зображення +Comment[ven]=Faela yau kala tshifanyiso +Comment[wa]=Passete po mete l' imådje al schåle +Comment[xh]=Icebo lokucoca ulwelo lokukala umfanekiso +Comment[zh_CN]=缩放图像的滤镜 +Comment[zh_HK]=用來縮放影像的過濾器 +Comment[zh_TW]=用來縮放影像的濾鏡 +Comment[zu]=Hluza isithombe esikaleni +Type=Plugin + +[X-KDE Plugin Info] +Author=Matthias Kretz +Email=kretz@kde.org +PluginName=kview_scale +Category=Filter +Version=0.1 diff --git a/kview/modules/scale/kview_scale.h b/kview/modules/scale/kview_scale.h new file mode 100644 index 00000000..2022f0ac --- /dev/null +++ b/kview/modules/scale/kview_scale.h @@ -0,0 +1,48 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Matthias Kretz <kretz@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +/* $Id$ */ + +#ifndef __kview_scale_h +#define __kview_scale_h + +#include <kparts/plugin.h> + +namespace KImageViewer { + class Viewer; + class Canvas; +} + +class KViewScale : public KParts::Plugin +{ + Q_OBJECT +public: + KViewScale( QObject* parent, const char* name, const QStringList & ); + virtual ~KViewScale(); + +private slots: + void slotScaleDlg(); + void slotScale(); + +private: + KImageViewer::Viewer * m_pViewer; + KImageViewer::Canvas * m_pCanvas; +}; + +// vim:sw=4:ts=4:cindent +#endif diff --git a/kview/modules/scale/kview_scale.rc b/kview/modules/scale/kview_scale.rc new file mode 100644 index 00000000..2f952be5 --- /dev/null +++ b/kview/modules/scale/kview_scale.rc @@ -0,0 +1,14 @@ +<!DOCTYPE kpartgui> +<kpartplugin name="kview_scale" library="kview_scale"> + <MenuBar> + <Menu name="image"><Text>&Image</Text> + <Action name="plugin_scale"/> + </Menu> + </MenuBar> + <!-- + <ToolBar name="extraToolBar"> + <text>&Extra Toolbar</text> + <Action name="plugin_scale"/> + </ToolBar> + --> +</kpartplugin> diff --git a/kview/modules/scale/scaledlg.cpp b/kview/modules/scale/scaledlg.cpp new file mode 100644 index 00000000..997be86d --- /dev/null +++ b/kview/modules/scale/scaledlg.cpp @@ -0,0 +1,311 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Matthias Kretz <kretz@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +// $Id$ + +#include "scaledlg.h" + +#include <qvbox.h> +#include <qlayout.h> +#include <qlabel.h> +#include <qspinbox.h> +#include <qcheckbox.h> +#include <qgroupbox.h> +#include <qsize.h> + +#include <kdebug.h> +#include <kcombobox.h> +#include <klocale.h> +#include <kdialog.h> +#include "kfloatspinbox.h" +#include <kglobal.h> + +#define ONEINCHINMM 2.54 + +ScaleDlg::ScaleDlg( const QSize & origsize, QVBox * parent, const char * name ) + : QObject( parent, name ) + , m_origsize( origsize ) + , m_newsizeunit( 0 ) + , m_newsizeunit2( 0 ) + , m_resolutionunit( 0 ) + , m_newwidth( origsize.width() ) + , m_newheight( origsize.height() ) + , m_resx( 72 ) + , m_resy( 72 ) +{ + QGroupBox * pixelgroup = new QGroupBox( i18n( "Pixel Dimensions" ), parent ); + QGroupBox * printgroup = new QGroupBox( i18n( "Print Size && Display Units" ), parent ); + + QGridLayout * pixelgroupgrid = new QGridLayout( pixelgroup, 1, 1, + KDialog::marginHint(), KDialog::spacingHint() ); + QGridLayout * printgroupgrid = new QGridLayout( printgroup, 1, 1, + KDialog::marginHint(), KDialog::spacingHint() ); + + QLabel * label; + + pixelgroupgrid->addRowSpacing( 0, KDialog::spacingHint() ); + + label = new QLabel( i18n( "Original width:" ), pixelgroup ); + label->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); + pixelgroupgrid->addWidget( label, 1, 0 ); + label = new QLabel( i18n( "Height:" ), pixelgroup ); + label->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); + pixelgroupgrid->addWidget( label, 2, 0 ); + + pixelgroupgrid->addRowSpacing( 3, KDialog::spacingHint() ); + + label = new QLabel( i18n( "New width:" ), pixelgroup ); + label->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); + pixelgroupgrid->addWidget( label, 4, 0 ); + label = new QLabel( i18n( "Height:" ), pixelgroup ); + label->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); + pixelgroupgrid->addWidget( label, 5, 0 ); + + pixelgroupgrid->addRowSpacing( 6, KDialog::spacingHint() ); + + label = new QLabel( i18n( "Ratio X:" ), pixelgroup ); + label->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); + pixelgroupgrid->addWidget( label, 7, 0 ); + label = new QLabel( i18n( "Y:" ), pixelgroup ); + label->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); + pixelgroupgrid->addWidget( label, 8, 0 ); + + printgroupgrid->addRowSpacing( 0, KDialog::spacingHint() ); + + label = new QLabel( i18n( "New width:" ), printgroup ); + label->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); + printgroupgrid->addWidget( label, 1, 0 ); + label = new QLabel( i18n( "Height:" ), printgroup ); + label->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); + printgroupgrid->addWidget( label, 2, 0 ); + + printgroupgrid->addRowSpacing( 3, KDialog::spacingHint() ); + + label = new QLabel( i18n( "Resolution X:" ), printgroup ); + label->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); + printgroupgrid->addWidget( label, 4, 0 ); + label = new QLabel( i18n( "Y:" ), printgroup ); + label->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); + printgroupgrid->addWidget( label, 5, 0 ); + + m_pOldWidth = new QLabel( QString::number( origsize.width() ), pixelgroup ); + m_pOldWidth->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); + pixelgroupgrid->addWidget( m_pOldWidth, 1, 1 ); + m_pOldHeight = new QLabel( QString::number( origsize.height() ), pixelgroup ); + m_pOldHeight->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); + pixelgroupgrid->addWidget( m_pOldHeight, 2, 1 ); + + m_pNewWidth = new KFloatSpinBox( 1.0, 100000.0, 10.0, 0, pixelgroup ); + pixelgroupgrid->addWidget( m_pNewWidth, 4, 1 ); + m_pNewHeight = new KFloatSpinBox( 1.0, 100000.0, 10.0, 0, pixelgroup ); + pixelgroupgrid->addWidget( m_pNewHeight, 5, 1 ); + + m_pNewSizeUnit = new KComboBox( pixelgroup ); + m_pNewSizeUnit->insertItem( i18n( "px" ) ); + m_pNewSizeUnit->insertItem( i18n( "%" ) ); + pixelgroupgrid->addMultiCellWidget( m_pNewSizeUnit, 4, 5, 2, 2, Qt::AlignVCenter ); + + m_pRatioX = new KFloatSpinBox( 0.0001, 10000.0, 0.1, 4, pixelgroup ); + pixelgroupgrid->addWidget( m_pRatioX, 7, 1 ); + m_pRatioY = new KFloatSpinBox( 0.0001, 10000.0, 0.1, 4, pixelgroup ); + pixelgroupgrid->addWidget( m_pRatioY, 8, 1 ); + + m_pLinkRatio = new QCheckBox( i18n( "Link" ), pixelgroup ); + pixelgroupgrid->addMultiCellWidget( m_pLinkRatio, 7, 8, 2, 2, Qt::AlignVCenter ); + + m_pNewWidth2 = new KFloatSpinBox( 0.0001, 10000.0, 0.1, 4, printgroup ); + printgroupgrid->addWidget( m_pNewWidth2, 1, 1 ); + m_pNewHeight2 = new KFloatSpinBox( 0.0001, 10000.0, 0.1, 4, printgroup ); + printgroupgrid->addWidget( m_pNewHeight2, 2, 1 ); + + m_pNewSizeUnit2 = new KComboBox( printgroup ); + m_pNewSizeUnit2->insertItem( i18n( "in" ) ); + m_pNewSizeUnit2->insertItem( i18n( "mm" ) ); + printgroupgrid->addMultiCellWidget( m_pNewSizeUnit2, 1, 2, 2, 2, Qt::AlignVCenter ); + + m_pResolutionX = new KFloatSpinBox( 0.0001, 6000.0, 1.0, 4, printgroup ); + printgroupgrid->addWidget( m_pResolutionX, 4, 1 ); + m_pResolutionY = new KFloatSpinBox( 0.0001, 6000.0, 1.0, 4, printgroup ); + printgroupgrid->addWidget( m_pResolutionY, 5, 1 ); + + m_pLinkResolution = new QCheckBox( i18n( "Link" ), printgroup ); + printgroupgrid->addMultiCellWidget( m_pLinkResolution, 4, 5, 2, 2, Qt::AlignVCenter ); + m_pResolutionUnit = new KComboBox( printgroup ); + m_pResolutionUnit->insertItem( i18n( "pixels/in" ) ); + m_pResolutionUnit->insertItem( i18n( "pixels/mm" ) ); + printgroupgrid->addMultiCellWidget( m_pResolutionUnit, 6, 6, 1, 2, Qt::AlignLeft ); + + m_pNewWidth->setValue( m_origsize.width() ); + m_pNewHeight->setValue( m_origsize.height() ); + + m_newsizeunit = 0; + m_newsizeunit2 = 0; + m_resolutionunit = 0; + + connect( m_pNewWidth, SIGNAL( valueChanged( float ) ), SLOT( slotNewWidth( float ) ) ); + connect( m_pNewHeight, SIGNAL( valueChanged( float ) ), SLOT( slotNewHeight( float ) ) ); + connect( m_pNewWidth2, SIGNAL( valueChanged( float ) ), SLOT( slotNewWidth2( float ) ) ); + connect( m_pNewHeight2, SIGNAL( valueChanged( float ) ), SLOT( slotNewHeight2( float ) ) ); + connect( m_pResolutionX, SIGNAL( valueChanged( float ) ), SLOT( slotResolutionX( float ) ) ); + connect( m_pResolutionY, SIGNAL( valueChanged( float ) ), SLOT( slotResolutionY( float ) ) ); + + connect( m_pNewSizeUnit, SIGNAL( activated( int ) ), SLOT( slotChangeNewSizeUnit( int ) ) ); + connect( m_pNewSizeUnit2, SIGNAL( activated( int ) ), SLOT( slotChangeNewSizeUnit2( int ) ) ); + connect( m_pResolutionUnit, SIGNAL( activated( int ) ), SLOT( slotChangeResolutionUnit( int ) ) ); +} + +ScaleDlg::~ScaleDlg() +{ +} + +void ScaleDlg::slotNewWidth( float newval ) +{ + float newwidth; + switch( m_newsizeunit ) + { + case 0: // Pixel + newwidth = newval; + break; + case 1: // Percent + newwidth = newval / 100.0 * m_origsize.width(); + break; + default: + kdError( 4630 ) << "unknown unit\n"; + break; + } + + m_newwidth = newwidth; + m_pNewWidth2->setValueBlocking( m_newwidth / m_resx / ( m_newsizeunit2 ? ONEINCHINMM : 1 ) ); + m_pRatioX->setValueBlocking( m_newwidth / m_origsize.width() ); + if( m_pLinkRatio->isChecked() ) + { + m_newheight = m_newwidth / m_origsize.width() * m_origsize.height(); + m_pNewHeight->setValueBlocking( m_newheight * ( m_newsizeunit ? 100.0 / m_origsize.height() : 1 ) ); + m_pRatioY->setValueBlocking( m_newheight / m_origsize.height() ); + m_pNewHeight2->setValueBlocking( m_newheight / m_resy / ( m_newsizeunit2 ? ONEINCHINMM : 1 ) ); + } +} + +void ScaleDlg::slotNewHeight( float newval ) +{ +} + +void ScaleDlg::slotNewWidth2( float newval ) +{ +} + +void ScaleDlg::slotNewHeight2( float newval ) +{ +} + +void ScaleDlg::slotResolutionX( float newval ) +{ +} + +void ScaleDlg::slotResolutionY( float newval ) +{ +} + +void ScaleDlg::slotChangeNewSizeUnit( int index ) +{ + if( m_newsizeunit == index ) + return; + + m_newsizeunit = index; + + switch( m_newsizeunit ) + { + case 0: + // Pixel + m_pNewWidth->setRange( 1.0, 100000.0, 10.0, 0 ); + m_pNewHeight->setRange( 1.0, 100000.0, 10.0, 0 ); + m_pNewWidth->setValueBlocking( m_newwidth ); + m_pNewHeight->setValueBlocking( m_newheight ); + break; + case 1: + // Percent + m_pNewWidth->setRange( 0.0001, 100000.0, 0.1, 4 ); + m_pNewHeight->setRange( 0.0001, 100000.0, 0.1, 4 ); + m_pNewWidth->setValueBlocking( m_newwidth * 100.0 / m_origsize.width() ); + m_pNewHeight->setValueBlocking( m_newheight * 100.0 / m_origsize.height() ); + break; + default: + kdError( 4630 ) << "change to unknown unit\n"; + break; + } +} + +void ScaleDlg::slotChangeNewSizeUnit2( int index ) +{ + if( m_newsizeunit2 == index ) + return; + + m_newsizeunit2 = index; + + switch( m_newsizeunit2 ) + { + case 0: + // Inch + m_pNewWidth2->setRange( 0.0001, 10000.0, 0.1, 4 ); + m_pNewHeight2->setRange( 0.0001, 10000.0, 0.1, 4 ); + m_pNewWidth2->setValueBlocking( m_newwidth / m_resx ); + m_pNewHeight2->setValueBlocking( m_newheight / m_resy ); + break; + case 1: + // Millimeter + m_pNewWidth2->setRange( 0.0002, 25400.0, 0.1, 4 ); + m_pNewHeight2->setRange( 0.0002, 25400.0, 0.1, 4 ); + m_pNewWidth2->setValueBlocking( m_newwidth / m_resx / ONEINCHINMM ); + m_pNewHeight2->setValueBlocking( m_newheight / m_resy / ONEINCHINMM ); + break; + default: + kdError( 4630 ) << "change to unknown unit\n"; + break; + } +} + +void ScaleDlg::slotChangeResolutionUnit( int index ) +{ + if( m_resolutionunit == index ) + return; + + m_resolutionunit = index; + + switch( m_resolutionunit ) + { + case 0: + // Pixels per Inch + m_pResolutionX->setRange( 0.0002, 25400.0, 0.1, 4 ); + m_pResolutionY->setRange( 0.0002, 25400.0, 0.1, 4 ); + m_pResolutionX->setValueBlocking( m_resx ); + m_pResolutionY->setValueBlocking( m_resy ); + break; + case 1: + // Pixels per Millimeter + m_pResolutionX->setRange( 0.0001, 10000.0, 0.1, 4 ); + m_pResolutionY->setRange( 0.0001, 10000.0, 0.1, 4 ); + m_pResolutionX->setValueBlocking( m_resx / ONEINCHINMM ); + m_pResolutionY->setValueBlocking( m_resy / ONEINCHINMM ); + break; + default: + kdError( 4630 ) << "change to unknown unit\n"; + break; + } +} + +#include "scaledlg.moc" diff --git a/kview/modules/scale/scaledlg.h b/kview/modules/scale/scaledlg.h new file mode 100644 index 00000000..ac5a6c44 --- /dev/null +++ b/kview/modules/scale/scaledlg.h @@ -0,0 +1,78 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Matthias Kretz <kretz@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +// $Id$ + +#ifndef __scaledlg_h_ +#define __scaledlg_h_ + +#include <qobject.h> + +class QLabel; +class KFloatSpinBox; +class KComboBox; +class QCheckBox; +class QVBox; +class QSize; + +class ScaleDlg : public QObject +{ + Q_OBJECT + public: + ScaleDlg( const QSize & originalsize, QVBox * parent, const char * name = 0 ); + ~ScaleDlg(); + + private slots: + void slotNewWidth( float ); + void slotNewHeight( float ); + void slotNewWidth2( float ); + void slotNewHeight2( float ); + void slotResolutionX( float ); + void slotResolutionY( float ); + void slotChangeNewSizeUnit( int ); + void slotChangeNewSizeUnit2( int ); + void slotChangeResolutionUnit( int ); + + private: + QSize m_origsize; + int m_newsizeunit; + int m_newsizeunit2; + int m_resolutionunit; + + float m_newwidth, m_newheight; // in Pixel + float m_resx, m_resy; // in dpi + + QLabel * m_pOldWidth; + QLabel * m_pOldHeight; + KFloatSpinBox * m_pNewWidth; + KFloatSpinBox * m_pNewHeight; + KComboBox * m_pNewSizeUnit; + KFloatSpinBox * m_pRatioX; + KFloatSpinBox * m_pRatioY; + QCheckBox * m_pLinkRatio; + + KFloatSpinBox * m_pNewWidth2; + KFloatSpinBox * m_pNewHeight2; + KComboBox * m_pNewSizeUnit2; + KFloatSpinBox * m_pResolutionX; + KFloatSpinBox * m_pResolutionY; + QCheckBox * m_pLinkResolution; + KComboBox * m_pResolutionUnit; +}; + +#endif |