gSAFE  1.3.8
dialib.cpp
1 /* gSAFE - LIB
2  general Sql dAtabase FrontEnd
3  http://hyperprog.com/gsafe/
4 
5  (C) 2005-2013 Peter Deak (hyper80@gmail.com)
6 
7  License: GPLv2 http://www.gnu.org/licenses/gpl-2.0.html
8 
9  dialib.cpp
10 */
11 
12 #include <QtCore>
13 #include <QtGui>
14 
15 #include "dialib.h"
16 #include "dconsole.h"
17 
19 {
20  table1 = NULL;
21  table2 = NULL;
22  list1 = NULL;
23  list2 = NULL;
24  dmatrix1 = NULL;
25  dmatrix2 = NULL;
26  toolbutton1 = NULL;
27  toolbutton2 = NULL;
28  t1C = false;
29  t1AC = false;
30  t2C = false;
31  t2AC = false;
32  EscC = false;
33  inscroll = false;
34  deletedata = false;
35  declose = false;
36 
37  tb1clicked = false;
38  tb2clicked = false;
39 }
40 
41 int HDialogData::makeGui(QWidget *basew,QString caption,HBase *dobj1,HBase *dobj2,
42  QString func,QString ttext,QString tbutt1,QString tbutt2,QList<QPixmap *> *toolbuttons,int xsize,int ysize)
43 {
44  sdebug("*** HDialog::makeGui ***");
45 
46  if(func.contains("EscC"))
47  EscC = true;
48 
49  if(func.contains("TB1cl")) //undocumented option == TB1Close (compatibility with older programs)
50  t1C = true;
51  if(func.contains("TB1Close"))
52  t1C = true;
53  if(func.contains("TB2cl")) //undocumented option == TB2Close (compatibility with older programs)
54  t2C = true;
55  if(func.contains("TB2Close"))
56  t2C = true;
57 
58  if(func.contains("TB1AcceptClose"))
59  t1AC = true;
60  if(func.contains("TB2AcceptClose"))
61  t2AC = true;
62 
63  if(func.contains("InScroll"))
64  inscroll = true;
65  if(func.contains("DeleteData"))
66  deletedata = true;
67  if(func.contains("DestructiveClose"))
68  declose = true;
69 
70  basew->setWindowTitle(caption.isEmpty() ? "Dialog..." : caption );
71 
72  //Creating widget elements
73  if(dobj1 != NULL)
74  {
75  if(dobj1->getWhoami() == "HTable")
76  {
77  if(inscroll)
78  {
79  sv1 = new QScrollArea(basew);
80 
81  table1 = new HDispTable(sv1,(HTable *)dobj1,KEEP_ALL,deletedata?DELETE_DATA:DONT_DELETE_DATA);
82  sv1->setWidget(table1);
83  sv1->setWidgetResizable(true);
84  }
85  else
86  table1 = new HDispTable(basew,(HTable *)dobj1,KEEP_ALL,deletedata?DELETE_DATA:DONT_DELETE_DATA);
87 
88  if(func.contains("StrToE"))
89  table1->addStretchToEnd();
90  }
91  if(dobj1->getWhoami() == "HList")
92  {
93  list1 = new HDispList(basew,(HList *)dobj1,KEEP_ALL,deletedata ? DELETE_DATA:DONT_DELETE_DATA);
94  basew->connect(list1,SIGNAL(listItemChanged()),basew,SLOT(lic()));
95  }
96  if(dobj1->getWhoami() == "HPlainDataMatrix")
97  {
98  dmatrix1 = new HDispPlainDataMatrix(basew,(HPlainDataMatrix *)dobj1,false,-1,deletedata ? DELETE_DATA:DONT_DELETE_DATA);
99  }
100 
101  }
102  if(dobj2 != NULL)
103  {
104  if(dobj2->getWhoami() == "HTable")
105  {
106  if(inscroll)
107  {
108  sv2 = new QScrollArea(basew);
109  table2 = new HDispTable(sv2,(HTable *)dobj2,KEEP_ALL,deletedata?DELETE_DATA:DONT_DELETE_DATA);
110  sv2->setWidget(table2);
111  sv2->setWidgetResizable(true);
112  }
113  else
114  table2 = new HDispTable(basew,(HTable *)dobj2,KEEP_ALL,deletedata?DELETE_DATA:DONT_DELETE_DATA);
115 
116  if(func.contains("StrToE"))
117  table2->addStretchToEnd();
118  }
119  if(dobj2->getWhoami() == "HList")
120  {
121  list2 = new HDispList(basew,(HList *)dobj2,KEEP_ALL,deletedata?DELETE_DATA:DONT_DELETE_DATA);
122  basew->connect(list2,SIGNAL(listItemChanged()),basew,SLOT(lic()));
123  }
124  if(dobj2->getWhoami() == "HPlainDataMatrix")
125  {
126  dmatrix2 = new HDispPlainDataMatrix(basew,(HPlainDataMatrix *)dobj2,false,-1,deletedata ? DELETE_DATA:DONT_DELETE_DATA);
127  }
128 
129  }
130 
131  closebutton=NULL;
132 
133  if(!tbutt1.isEmpty())
134  toolbutton1 = new QPushButton(tbutt1,basew);
135 
136  if(!tbutt2.isEmpty())
137  toolbutton2 = new QPushButton(tbutt2,basew);
138 
139  //Layouts
140  QVBoxLayout *mainLayout = new QVBoxLayout(basew);
141 
142  if(!ttext.isEmpty())
143  {
144  QBoxLayout *titleLayout = new QHBoxLayout(0);
145  titleLayout->setMargin(5);
146  titleLayout->setSpacing(5);
147  titleLayout->addStretch();
148  titleLayout->addWidget(new QLabel(ttext,basew));
149  titleLayout->addStretch();
150  mainLayout->addLayout(titleLayout);
151  }
152 
153  if(toolbuttons)
154  {
155  int i;
156 
157  QHBoxLayout *pixtoollay = new QHBoxLayout(0);
158  pixtoollay->setMargin(2);
159  pixtoollay->setSpacing(2);
160  for(i=0;i<8;i++)
161  pixTool[i] = NULL;
162  if(func.contains("ToolCenter"))
163  pixtoollay->addStretch();
164  for(i=0;i<(int)toolbuttons->count();i++)
165  {
166  sdebug(QString("Pixmap toolbutton %1 initializing...").arg(i));
167  pixTool[i] = new QToolButton(basew);
168  pixTool[i]->setIcon( *(toolbuttons->at(i)));
169  pixTool[i]->resize(25,25);
170  pixtoollay->addWidget(pixTool[i]);
171  }
172 
173  pixtoollay->addStretch();
174  mainLayout->addLayout(pixtoollay);
175  }
176 
177  if(table1 != NULL || table2 != NULL || list1 != NULL || list2 != NULL || dmatrix1 != NULL || dmatrix2 != NULL)
178  {
179  QBoxLayout *dviewLayout;
180  if(func.contains("DHoriz"))
181  dviewLayout = new QHBoxLayout(0);
182  else
183  dviewLayout = new QVBoxLayout(0);
184 
185  dviewLayout->setMargin(5);
186  dviewLayout->setSpacing(5);
187  if(table1 != NULL)
188  dviewLayout->addWidget(inscroll ? (QWidget *)sv1 : (QWidget *)table1);
189  if(list1 != NULL)
190  dviewLayout->addWidget(list1 );
191  if(dmatrix1 != NULL)
192  dviewLayout->addWidget(dmatrix1);
193 
194  if(table2 != NULL)
195  dviewLayout->addWidget(inscroll ? (QWidget *)sv2 : (QWidget *)table2);
196  if(list2 != NULL)
197  dviewLayout->addWidget(list2 );
198  if(dmatrix2 != NULL)
199  dviewLayout->addWidget(dmatrix2);
200 
201  mainLayout->addLayout(dviewLayout);
202  }
203 
204  if(toolbutton1 != NULL || toolbutton2 != NULL)
205  {
206  QBoxLayout *toolLayout;
207  if(func.contains("THoriz"))
208  toolLayout = new QHBoxLayout(0);
209  else
210  toolLayout = new QVBoxLayout(0);
211  toolLayout->setMargin(5);
212  toolLayout->setSpacing(5);
213  if(func.contains("THoriz"))
214  toolLayout->addStretch();
215  if(toolbutton1 != NULL)
216  toolLayout->addWidget(toolbutton1);
217  if(toolbutton2 != NULL)
218  toolLayout->addWidget(toolbutton2);
219  if(func.contains("THoriz"))
220  toolLayout->addStretch();
221  mainLayout->addLayout(toolLayout);
222  }
223 
224  if(func.contains("Ok"))
225  {
226  closebutton = new QPushButton("Ok",basew);
227 
228  QBoxLayout *closeLayout = new QHBoxLayout(0);
229  closeLayout->setMargin(5);
230  closeLayout->setSpacing(5);
231  closeLayout->addStretch();
232  closeLayout->addWidget(closebutton);
233  closeLayout->addStretch();
234  mainLayout->addLayout(closeLayout);
235  }
236 
237  //connects
238 
239  if(closebutton != NULL)
240  {
241  if(func.contains("OkIsAccept"))
242  {
243  if(!basew->connect(closebutton,SIGNAL(clicked()),basew,SLOT(accept())))
244  error("In HDialogData::makeGui cannot connect: closebutton,SIGNAL(clicked()) to basew,SLOT(accept()) !");
245  }
246  else
247  {
248  if(!basew->connect(closebutton,SIGNAL(clicked()),basew,SLOT(close())))
249  error("In HDialogData::makeGui cannot connect: closebutton,SIGNAL(clicked()) to basew,SLOT(close()) !");
250  }
251  }
252  if(toolbutton1 != NULL)
253  basew->connect(toolbutton1,SIGNAL(clicked()),basew,SLOT(tbutton1Cl()));
254  if(toolbutton2 != NULL)
255  basew->connect(toolbutton2,SIGNAL(clicked()),basew,SLOT(tbutton2Cl()));
256 
257  if(xsize != 0 || ysize != 0)
258  basew->resize(xsize,ysize);
259 
260  sdebug("*** HDialog::makeGui *** END");
261 
262  return 0;
263 }
264 
265 int HDialog::run(QWidget *parent,QString caption,HBase *dobj1,HBase *dobj2,QString func,
266  QString ttext,QString tbutt1,QString tbutt2,QList<QPixmap *> *toolbuttons,int xsize,int ysize)
267 {
268  int result;
269  HDialog *d;
270 
271  if(func.contains("AutoExec"))
272  {
273  error("Do not pass \"AutoExec\" option to HDialog::run !");
274  return -1;
275  }
276 
277  d = new HDialog(parent,caption,dobj1,dobj2,func,ttext,tbutt1,tbutt2,toolbuttons,xsize,ysize);
278  result = d->exec();
279  delete d;
280  return result;
281 }
282 
283 // ///////////////////////////////////////////////////////////////////////////////////////////////
284 
285 HDialog::HDialog(QWidget *parent,QString caption,HBase *dobj1,HBase *dobj2,QString func,
286  QString ttext,QString tbutt1,QString tbutt2,QList<QPixmap *> *toolbuttons,int xsize,int ysize)
287  : QDialog(parent,Qt::WindowMaximizeButtonHint|Qt::WindowCloseButtonHint),
288  HDialogData()
289 {
290  sdebug("*** HDialog::HDialog ***");
291 
292  if(!func.contains("NonModal"))
293  setModal(true);
294 
295  parent_dialog = parent;
296 
297  makeGui(this,caption,dobj1,dobj2,func,ttext,tbutt1,tbutt2,toolbuttons,xsize,ysize);
298 
299  if(declose)
300  setAttribute(Qt::WA_DeleteOnClose);
301 
302  setSizeGripEnabled(true);
303 
304  //Execute dialog if necessary
305  if(func.contains("AutoExec"))
306  exec();
307  sdebug("*** HDialog::HDialog *** END");
308 }
309 
311 {
312  sdebug("*** HDialog::HDialog ***");
313  sdebug("*** HDialog::HDialog *** END");
314 }
315 
316 int HDialog::lic(void)
317 {
318  emit listItemChanged();
319  return 0;
320 }
321 
322 
323 int HDialog::tbutton1Cl(void)
324 {
325  emit tbutton1Clicked();
326 
327  if(t1C)
328  {
329  tb1clicked = true;
330  if(t1AC)
331  accept();
332  else
333  close();
334  }
335 
336  return 0;
337 }
338 
339 int HDialog::tbutton2Cl(void)
340 {
341  emit tbutton2Clicked();
342 
343  if(t2C)
344  {
345  tb2clicked = true;
346  if(t2AC)
347  accept();
348  else
349  close();
350  }
351 
352  return 0;
353 }
354 
355 void HDialog::keyPressEvent(QKeyEvent *e)
356 {
357  if(e->key() == Qt::Key_Escape)
358  {
359  if(EscC)
360  {
361  close();
362  return;
363  }
364  else return;
365  }
366 
367  QDialog::keyPressEvent(e);
368 }
369 
370 
371 // ///////////////////////////////////////////////////////////////////////////
372 // /class HGetTextBox //
373 // ///////////////////////////////////////////////////////////////////////////
374 
375 HGetTextBox::HGetTextBox(QWidget *parent,QString cap,QString text,QList<QString> exptexts,bool largetexts)
376 : QDialog(parent)
377 {
378  int i,size;
379 
380  large=largetexts;
381  setWindowTitle(cap);
382  QVBoxLayout *mainlay = new QVBoxLayout(this);
383  mainlay->setMargin(5);
384  mainlay->setSpacing(5);
385  QHBoxLayout *toplay = new QHBoxLayout(0);
386  toplay->setMargin(5);
387  toplay->setSpacing(5);
388  QLabel *label = new QLabel(text,this);
389  toplay->addStretch();
390  toplay->addWidget(label);
391  toplay->addStretch();
392  mainlay->addLayout(toplay);
393 
394 
395  QVBoxLayout *leftlay = new QVBoxLayout(0);
396  leftlay->setMargin(5);
397  leftlay->setSpacing(5);
398 
399  QVBoxLayout *rightlay = new QVBoxLayout(0);
400  rightlay->setMargin(5);
401  rightlay->setSpacing(5);
402 
403  size=(int)exptexts.size();
404  for(i=0;i<size;++i)
405  {
406  QHBoxLayout *midlay = new QHBoxLayout(0);
407  midlay->setMargin(5);
408  midlay->setSpacing(5);
409  QLabel *sublabel = new QLabel(exptexts[i],this);
410 
411  if(largetexts)
412  {
413  QTextEdit *mline = new QTextEdit("",this);
414  leftlay->addWidget(sublabel);
415  rightlay->addWidget(mline);
416 
417  mledits.push_back(mline);
418  }
419  else
420  {
421  QLineEdit *line = new QLineEdit("",this);
422  leftlay->addWidget(sublabel);
423  rightlay->addWidget(line);
424 
425  ledits.push_back(line);
426  }
427 
428  }
429 
430  QHBoxLayout *midlay = new QHBoxLayout(0);
431  midlay->setMargin(5);
432  midlay->setSpacing(5);
433 
434  midlay->addLayout(leftlay);
435  midlay->addStretch();
436  midlay->addLayout(rightlay);
437  mainlay->addLayout(midlay);
438 
439  QHBoxLayout *sublay = new QHBoxLayout(0);
440  sublay->setMargin(5);
441  sublay->setSpacing(5);
442 
443  QPushButton *button = new QPushButton("Ok",this);
444  sublay->addStretch();
445  sublay->addWidget(button);
446  sublay->addStretch();
447  mainlay->addLayout(sublay);
448 
449  connect(button,SIGNAL(clicked()),this,SLOT(clickOk()));
450 }
451 
452 int HGetTextBox::clickOk(void)
453 {
454  int i,size;
455 
456  if(large)
457  {
458  size=(int)mledits.size();
459  results.clear();
460  for(i=0;i<size;++i)
461  {
462  results.push_back(mledits[i]->toPlainText());
463  }
464 
465  }
466  else
467  {
468  size=(int)ledits.size();
469  results.clear();
470  for(i=0;i<size;++i)
471  {
472  results.push_back(ledits[i]->text());
473  }
474  }
475  accept();
476  return 0;
477 }
478 
479 //end code.
QWidget * parent_dialog
Definition: dialib.h:193
#define DONT_DELETE_DATA
Definition: guilib.h:59
~HDialog(void)
Definition: dialib.cpp:310
static int run(QWidget *parent=0, QString caption=0, HBase *dobj1=NULL, HBase *dobj2=NULL, QString func="Ok|EscC|Vert", QString ttext="", QString tbutt1="", QString tbutt2="", QList< QPixmap * > *toolbuttons=NULL, int xsize=320, int ysize=240)
Definition: dialib.cpp:265
#define DELETE_DATA
Definition: guilib.h:60
HDialog(QWidget *parent=0, QString caption=0, HBase *dobj1=NULL, HBase *dobj2=NULL, QString func="Ok|EscC|Vert", QString ttext="", QString tbutt1="", QString tbutt2="", QList< QPixmap * > *toolbuttons=NULL, int xsize=320, int ysize=240)
Definition: dialib.cpp:285
void listItemChanged(void)
int addStretchToEnd(void)
Definition: guilib.cpp:2623
Definition: datalib.h:312
int makeGui(QWidget *basew, QString caption=0, HBase *dobj1=NULL, HBase *dobj2=NULL, QString func="Ok|EscC|Vert", QString ttext="", QString tbutt1="", QString tbutt2="", QList< QPixmap * > *toolbuttons=NULL, int xsize=320, int ysize=240)
Definition: dialib.cpp:41
void sdebug(QString s)
Definition: dconsole.cpp:48
QString getWhoami(void)
Definition: datalib.cpp:774
bool tb2clicked
Definition: dialib.h:125
void tbutton2Clicked(void)
void error(QString s)
Definition: datalib.cpp:37
#define KEEP_ALL
Definition: guilib.h:48
HGetTextBox(QWidget *parent, QString cap, QString text, QList< QString > exptexts, bool largetexts=false)
Definition: dialib.cpp:375
QList< QString > results
Definition: dialib.h:242
bool tb1clicked
Definition: dialib.h:123
HDialogData(void)
Definition: dialib.cpp:18
void tbutton1Clicked(void)