diff options
Diffstat (limited to 'src/utilities/imageeditor/tools')
-rw-r--r-- | src/utilities/imageeditor/tools/Makefile.am | 19 | ||||
-rw-r--r-- | src/utilities/imageeditor/tools/imageprint.cpp | 814 | ||||
-rw-r--r-- | src/utilities/imageeditor/tools/imageprint.h | 122 | ||||
-rw-r--r-- | src/utilities/imageeditor/tools/imageresize.cpp | 650 | ||||
-rw-r--r-- | src/utilities/imageeditor/tools/imageresize.h | 82 |
5 files changed, 1687 insertions, 0 deletions
diff --git a/src/utilities/imageeditor/tools/Makefile.am b/src/utilities/imageeditor/tools/Makefile.am new file mode 100644 index 00000000..b76207ff --- /dev/null +++ b/src/utilities/imageeditor/tools/Makefile.am @@ -0,0 +1,19 @@ +METASOURCES = AUTO + +noinst_LTLIBRARIES = libdimgeditortools.la + +libdimgeditortools_la_SOURCES = imageresize.cpp imageprint.cpp + +libdimgeditortools_la_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_TDEPRINT) + +INCLUDES= -I$(top_srcdir)/src/digikam \ + -I$(top_srcdir)/src/libs/dimg \ + -I$(top_srcdir)/src/libs/dimg/filters \ + -I$(top_srcdir)/src/libs/dmetadata \ + -I$(top_srcdir)/src/libs/widgets/common \ + -I$(top_srcdir)/src/libs/greycstoration \ + -I$(top_srcdir)/src/utilities/imageeditor/canvas \ + -I$(top_srcdir)/src/utilities/imageeditor/editor \ + $(LIBKDCRAW_CFLAGS) \ + $(all_includes) + diff --git a/src/utilities/imageeditor/tools/imageprint.cpp b/src/utilities/imageeditor/tools/imageprint.cpp new file mode 100644 index 00000000..5cab236b --- /dev/null +++ b/src/utilities/imageeditor/tools/imageprint.cpp @@ -0,0 +1,814 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2004-07-13 + * Description : image editor printing interface. + * + * Copyright (C) 2006 by F.J. Cruz <[email protected]> + * Copyright (C) 2004-2007 by Gilles Caulier <caulier dot gilles at gmail dot com> + * + * KeepRatio and Alignment options imported from Gwenview program. + * Copyright (c) 2003 Angelo Naselli <anaselli at linux dot it> + * + * Original printing code from Kuickshow program. + * Copyright (C) 2002 Carsten Pfeiffer <pfeiffer at kde.org> + * + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; + * either version 2, or (at your option) + * any later version. + * + * 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. + * + * ============================================================ */ + +// TQt includes. + +#include <tqobject.h> +#include <tqpixmap.h> +#include <tqlayout.h> +#include <tqgroupbox.h> +#include <tqbuttongroup.h> +#include <tqstring.h> +#include <tqsize.h> +#include <tqcursor.h> +#include <tqlabel.h> +#include <tqhbox.h> +#include <tqcheckbox.h> +#include <tqfont.h> +#include <tqgrid.h> +#include <tqimage.h> +#include <tqpaintdevicemetrics.h> +#include <tqpainter.h> +#include <tqradiobutton.h> +#include <tqvbuttongroup.h> +#include <tqcolor.h> +#include <tqcombobox.h> +#include <tqstyle.h> +#include <tqpushbutton.h> + +// KDE includes. + +#include <tdelocale.h> +#include <tdemessagebox.h> +#include <kstandarddirs.h> +#include <tdeapplication.h> +#include <tdeconfig.h> +#include <kimageio.h> +#include <kcombobox.h> +#include <tdeglobalsettings.h> +#include <knuminput.h> +#include <kprinter.h> +#include <tdetempfile.h> +#include <kpropertiesdialog.h> + +// Local includes. + +#include "ddebug.h" +#include "dimg.h" +#include "editorwindow.h" +#include "icctransform.h" +#include "imageprint.h" +#include "imageprint.moc" + +namespace Digikam +{ + +class ImagePrintPrivate +{ + +public: + + ImagePrintPrivate(){} + + TQString filename; + TQString inProfilePath; + TQString outputProfilePath; + + DImg image; +}; + +ImagePrint::ImagePrint(DImg& image, KPrinter& printer, const TQString& filename) + : m_printer(printer) +{ + d = new ImagePrintPrivate(); + d->image = image; + d->filename = filename; +} + +ImagePrint::~ImagePrint() +{ + delete d; +} + +bool ImagePrint::printImageWithTQt() +{ + if ( d->image.isNull() ) + { + DWarning() << "Supplied Image for printing is null" << endl; + return false; + } + + TQString t = "true"; + TQString f = "false"; + + if (m_printer.option( "app-imageeditor-color-managed") != f) + { + IccTransform *transform = new IccTransform(); + readSettings(); + + if (d->image.getICCProfil().isNull()) + { + transform->setProfiles( d->inProfilePath, d->outputProfilePath ); + } + else + { + transform->setProfiles(d->outputProfilePath); + } + + transform->apply( d->image ); + } + + TQImage image2Print = d->image.copyTQImage(); + + // Black & white print ? + if ( m_printer.option( "app-imageeditor-blackwhite" ) != f) + { + image2Print = image2Print.convertDepth( 1, TQt::MonoOnly | + TQt::ThresholdDither | + TQt::AvoidDither ); + } + + TQPainter p; + p.begin( &m_printer ); + + TQPaintDeviceMetrics metrics( &m_printer ); + p.setFont( TDEGlobalSettings::generalFont() ); + TQFontMetrics fm = p.fontMetrics(); + + int w, h; // will be set to the width and height of the printer + // when the orientation is decided. + w = metrics.width(); + h = metrics.height(); + int filenameOffset = 0; + + TQSize size = image2Print.size(); + + bool printFilename = m_printer.option( "app-imageeditor-printFilename" ) != f; + if ( printFilename ) + { + // filename goes into one line! + filenameOffset = fm.lineSpacing() + 14; + h -= filenameOffset; + } + + if ( m_printer.option( "app-imageeditor-scaleToFit" ) != f ) + { + if ( m_printer.option( "app-imageeditor-auto-rotate" ) == t ) + m_printer.setOrientation( size.width() <= size.height() ? KPrinter::Portrait + : KPrinter::Landscape ); + + // Scale image to fit pagesize + size.scale( w, h, TQSize::ScaleMin ); + } + else + { + int unit = (m_printer.option("app-imageeditor-scale-unit").isEmpty() ? + ImageEditorPrintDialogPage::DK_INCHES : m_printer.option("app-imageeditor-scale-unit").toInt()); + double inches = 1; + + if (unit == ImageEditorPrintDialogPage::DK_MILLIMETERS) + { + inches = 1/25.4; + } + else if (unit == ImageEditorPrintDialogPage::DK_CENTIMETERS) + { + inches = 1/2.54; + } + + double wImg = (m_printer.option("app-imageeditor-scale-width").isEmpty() ? + 1 : m_printer.option("app-imageeditor-scale-width").toDouble()) * inches; + double hImg = (m_printer.option("app-imageeditor-scale-height").isEmpty() ? + 1 : m_printer.option("app-imageeditor-scale-height").toDouble()) * inches; + size.setWidth( int(wImg * m_printer.resolution()) ); + size.setHeight( int(hImg * m_printer.resolution()) ); + + if ( m_printer.option( "app-imageeditor-auto-rotate" ) == t ) + m_printer.setOrientation( wImg <= hImg ? KPrinter::Portrait : KPrinter::Landscape ); + + if (size.width() > w || size.height() > h) + { + int resp = KMessageBox::warningYesNoCancel(TDEApplication::kApplication()->mainWidget(), + i18n("The image will not fit on the page, what do you want to do?"), + TQString(),KStdGuiItem::cont(), + i18n("Shrink") ); + + if (resp==KMessageBox::Cancel) + { + m_printer.abort(); + // no need to return false, user decided to abort + return true; + } + else if (resp == KMessageBox::No) + { // Shrink + size.scale(w, h, TQSize::ScaleMin); + } + } + } + + // Align image. + int alignment = (m_printer.option("app-imageeditor-alignment").isEmpty() ? + TQt::AlignCenter : m_printer.option("app-imageeditor-alignment").toInt()); + + int x = 0; + int y = 0; + + // x - alignment + if ( alignment & TQt::AlignHCenter ) + x = (w - size.width())/2; + else if ( alignment & TQt::AlignLeft ) + x = 0; + else if ( alignment & TQt::AlignRight ) + x = w - size.width(); + + // y - alignment + if ( alignment & TQt::AlignVCenter ) + y = (h - size.height())/2; + else if ( alignment & TQt::AlignTop ) + y = 0; + else if ( alignment & TQt::AlignBottom ) + y = h - size.height(); + + // Perform the actual drawing. + p.drawImage( TQRect( x, y, size.width(), size.height()), image2Print ); + + if ( printFilename ) + { + TQString fname = minimizeString( d->filename, fm, w ); + + if ( !fname.isEmpty() ) + { + int fw = fm.width( fname ); + int x = (w - fw)/2; + int y = metrics.height() - filenameOffset/2; + p.drawText( x, y, fname ); + } + } + + p.end(); + + return true; +} + +TQString ImagePrint::minimizeString( TQString text, const TQFontMetrics& metrics, + int maxWidth ) +{ + // no sense to cut that tiny little string + if ( text.length() <= 5 ) + return TQString(); + + bool changed = false; + + while ( metrics.width( text ) > maxWidth ) + { + int mid = text.length() / 2; + // remove 2 characters in the middle + text.remove( mid, 2 ); + changed = true; + } + + // add "..." in the middle + if ( changed ) + { + int mid = text.length() / 2; + + // sanity check + if ( mid <= 5 ) + return TQString(); + + text.replace( mid - 1, 3, "..." ); + } + + return text; +} + +void ImagePrint::readSettings() +{ + TDEConfig* config = kapp->config(); + + config->setGroup("Color Management"); + + d->inProfilePath = config->readPathEntry("WorkSpaceProfile"); + d->outputProfilePath = config->readPathEntry("ProofProfileFile"); +} + +// Image print dialog class ------------------------------------------------------------- + +class ImageEditorPrintDialogPagePrivate +{ + +public: + + ImageEditorPrintDialogPagePrivate() + { + cmEnabled = false; + position = 0; + keepRatio = 0; + scaleToFit = 0; + scale = 0; + addFileName = 0; + blackwhite = 0; + autoRotate = 0; + colorManaged = 0; + cmPreferences = 0; + parent = 0; + width = 0; + height = 0; + units = 0; + } + + bool cmEnabled; + + TQRadioButton *scaleToFit; + TQRadioButton *scale; + + TQCheckBox *keepRatio; + TQCheckBox *addFileName; + TQCheckBox *blackwhite; + TQCheckBox *autoRotate; + TQCheckBox *colorManaged; + + TQPushButton *cmPreferences; + + TQWidget *parent; + + KDoubleNumInput *width; + KDoubleNumInput *height; + + KComboBox *position; + KComboBox *units; + + DImg image; + + ImageEditorPrintDialogPage::Unit previousUnit; +}; + +ImageEditorPrintDialogPage::ImageEditorPrintDialogPage(DImg& image, TQWidget *parent, const char *name ) + : KPrintDialogPage( parent, name ) +{ + d = new ImageEditorPrintDialogPagePrivate; + d->image = image; + d->parent = parent; + setTitle( i18n("Image Settings") ); + + readSettings(); + + TQVBoxLayout *layout = new TQVBoxLayout( this ); + layout->setMargin( KDialog::marginHint() ); + layout->setSpacing( KDialog::spacingHint() ); + + // ------------------------------------------------------------------------ + + TQHBoxLayout *layout2 = new TQHBoxLayout( layout ); + layout2->setSpacing(3); + + TQLabel* textLabel = new TQLabel( this, "Image position:" ); + textLabel->setText( i18n( "Image position:" ) ); + layout2->addWidget( textLabel ); + d->position = new KComboBox( false, this, "Print position" ); + d->position->clear(); + d->position->insertItem( i18n( "Top-Left" ) ); + d->position->insertItem( i18n( "Top-Central" ) ); + d->position->insertItem( i18n( "Top-Right" ) ); + d->position->insertItem( i18n( "Central-Left" ) ); + d->position->insertItem( i18n( "Central" ) ); + d->position->insertItem( i18n( "Central-Right" ) ); + d->position->insertItem( i18n( "Bottom-Left" ) ); + d->position->insertItem( i18n( "Bottom-Central" ) ); + d->position->insertItem( i18n( "Bottom-Right" ) ); + layout2->addWidget( d->position ); + TQSpacerItem *spacer1 = new TQSpacerItem( 101, 21, TQSizePolicy::Expanding, TQSizePolicy::Minimum ); + layout2->addItem( spacer1 ); + + d->addFileName = new TQCheckBox( i18n("Print fi&lename below image"), this); + d->addFileName->setChecked( false ); + layout->addWidget( d->addFileName ); + + d->blackwhite = new TQCheckBox ( i18n("Print image in &black and white"), this); + d->blackwhite->setChecked( false ); + layout->addWidget (d->blackwhite ); + + d->autoRotate = new TQCheckBox( i18n("&Auto-rotate page"), this ); + d->autoRotate->setChecked( false ); + layout->addWidget( d->autoRotate ); + + // ------------------------------------------------------------------------ + + TQHBox *cmbox = new TQHBox(this); + + d->colorManaged = new TQCheckBox(i18n("Use Color Management for Printing"), cmbox); + d->colorManaged->setChecked( false ); + + d->cmPreferences = new TQPushButton(i18n("Settings..."), cmbox); + + TQWidget *space = new TQWidget(cmbox); + cmbox->setStretchFactor(space, 10); + cmbox->setSpacing(KDialog::spacingHint()); + + layout->addWidget(cmbox); + + // ------------------------------------------------------------------------ + + TQVButtonGroup *group = new TQVButtonGroup( i18n("Scaling"), this ); + group->setRadioButtonExclusive( true ); + layout->addWidget( group ); + + d->scaleToFit = new TQRadioButton( i18n("Scale image to &fit"), group ); + d->scaleToFit->setChecked( true ); + + d->scale = new TQRadioButton( i18n("Print e&xact size: "), group ); + + TQHBox *hb = new TQHBox( group ); + hb->setSpacing( KDialog::spacingHint() ); + TQWidget *w = new TQWidget(hb); + w->setFixedWidth(d->scale->style().subRect( TQStyle::SR_RadioButtonIndicator, d->scale ).width()); + + d->width = new KDoubleNumInput( hb, "exact width" ); + d->width->setMinValue( 1 ); + + new TQLabel( "x", hb ); + + d->height = new KDoubleNumInput( hb, "exact height" ); + d->height->setMinValue( 1 ); + + d->units = new KComboBox( false, hb, "unit combobox" ); + d->units->insertItem( i18n("Millimeters") ); + d->units->insertItem( i18n("Centimeters") ); + d->units->insertItem( i18n("Inches") ); + + d->keepRatio = new TQCheckBox( i18n("Keep ratio"), hb); + + w = new TQWidget(hb); + hb->setStretchFactor( w, 1 ); + d->previousUnit = DK_MILLIMETERS; + + // ------------------------------------------------------------------------ + + connect( d->colorManaged, TQ_SIGNAL(toggled(bool)), + this, TQ_SLOT(slotAlertSettings( bool )) ); + + connect( d->cmPreferences, TQ_SIGNAL(clicked()), + this, TQ_SLOT(slotSetupDlg()) ); + + connect( d->scale, TQ_SIGNAL( toggled( bool )), + this, TQ_SLOT( toggleScaling( bool ))); + + connect(d->width, TQ_SIGNAL( valueChanged( double )), + this, TQ_SLOT( slotWidthChanged( double ))); + + connect(d->height, TQ_SIGNAL( valueChanged( double )), + this, TQ_SLOT( slotHeightChanged( double ))); + + connect(d->keepRatio, TQ_SIGNAL( toggled( bool )), + this, TQ_SLOT( toggleRatio( bool ))); + + connect(d->units, TQ_SIGNAL(activated(const TQString &)), + this, TQ_SLOT(slotUnitChanged(const TQString& ))); +} + +ImageEditorPrintDialogPage::~ImageEditorPrintDialogPage() +{ + delete d; +} + +void ImageEditorPrintDialogPage::getOptions( TQMap<TQString,TQString>& opts, bool /*incldef*/ ) +{ + TQString t = "true"; + TQString f = "false"; + + opts["app-imageeditor-alignment"] = TQString::number(getPosition(d->position->currentText())); + opts["app-imageeditor-printFilename"] = d->addFileName->isChecked() ? t : f; + opts["app-imageeditor-blackwhite"] = d->blackwhite->isChecked() ? t : f; + opts["app-imageeditor-scaleToFit"] = d->scaleToFit->isChecked() ? t : f; + opts["app-imageeditor-scale"] = d->scale->isChecked() ? t : f; + opts["app-imageeditor-scale-unit"] = TQString::number(stringToUnit(d->units->currentText())); + opts["app-imageeditor-scale-width"] = TQString::number( d->width->value() ); + opts["app-imageeditor-scale-height"] = TQString::number( d->height->value() ); + opts["app-imageeditor-scale-KeepRatio"] = d->keepRatio->isChecked() ? t : f; + opts["app-imageeditor-auto-rotate"] = d->autoRotate->isChecked() ? t : f; + opts["app-imageeditor-color-managed"] = d->colorManaged->isChecked() ? t : f; +} + +void ImageEditorPrintDialogPage::setOptions( const TQMap<TQString,TQString>& opts ) +{ + TQString t = "true"; + TQString f = "false"; + TQString stVal; + bool ok; + double dVal; + int iVal; + + iVal = opts["app-imageeditor-alignment"].toInt( &ok ); + if (ok) + { + stVal = setPosition(iVal); + d->position->setCurrentItem(stVal); + } + + d->addFileName->setChecked( opts["app-imageeditor-printFilename"] != f ); + // This sound strange, but if I copy the code on the line above, the checkbox + // was always checked. And this is not the wanted behavior. So, with this works. + // KPrint magic ;-) + d->blackwhite->setChecked ( false ); + d->scaleToFit->setChecked( opts["app-imageeditor-scaleToFit"] != f ); + d->scale->setChecked( opts["app-imageeditor-scale"] == t ); + d->autoRotate->setChecked( opts["app-imageeditor-auto-rotate"] == t ); + + d->colorManaged->setChecked( false ); + + Unit unit = static_cast<Unit>( opts["app-imageeditor-scale-unit"].toInt( &ok ) ); + if (ok) + { + stVal = unitToString(unit); + d->units->setCurrentItem(stVal); + d->previousUnit = unit; + } + else + { + //for back compatibility + d->units->setCurrentItem(i18n("Millimeters")); + } + + dVal = opts["app-imageeditor-scale-width"].toDouble( &ok ); + + if ( ok ) + d->width->setValue( dVal ); + + dVal = opts["app-imageeditor-scale-height"].toDouble( &ok ); + + if ( ok ) + d->height->setValue( dVal ); + + if ( d->scale->isChecked() == d->scaleToFit->isChecked() ) + d->scaleToFit->setChecked( !d->scale->isChecked() ); + + d->keepRatio->setChecked( opts["app-imageeditor-scale-KeepRatio"] == t ); + +} +int ImageEditorPrintDialogPage::getPosition(const TQString& align) +{ + int alignment; + + if (align == i18n("Central-Left")) + { + alignment = TQt::AlignLeft | TQt::AlignVCenter; + } + else if (align == i18n("Central-Right")) + { + alignment = TQt::AlignRight | TQt::AlignVCenter; + } + else if (align == i18n("Top-Left")) + { + alignment = TQt::AlignTop | TQt::AlignLeft; + } + else if (align == i18n("Top-Right")) + { + alignment = TQt::AlignTop | TQt::AlignRight; + } + else if (align == i18n("Bottom-Left")) + { + alignment = TQt::AlignBottom | TQt::AlignLeft; + } + else if (align == i18n("Bottom-Right")) + { + alignment = TQt::AlignBottom | TQt::AlignRight; + } + else if (align == i18n("Top-Central")) + { + alignment = TQt::AlignTop | TQt::AlignHCenter; + } + else if (align == i18n("Bottom-Central")) + { + alignment = TQt::AlignBottom | TQt::AlignHCenter; + } + else + { + // Central + alignment = TQt::AlignCenter; // TQt::AlignHCenter || TQt::AlignVCenter + } + + return alignment; +} + +TQString ImageEditorPrintDialogPage::setPosition(int align) +{ + TQString alignment; + + if (align == (TQt::AlignLeft | TQt::AlignVCenter)) + { + alignment = i18n("Central-Left"); + } + else if (align == (TQt::AlignRight | TQt::AlignVCenter)) + { + alignment = i18n("Central-Right"); + } + else if (align == (TQt::AlignTop | TQt::AlignLeft)) + { + alignment = i18n("Top-Left"); + } + else if (align == (TQt::AlignTop | TQt::AlignRight)) + { + alignment = i18n("Top-Right"); + } + else if (align == (TQt::AlignBottom | TQt::AlignLeft)) + { + alignment = i18n("Bottom-Left"); + } + else if (align == (TQt::AlignBottom | TQt::AlignRight)) + { + alignment = i18n("Bottom-Right"); + } + else if (align == (TQt::AlignTop | TQt::AlignHCenter)) + { + alignment = i18n("Top-Central"); + } + else if (align == (TQt::AlignBottom | TQt::AlignHCenter)) + { + alignment = i18n("Bottom-Central"); + } + else + { + // Central: TQt::AlignCenter or (TQt::AlignHCenter || TQt::AlignVCenter) + alignment = i18n("Central"); + } + + return alignment; +} + +void ImageEditorPrintDialogPage::toggleScaling( bool enable ) +{ + d->width->setEnabled( enable ); + d->height->setEnabled( enable ); + d->units->setEnabled( enable ); + d->keepRatio->setEnabled( enable ); +} + +void ImageEditorPrintDialogPage::slotHeightChanged (double value) +{ + d->width->blockSignals(true); + d->height->blockSignals(true); + + if (d->keepRatio->isChecked()) + { + double width = (d->image.width() * value) / d->image.height(); + d->width->setValue( width ? width : 1.); + } + d->height->setValue(value); + + d->width->blockSignals(false); + d->height->blockSignals(false); +} + +void ImageEditorPrintDialogPage::slotWidthChanged (double value) +{ + d->width->blockSignals(true); + d->height->blockSignals(true); + + if (d->keepRatio->isChecked()) + { + double height = (d->image.height() * value) / d->image.width(); + d->height->setValue( height ? height : 1); + } + d->width->setValue(value); + + d->width->blockSignals(false); + d->height->blockSignals(false); +} + +void ImageEditorPrintDialogPage::toggleRatio( bool enable ) +{ + if (!enable) return; + // choosing a startup value of 15x10 cm (common photo dimention) + // mContent->mHeight->value() or mContent->mWidth->value() + // are usually empty at startup and hxw (0x0) is not good IMO keeping ratio + double hValue, wValue; + if (d->image.height() > d->image.width()) + { + hValue = d->height->value(); + if (!hValue) hValue = 150*unitToMM(d->previousUnit); + wValue = (d->image.width() * hValue)/ d->image.height(); + } + else + { + wValue = d->width->value(); + if (!wValue) wValue = 150*unitToMM(d->previousUnit); + hValue = (d->image.height() * wValue)/ d->image.width(); + } + + d->width->blockSignals(true); + d->height->blockSignals(true); + + d->width->setValue(wValue); + d->height->setValue(hValue); + + d->width->blockSignals(false); + d->height->blockSignals(false); +} + +void ImageEditorPrintDialogPage::slotUnitChanged(const TQString& string) +{ + Unit newUnit = stringToUnit(string); + double ratio = unitToMM(d->previousUnit) / unitToMM(newUnit); + + d->width->blockSignals(true); + d->height->blockSignals(true); + + d->width->setValue( d->width->value() * ratio); + d->height->setValue( d->height->value() * ratio); + + d->width->blockSignals(false); + d->height->blockSignals(false); + + d->previousUnit = newUnit; +} + +void ImageEditorPrintDialogPage::readSettings() +{ + TDEConfig* config = kapp->config(); + config->setGroup("Color Management"); + d->cmEnabled = config->readBoolEntry("EnableCM", false); +} + +void ImageEditorPrintDialogPage::slotSetupDlg() +{ + EditorWindow* editor = dynamic_cast<EditorWindow*>(d->parent); + editor->setup(true); +} + +void ImageEditorPrintDialogPage::slotAlertSettings( bool t) +{ + if (t && !d->cmEnabled) + { + TQString message = i18n("<p>Color Management is disabled.</p> \ + <p>You can enable it now by clicking on the \"Settings\" button.</p>"); + KMessageBox::information(this, message); + d->colorManaged->setChecked(!t); + } +} + +double ImageEditorPrintDialogPage::unitToMM(Unit unit) +{ + if (unit == DK_MILLIMETERS) + { + return 1.; + } + else if (unit == DK_CENTIMETERS) + { + return 10.; + } + else + { //DK_INCHES + return 25.4; + } +} + +ImageEditorPrintDialogPage::Unit ImageEditorPrintDialogPage::stringToUnit(const TQString& unit) +{ + if (unit == i18n("Millimeters")) + { + return DK_MILLIMETERS; + } + else if (unit == i18n("Centimeters")) + { + return DK_CENTIMETERS; + } + else + {//Inches + return DK_INCHES; + } +} + +TQString ImageEditorPrintDialogPage::unitToString(Unit unit) +{ + if (unit == DK_MILLIMETERS) + { + return i18n("Millimeters"); + } + else if (unit == DK_CENTIMETERS) + { + return i18n("Centimeters"); + } + else + { //DK_INCHES + return i18n("Inches"); + } +} + +} // namespace Digikam + diff --git a/src/utilities/imageeditor/tools/imageprint.h b/src/utilities/imageeditor/tools/imageprint.h new file mode 100644 index 00000000..66276701 --- /dev/null +++ b/src/utilities/imageeditor/tools/imageprint.h @@ -0,0 +1,122 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2004-07-13 + * Description : image editor printing interface. + * + * Copyright (C) 2006 by F.J. Cruz <[email protected]> + * Copyright (C) 2004-2007 by Gilles Caulier <caulier dot gilles at gmail dot com> + * + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; + * either version 2, or (at your option) + * any later version. + * + * 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. + * + * ============================================================ */ + +#ifndef IMAGEPRINT_H +#define IMAGEPRINT_H + +// TQt includes. + +#include <tqwidget.h> +#include <tqstring.h> + +// KDE includes. + +#include <kurl.h> +#include <kprinter.h> +#include <tdeprint/kprintdialogpage.h> + +// Local includes. + +#include "digikam_export.h" + +namespace Digikam +{ + +class ImagePrintPrivate; + +class DIGIKAM_EXPORT ImagePrint +{ +public: + + ImagePrint(DImg& image, KPrinter& printer, const TQString& fileName); + ~ImagePrint(); + + bool printImageWithTQt(); + +private: + + TQString minimizeString(TQString text, const TQFontMetrics& metrics, int maxWidth); + void readSettings(); + +private: + + KPrinter& m_printer; + + ImagePrintPrivate *d; +}; + +//----------------------------------------------------------------------------- + +class ImageEditorPrintDialogPagePrivate; + +class DIGIKAM_EXPORT ImageEditorPrintDialogPage : public KPrintDialogPage +{ + TQ_OBJECT + + +public: + + enum Unit + { + DK_MILLIMETERS = 1, + DK_CENTIMETERS, + DK_INCHES + }; + + static inline double unitToMM(Unit unit); + static inline Unit stringToUnit(const TQString& unit); + static inline TQString unitToString(Unit unit); + +public: + + ImageEditorPrintDialogPage(DImg& image, TQWidget *parent=0L, const char *name=0); + ~ImageEditorPrintDialogPage(); + + virtual void getOptions(TQMap<TQString,TQString>& opts, bool incldef = false); + virtual void setOptions(const TQMap<TQString,TQString>& opts); + +private slots: + + void toggleScaling( bool enable ); + void toggleRatio( bool enable ); + void slotUnitChanged(const TQString& string); + void slotHeightChanged(double value); + void slotWidthChanged(double value); + void slotSetupDlg(); + void slotAlertSettings(bool t); + +private: + + void readSettings(); + int getPosition(const TQString& align); + TQString setPosition(int align); + +private: + + ImageEditorPrintDialogPagePrivate *d; +}; + +} // namespace Digikam + +#endif // IMAGEPRINT_H diff --git a/src/utilities/imageeditor/tools/imageresize.cpp b/src/utilities/imageeditor/tools/imageresize.cpp new file mode 100644 index 00000000..c779b71e --- /dev/null +++ b/src/utilities/imageeditor/tools/imageresize.cpp @@ -0,0 +1,650 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2005-04-07 + * Description : a tool to resize an image + * + * Copyright (C) 2005-2009 by Gilles Caulier <caulier dot gilles at gmail dot com> + * + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; + * either version 2, or (at your option) + * any later version. + * + * 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. + * + * ============================================================ */ + +// C++ includes. + +#include <cmath> + +// TQt includes. + +#include <tqvgroupbox.h> +#include <tqlabel.h> +#include <tqpushbutton.h> +#include <tqtooltip.h> +#include <tqwhatsthis.h> +#include <tqlayout.h> +#include <tqframe.h> +#include <tqcheckbox.h> +#include <tqcombobox.h> +#include <tqtabwidget.h> +#include <tqtimer.h> +#include <tqevent.h> +#include <tqpixmap.h> +#include <tqbrush.h> +#include <tqfile.h> +#include <tqimage.h> + +// KDE includes. + +#include <kseparator.h> +#include <kcursor.h> +#include <kurllabel.h> +#include <tdelocale.h> +#include <kiconloader.h> +#include <tdeapplication.h> +#include <tdefiledialog.h> +#include <kstandarddirs.h> +#include <kprogress.h> +#include <tdemessagebox.h> +#include <knuminput.h> +#include <tdeglobalsettings.h> + +// LibKDcraw includes. + +#include <libkdcraw/rnuminput.h> + +// Digikam includes. + +#include "dimg.h" +#include "ddebug.h" +#include "imageiface.h" +#include "dimgthreadedfilter.h" +#include "greycstorationiface.h" +#include "greycstorationwidget.h" +#include "greycstorationsettings.h" + +// Local includes. + +#include "imageresize.h" +#include "imageresize.moc" + +using namespace KDcrawIface; + +namespace Digikam +{ + +class ImageResizePriv +{ +public: + + enum RunningMode + { + NoneRendering=0, + FinalRendering + }; + + ImageResizePriv() + { + currentRenderingMode = NoneRendering; + parent = 0; + preserveRatioBox = 0; + useGreycstorationBox = 0; + mainTab = 0; + wInput = 0; + hInput = 0; + wpInput = 0; + hpInput = 0; + progressBar = 0; + greycstorationIface = 0; + settingsWidget = 0; + cimgLogoLabel = 0; + restorationTips = 0; + } + + int currentRenderingMode; + int orgWidth; + int orgHeight; + int prevW; + int prevH; + + double prevWP; + double prevHP; + + TQWidget *parent; + + TQLabel *restorationTips; + + TQCheckBox *preserveRatioBox; + TQCheckBox *useGreycstorationBox; + + TQTabWidget *mainTab; + + RIntNumInput *wInput; + RIntNumInput *hInput; + + RDoubleNumInput *wpInput; + RDoubleNumInput *hpInput; + + KProgress *progressBar; + + KURLLabel *cimgLogoLabel; + + GreycstorationIface *greycstorationIface; + GreycstorationWidget *settingsWidget; +}; + +ImageResize::ImageResize(TQWidget* parent) + : KDialogBase(Plain, i18n("Resize Image"), + Help|Default|User2|User3|Ok|Cancel, Ok, + parent, 0, true, false, + TQString(), + i18n("&Save As..."), + i18n("&Load...")) +{ + d = new ImageResizePriv; + d->parent = parent; + setHelp("resizetool.anchor", "digikam"); + TQString whatsThis; + setButtonWhatsThis( Default, i18n("<p>Reset all filter parameters to their default values.") ); + setButtonWhatsThis( User3, i18n("<p>Load all filter parameters from settings text file.") ); + setButtonWhatsThis( User2, i18n("<p>Save all filter parameters to settings text file.") ); + enableButton(Ok, false); + + ImageIface iface(0, 0); + d->orgWidth = iface.originalWidth(); + d->orgHeight = iface.originalHeight(); + d->prevW = d->orgWidth; + d->prevH = d->orgHeight; + d->prevWP = 100.0; + d->prevHP = 100.0; + + // ------------------------------------------------------------- + + TQVBoxLayout *vlay = new TQVBoxLayout(plainPage(), 0, spacingHint()); + d->mainTab = new TQTabWidget( plainPage() ); + + TQWidget* firstPage = new TQWidget( d->mainTab ); + TQGridLayout* grid = new TQGridLayout( firstPage, 8, 2, spacingHint()); + d->mainTab->addTab( firstPage, i18n("New Size") ); + + TQLabel *label1 = new TQLabel(i18n("Width:"), firstPage); + d->wInput = new RIntNumInput(firstPage); + d->wInput->setRange(1, TQMAX(d->orgWidth * 10, 9999), 1); + d->wInput->setName("d->wInput"); + d->wInput->setDefaultValue(d->orgWidth); + TQWhatsThis::add( d->wInput, i18n("<p>Set here the new image width in pixels.")); + + TQLabel *label2 = new TQLabel(i18n("Height:"), firstPage); + d->hInput = new RIntNumInput(firstPage); + d->hInput->setRange(1, TQMAX(d->orgHeight * 10, 9999), 1); + d->hInput->setName("d->hInput"); + d->hInput->setDefaultValue(d->orgHeight); + TQWhatsThis::add( d->hInput, i18n("<p>Set here the new image height in pixels.")); + + TQLabel *label3 = new TQLabel(i18n("Width (%):"), firstPage); + d->wpInput = new RDoubleNumInput(firstPage); + d->wpInput->setRange(1.0, 999.0, 1.0); + d->wpInput->setName("d->wpInput"); + d->wpInput->setDefaultValue(100.0); + TQWhatsThis::add( d->wpInput, i18n("<p>Set here the new image width in percent.")); + + TQLabel *label4 = new TQLabel(i18n("Height (%):"), firstPage); + d->hpInput = new RDoubleNumInput(firstPage); + d->hpInput->setRange(1.0, 999.0, 1.0); + d->hpInput->setName("d->hpInput"); + d->hpInput->setDefaultValue(100.0); + TQWhatsThis::add( d->hpInput, i18n("<p>Set here the new image height in percent.")); + + d->preserveRatioBox = new TQCheckBox(i18n("Maintain aspect ratio"), firstPage); + TQWhatsThis::add( d->preserveRatioBox, i18n("<p>Enable this option to maintain aspect " + "ratio with new image sizes.")); + + d->cimgLogoLabel = new KURLLabel(firstPage); + d->cimgLogoLabel->setText(TQString()); + d->cimgLogoLabel->setURL("http://cimg.sourceforge.net"); + TDEGlobal::dirs()->addResourceType("logo-cimg", TDEGlobal::dirs()->kde_default("data") + + "digikam/data"); + TQString directory = TDEGlobal::dirs()->findResourceDir("logo-cimg", "logo-cimg.png"); + d->cimgLogoLabel->setPixmap( TQPixmap( directory + "logo-cimg.png" ) ); + TQToolTip::add(d->cimgLogoLabel, i18n("Visit CImg library website")); + + d->useGreycstorationBox = new TQCheckBox(i18n("Restore photograph"), firstPage); + TQWhatsThis::add( d->useGreycstorationBox, i18n("<p>Enable this option to restore photograph content. " + "This way is usefull to scale-up an image to an huge size. " + "Warning: this process can take a while.")); + + d->restorationTips = new TQLabel(i18n("<b>Note: use Restoration Mode to only scale-up an image to huge size. " + "Warning, this process can take a while.</b>"), firstPage); + + d->progressBar = new KProgress(100, firstPage); + d->progressBar->setValue(0); + TQWhatsThis::add(d->progressBar, i18n("<p>This shows the current progress when you use Restoration mode.")); + + grid->addMultiCellWidget(d->preserveRatioBox, 0, 0, 0, 2); + grid->addMultiCellWidget(label1, 1, 1, 0, 0); + grid->addMultiCellWidget(d->wInput, 1, 1, 1, 2); + grid->addMultiCellWidget(label2, 2, 2, 0, 0); + grid->addMultiCellWidget(d->hInput, 2, 2, 1, 2); + grid->addMultiCellWidget(label3, 3, 3, 0, 0); + grid->addMultiCellWidget(d->wpInput, 3, 3, 1, 2); + grid->addMultiCellWidget(label4, 4, 4, 0, 0); + grid->addMultiCellWidget(d->hpInput, 4, 4, 1, 2); + grid->addMultiCellWidget(new KSeparator(firstPage), 5, 5, 0, 2); + grid->addMultiCellWidget(d->cimgLogoLabel, 6, 8, 0, 0); + grid->addMultiCellWidget(d->useGreycstorationBox, 6, 6, 1, 2); + grid->addMultiCellWidget(d->restorationTips, 7, 7, 1, 2); + grid->addMultiCellWidget(d->progressBar, 8, 8, 1, 2); + grid->setRowStretch(8, 10); + + // ------------------------------------------------------------- + + d->settingsWidget = new GreycstorationWidget(d->mainTab); + vlay->addWidget(d->mainTab); + + // ------------------------------------------------------------- + + adjustSize(); + disableResize(); + TQTimer::singleShot(0, this, TQ_SLOT(readUserSettings())); + + // ------------------------------------------------------------- + + connect(d->cimgLogoLabel, TQ_SIGNAL(leftClickedURL(const TQString&)), + this, TQ_SLOT(processCImgURL(const TQString&))); + + connect(d->wInput, TQ_SIGNAL(valueChanged(int)), + this, TQ_SLOT(slotValuesChanged())); + + connect(d->hInput, TQ_SIGNAL(valueChanged(int)), + this, TQ_SLOT(slotValuesChanged())); + + connect(d->wpInput, TQ_SIGNAL(valueChanged(double)), + this, TQ_SLOT(slotValuesChanged())); + + connect(d->hpInput, TQ_SIGNAL(valueChanged(double)), + this, TQ_SLOT(slotValuesChanged())); + + connect(d->useGreycstorationBox, TQ_SIGNAL(toggled(bool)), + this, TQ_SLOT(slotRestorationToggled(bool)) ); + + // ------------------------------------------------------------- + + Digikam::GreycstorationSettings defaults; + defaults.setResizeDefaultSettings(); + d->settingsWidget->setDefaultSettings(defaults); +} + +ImageResize::~ImageResize() +{ + if (d->greycstorationIface) + delete d->greycstorationIface; + + delete d; +} + +void ImageResize::slotRestorationToggled(bool b) +{ + d->settingsWidget->setEnabled(b); + d->progressBar->setEnabled(b); + d->cimgLogoLabel->setEnabled(b); + enableButton(User2, b); + enableButton(User3, b); +} + +void ImageResize::readUserSettings() +{ + TDEConfig* config = kapp->config(); + config->setGroup("resize Tool Dialog"); + + GreycstorationSettings settings; + GreycstorationSettings defaults; + defaults.setResizeDefaultSettings(); + + settings.fastApprox = config->readBoolEntry("FastApprox", defaults.fastApprox); + settings.interp = config->readNumEntry("Interpolation", defaults.interp); + settings.amplitude = config->readDoubleNumEntry("Amplitude", defaults.amplitude); + settings.sharpness = config->readDoubleNumEntry("Sharpness", defaults.sharpness); + settings.anisotropy = config->readDoubleNumEntry("Anisotropy", defaults.anisotropy); + settings.alpha = config->readDoubleNumEntry("Alpha", defaults.alpha); + settings.sigma = config->readDoubleNumEntry("Sigma", defaults.sigma); + settings.gaussPrec = config->readDoubleNumEntry("GaussPrec", defaults.gaussPrec); + settings.dl = config->readDoubleNumEntry("Dl", defaults.dl); + settings.da = config->readDoubleNumEntry("Da", defaults.da); + settings.nbIter = config->readNumEntry("Iteration", defaults.nbIter); + settings.tile = config->readNumEntry("Tile", defaults.tile); + settings.btile = config->readNumEntry("BTile", defaults.btile); + d->settingsWidget->setSettings(settings); + + d->useGreycstorationBox->setChecked(config->readBoolEntry("RestorePhotograph", false)); + slotRestorationToggled(d->useGreycstorationBox->isChecked()); + + d->preserveRatioBox->blockSignals(true); + d->wInput->blockSignals(true); + d->hInput->blockSignals(true); + d->wpInput->blockSignals(true); + d->hpInput->blockSignals(true); + + d->preserveRatioBox->setChecked(true); + d->wInput->slotReset(); + d->hInput->slotReset(); + d->wpInput->slotReset(); + d->hpInput->slotReset(); + + d->preserveRatioBox->blockSignals(false); + d->wInput->blockSignals(false); + d->hInput->blockSignals(false); + d->wpInput->blockSignals(false); + d->hpInput->blockSignals(false); +} + +void ImageResize::writeUserSettings() +{ + GreycstorationSettings settings = d->settingsWidget->getSettings(); + TDEConfig* config = kapp->config(); + config->setGroup("resize Tool Dialog"); + config->writeEntry("FastApprox", settings.fastApprox); + config->writeEntry("Interpolation", settings.interp); + config->writeEntry("Amplitude", settings.amplitude); + config->writeEntry("Sharpness", settings.sharpness); + config->writeEntry("Anisotropy", settings.anisotropy); + config->writeEntry("Alpha", settings.alpha); + config->writeEntry("Sigma", settings.sigma); + config->writeEntry("GaussPrec", settings.gaussPrec); + config->writeEntry("Dl", settings.dl); + config->writeEntry("Da", settings.da); + config->writeEntry("Iteration", settings.nbIter); + config->writeEntry("Tile", settings.tile); + config->writeEntry("BTile", settings.btile); + config->writeEntry("RestorePhotograph", d->useGreycstorationBox->isChecked()); + config->sync(); +} + +void ImageResize::slotDefault() +{ + GreycstorationSettings settings; + settings.setResizeDefaultSettings(); + + d->settingsWidget->setSettings(settings); + d->useGreycstorationBox->setChecked(false); + slotRestorationToggled(d->useGreycstorationBox->isChecked()); + + d->preserveRatioBox->blockSignals(true); + d->wInput->blockSignals(true); + d->hInput->blockSignals(true); + d->wpInput->blockSignals(true); + d->hpInput->blockSignals(true); + d->preserveRatioBox->setChecked(true); + d->wInput->setValue(d->orgWidth); + d->hInput->setValue(d->orgHeight); + d->wpInput->setValue(100.0); + d->hpInput->setValue(100.0); + d->preserveRatioBox->blockSignals(false); + d->wInput->blockSignals(false); + d->hInput->blockSignals(false); + d->wpInput->blockSignals(false); + d->hpInput->blockSignals(false); +} + +void ImageResize::slotValuesChanged() +{ + enableButton(Ok, true); + d->wInput->blockSignals(true); + d->hInput->blockSignals(true); + d->wpInput->blockSignals(true); + d->hpInput->blockSignals(true); + + TQString s(sender()->name()); + + if (s == "d->wInput") + { + double val = d->wInput->value(); + double wp = val/(double)(d->orgWidth) * 100.0; + d->wpInput->setValue(wp); + + if (d->preserveRatioBox->isChecked()) + { + d->hpInput->setValue(wp); + int h = (int)(wp*d->orgHeight/100); + d->hInput->setValue(h); + } + } + else if (s == "d->hInput") + { + double val = d->hInput->value(); + double hp = val/(double)(d->orgHeight) * 100.0; + d->hpInput->setValue(hp); + + if (d->preserveRatioBox->isChecked()) + { + d->wpInput->setValue(hp); + int w = (int)(hp*d->orgWidth/100); + d->wInput->setValue(w); + } + } + else if (s == "d->wpInput") + { + double val = d->wpInput->value(); + int w = (int)(val*d->orgWidth/100); + d->wInput->setValue(w); + + if (d->preserveRatioBox->isChecked()) + { + d->hpInput->setValue(val); + int h = (int)(val*d->orgHeight/100); + d->hInput->setValue(h); + } + } + else if (s == "d->hpInput") + { + double val = d->hpInput->value(); + int h = (int)(val*d->orgHeight/100); + d->hInput->setValue(h); + + if (d->preserveRatioBox->isChecked()) + { + d->wpInput->setValue(val); + int w = (int)(val*d->orgWidth/100); + d->wInput->setValue(w); + } + } + + d->prevW = d->wInput->value(); + d->prevH = d->hInput->value(); + d->prevWP = d->wpInput->value(); + d->prevHP = d->hpInput->value(); + + d->wInput->blockSignals(false); + d->hInput->blockSignals(false); + d->wpInput->blockSignals(false); + d->hpInput->blockSignals(false); +} + +void ImageResize::slotCancel() +{ + if (d->currentRenderingMode != ImageResizePriv::NoneRendering) + { + d->greycstorationIface->stopComputation(); + d->parent->unsetCursor(); + } + + done(Cancel); +} + +void ImageResize::processCImgURL(const TQString& url) +{ + TDEApplication::kApplication()->invokeBrowser(url); +} + +void ImageResize::closeEvent(TQCloseEvent *e) +{ + if (d->currentRenderingMode != ImageResizePriv::NoneRendering) + { + d->greycstorationIface->stopComputation(); + d->parent->unsetCursor(); + } + + e->accept(); +} + +void ImageResize::slotOk() +{ + if (d->prevW != d->wInput->value() || d->prevH != d->hInput->value() || + d->prevWP != d->wpInput->value() || d->prevHP != d->hpInput->value()) + slotValuesChanged(); + + d->currentRenderingMode = ImageResizePriv::FinalRendering; + d->mainTab->setCurrentPage(0); + d->settingsWidget->setEnabled(false); + d->preserveRatioBox->setEnabled(false); + d->useGreycstorationBox->setEnabled(false); + d->wInput->setEnabled(false); + d->hInput->setEnabled(false); + d->wpInput->setEnabled(false); + d->hpInput->setEnabled(false); + enableButton(Ok, false); + enableButton(Default, false); + enableButton(User2, false); + enableButton(User3, false); + + d->parent->setCursor( KCursor::waitCursor() ); + writeUserSettings(); + ImageIface iface(0, 0); + uchar *data = iface.getOriginalImage(); + DImg image = DImg(iface.originalWidth(), iface.originalHeight(), + iface.originalSixteenBit(), iface.originalHasAlpha(), data); + delete [] data; + + if (d->useGreycstorationBox->isChecked()) + { + d->progressBar->setValue(0); + d->progressBar->setEnabled(true); + + if (d->greycstorationIface) + { + delete d->greycstorationIface; + d->greycstorationIface = 0; + } + + d->greycstorationIface = new GreycstorationIface( + &image, d->settingsWidget->getSettings(), + GreycstorationIface::Resize, + d->wInput->value(), + d->hInput->value(), + 0, this); + } + else + { + // See B.K.O #152192: CImg resize() sound like bugous or unadapted + // to resize image without good quality. + + image.resize(d->wInput->value(), d->hInput->value()); + iface.putOriginalImage(i18n("Resize"), image.bits(), + image.width(), image.height()); + d->parent->unsetCursor(); + accept(); + } +} + +void ImageResize::customEvent(TQCustomEvent *event) +{ + if (!event) return; + + GreycstorationIface::EventData *data = (GreycstorationIface::EventData*) event->data(); + + if (!data) return; + + if (data->starting) // Computation in progress ! + { + d->progressBar->setValue(data->progress); + } + else + { + if (data->success) // Computation Completed ! + { + switch (d->currentRenderingMode) + { + case ImageResizePriv::FinalRendering: + { + DDebug() << "Final resizing completed..." << endl; + + ImageIface iface(0, 0); + DImg resizedImage = d->greycstorationIface->getTargetImage(); + + iface.putOriginalImage(i18n("Resize"), resizedImage.bits(), + resizedImage.width(), resizedImage.height()); + d->parent->unsetCursor(); + accept(); + break; + } + } + } + else // Computation Failed ! + { + switch (d->currentRenderingMode) + { + case ImageResizePriv::FinalRendering: + break; + } + } + } + + delete data; +} + +void ImageResize::slotUser3() +{ + KURL loadBlowupFile = KFileDialog::getOpenURL(TDEGlobalSettings::documentPath(), + TQString( "*" ), this, + TQString( i18n("Photograph Resizing Settings File to Load")) ); + if( loadBlowupFile.isEmpty() ) + return; + + TQFile file(loadBlowupFile.path()); + + if ( file.open(IO_ReadOnly) ) + { + if (!d->settingsWidget->loadSettings(file, TQString("# Photograph Resizing Configuration File"))) + { + KMessageBox::error(this, + i18n("\"%1\" is not a Photograph Resizing settings text file.") + .arg(loadBlowupFile.fileName())); + file.close(); + return; + } + } + else + KMessageBox::error(this, i18n("Cannot load settings from the Photograph Resizing text file.")); + + file.close(); +} + +void ImageResize::slotUser2() +{ + KURL saveBlowupFile = KFileDialog::getSaveURL(TDEGlobalSettings::documentPath(), + TQString( "*" ), this, + TQString( i18n("Photograph Resizing Settings File to Save")) ); + if( saveBlowupFile.isEmpty() ) + return; + + TQFile file(saveBlowupFile.path()); + + if ( file.open(IO_WriteOnly) ) + d->settingsWidget->saveSettings(file, TQString("# Photograph Resizing Configuration File")); + else + KMessageBox::error(this, i18n("Cannot save settings to the Photograph Resizing text file.")); + + file.close(); +} + +} // NameSpace Digikam + diff --git a/src/utilities/imageeditor/tools/imageresize.h b/src/utilities/imageeditor/tools/imageresize.h new file mode 100644 index 00000000..3f8b1c23 --- /dev/null +++ b/src/utilities/imageeditor/tools/imageresize.h @@ -0,0 +1,82 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2005-04-07 + * Description : a tool to resize an image + * + * Copyright (C) 2005-2009 by Gilles Caulier <caulier dot gilles at gmail dot com> + * + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; + * either version 2, or (at your option) + * any later version. + * + * 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. + * + * ============================================================ */ + +#ifndef IMAGE_RESIZE_H +#define IMAGE_RESIZE_H + +// TQt includes. + +#include <tqstring.h> + +// KDE includes. + +#include <kdialogbase.h> + +// Local includes. + +#include "digikam_export.h" + +namespace Digikam +{ + +class ImageResizePriv; + +class DIGIKAM_EXPORT ImageResize : public KDialogBase +{ + TQ_OBJECT + + +public: + + ImageResize(TQWidget* parent); + ~ImageResize(); + +protected: + + void closeEvent(TQCloseEvent *e); + +private: + + void customEvent(TQCustomEvent *event); + void writeUserSettings(); + +private slots: + + void slotOk(); + void slotCancel(); + void slotDefault(); + void slotUser2(); + void slotUser3(); + void processCImgURL(const TQString&); + void slotValuesChanged(); + void readUserSettings(); + void slotRestorationToggled(bool); + +private: + + ImageResizePriv *d; +}; + +} // NameSpace Digikam + +#endif /* IMAGE_RESIZE_H */ |