SilentEye 0.4.1

modules/seformatbmp/optionwidget.cpp

Go to the documentation of this file.
00001 //  This file is part of SilentEye.
00002 //
00003 //  SilentEye is free software: you can redistribute it and/or modify
00004 //  it under the terms of the GNU General Public License as published by
00005 //  the Free Software Foundation, either version 3 of the License, or
00006 //  (at your option) any later version.
00007 //
00008 //  SilentEye is distributed in the hope that it will be useful,
00009 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 //  GNU General Public License for more details.
00012 //
00013 //  You should have received a copy of the GNU General Public License
00014 //  along with SilentEye.  If not, see <http://www.gnu.org/licenses/>.
00015 
00016 #include "optionwidget.h"
00017 #include <math.h>
00018 
00019 namespace SEFormatBMP {
00020 
00021     OptionWidget::OptionWidget(QWidget* parent)
00022         : QWidget(parent)
00023     {
00024         this->setObjectName("SEFormatBmpOptionWidget");
00025         m_logger = new Logger(this);
00026         m_dontUpdate = false;
00027 
00028         setupUi(this);
00029         advancedWidget->setVisible(false);
00030 
00031         settingsChanged();
00032 
00033         connect(advancedButton, SIGNAL(toggled(bool)), this, SLOT(advButtonPressed(bool)));
00034         connect(qualityComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(qualityChanged(int)));
00035         connect(redCheckBox, SIGNAL(stateChanged(int)), this, SLOT(settingsChanged(int)));
00036         connect(greenCheckBox, SIGNAL(stateChanged(int)), this, SLOT(settingsChanged(int)));
00037         connect(blueCheckBox, SIGNAL(stateChanged(int)), this, SLOT(settingsChanged(int)));
00038         connect(nbBitsSpinBox, SIGNAL(valueChanged(int)), this, SLOT(settingsChanged(int)));
00039     }
00040 
00041     OptionWidget::~OptionWidget()
00042     {
00043         delete m_logger;
00044     }
00045 
00046     int OptionWidget::nbBits() const
00047     {
00048         return nbBitsSpinBox->value();
00049     }
00050 
00051     bool OptionWidget::isRedUsed() const
00052     {
00053         return redCheckBox->checkState() != Qt::Unchecked;
00054     }
00055 
00056     bool OptionWidget::isGreenUsed() const
00057     {
00058         return greenCheckBox->checkState() != Qt::Unchecked;
00059     }
00060 
00061     bool OptionWidget::isBlueUsed() const
00062     {
00063         return blueCheckBox->checkState() != Qt::Unchecked;
00064     }
00065 
00066     ImageBMP::DataDistribution OptionWidget::distribution() const
00067     {
00068         ImageBMP::DataDistribution dist = ImageBMP::EQUI;
00069         switch(distributionComboBox->currentIndex())
00070         {
00071             case 0:
00072                 dist = ImageBMP::EQUI;
00073                 break;
00074             case 1:
00075                 dist = ImageBMP::INLINE;
00076                 break;
00077             default:
00078                 m_logger->warning("Unhandle distribution switch value: " + QString::number(distributionComboBox->currentIndex()));
00079                 break;
00080         }
00081         return dist;
00082     }
00083 
00084     ImageBMP::HeaderPosition OptionWidget::headerPosition() const
00085     {
00086         ImageBMP::HeaderPosition pos = ImageBMP::SIGNATURE;
00087         switch(headerComboBox->currentIndex())
00088         {
00089             case 0:
00090                 pos = ImageBMP::TOP;
00091                 break;
00092             case 1:
00093                 pos = ImageBMP::BOTTOM;
00094                 break;
00095             case 2:
00096                 pos = ImageBMP::SIGNATURE;
00097                 break;
00098             default:
00099                 m_logger->warning("Unhandle header switch value: " + headerComboBox->currentIndex());
00100                 break;
00101         }
00102         return pos;
00103     }
00104 
00105     void OptionWidget::advButtonPressed(bool value)
00106     {
00107         advancedWidget->setVisible(value);
00108     }
00109 
00110     void OptionWidget::qualityChanged(int value)
00111     {
00112         if (!m_dontUpdate)
00113         {
00114             m_dontUpdate = true;
00115             switch(value)
00116             {
00117                 case 0: // very low
00118                     redCheckBox->setChecked(true);
00119                     greenCheckBox->setChecked(true);
00120                     blueCheckBox->setChecked(true);
00121                     nbBitsSpinBox->setValue(6);
00122                     headerComboBox->setCurrentIndex(0);
00123                     break;
00124                 case 1: // low
00125                     redCheckBox->setChecked(true);
00126                     greenCheckBox->setChecked(true);
00127                     blueCheckBox->setChecked(true);
00128                     nbBitsSpinBox->setValue(5);
00129                     headerComboBox->setCurrentIndex(0);
00130                     break;
00131                 case 2: // normal
00132                     redCheckBox->setChecked(true);
00133                     greenCheckBox->setChecked(true);
00134                     blueCheckBox->setChecked(true);
00135                     nbBitsSpinBox->setValue(3);
00136                     headerComboBox->setCurrentIndex(2);
00137                     break;
00138                 case 3: // high
00139                     redCheckBox->setChecked(true);
00140                     greenCheckBox->setChecked(true);
00141                     blueCheckBox->setChecked(true);
00142                     nbBitsSpinBox->setValue(2);
00143                     headerComboBox->setCurrentIndex(2);
00144                     break;
00145                 case 4: // best
00146                     redCheckBox->setChecked(false);
00147                     greenCheckBox->setChecked(false);
00148                     blueCheckBox->setChecked(true);
00149                     nbBitsSpinBox->setValue(1);
00150                     headerComboBox->setCurrentIndex(2);
00151                     break;
00152                 default:
00153                     m_logger->warning("Unhandle quality mode switch value: " + QString::number(value));
00154                     break;
00155             }
00156             m_dontUpdate = false;
00157             settingsChanged();
00158         }
00159     }
00160 
00161     void OptionWidget::settingsChanged(int value)
00162     {
00163         Q_UNUSED(value);
00164 
00165         if (!m_dontUpdate)
00166         {
00167             m_dontUpdate = true;
00168             int nbPixel = 0;
00169             if (isRedUsed()) {
00170                 nbPixel++;
00171             }
00172             if (isGreenUsed()) {
00173                 nbPixel++;
00174             }
00175             if (isBlueUsed()) {
00176                 nbPixel++;
00177             }
00178             m_logger->debug("nb pixel used: " + QString::number(nbPixel) + ", nb bits: " + QString::number(nbBits()));
00179 
00180             double quality = (1 - ((pow(2, nbBits()) * nbPixel) / 768.0)) * 100.0;
00181             pourcentLabel->setText(QString::number(quality) + "%");
00182             m_logger->debug("computed quality: " + QString::number(quality));
00183 
00184             if (quality > 99)
00185                 qualityComboBox->setCurrentIndex(4); // best
00186             else if (quality > 98)
00187                 qualityComboBox->setCurrentIndex(3); // high
00188             else if (quality > 95)
00189                 qualityComboBox->setCurrentIndex(2); // normal
00190             else if (quality > 85)
00191                 qualityComboBox->setCurrentIndex(1); // low
00192             else
00193                 qualityComboBox->setCurrentIndex(0); // very low
00194 
00195             emit optionHasChanged();
00196             m_dontUpdate = false;
00197         }
00198     }
00199 }