DlgInputDialogImp.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2006 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 "DlgInputDialogImp.h"
00027 #include "SpinBox.h"
00028 
00029 
00030 using namespace Gui::Dialog;
00031 
00032 /* TRANSLATOR Gui::Dialog::DlgInputDialogImp */
00033 
00041 DlgInputDialogImp::DlgInputDialogImp( const QString& labelTxt, QWidget* parent, bool modal, Type type )
00042   : QDialog( parent )
00043 {
00044     this->setModal(modal);
00045     this->setupUi(this);
00046     label->setText(labelTxt);
00047 
00048     QSize bs = buttonOk->sizeHint().expandedTo(buttonCancel->sizeHint());
00049     buttonOk->setFixedSize( bs );
00050     buttonCancel->setFixedSize( bs );
00051 
00052     QSize sh = sizeHint();
00053     setType(type);
00054     resize(qMax(sh.width(), 400), 1);
00055 
00056     connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(tryAccept()));
00057     connect(lineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(textChanged(const QString&)));
00058 }
00059 
00063 DlgInputDialogImp::~DlgInputDialogImp()
00064 {
00065     // no need to delete child widgets, Qt does it all for us
00066 }
00067 
00068 void DlgInputDialogImp::textChanged( const QString &s )
00069 {
00070     bool on = TRUE;
00071 
00072     if (lineEdit->validator()) {
00073         QString str = lineEdit->text();
00074         int index = lineEdit->cursorPosition();
00075         on = ( lineEdit->validator()->validate(str, index) == QValidator::Acceptable );
00076     }
00077     else if ( type() != LineEdit ) {
00078         on = !s.isEmpty();
00079     }
00080 
00081     buttonOk->setEnabled( on );
00082 }
00083 
00084 void DlgInputDialogImp::tryAccept()
00085 {
00086     if (!lineEdit->text().isEmpty())
00087         accept();
00088 }
00089 
00090 void DlgInputDialogImp::setType( DlgInputDialogImp::Type t )
00091 {
00092     inputtype = t;
00093 
00094     QWidget *input = 0;
00095     switch (inputtype)
00096     {
00097     case LineEdit:
00098         input = lineEdit;
00099         break;
00100     case SpinBox:
00101         input = spinBox;
00102         break;
00103     case UIntBox:
00104         input = uIntSpinBox;
00105         break;
00106     case FloatSpinBox:
00107         input = floatSpinBox;
00108         break;
00109     case ComboBox:
00110         input = comboBox;
00111         break;
00112     default:
00113         break;
00114     }
00115 
00116     if (input) {
00117         stack->setCurrentWidget(input->parentWidget());
00118         stack->setFixedHeight( input->sizeHint().height() );
00119         input->setFocus();
00120         label->setBuddy( input );
00121     }
00122 }
00123 
00124 DlgInputDialogImp::Type DlgInputDialogImp::type() const
00125 {
00126     return inputtype;
00127 }
00128 
00129 QSpinBox *DlgInputDialogImp::getSpinBox() const
00130 {
00131     return spinBox;
00132 }
00133 
00134 Gui::UIntSpinBox *DlgInputDialogImp::getUIntBox() const
00135 {
00136     return uIntSpinBox;
00137 }
00138 
00139 QDoubleSpinBox *DlgInputDialogImp::getFloatSpinBox() const
00140 {
00141     return floatSpinBox;
00142 }
00143 
00144 QLineEdit *DlgInputDialogImp::getLineEdit() const
00145 {
00146     return lineEdit;
00147 }
00148 
00149 QComboBox *DlgInputDialogImp::getComboBox() const
00150 {
00151     return comboBox;
00152 }
00153 
00154 #include "moc_DlgInputDialogImp.cpp"

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