My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
qucssettingsdialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qucssettingsdialog.cpp
3  ------------------------
4  begin : Sun May 23 2004
5  copyright : (C) 2003 by Michael Margraf
6  email : michael.margraf@alumni.tu-berlin.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21 
22 #include "qucssettingsdialog.h"
23 #include "main.h"
24 #include "textdoc.h"
25 #include "schematic.h"
26 
27 #include <qwidget.h>
28 #include <qlabel.h>
29 #include <qhbox.h>
30 #include <qtabwidget.h>
31 #include <qlayout.h>
32 #include <qcolordialog.h>
33 #include <qfontdialog.h>
34 #include <qvalidator.h>
35 #include <qpushbutton.h>
36 #include <qlineedit.h>
37 #include <qlistview.h>
38 #include <qcombobox.h>
39 #include <qmessagebox.h>
40 #include <qcheckbox.h>
41 
42 
44  : QDialog(parent, name, TRUE, Qt::WDestructiveClose)
45 {
46  App = parent;
47  setCaption(tr("Edit Qucs Properties"));
48 
49  Expr.setPattern("[\\w_]+");
50  Validator = new QRegExpValidator(Expr, this);
51 
52  all = new QVBoxLayout(this); // to provide the neccessary size
53  QTabWidget *t = new QTabWidget(this);
54  all->addWidget(t);
55 
56  // ...........................................................
57  QWidget *Tab1 = new QWidget(t);
58  QGridLayout *gp = new QGridLayout(Tab1,6,2,6,6);
59 
60  gp->addWidget(new QLabel(tr("Font (set after reload):"), Tab1), 0,0);
61  FontButton = new QPushButton(Tab1);
62  connect(FontButton, SIGNAL(clicked()), SLOT(slotFontDialog()));
63  gp->addWidget(FontButton,0,1);
64 
65  gp->addWidget(new QLabel(tr("Document Background Color:"), Tab1) ,1,0);
66  BGColorButton = new QPushButton(" ", Tab1);
67  connect(BGColorButton, SIGNAL(clicked()), SLOT(slotBGColorDialog()));
68  gp->addWidget(BGColorButton,1,1);
69 
70  gp->addWidget(new QLabel(tr("Language (set after reload):"), Tab1) ,2,0);
71  LanguageCombo = new QComboBox(Tab1);
72  LanguageCombo->insertItem(tr("system language"));
73  LanguageCombo->insertItem(tr("English")+" (en)");
74  LanguageCombo->insertItem(tr("German")+" (de)");
75  LanguageCombo->insertItem(tr("French")+" (fr)");
76  LanguageCombo->insertItem(tr("Spanish")+" (es)");
77  LanguageCombo->insertItem(tr("Italian")+" (it)");
78  LanguageCombo->insertItem(tr("Polish")+" (pl)");
79  LanguageCombo->insertItem(tr("Romanian")+" (ro)");
80  LanguageCombo->insertItem(tr("Japanese")+" (jp)");
81  LanguageCombo->insertItem(tr("Swedish")+" (sv)");
82  LanguageCombo->insertItem(tr("Hungarian")+" (hu)");
83  LanguageCombo->insertItem(tr("Hebrew")+" (he)");
84  LanguageCombo->insertItem(tr("Portuguese")+" (pt)");
85  LanguageCombo->insertItem(tr("Turkish")+" (tr)");
86  LanguageCombo->insertItem(tr("Ukrainian")+" (uk)");
87  LanguageCombo->insertItem(tr("Russian")+" (ru)");
88  LanguageCombo->insertItem(tr("Czech")+" (cs)");
89  LanguageCombo->insertItem(tr("Catalan")+" (ca)");
90  LanguageCombo->insertItem(tr("Arabic")+" (ar)");
91  LanguageCombo->insertItem(tr("Kazakh")+" (kk)");
92  gp->addWidget(LanguageCombo,2,1);
93 
94  val200 = new QIntValidator(0, 200, this);
95  gp->addWidget(new QLabel(tr("maximum undo operations:"), Tab1) ,3,0);
96  undoNumEdit = new QLineEdit(Tab1);
97  undoNumEdit->setValidator(val200);
98  gp->addWidget(undoNumEdit,3,1);
99 
100  gp->addWidget(new QLabel(tr("text editor:"), Tab1) ,4,0);
101  editorEdit = new QLineEdit(Tab1);
102  gp->addWidget(editorEdit,4,1);
103 
104  gp->addWidget(new QLabel(tr("start wiring when clicking open node:"), Tab1) ,5,0);
105  checkWiring = new QCheckBox(Tab1);
106  gp->addWidget(checkWiring,5,1);
107 
108 
109  t->addTab(Tab1, tr("Settings"));
110 
111  // ...........................................................
112  QWidget *Tab3 = new QWidget(t);
113  QGridLayout *gp3 = new QGridLayout(Tab3,5,3,5,5);
114 
115  gp3->addMultiCellWidget(new QLabel(tr("Colors for Syntax Highlighting:"), Tab3), 0,0,0,1);
116 
117  ColorComment = new QPushButton(tr("Comment"), Tab3);
118  ColorComment->setPaletteForegroundColor(QucsSettings.Comment);
119  ColorComment->setPaletteBackgroundColor(QucsSettings.BGColor);
120  connect(ColorComment, SIGNAL(clicked()), SLOT(slotColorComment()));
121  gp3->addWidget(ColorComment,1,0);
122 
123  ColorString = new QPushButton(tr("String"), Tab3);
124  ColorString->setPaletteForegroundColor(QucsSettings.String);
125  ColorString->setPaletteBackgroundColor(QucsSettings.BGColor);
126  connect(ColorString, SIGNAL(clicked()), SLOT(slotColorString()));
127  gp3->addWidget(ColorString,1,1);
128 
129  ColorInteger = new QPushButton(tr("Integer Number"), Tab3);
130  ColorInteger->setPaletteForegroundColor(QucsSettings.Integer);
131  ColorInteger->setPaletteBackgroundColor(QucsSettings.BGColor);
132  connect(ColorInteger, SIGNAL(clicked()), SLOT(slotColorInteger()));
133  gp3->addWidget(ColorInteger,1,2);
134 
135  ColorReal = new QPushButton(tr("Real Number"), Tab3);
136  ColorReal->setPaletteForegroundColor(QucsSettings.Real);
137  ColorReal->setPaletteBackgroundColor(QucsSettings.BGColor);
138  connect(ColorReal, SIGNAL(clicked()), SLOT(slotColorReal()));
139  gp3->addWidget(ColorReal,2,0);
140 
141  ColorCharacter = new QPushButton(tr("Character"), Tab3);
142  ColorCharacter->setPaletteForegroundColor(QucsSettings.Character);
143  ColorCharacter->setPaletteBackgroundColor(QucsSettings.BGColor);
144  connect(ColorCharacter, SIGNAL(clicked()), SLOT(slotColorCharacter()));
145  gp3->addWidget(ColorCharacter,2,1);
146 
147  ColorDataType = new QPushButton(tr("Data Type"), Tab3);
148  ColorDataType->setPaletteForegroundColor(QucsSettings.Type);
149  ColorDataType->setPaletteBackgroundColor(QucsSettings.BGColor);
150  connect(ColorDataType, SIGNAL(clicked()), SLOT(slotColorDataType()));
151  gp3->addWidget(ColorDataType,2,2);
152 
153  ColorAttribute = new QPushButton(tr("Attribute"), Tab3);
154  ColorAttribute->setPaletteForegroundColor(QucsSettings.Attribute);
155  ColorAttribute->setPaletteBackgroundColor(QucsSettings.BGColor);
156  connect(ColorAttribute, SIGNAL(clicked()), SLOT(slotColorAttribute()));
157  gp3->addWidget(ColorAttribute,3,0);
158 
159  ColorDirective = new QPushButton(tr("Directive"), Tab3);
160  ColorDirective->setPaletteForegroundColor(QucsSettings.Directive);
161  ColorDirective->setPaletteBackgroundColor(QucsSettings.BGColor);
162  connect(ColorDirective, SIGNAL(clicked()), SLOT(slotColorDirective()));
163  gp3->addWidget(ColorDirective,3,1);
164 
165  ColorTask = new QPushButton(tr("Task"), Tab3);
166  ColorTask->setPaletteForegroundColor(QucsSettings.Task);
167  ColorTask->setPaletteBackgroundColor(QucsSettings.BGColor);
168  connect(ColorTask, SIGNAL(clicked()), SLOT(slotColorTask()));
169  gp3->addWidget(ColorTask,3,2);
170 
171  t->addTab(Tab3, tr("Source Code Editor"));
172 
173  // ...........................................................
174  QWidget *Tab2 = new QWidget(t);
175  QGridLayout *gp2 = new QGridLayout(Tab2,5,3,3,3);
176 
177  QLabel *l7 = new QLabel(
178  tr("Register filename extensions here in order to\nopen files with an appropriate program.")
179  , Tab2);
180  gp2->addMultiCellWidget(l7,0,0,0,2);
181 
182  List_Suffix = new QListView(Tab2);
183  List_Suffix->addColumn(tr("Suffix"));
184  List_Suffix->addColumn(tr("Program"));
185  gp2->addMultiCellWidget(List_Suffix,1,4,0,0);
186  connect(List_Suffix, SIGNAL(clicked(QListViewItem*)),
187  SLOT(slotEditSuffix(QListViewItem*)));
188 
189  // fill listview with already registered file extensions
190  QStringList::Iterator it = QucsSettings.FileTypes.begin();
191  while(it != QucsSettings.FileTypes.end()) {
192  new QListViewItem(List_Suffix,
193  (*it).section('/',0,0), (*it).section('/',1,1));
194  it++;
195  }
196 
197  QLabel *l5 = new QLabel(tr("Suffix:"), Tab2);
198  gp2->addWidget(l5,1,1);
199  Input_Suffix = new QLineEdit(Tab2);
200  Input_Suffix->setValidator(Validator);
201  gp2->addWidget(Input_Suffix,1,2);
202 // connect(Input_Suffix, SIGNAL(returnPressed()), SLOT(slotGotoProgEdit()));
203 
204  QLabel *l6 = new QLabel(tr("Program:"), Tab2);
205  gp2->addWidget(l6,2,1);
206  Input_Program = new QLineEdit(Tab2);
207  gp2->addWidget(Input_Program,2,2);
208 
209  QHBox *h = new QHBox(Tab2);
210  h->setSpacing(3);
211  gp2->addMultiCellWidget(h,3,3,1,2);
212 
213  QPushButton *AddButt = new QPushButton(tr("Set"), h);
214  connect(AddButt, SIGNAL(clicked()), SLOT(slotAdd()));
215  QPushButton *RemoveButt = new QPushButton(tr("Remove"), h);
216  connect(RemoveButt, SIGNAL(clicked()), SLOT(slotRemove()));
217 
218  gp2->setRowStretch(4,5);
219  t->addTab(Tab2, tr("File Types"));
220 
221  // ...........................................................
222  // buttons on the bottom of the dialog (independent of the TabWidget)
223  QHBox *Butts = new QHBox(this);
224  Butts->setSpacing(3);
225  Butts->setMargin(3);
226  all->addWidget(Butts);
227 
228  QPushButton *OkButt = new QPushButton(tr("OK"), Butts);
229  connect(OkButt, SIGNAL(clicked()), SLOT(slotOK()));
230  QPushButton *ApplyButt = new QPushButton(tr("Apply"), Butts);
231  connect(ApplyButt, SIGNAL(clicked()), SLOT(slotApply()));
232  QPushButton *CancelButt = new QPushButton(tr("Cancel"), Butts);
233  connect(CancelButt, SIGNAL(clicked()), SLOT(reject()));
234  QPushButton *DefaultButt = new QPushButton(tr("Default Values"), Butts);
235  connect(DefaultButt, SIGNAL(clicked()), SLOT(slotDefaultValues()));
236 
237  OkButt->setDefault(true);
238 
239  // ...........................................................
240  // fill the fields with the Qucs-Properties
241 
243  FontButton->setText(Font.toString());
244  BGColorButton->setPaletteBackgroundColor(QucsSettings.BGColor);
245  undoNumEdit->setText(QString::number(QucsSettings.maxUndo));
246  editorEdit->setText(QucsSettings.Editor);
247  checkWiring->setChecked(QucsSettings.NodeWiring);
248 
249  for(int z=LanguageCombo->count()-1; z>=0; z--)
250  if(LanguageCombo->text(z).section('(',1,1).remove(')') == QucsSettings.Language)
251  LanguageCombo->setCurrentItem(z);
252 
253  resize(300, 200);
254 }
255 
257 {
258  delete all;
259  delete val200;
260  delete Validator;
261 }
262 
263 // -----------------------------------------------------------
264 void QucsSettingsDialog::slotEditSuffix(QListViewItem *Item)
265 {
266  if(Item) {
267  Input_Suffix->setText(Item->text(0));
268  Input_Program->setText(Item->text(1));
269  }
270  else {
271  Input_Suffix->setFocus();
272  Input_Suffix->setText("");
273  Input_Program->setText("");
274  }
275 }
276 
277 // -----------------------------------------------------------
278 void QucsSettingsDialog::slotAdd()
279 {
280  QListViewItem *Item = List_Suffix->selectedItem();
281  if(Item) {
282  Item->setText(0, Input_Suffix->text());
283  Item->setText(1, Input_Program->text());
284  return;
285  }
286 
287 
288  for(Item = List_Suffix->firstChild(); Item!=0; Item = Item->itemBelow())
289  if(Item->text(0) == Input_Suffix->text()) {
290  QMessageBox::critical(this, tr("Error"),
291  tr("This suffix is already registered!"));
292  return;
293  }
294 
295  List_Suffix->ensureItemVisible(
296  new QListViewItem(List_Suffix, List_Suffix->lastItem(),
297  Input_Suffix->text(), Input_Program->text()));
298  Input_Suffix->setFocus();
299  Input_Suffix->setText("");
300  Input_Program->setText("");
301 }
302 
303 // -----------------------------------------------------------
304 void QucsSettingsDialog::slotRemove()
305 {
306  QListViewItem *Item = List_Suffix->selectedItem();
307  if(Item == 0) return;
308 
309  List_Suffix->takeItem(Item); // remove from ListView
310  delete Item;
311 
312  Input_Suffix->setText("");
313  Input_Program->setText("");
314 }
315 
316 // -----------------------------------------------------------
317 void QucsSettingsDialog::slotOK()
318 {
319  slotApply();
320  accept();
321 }
322 
323 // -----------------------------------------------------------
324 void QucsSettingsDialog::slotApply()
325 {
326  bool changed = false;
327 
328  if(QucsSettings.BGColor != BGColorButton->paletteBackgroundColor()) {
329  QucsSettings.BGColor = BGColorButton->paletteBackgroundColor();
330 
331  int No=0;
332  QWidget *w;
333  while((w=App->DocumentTab->page(No++)) != 0)
334  if(w->inherits("QTextEdit"))
335  ((TextDoc*)w)->viewport()->setPaletteBackgroundColor(
337  else
338  ((Schematic*)w)->viewport()->setPaletteBackgroundColor(
340  changed = true;
341  }
342 
343  if(savingFont != Font) {
344  savingFont = Font;
345  changed = true;
346  }
347 
349  LanguageCombo->currentText().section('(',1,1).remove(')');
350 
351  if(QucsSettings.Comment != ColorComment->paletteForegroundColor()) {
352  QucsSettings.Comment = ColorComment->paletteForegroundColor();
353  changed = true;
354  }
355  if(QucsSettings.String != ColorString->paletteForegroundColor()) {
356  QucsSettings.String = ColorString->paletteForegroundColor();
357  changed = true;
358  }
359  if(QucsSettings.Integer != ColorInteger->paletteForegroundColor()) {
360  QucsSettings.Integer = ColorInteger->paletteForegroundColor();
361  changed = true;
362  }
363  if(QucsSettings.Real != ColorReal->paletteForegroundColor()) {
364  QucsSettings.Real = ColorReal->paletteForegroundColor();
365  changed = true;
366  }
367  if(QucsSettings.Character != ColorCharacter->paletteForegroundColor()) {
368  QucsSettings.Character = ColorCharacter->paletteForegroundColor();
369  changed = true;
370  }
371  if(QucsSettings.Type != ColorDataType->paletteForegroundColor()) {
372  QucsSettings.Type = ColorDataType->paletteForegroundColor();
373  changed = true;
374  }
375  if(QucsSettings.Attribute != ColorAttribute->paletteForegroundColor()) {
376  QucsSettings.Attribute = ColorAttribute->paletteForegroundColor();
377  changed = true;
378  }
379  if(QucsSettings.Directive != ColorDirective->paletteForegroundColor()) {
380  QucsSettings.Directive = ColorDirective->paletteForegroundColor();
381  changed = true;
382  }
383  if(QucsSettings.Task != ColorTask->paletteForegroundColor()) {
384  QucsSettings.Task = ColorTask->paletteForegroundColor();
385  changed = true;
386  }
387 
388  bool ok;
389  if(QucsSettings.maxUndo != undoNumEdit->text().toUInt(&ok)) {
390  QucsSettings.maxUndo = undoNumEdit->text().toInt(&ok);
391  changed = true;
392  }
393  if(QucsSettings.Editor != editorEdit->text()) {
394  QucsSettings.Editor = editorEdit->text();
395  changed = true;
396  }
397  if(QucsSettings.NodeWiring != (unsigned)checkWiring->isChecked()) {
398  QucsSettings.NodeWiring = checkWiring->isChecked();
399  changed = true;
400  }
401 
402  QListViewItem *Item;
403  QucsSettings.FileTypes.clear();
404  for(Item = List_Suffix->firstChild(); Item!=0; Item = Item->itemBelow())
405  QucsSettings.FileTypes.append(Item->text(0)+"/"+Item->text(1));
406 
407 
408  saveApplSettings(App); // also sets the small and large font
409  if(changed)
410  App->repaint();
411 }
412 
413 // -----------------------------------------------------------
414 void QucsSettingsDialog::slotFontDialog()
415 {
416  bool ok;
417  QFont tmpFont = QFontDialog::getFont(&ok, Font, this);
418  if(ok) {
419  Font = tmpFont;
420  FontButton->setText(Font.toString());
421  }
422 }
423 
424 // -----------------------------------------------------------
425 void QucsSettingsDialog::slotBGColorDialog()
426 {
427  QColor c = QColorDialog::getColor(
428  BGColorButton->paletteBackgroundColor(), this);
429  if(c.isValid())
430  BGColorButton->setPaletteBackgroundColor(c);
431 }
432 
433 // -----------------------------------------------------------
434 void QucsSettingsDialog::slotDefaultValues()
435 {
436  Font = QFont("Helvetica", 12);
437  FontButton->setText(Font.toString());
438  LanguageCombo->setCurrentItem(0);
439  BGColorButton->setPaletteBackgroundColor(QColor(255,250,225));
440 
441  ColorComment->setPaletteForegroundColor(Qt::gray);
442  ColorString->setPaletteForegroundColor(Qt::red);
443  ColorInteger->setPaletteForegroundColor(Qt::blue);
444  ColorReal->setPaletteForegroundColor(Qt::darkMagenta);
445  ColorCharacter->setPaletteForegroundColor(Qt::magenta);
446  ColorDataType->setPaletteForegroundColor(Qt::darkRed);
447  ColorAttribute->setPaletteForegroundColor(Qt::darkCyan);
448  ColorDirective->setPaletteForegroundColor(Qt::darkCyan);
449  ColorTask->setPaletteForegroundColor(Qt::darkRed);
450 
451  undoNumEdit->setText("20");
452  editorEdit->setText(QucsSettings.BinDir + "qucsedit");
453  checkWiring->setChecked(false);
454 }
455 
456 // -----------------------------------------------------------
457 void QucsSettingsDialog::slotColorComment()
458 {
459  QColor c = QColorDialog::getColor(
460  ColorComment->paletteForegroundColor(), this);
461  if(c.isValid())
462  ColorComment->setPaletteForegroundColor(c);
463 }
464 
465 // -----------------------------------------------------------
466 void QucsSettingsDialog::slotColorString()
467 {
468  QColor c = QColorDialog::getColor(
469  ColorString->paletteForegroundColor(), this);
470  if(c.isValid())
471  ColorString->setPaletteForegroundColor(c);
472 }
473 
474 // -----------------------------------------------------------
475 void QucsSettingsDialog::slotColorInteger()
476 {
477  QColor c = QColorDialog::getColor(
478  ColorInteger->paletteForegroundColor(), this);
479  if(c.isValid())
480  ColorInteger->setPaletteForegroundColor(c);
481 }
482 
483 // -----------------------------------------------------------
484 void QucsSettingsDialog::slotColorReal()
485 {
486  QColor c = QColorDialog::getColor(
487  ColorReal->paletteForegroundColor(), this);
488  if(c.isValid())
489  ColorReal->setPaletteForegroundColor(c);
490 }
491 
492 // -----------------------------------------------------------
493 void QucsSettingsDialog::slotColorCharacter()
494 {
495  QColor c = QColorDialog::getColor(
496  ColorCharacter->paletteForegroundColor(), this);
497  if(c.isValid())
498  ColorCharacter->setPaletteForegroundColor(c);
499 }
500 
501 // -----------------------------------------------------------
502 void QucsSettingsDialog::slotColorDataType()
503 {
504  QColor c = QColorDialog::getColor(
505  ColorDataType->paletteForegroundColor(), this);
506  if(c.isValid())
507  ColorDataType->setPaletteForegroundColor(c);
508 }
509 
510 // -----------------------------------------------------------
511 void QucsSettingsDialog::slotColorAttribute()
512 {
513  QColor c = QColorDialog::getColor(
514  ColorAttribute->paletteForegroundColor(), this);
515  if(c.isValid())
516  ColorAttribute->setPaletteForegroundColor(c);
517 }
518 
519 // -----------------------------------------------------------
520 void QucsSettingsDialog::slotColorDirective()
521 {
522  QColor c = QColorDialog::getColor(
523  ColorDirective->paletteForegroundColor(), this);
524  if(c.isValid())
525  ColorDirective->setPaletteForegroundColor(c);
526 }
527 
528 // -----------------------------------------------------------
529 void QucsSettingsDialog::slotColorTask()
530 {
531  QColor c = QColorDialog::getColor(
532  ColorTask->paletteForegroundColor(), this);
533  if(c.isValid())
534  ColorTask->setPaletteForegroundColor(c);
535 }