File: rparameterdialog.cpp

package info (click to toggle)
qcad 1.3.3-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 4,504 kB
  • ctags: 2,449
  • sloc: cpp: 29,400; makefile: 49; sh: 15
file content (202 lines) | stat: -rw-r--r-- 4,108 bytes parent folder | download
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/***************************************************************************
                          rparameterdialog.cpp  -  description
                             -------------------
    begin                : Mon Sep 27 1999
    copyright            : (C) 1999 by Andreas Mustun
    email                : andrew@ribbonsoft.com
 ***************************************************************************/


/****************************************************************************
** RParameterDialog.cpp 1998/09/03 A. Mustun RibbonSoft
**
** Copyright (C) 1998 RibbonSoft.  All rights reserved.
**
*****************************************************************************/


#include <string.h>

#include <qapplication.h>
#include <qkeycode.h>
#include <qlayout.h>
#include <qstring.h>

#include "rconfig.h"
#include "rparameterdialog.h"
#include "rlabel.h"
#include "rlineedit.h"
#include "rlog.h"
#include "rprgdef.h"
#include "rpushbutton.h"
#include "rstring.h"

#define DEF_MAXENTRIES 6

// Constructor:
//
RParameterDialog::RParameterDialog(QWidget* _parent, 
                                   const char* _title, 
                                   QPixmap& _pixmap)
  :QDialog(_parent, _title, true, WStyle_NormalBorder)
{
  setCaption(_title);

  setFixedSize(DEF_PARAMDLG_WIDTH, DEF_PARAMDLG_HEIGHT);
  
  gl = new QGridLayout(this, DEF_MAXENTRIES+2, 4, 8, 0);
  for(int i=0; i<DEF_MAXENTRIES+2; ++i) {
    gl->setRowStretch(i, 1);
  }
  
  gl->setColStretch(0, 17);
  gl->setColStretch(1, 8);
  gl->setColStretch(2, 8);
  gl->setColStretch(3, 8);
  
  
  RLabel* pixmap = new RLabel(this);
  pixmap->setPixmap(_pixmap);
  gl->addMultiCellWidget(pixmap, 0, DEF_MAXENTRIES+1, 0, 0);

  bOk = new RPushButton(RMES(46), this);
  bOk->setAccel(Key_Return);
  gl->addWidget(bOk, DEF_MAXENTRIES+1, 2);
  connect(bOk, SIGNAL(clicked()), SLOT(accept()));
  
  bCancel = new RPushButton(RMES(47), this);
  bCancel->setAccel(Key_Escape);
  gl->addWidget(bCancel, DEF_MAXENTRIES+1, 3);
  connect(bCancel, SIGNAL(clicked()), SLOT(reject()));

  /*
  bHelp = new RPushButton(RMES(48), this);
  bHelp->setAccel(Key_F1);
  gl->addWidget(bHelp, DEF_MAXENTRIES+1, 3);
  */
  
  lLabel.setAutoDelete(true);
  eInput.setAutoDelete(true);
  
  insertPos=0;

}



// Destructor:
//
RParameterDialog::~RParameterDialog()
{

}



// Add an input with a char* as default value:
//
void 
RParameterDialog::addEntry(const char* _mes, const char* _val)
{
  RLabel* label = new RLabel(_mes, this);
  label->setAlignment(AlignRight|AlignVCenter);
  gl->addMultiCellWidget(label, insertPos+1, insertPos+1, 1, 2);
  lLabel.append(label);

  RLineEdit* input = new RLineEdit(this);
  input->setText(_val);
  gl->addWidget(input, insertPos+1, 3);
  eInput.append(input);
  if(insertPos<DEF_MAXENTRIES) ++insertPos;
}



// Add an input with an int as default value:
//
void 
RParameterDialog::addEntry(const char* _mes, int _val)
{
  char val[256];
  sprintf(val, "%d", _val);
  addEntry(_mes, val);
}



// Add an input with a float as default value:
//
void 
RParameterDialog::addEntry(const char* _mes, float _val)
{
  char val[256];
  strncpy(val, strFloatToString(_val).latin1(), 255);
  addEntry(_mes, val);
}



// Get the input in field _index as a string:
//
const char*
RParameterDialog::getStringInput(int _index)
{
  if(_index>=0 && _index<(int)eInput.count()) {
  
    RLOG("\nStringInput at ");
    RLOG(_index);
    RLOG(" is ");
    RLOG(eInput.at(_index)->text());
    
    return eInput.at(_index)->text();
  }
  else {
    return 0;
  }
}



// Get the input in field _index as an int:
//
int
RParameterDialog::getIntInput(int _index)
{
  QCString val=getStringInput(_index);
  
  if(!val.isEmpty()) {
  
    RLOG("\nIntInput at ");
    RLOG(_index);
    RLOG(" is ");
    RLOG(val.toInt());
    
    return val.toInt();
  }
  else {
    return 0;
  }
}



// Get the input in field _index as a float:
//
float
RParameterDialog::getFloatInput(int _index)
{
  QCString val=getStringInput(_index);
  
  if(!val.isEmpty()) {
    return val.toFloat();
  }
  else {
    return 0;
  }
}



// EOF3