File indexing completed on 2024-05-05 16:38:59
0001 /* This file is part of the KDE project 0002 Copyright (C) 1998-2002 Carsten Pfeiffer <pfeiffer@kde.org> 0003 0004 This program is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU General Public 0006 License as published by the Free Software Foundation, version 2. 0007 0008 This program is distributed in the hope that it will be useful, 0009 but WITHOUT ANY WARRANTY; without even the implied warranty of 0010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0011 General Public License for more details. 0012 0013 You should have received a copy of the GNU General Public License 0014 along with this program; see the file COPYING. If not, write to 0015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0016 Boston, MA 02110-1301, USA. 0017 */ 0018 0019 #include "defaultswidget.h" 0020 #include <ui_defaultswidget.h> 0021 0022 #include <QStandardPaths> 0023 #include <QUrl> 0024 0025 #include "imlibwidget.h" 0026 0027 0028 DefaultsWidget::DefaultsWidget( QWidget *parent ) 0029 : QWidget( parent ) 0030 { 0031 // setup the widget based on its .ui file 0032 ui = new Ui::DefaultsWidget; 0033 ui->setupUi(this); 0034 0035 0036 // set the properties that couldn't be set in the .ui file 0037 QGridLayout* gbPreviewLayout = dynamic_cast<QGridLayout*>(ui->gbPreview->layout()); 0038 0039 // The image widgets have to be created here, because the required parameters can only be set on creation. 0040 // The generated code won't do that. 0041 imOrig = new ImlibWidget(0L, ui->gbPreview); 0042 gbPreviewLayout->addWidget(imOrig, 1, 0, Qt::AlignCenter | Qt::AlignTop); 0043 0044 imFiltered = new ImlibWidget(0L, imOrig->getImlibData(), ui->gbPreview); 0045 gbPreviewLayout->addWidget(imFiltered, 1, 1, Qt::AlignCenter | Qt::AlignTop); 0046 0047 0048 // actions 0049 connect( ui->cbEnableMods, SIGNAL( toggled(bool) ), SLOT( enableWidgets(bool) )); 0050 0051 connect(ui->cbUpScale, SIGNAL( toggled(bool)), ui->sbMaxUpScaleFactor, 0052 SLOT( setEnabled(bool) )); 0053 0054 connect( imFiltered, SIGNAL( destroyed() ), SLOT( slotNoImage() )); 0055 0056 connect( ui->cbDownScale, SIGNAL( clicked() ), SLOT( updatePreview() )); 0057 connect( ui->cbUpScale, SIGNAL( clicked() ), SLOT( updatePreview() )); 0058 connect( ui->cbFlipVertically, SIGNAL( clicked() ), SLOT( updatePreview() )); 0059 connect( ui->cbFlipHorizontally, SIGNAL( clicked() ), SLOT( updatePreview() )); 0060 connect( ui->sbMaxUpScaleFactor, SIGNAL( valueChanged(int) ), SLOT( updatePreview() )); 0061 connect( ui->sbBrightness, SIGNAL( valueChanged(int) ), SLOT( updatePreview() )); 0062 connect( ui->sbContrast, SIGNAL( valueChanged(int) ), SLOT( updatePreview() )); 0063 connect( ui->sbGamma, SIGNAL( valueChanged(int) ), SLOT( updatePreview() )); 0064 0065 connect( ui->comboRotate, SIGNAL( activated(int) ), SLOT( updatePreview() )); 0066 0067 0068 // load and display the test image 0069 QString filename = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kuickshow/pics/calibrate.png")); 0070 if ( !imOrig->loadImage( QUrl::fromLocalFile(filename) ) ) 0071 imOrig = 0L; // FIXME - display some errormessage! 0072 if ( !imFiltered->loadImage( QUrl::fromLocalFile(filename) ) ) 0073 imFiltered = 0L; // FIXME - display some errormessage! 0074 0075 loadSettings( *kdata ); 0076 0077 if ( imOrig ) 0078 imOrig->setFixedSize( imOrig->size() ); 0079 if ( imFiltered ) 0080 imFiltered->setFixedSize( imFiltered->size() ); 0081 0082 //layout()->activate(); 0083 } 0084 0085 0086 DefaultsWidget::~DefaultsWidget() 0087 { 0088 // those need to be deleted in the right order, as imFiltered 0089 // references ImlibData from imOrig 0090 delete imFiltered; 0091 delete imOrig; 0092 0093 delete ui; 0094 } 0095 0096 void DefaultsWidget::loadSettings( const KuickData& data ) 0097 { 0098 ui->cbDownScale->setChecked( data.downScale ); 0099 ui->cbUpScale->setChecked( data.upScale ); 0100 ui->sbMaxUpScaleFactor->setValue( data.maxUpScale ); 0101 0102 ui->cbFlipVertically->setChecked( data.flipVertically ); 0103 ui->cbFlipHorizontally->setChecked( data.flipHorizontally ); 0104 0105 ui->comboRotate->setCurrentIndex( ( int )data.rotation ); 0106 0107 ImData *id = data.idata; 0108 0109 ui->sbBrightness->setValue( id->brightness ); 0110 ui->sbContrast->setValue( id->contrast ); 0111 ui->sbGamma->setValue( id->gamma ); 0112 0113 ui->cbEnableMods->setChecked( data.isModsEnabled ); 0114 enableWidgets( data.isModsEnabled ); 0115 0116 updatePreview(); 0117 } 0118 0119 void DefaultsWidget::applySettings( KuickData& data ) 0120 { 0121 data.isModsEnabled = ui->cbEnableMods->isChecked(); 0122 0123 data.downScale = ui->cbDownScale->isChecked(); 0124 data.upScale = ui->cbUpScale->isChecked(); 0125 data.maxUpScale = ui->sbMaxUpScaleFactor->value(); 0126 0127 data.flipVertically = ui->cbFlipVertically->isChecked(); 0128 data.flipHorizontally = ui->cbFlipHorizontally->isChecked(); 0129 0130 data.rotation = currentRotation(); 0131 0132 ImData *id = data.idata; 0133 0134 id->brightness = ui->sbBrightness->value(); 0135 id->contrast = ui->sbContrast->value(); 0136 id->gamma = ui->sbGamma->value(); 0137 } 0138 0139 void DefaultsWidget::updatePreview() 0140 { 0141 if ( !imFiltered ) 0142 return; 0143 0144 imFiltered->setAutoRender( false ); 0145 0146 int flipMode = ui->cbFlipHorizontally->isChecked() ? FlipHorizontal : FlipNone; 0147 flipMode |= ui->cbFlipVertically->isChecked() ? FlipVertical : FlipNone; 0148 imFiltered->setFlipMode( flipMode ); 0149 0150 Rotation rotation = ui->cbEnableMods->isChecked() ? currentRotation() : ROT_0; 0151 imFiltered->setRotation( rotation ); 0152 0153 imFiltered->setBrightness( ui->sbBrightness->value() ); 0154 imFiltered->setContrast( ui->sbContrast->value() ); 0155 imFiltered->setGamma( ui->sbGamma->value() ); 0156 0157 imFiltered->updateImage(); 0158 imFiltered->setAutoRender( true ); 0159 } 0160 0161 0162 void DefaultsWidget::enableWidgets( bool enable ) 0163 { 0164 ui->gbScale->setEnabled( enable ); 0165 ui->sbMaxUpScaleFactor->setEnabled( enable & ui->cbUpScale->isChecked() ); 0166 0167 ui->gbGeometry->setEnabled( enable ); 0168 ui->gbAdjust->setEnabled( enable ); 0169 ui->gbPreview->setEnabled( enable ); 0170 updatePreview(); 0171 } 0172 0173 0174 Rotation DefaultsWidget::currentRotation() const 0175 { 0176 return (Rotation) ui->comboRotate->currentIndex(); 0177 }