DlgSettingsImageImp.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2005 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 
00026 #include "DlgSettingsImageImp.h"
00027 #include "SpinBox.h"
00028 
00029 using namespace Gui::Dialog;
00030 using namespace std;
00031 
00032 /* TRANSLATOR Gui::Dialog::DlgSettingsImageImp */
00033 
00038 DlgSettingsImageImp::DlgSettingsImageImp( QWidget* parent )
00039   : QWidget( parent )
00040 {
00041     this->setupUi(this);
00042     SbVec2s res = SoOffscreenRenderer::getMaximumResolution();
00043     spinWidth->setMaximum((int)res[0]);
00044     spinHeight->setMaximum((int)res[1]);
00045 
00046     _width = width();
00047     _height = height();
00048     _fRatio = (float)_width/(float)_height;
00049 }
00050 
00054 DlgSettingsImageImp::~DlgSettingsImageImp()
00055 {
00056     // no need to delete child widgets, Qt does it all for us
00057 }
00058 
00059 void DlgSettingsImageImp::changeEvent(QEvent *e)
00060 {
00061     if (e->type() == QEvent::LanguageChange) {
00062         this->retranslateUi(this);
00063     }
00064     QWidget::changeEvent(e);
00065 }
00066 
00070 void DlgSettingsImageImp::setImageSize(int w, int h)
00071 {
00072     // set current screen size
00073     standardSizeBox->setItemData(0, QSize(w,h));
00074 
00075     spinWidth->setValue(w);
00076     spinHeight->setValue(h);
00077 
00078     // As the image size is in pixel why shouldn't _width and _height be integers?
00079     _width  = w;
00080     _height = h;
00081     _fRatio = (float)_width/(float)_height;
00082 }
00083 
00087 void DlgSettingsImageImp::setImageSize( const QSize& s )
00088 {
00089     // set current screen size
00090     standardSizeBox->setItemData(0, s);
00091 
00092     spinWidth->setValue( s.width() );
00093     spinHeight->setValue( s.height() );
00094 
00095     // As the image size is in pixel why shouldn't _width and _height be integers?
00096     _width  = s.width();
00097     _height = s.height();
00098     _fRatio = (float)_width/(float)_height;
00099 }
00100 
00104 QSize DlgSettingsImageImp::imageSize() const
00105 {
00106     return QSize( spinWidth->value(), spinHeight->value() );
00107 }
00108 
00112 int DlgSettingsImageImp::imageWidth() const
00113 {
00114     return spinWidth->value();
00115 }
00116 
00120 int DlgSettingsImageImp::imageHeight() const
00121 {
00122     return spinHeight->value();
00123 }
00124 
00129 QString DlgSettingsImageImp::comment() const
00130 {
00131     if ( !textEditComment->isEnabled() )
00132         return QString::null;
00133     else
00134         return textEditComment->toPlainText();
00135 }
00136 
00137 int DlgSettingsImageImp::backgroundType() const
00138 {
00139     return comboBackground->currentIndex();
00140 }
00141 
00142 void DlgSettingsImageImp::onSelectedFilter(const QString& filter)
00143 {
00144     bool ok = (filter.startsWith(QLatin1String("JPG")) ||
00145                filter.startsWith(QLatin1String("JPEG")) ||
00146                filter.startsWith(QLatin1String("PNG")));
00147     buttonGroupComment->setEnabled( ok );
00148 }
00149 
00150 void DlgSettingsImageImp::adjustImageSize(float fRatio)
00151 {
00152     // if width has changed then adjust height and vice versa, if both has changed then adjust width
00153     if (_height != spinHeight->value())
00154     {
00155         _height = spinHeight->value();
00156         _width = (int)((float)_height*fRatio);
00157         spinWidth->setValue( (int)_width );
00158     }
00159     else // if( _width != spinWidth->value() )
00160     {
00161         _width = spinWidth->value();
00162         _height = (int)((float)_width/fRatio);
00163         spinHeight->setValue( (int)_height );
00164     }
00165 }
00166 
00167 void DlgSettingsImageImp::on_buttonRatioScreen_clicked()
00168 {
00169     adjustImageSize(_fRatio);
00170 }
00171 
00172 void DlgSettingsImageImp::on_buttonRatio4x3_clicked()
00173 {
00174     adjustImageSize(4.0f/3.0f);
00175 }
00176 
00177 void DlgSettingsImageImp::on_buttonRatio16x9_clicked()
00178 {
00179     adjustImageSize(16.0f/9.0f);
00180 }
00181 
00182 void DlgSettingsImageImp::on_buttonRatio1x1_clicked()
00183 {
00184     adjustImageSize(1.0f);
00185 }
00186 
00187 void DlgSettingsImageImp::on_standardSizeBox_activated(int index)
00188 {
00189     if (index == 0) {
00190         // we have set the user data for the 1st item
00191         QSize s = standardSizeBox->itemData(0).toSize();
00192         spinWidth->setValue(s.width());
00193         spinHeight->setValue(s.height());
00194     }
00195     else {
00196         // try to extract from the string
00197         QString text = standardSizeBox->itemText(index);
00198         QRegExp rx(QLatin1String("\\b\\d{2,4}\\b"));
00199         int pos = 0;
00200         pos = rx.indexIn(text, pos);
00201         QString w = text.mid(pos, rx.matchedLength());
00202         spinWidth->setValue(w.toInt());
00203         pos += rx.matchedLength();
00204         pos = rx.indexIn(text, pos);
00205         QString h = text.mid(pos, rx.matchedLength());
00206         spinHeight->setValue(h.toInt());
00207     }
00208 }
00209 
00210 #include "moc_DlgSettingsImageImp.cpp"

Generated on Wed Nov 23 19:00:07 2011 for FreeCAD by  doxygen 1.6.1