Orb/Doxygen/addon/doxywizard/inputint.cpp
changeset 0 42188c7ea2d9
equal deleted inserted replaced
-1:000000000000 0:42188c7ea2d9
       
     1 /******************************************************************************
       
     2  *
       
     3  * 
       
     4  *
       
     5  * Copyright (C) 1997-2007 by Dimitri van Heesch.
       
     6  *
       
     7  * Permission to use, copy, modify, and distribute this software and its
       
     8  * documentation under the terms of the GNU General Public License is hereby 
       
     9  * granted. No representations are made about the suitability of this software 
       
    10  * for any purpose. It is provided "as is" without express or implied warranty.
       
    11  * See the GNU General Public License for more details.
       
    12  *
       
    13  */
       
    14 
       
    15 #include "inputint.h"
       
    16 #include "helplabel.h"
       
    17 
       
    18 #include <QtGui>
       
    19 
       
    20 InputInt::InputInt( QGridLayout *layout,int &row,
       
    21                     const QString & id, 
       
    22                     int defVal, int minVal,int maxVal,
       
    23                     const QString & docs )
       
    24   : m_default(defVal), m_minVal(minVal), m_maxVal(maxVal), m_docs(docs), m_id(id)
       
    25 {
       
    26   m_lab = new HelpLabel(id);
       
    27   m_sp  = new QSpinBox;
       
    28   m_sp->setMinimum(minVal);
       
    29   m_sp->setMaximum(maxVal);
       
    30   m_sp->setSingleStep(1);
       
    31   m_val=defVal-1; // force update
       
    32   setValue(defVal);
       
    33 
       
    34   layout->addWidget( m_lab, row, 0 );
       
    35   layout->addWidget( m_sp, row, 1 );
       
    36 
       
    37   connect(m_sp, SIGNAL(valueChanged(int)), 
       
    38           this, SLOT(setValue(int)) );
       
    39   connect( m_lab, SIGNAL(enter()), SLOT(help()) );
       
    40   connect( m_lab, SIGNAL(reset()), SLOT(reset()) );
       
    41   row++;
       
    42 }
       
    43 
       
    44 void InputInt::help()
       
    45 {
       
    46   showHelp(this);
       
    47 }
       
    48 
       
    49 
       
    50 void InputInt::setValue(int val)
       
    51 {
       
    52   val = qMax(m_minVal,val);
       
    53   val = qMin(m_maxVal,val);
       
    54   if (val!=m_val) 
       
    55   {
       
    56     m_val = val;
       
    57     m_sp->setValue(val);
       
    58     m_value = m_val;
       
    59     if (m_val==m_default)
       
    60     {
       
    61       m_lab->setText(QString::fromAscii("<qt>")+m_id+QString::fromAscii("</qt"));
       
    62     }
       
    63     else
       
    64     {
       
    65       m_lab->setText(QString::fromAscii("<qt><font color='red'>")+m_id+QString::fromAscii("</font></qt>"));
       
    66     }
       
    67     emit changed(); 
       
    68   }
       
    69 }
       
    70 
       
    71 void InputInt::setEnabled(bool state)
       
    72 {
       
    73   m_lab->setEnabled(state);
       
    74   m_sp->setEnabled(state);
       
    75 }
       
    76 
       
    77 QVariant &InputInt::value() 
       
    78 {
       
    79   return m_value;
       
    80 }
       
    81 
       
    82 void InputInt::update()
       
    83 {
       
    84   setValue(m_value.toInt());
       
    85 }
       
    86 
       
    87 void InputInt::reset()
       
    88 {
       
    89   setValue(m_default);
       
    90 }
       
    91 
       
    92 void InputInt::writeValue(QTextStream &t,QTextCodec *)
       
    93 {
       
    94   t << m_val;
       
    95 }
       
    96