summaryrefslogtreecommitdiffstats
path: root/addon/doxywizard/inputstring.cpp
blob: 7a6004ab53c7a40981d7c0478007c6a94309126e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/******************************************************************************
 *
 * 
 *
 * Copyright (C) 1997-2007 by Dimitri van Heesch.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation under the terms of the GNU General Public License is hereby 
 * granted. No representations are made about the suitability of this software 
 * for any purpose. It is provided "as is" without express or implied warranty.
 * See the GNU General Public License for more details.
 *
 */

#include "inputstring.h"
//#include "pixmaps.h"

#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qwindowsstyle.h>
#include <qcstring.h>
#include <qpushbutton.h>
#include <qfiledialog.h>
#include <qcombobox.h>
#include <qtooltip.h>


InputString::InputString( const QString & label, 
                          QWidget *parent, QCString &s, StringMode m )
  : QWidget( parent ), str(s), sm(m), m_values(0), m_index(0)
{
  if (m==StringFixed)
  {
    QHBoxLayout *layout = new QHBoxLayout( this, 5);
    lab = new QLabel( label, this );
    lab->setMinimumSize( lab->sizeHint() );
    layout->addWidget( lab );
    com = new QComboBox( this ); 
    com->setMinimumSize(com->sizeHint());
    layout->addWidget( com );
    layout->addStretch( 1 );
    le=0;
    br=0;
    layout->activate();
    setMinimumSize( sizeHint() );
  }
  else
  {
    QGridLayout *layout = new QGridLayout( this, 1, m==StringFree ? 1 : 3, 5 );
    lab = new QLabel( label, this );
    lab->setMinimumSize( lab->sizeHint() );
    layout->addWidget( lab,0,0 );
    le = new QLineEdit( this );
    le->setMinimumSize( le->sizeHint() );
    le->setText( s );
    layout->addWidget( le,0,1 );
    if (m==StringFile || m==StringDir)
    {
      //QPixmap pixmap = QPixmap(m==StringFile ? 
      //                         file_xpm :
      //                         folder_xpm );
      br = new QPushButton( this );
      br->setMinimumSize( br->sizeHint() );  
      if (m==StringFile) 
      {
        br->setText("File...");
        QToolTip::add(br,"Browse to a file");
      }
      else 
      {
        br->setText("Folder...");
        QToolTip::add(br,"Browse to a folder");
      }
      layout->addWidget( br,0,2 );
    }
    else
    {
      br=0;
    }
    com=0;
    layout->activate();
    setMinimumSize( sizeHint() );
  }

  if (le)  connect( le,   SIGNAL(textChanged(const QString&)), 
                    this, SLOT(textChanged(const QString&)) );
  if (br)  connect( br,   SIGNAL(clicked()), this, SLOT(browse()) );
  if (com) connect( com,  SIGNAL(activated(const QString &)), 
                    this, SLOT(textChanged(const QString &)) );
}

InputString::~InputString()
{
  if (m_values) delete m_values;
}


void InputString::textChanged(const QString &s)
{
  if (str!=(const char *)s)
  {
    str = s;
    emit changed();
  }
}

void InputString::setEnabled(bool state)
{
  lab->setEnabled(state);
  if (le) le->setEnabled(state);
  if (br) br->setEnabled(state);
  if (com) com->setEnabled(state);
}

void InputString::browse()
{
  if (sm==StringFile)
  {
    QString fileName = QFileDialog::getOpenFileName();

    if (!fileName.isNull()) 
    {
      le->setText( fileName );
      if (str!=(const char *)le->text())
      {
        str = le->text(); 
        emit changed();
      }
    }
  }
  else // sm==StringDir
  {
    QString dirName = QFileDialog::getExistingDirectory();

    if (!dirName.isNull())
    {
      le->setText( dirName ); 	
      if (str!=(const char *)le->text())
      {
        str = le->text();
        emit changed();
      }
    }	
  }
}

void InputString::clear()
{
  le->setText("");
  if (!str.isEmpty())
  {
    emit changed();
    str = "";
  }
}

void InputString::addValue(const char *s)
{
  if (sm==StringFixed)
  {
    if (m_values==0) m_values = new QDict<int>;
    m_values->setAutoDelete(TRUE);
    m_values->insert(s,new int(m_index++));
    com->insertItem(s);
  }
}

void InputString::init()
{
  if (sm==StringFixed)
  {
    int *itemIndex = m_values->find(str);
    if (itemIndex)
    {
      com->setCurrentItem(*itemIndex);
    } 
    else
    {
      com->setCurrentItem(0);
    }
  }
  else
  {
    le->setText(str);
  }
}