Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/dialogs/qucssettingsdialog.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                            qucssettingsdialog.cpp
00003                           ------------------------
00004     begin                : Sun May 23 2004
00005     copyright            : (C) 2003 by Michael Margraf
00006     email                : michael.margraf@alumni.tu-berlin.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00023 #ifdef HAVE_CONFIG_H
00024 # include <config.h>
00025 #endif
00026 
00027 #include "qucssettingsdialog.h"
00028 #include <iostream>
00029 #include <cmath>
00030 #include <QGridLayout>
00031 #include <QVBoxLayout>
00032 #include "main.h"
00033 #include "textdoc.h"
00034 #include "schematic.h"
00035 
00036 #include <QWidget>
00037 #include <QLabel>
00038 #include <QTabWidget>
00039 #include <QLayout>
00040 #include <QColorDialog>
00041 #include <QFontDialog>
00042 #include <QValidator>
00043 #include <QPushButton>
00044 #include <QLineEdit>
00045 #include <QComboBox>
00046 #include <QMessageBox>
00047 #include <QCheckBox>
00048 #include <QTableWidget>
00049 #include <QTableWidgetItem>
00050 #include <QHeaderView>
00051 #include <QFileDialog>
00052 #include <QDirIterator>
00053 #include <QDebug>
00054 
00055 using namespace std;
00056 
00057 QucsSettingsDialog::QucsSettingsDialog(QucsApp *parent, const char *name)
00058     : QDialog(parent, name)
00059 {
00060     App = parent;
00061     setWindowTitle(tr("Edit Qucs Properties"));
00062 
00063     Expr.setPattern("[\\w_]+");
00064     Validator  = new QRegExpValidator(Expr, this);
00065 
00066     all = new QVBoxLayout(this); // to provide the necessary size
00067     QTabWidget *t = new QTabWidget();
00068     all->addWidget(t);
00069 
00070     // ...........................................................
00071     // The application settings tab
00072     QWidget *appSettingsTab = new QWidget(t);
00073     QGridLayout *appSettingsGrid = new QGridLayout(appSettingsTab);
00074 
00075     appSettingsGrid->addWidget(new QLabel(tr("Font (set after reload):"), appSettingsTab), 0,0);
00076     FontButton = new QPushButton(appSettingsTab);
00077     connect(FontButton, SIGNAL(clicked()), SLOT(slotFontDialog()));
00078     appSettingsGrid->addWidget(FontButton,0,1);
00079 
00080     val50 = new QIntValidator(1, 50, this);
00081     appSettingsGrid->addWidget(new QLabel(tr("Large font size:"), appSettingsTab), 1,0);
00082     LargeFontSizeEdit = new QLineEdit(appSettingsTab);
00083     LargeFontSizeEdit->setValidator(val50);
00084     appSettingsGrid->addWidget(LargeFontSizeEdit,1,1);
00085 
00086     appSettingsGrid->addWidget(new QLabel(tr("Document Background Color:"), appSettingsTab) ,2,0);
00087     BGColorButton = new QPushButton("      ", appSettingsTab);
00088     connect(BGColorButton, SIGNAL(clicked()), SLOT(slotBGColorDialog()));
00089     appSettingsGrid->addWidget(BGColorButton,2,1);
00090 
00091     appSettingsGrid->addWidget(new QLabel(tr("Language (set after reload):"), appSettingsTab) ,3,0);
00092     LanguageCombo = new QComboBox(appSettingsTab);
00093     LanguageCombo->insertItem(tr("system language"));
00094     LanguageCombo->insertItem(tr("English")+" (en)");
00095     LanguageCombo->insertItem(tr("Arabic")+" (ar)");
00096     LanguageCombo->insertItem(tr("Catalan")+" (ca)");
00097     LanguageCombo->insertItem(tr("Czech")+" (cs)");
00098     LanguageCombo->insertItem(tr("Chinese")+" (zh_CN)");
00099     LanguageCombo->insertItem(tr("French")+" (fr)");
00100     LanguageCombo->insertItem(tr("German")+" (de)");
00101     LanguageCombo->insertItem(tr("Hebrew")+" (he)");
00102     LanguageCombo->insertItem(tr("Hungarian")+" (hu)");
00103     LanguageCombo->insertItem(tr("Italian")+" (it)");
00104     LanguageCombo->insertItem(tr("Japanese")+" (jp)");
00105     LanguageCombo->insertItem(tr("Kazakh")+" (kk)");
00106     LanguageCombo->insertItem(tr("Polish")+" (pl)");
00107     LanguageCombo->insertItem(tr("Portuguese-BR")+" (pt_BR)");
00108     LanguageCombo->insertItem(tr("Portuguese-PT")+" (pt_PT)");
00109     LanguageCombo->insertItem(tr("Romanian")+" (ro)");
00110     LanguageCombo->insertItem(tr("Russian")+" (ru)");
00111     LanguageCombo->insertItem(tr("Spanish")+" (es)");
00112     LanguageCombo->insertItem(tr("Swedish")+" (sv)");
00113     LanguageCombo->insertItem(tr("Turkish")+" (tr)");
00114     LanguageCombo->insertItem(tr("Ukrainian")+" (uk)");
00115     appSettingsGrid->addWidget(LanguageCombo,3,1);
00116 
00117     val200 = new QIntValidator(0, 200, this);
00118     appSettingsGrid->addWidget(new QLabel(tr("Maximum undo operations:"), appSettingsTab) ,4,0);
00119     undoNumEdit = new QLineEdit(appSettingsTab);
00120     undoNumEdit->setValidator(val200);
00121     appSettingsGrid->addWidget(undoNumEdit,4,1);
00122 
00123     appSettingsGrid->addWidget(new QLabel(tr("Text editor:"), appSettingsTab) ,5,0);
00124     editorEdit = new QLineEdit(appSettingsTab);
00125     editorEdit->setToolTip(tr("Set to qucs, qucsedit or the path to your favorite text editor."));
00126     appSettingsGrid->addWidget(editorEdit,5,1);
00127 
00128     appSettingsGrid->addWidget(new QLabel(tr("Start wiring when clicking open node:"), appSettingsTab) ,6,0);
00129     checkWiring = new QCheckBox(appSettingsTab);
00130     appSettingsGrid->addWidget(checkWiring,6,1);
00131 
00132     appSettingsGrid->addWidget(new QLabel(tr("Load documents from future versions:")));
00133     checkLoadFromFutureVersions = new QCheckBox(appSettingsTab);
00134     checkLoadFromFutureVersions->setToolTip(tr("Try to load also documents created with newer versions of Qucs."));
00135     appSettingsGrid->addWidget(checkLoadFromFutureVersions,7,1);
00136     checkLoadFromFutureVersions->setChecked(QucsSettings.IgnoreFutureVersion);
00137 
00138     appSettingsGrid->addWidget(new QLabel(tr("Draw diagrams with anti-aliasing feature:")));
00139     checkAntiAliasing = new QCheckBox(appSettingsTab);
00140     checkAntiAliasing->setToolTip(tr("Use anti-aliasing for graphs for a smoother appereance."));
00141     appSettingsGrid->addWidget(checkAntiAliasing,8,1);
00142     checkAntiAliasing->setChecked(QucsSettings.GraphAntiAliasing);
00143 
00144     appSettingsGrid->addWidget(new QLabel(tr("Draw text with anti-aliasing feature:")));
00145     checkTextAntiAliasing = new QCheckBox(appSettingsTab);
00146     checkTextAntiAliasing->setToolTip(tr("Use anti-aliasing for text for a smoother appereance."));
00147     appSettingsGrid->addWidget(checkTextAntiAliasing,9,1);
00148     checkTextAntiAliasing->setChecked(QucsSettings.TextAntiAliasing);
00149 
00150     t->addTab(appSettingsTab, tr("Settings"));
00151 
00152     // ...........................................................
00153     // The source code editor settings tab
00154     QWidget *editorTab = new QWidget(t);
00155     QGridLayout *editorGrid = new QGridLayout(editorTab);
00156 
00157     editorGrid->addMultiCellWidget(new QLabel(tr("Colors for Syntax Highlighting:"), editorTab), 0,0,0,1);
00158 
00159     ColorComment = new QPushButton(tr("Comment"), editorTab);
00160     ColorComment->setPaletteForegroundColor(QucsSettings.Comment);
00161     ColorComment->setPaletteBackgroundColor(QucsSettings.BGColor);
00162     connect(ColorComment, SIGNAL(clicked()), SLOT(slotColorComment()));
00163     editorGrid->addWidget(ColorComment,1,0);
00164 
00165     ColorString = new QPushButton(tr("String"), editorTab);
00166     ColorString->setPaletteForegroundColor(QucsSettings.String);
00167     ColorString->setPaletteBackgroundColor(QucsSettings.BGColor);
00168     connect(ColorString, SIGNAL(clicked()), SLOT(slotColorString()));
00169     editorGrid->addWidget(ColorString,1,1);
00170 
00171     ColorInteger = new QPushButton(tr("Integer Number"), editorTab);
00172     ColorInteger->setPaletteForegroundColor(QucsSettings.Integer);
00173     ColorInteger->setPaletteBackgroundColor(QucsSettings.BGColor);
00174     connect(ColorInteger, SIGNAL(clicked()), SLOT(slotColorInteger()));
00175     editorGrid->addWidget(ColorInteger,1,2);
00176 
00177     ColorReal = new QPushButton(tr("Real Number"), editorTab);
00178     ColorReal->setPaletteForegroundColor(QucsSettings.Real);
00179     ColorReal->setPaletteBackgroundColor(QucsSettings.BGColor);
00180     connect(ColorReal, SIGNAL(clicked()), SLOT(slotColorReal()));
00181     editorGrid->addWidget(ColorReal,2,0);
00182 
00183     ColorCharacter = new QPushButton(tr("Character"), editorTab);
00184     ColorCharacter->setPaletteForegroundColor(QucsSettings.Character);
00185     ColorCharacter->setPaletteBackgroundColor(QucsSettings.BGColor);
00186     connect(ColorCharacter, SIGNAL(clicked()), SLOT(slotColorCharacter()));
00187     editorGrid->addWidget(ColorCharacter,2,1);
00188 
00189     ColorDataType = new QPushButton(tr("Data Type"), editorTab);
00190     ColorDataType->setPaletteForegroundColor(QucsSettings.Type);
00191     ColorDataType->setPaletteBackgroundColor(QucsSettings.BGColor);
00192     connect(ColorDataType, SIGNAL(clicked()), SLOT(slotColorDataType()));
00193     editorGrid->addWidget(ColorDataType,2,2);
00194 
00195     ColorAttribute = new QPushButton(tr("Attribute"), editorTab);
00196     ColorAttribute->setPaletteForegroundColor(QucsSettings.Attribute);
00197     ColorAttribute->setPaletteBackgroundColor(QucsSettings.BGColor);
00198     connect(ColorAttribute, SIGNAL(clicked()), SLOT(slotColorAttribute()));
00199     editorGrid->addWidget(ColorAttribute,3,0);
00200 
00201     ColorDirective = new QPushButton(tr("Directive"), editorTab);
00202     ColorDirective->setPaletteForegroundColor(QucsSettings.Directive);
00203     ColorDirective->setPaletteBackgroundColor(QucsSettings.BGColor);
00204     connect(ColorDirective, SIGNAL(clicked()), SLOT(slotColorDirective()));
00205     editorGrid->addWidget(ColorDirective,3,1);
00206 
00207     ColorTask = new QPushButton(tr("Task"), editorTab);
00208     ColorTask->setPaletteForegroundColor(QucsSettings.Task);
00209     ColorTask->setPaletteBackgroundColor(QucsSettings.BGColor);
00210     connect(ColorTask, SIGNAL(clicked()), SLOT(slotColorTask()));
00211     editorGrid->addWidget(ColorTask,3,2);
00212 
00213 
00214     t->addTab(editorTab, tr("Source Code Editor"));
00215 
00216     // ...........................................................
00217     // The file types tab
00218     QWidget *fileTypesTab = new QWidget(t);
00219     QGridLayout *fileTypesGrid = new QGridLayout(fileTypesTab);
00220 
00221     QLabel *note = new QLabel(
00222         tr("Register filename extensions here in order to\nopen files with an appropriate program."));
00223     fileTypesGrid->addWidget(note,0,0,1,2);
00224 
00225     // the fileTypesTableWidget displays information on the file types
00226     fileTypesTableWidget = new QTableWidget(fileTypesTab);
00227     fileTypesTableWidget->setColumnCount(2);
00228 
00229     QTableWidgetItem *item1 = new QTableWidgetItem();
00230     QTableWidgetItem *item2 = new QTableWidgetItem();
00231 
00232     fileTypesTableWidget->setHorizontalHeaderItem(0, item1);
00233     fileTypesTableWidget->setHorizontalHeaderItem(1, item2);
00234 
00235     item1->setText(tr("Suffix"));
00236     item2->setText(tr("Program"));
00237 
00238     fileTypesTableWidget->horizontalHeader()->setStretchLastSection(true);
00239     fileTypesTableWidget->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
00240     fileTypesTableWidget->horizontalHeader()->setClickable(false); // no action when clicking on the header 
00241     fileTypesTableWidget->verticalHeader()->hide();
00242     connect(fileTypesTableWidget, SIGNAL(cellClicked(int,int)), SLOT(slotTableClicked(int,int)));
00243     fileTypesGrid->addWidget(fileTypesTableWidget,1,0,3,1);
00244 
00245     // fill listview with already registered file extensions
00246     QStringList::Iterator it = QucsSettings.FileTypes.begin();
00247     while(it != QucsSettings.FileTypes.end())
00248     {
00249         int row = fileTypesTableWidget->rowCount();
00250         fileTypesTableWidget->setRowCount(row+1);
00251         QTableWidgetItem *suffix = new QTableWidgetItem(QString((*it).section('/',0,0)));
00252         QTableWidgetItem *program = new QTableWidgetItem(QString((*it).section('/',1,1)));
00253         suffix->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
00254         program->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
00255         fileTypesTableWidget->setItem(row, 0, suffix);
00256         fileTypesTableWidget->setItem(row, 1, program);
00257         it++;
00258     }
00259 
00260     QLabel *l5 = new QLabel(tr("Suffix:"), fileTypesTab);
00261     fileTypesGrid->addWidget(l5,1,1);
00262     Input_Suffix = new QLineEdit(fileTypesTab);
00263     Input_Suffix->setValidator(Validator);
00264     fileTypesGrid->addWidget(Input_Suffix,1,2);
00265 //  connect(Input_Suffix, SIGNAL(returnPressed()), SLOT(slotGotoProgEdit())); //not implemented
00266 
00267     QLabel *l6 = new QLabel(tr("Program:"), fileTypesTab);
00268     fileTypesGrid->addWidget(l6,2,1);
00269     Input_Program = new QLineEdit(fileTypesTab);
00270     fileTypesGrid->addWidget(Input_Program,2,2);
00271 
00272     QPushButton *AddButt = new QPushButton(tr("Set"));
00273     fileTypesGrid->addWidget(AddButt,3,1);
00274     connect(AddButt, SIGNAL(clicked()), SLOT(slotAddFileType()));
00275     QPushButton *RemoveButt = new QPushButton(tr("Remove"));
00276     fileTypesGrid->addWidget(RemoveButt,3,2);
00277     connect(RemoveButt, SIGNAL(clicked()), SLOT(slotRemoveFileType()));
00278 
00279     fileTypesGrid->setRowStretch(3,4);
00280     t->addTab(fileTypesTab, tr("File Types"));
00281 
00282     // ...........................................................
00283     // The locations tab
00284     QWidget *locationsTab = new QWidget(t);
00285     QGridLayout *locationsGrid = new QGridLayout(locationsTab);
00286 
00287     QLabel *note2 = new QLabel(
00288         tr("Edit the standard paths and external applications"));
00289     locationsGrid->addWidget(note2,0,0,1,2);
00290 
00291     locationsGrid->addWidget(new QLabel(tr("Qucs Home:"), locationsTab) ,1,0);
00292     homeEdit = new QLineEdit(locationsTab);
00293     locationsGrid->addWidget(homeEdit,1,1);
00294     QPushButton *HomeButt = new QPushButton("...");
00295     locationsGrid->addWidget(HomeButt, 1, 2);
00296     connect(HomeButt, SIGNAL(clicked()), SLOT(slotHomeDirBrowse()));
00297 
00298     locationsGrid->addWidget(new QLabel(tr("AdmsXml Path:"), locationsTab) ,2,0);
00299     admsXmlEdit = new QLineEdit(locationsTab);
00300     locationsGrid->addWidget(admsXmlEdit,2,1);
00301     QPushButton *AdmsXmlButt = new QPushButton("...");
00302     locationsGrid->addWidget(AdmsXmlButt, 2, 2);
00303     connect(AdmsXmlButt, SIGNAL(clicked()), SLOT(slotAdmsXmlDirBrowse()));
00304 
00305     locationsGrid->addWidget(new QLabel(tr("ASCO Path:"), locationsTab) ,3,0);
00306     ascoEdit = new QLineEdit(locationsTab);
00307     locationsGrid->addWidget(ascoEdit,3,1);
00308     QPushButton *ascoButt = new QPushButton("...");
00309     locationsGrid->addWidget(ascoButt, 3, 2);
00310     connect(ascoButt, SIGNAL(clicked()), SLOT(slotAscoDirBrowse()));
00311 
00312     locationsGrid->addWidget(new QLabel(tr("Octave Path:"), locationsTab) ,4,0);
00313     octaveEdit = new QLineEdit(locationsTab);
00314     locationsGrid->addWidget(octaveEdit,4,1);
00315     QPushButton *OctaveButt = new QPushButton("...");
00316     locationsGrid->addWidget(OctaveButt, 4, 2);
00317     connect(OctaveButt, SIGNAL(clicked()), SLOT(slotOctaveDirBrowse()));
00318 
00319 
00320     // the pathsTableWidget displays the path list
00321     pathsTableWidget = new QTableWidget(locationsTab);
00322     pathsTableWidget->setColumnCount(1);
00323 
00324     QTableWidgetItem *pitem1 = new QTableWidgetItem();
00325 
00326     pathsTableWidget->setHorizontalHeaderItem(0, pitem1);
00327 
00328     pitem1->setText(tr("Subcircuit Search Path List"));
00329 
00330     pathsTableWidget->horizontalHeader()->setStretchLastSection(true);
00331     pathsTableWidget->verticalHeader()->hide();
00332     // allow multiple items to be selected
00333     pathsTableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
00334     connect(pathsTableWidget, SIGNAL(cellClicked(int,int)), SLOT(slotPathTableClicked(int,int)));
00335     locationsGrid->addWidget(pathsTableWidget,5,0,3,2);
00336 
00337     QPushButton *AddPathButt = new QPushButton("Add Path");
00338     locationsGrid->addWidget(AddPathButt, 5, 2);
00339     connect(AddPathButt, SIGNAL(clicked()), SLOT(slotAddPath()));
00340 
00341     QPushButton *AddPathSubFolButt = new QPushButton("Add Path With SubFolders");
00342     locationsGrid->addWidget(AddPathSubFolButt, 6, 2);
00343     connect(AddPathSubFolButt, SIGNAL(clicked()), SLOT(slotAddPathWithSubFolders()));
00344 
00345     QPushButton *RemovePathButt = new QPushButton("Remove Path");
00346     locationsGrid->addWidget(RemovePathButt , 7, 2);
00347     connect(RemovePathButt, SIGNAL(clicked()), SLOT(slotRemovePath()));
00348 
00349     // create a copy of the current global path list
00350     currentPaths = QStringList(qucsPathList);
00351     makePathTable();
00352 
00353     t->addTab(locationsTab, tr("Locations"));
00354 
00355     // ...........................................................
00356     // buttons on the bottom of the dialog (independent of the TabWidget)
00357 
00358     QHBoxLayout *Butts = new QHBoxLayout();
00359     Butts->setSpacing(3);
00360     Butts->setMargin(3);
00361     all->addLayout(Butts);
00362 
00363     QPushButton *OkButt = new QPushButton(tr("OK"));
00364     Butts->addWidget(OkButt);
00365     connect(OkButt, SIGNAL(clicked()), SLOT(slotOK()));
00366     QPushButton *ApplyButt = new QPushButton(tr("Apply"));
00367     Butts->addWidget(ApplyButt);
00368     connect(ApplyButt, SIGNAL(clicked()), SLOT(slotApply()));
00369     QPushButton *CancelButt = new QPushButton(tr("Cancel"));
00370     Butts->addWidget(CancelButt);
00371     connect(CancelButt, SIGNAL(clicked()), SLOT(reject()));
00372     QPushButton *DefaultButt = new QPushButton(tr("Default Values"));
00373     Butts->addWidget(DefaultButt);
00374     connect(DefaultButt, SIGNAL(clicked()), SLOT(slotDefaultValues()));
00375 
00376     OkButt->setDefault(true);
00377 
00378     // ...........................................................
00379     // fill the fields with the Qucs-Properties
00380     Font  = QucsSettings.font;
00381     FontButton->setText(Font.toString());
00382     QString s = QString::number(QucsSettings.largeFontSize, 'f', 1);
00383     LargeFontSizeEdit->setText(s);
00384     BGColorButton->setPaletteBackgroundColor(QucsSettings.BGColor);
00385     undoNumEdit->setText(QString::number(QucsSettings.maxUndo));
00386     editorEdit->setText(QucsSettings.Editor);
00387     checkWiring->setChecked(QucsSettings.NodeWiring);
00388 
00389     for(int z=LanguageCombo->count()-1; z>=0; z--)
00390         if(LanguageCombo->text(z).section('(',1,1).remove(')') == QucsSettings.Language)
00391             LanguageCombo->setCurrentItem(z);
00392 
00394     homeEdit->setText(QucsSettings.QucsHomeDir.canonicalPath());
00395     admsXmlEdit->setText(QucsSettings.AdmsXmlBinDir.canonicalPath());
00396     ascoEdit->setText(QucsSettings.AscoBinDir.canonicalPath());
00397     octaveEdit->setText(QucsSettings.OctaveBinDir.canonicalPath());
00398 
00399 
00400     resize(300, 200);
00401 }
00402 
00403 QucsSettingsDialog::~QucsSettingsDialog()
00404 {
00405     delete all;
00406     delete val50;
00407     delete val200;
00408     delete Validator;
00409 }
00410 
00411 // -----------------------------------------------------------
00412 void QucsSettingsDialog::slotAddFileType()
00413 {
00414     QModelIndexList indexes = fileTypesTableWidget->selectionModel()->selection().indexes();
00415     if (indexes.count())
00416     {
00417         fileTypesTableWidget->item(indexes.at(0).row(),0)->setText(Input_Suffix->text());
00418         fileTypesTableWidget->item(indexes.at(0).row(),1)->setText(Input_Program->text());
00419         fileTypesTableWidget->selectionModel()->clear();
00420         return;
00421     }
00422 
00423     //check before append
00424     for(int r=0; r < fileTypesTableWidget->rowCount(); r++)
00425         if(fileTypesTableWidget->item(r,0)->text() == Input_Suffix->text())
00426         {
00427             QMessageBox::critical(this, tr("Error"),
00428                                   tr("This suffix is already registered!"));
00429             return;
00430         }
00431 
00432     int row = fileTypesTableWidget->rowCount();
00433     fileTypesTableWidget->setRowCount(row+1);
00434 
00435     QTableWidgetItem *newSuffix = new QTableWidgetItem(QString(Input_Suffix->text()));
00436     newSuffix->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
00437     fileTypesTableWidget->setItem(row, 0, newSuffix);
00438 
00439     QTableWidgetItem *newProgram = new QTableWidgetItem(Input_Program->text());
00440     fileTypesTableWidget->setItem(row, 1, newProgram);
00441     newProgram->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
00442 
00443     Input_Suffix->setFocus();
00444     Input_Suffix->clear();
00445     Input_Program->clear();
00446 }
00447 
00448 // -----------------------------------------------------------
00449 void QucsSettingsDialog::slotRemoveFileType()
00450 {
00451     QModelIndexList indexes = fileTypesTableWidget->selectionModel()->selection().indexes();
00452     if (indexes.count())
00453     {
00454         fileTypesTableWidget->removeRow(indexes.at(0).row());
00455         fileTypesTableWidget->selectionModel()->clear();
00456         Input_Suffix->setText("");
00457         Input_Program->setText("");
00458         return;
00459     }
00460 }
00461 
00462 // -----------------------------------------------------------
00463 // Applies any changed settings and closes the dialog
00464 void QucsSettingsDialog::slotOK()
00465 {
00466     slotApply();
00467     accept();
00468 }
00469 
00470 // -----------------------------------------------------------
00471 // Applies any changed settings
00472 void QucsSettingsDialog::slotApply()
00473 {
00474     bool changed = false;
00475 
00476     if(QucsSettings.BGColor != BGColorButton->paletteBackgroundColor())
00477     {
00478         QucsSettings.BGColor = BGColorButton->paletteBackgroundColor();
00479 
00480         int No=0;
00481         QWidget *w;
00482         while((w=App->DocumentTab->page(No++)) != 0)
00483             if(w->inherits("QTextEdit"))
00484                 ((TextDoc*)w)->viewport()->setPaletteBackgroundColor(
00485                     QucsSettings.BGColor);
00486             else
00487                 ((Schematic*)w)->viewport()->setPaletteBackgroundColor(
00488                     QucsSettings.BGColor);
00489         changed = true;
00490     }
00491 
00492     QucsSettings.font=Font;
00493 
00494     QucsSettings.Language =
00495         LanguageCombo->currentText().section('(',1,1).remove(')');
00496 
00497     if(QucsSettings.Comment != ColorComment->paletteForegroundColor())
00498     {
00499         QucsSettings.Comment = ColorComment->paletteForegroundColor();
00500         changed = true;
00501     }
00502     if(QucsSettings.String != ColorString->paletteForegroundColor())
00503     {
00504         QucsSettings.String = ColorString->paletteForegroundColor();
00505         changed = true;
00506     }
00507     if(QucsSettings.Integer != ColorInteger->paletteForegroundColor())
00508     {
00509         QucsSettings.Integer = ColorInteger->paletteForegroundColor();
00510         changed = true;
00511     }
00512     if(QucsSettings.Real != ColorReal->paletteForegroundColor())
00513     {
00514         QucsSettings.Real = ColorReal->paletteForegroundColor();
00515         changed = true;
00516     }
00517     if(QucsSettings.Character != ColorCharacter->paletteForegroundColor())
00518     {
00519         QucsSettings.Character = ColorCharacter->paletteForegroundColor();
00520         changed = true;
00521     }
00522     if(QucsSettings.Type != ColorDataType->paletteForegroundColor())
00523     {
00524         QucsSettings.Type = ColorDataType->paletteForegroundColor();
00525         changed = true;
00526     }
00527     if(QucsSettings.Attribute != ColorAttribute->paletteForegroundColor())
00528     {
00529         QucsSettings.Attribute = ColorAttribute->paletteForegroundColor();
00530         changed = true;
00531     }
00532     if(QucsSettings.Directive != ColorDirective->paletteForegroundColor())
00533     {
00534         QucsSettings.Directive = ColorDirective->paletteForegroundColor();
00535         changed = true;
00536     }
00537     if(QucsSettings.Task != ColorTask->paletteForegroundColor())
00538     {
00539         QucsSettings.Task = ColorTask->paletteForegroundColor();
00540         changed = true;
00541     }
00542 
00543     bool ok;
00544     if(QucsSettings.maxUndo != undoNumEdit->text().toUInt(&ok))
00545     {
00546         QucsSettings.maxUndo = undoNumEdit->text().toInt(&ok);
00547         changed = true;
00548     }
00549     if(QucsSettings.Editor != editorEdit->text())
00550     {
00551         QucsSettings.Editor = editorEdit->text();
00552         changed = true;
00553     }
00554     if(QucsSettings.NodeWiring != (unsigned)checkWiring->isChecked())
00555     {
00556         QucsSettings.NodeWiring = checkWiring->isChecked();
00557         changed = true;
00558     }
00559 
00560     QucsSettings.FileTypes.clear();
00561     for (int row=0; row < fileTypesTableWidget->rowCount(); row++)
00562     {
00563         QucsSettings.FileTypes.append(fileTypesTableWidget->item(row,0)->text()
00564                                       +"/"+
00565                                       fileTypesTableWidget->item(row,1)->text());
00566     }
00567 
00569     QucsSettings.QucsHomeDir = homeEdit->text();
00570     QucsSettings.AdmsXmlBinDir = admsXmlEdit->text();
00571     QucsSettings.AscoBinDir = ascoEdit->text();
00572     QucsSettings.OctaveBinDir = octaveEdit->text();
00573 
00574     QucsSettings.IgnoreFutureVersion = checkLoadFromFutureVersions->isChecked();
00575 
00576     if (QucsSettings.GraphAntiAliasing != checkAntiAliasing->isChecked())
00577     {
00578       QucsSettings.GraphAntiAliasing = checkAntiAliasing->isChecked();
00579       changed = true;
00580     }
00581 
00582     if (QucsSettings.TextAntiAliasing != checkTextAntiAliasing->isChecked())
00583     {
00584       QucsSettings.TextAntiAliasing = checkTextAntiAliasing->isChecked();
00585       changed = true;
00586     }
00587 
00588     // use toDouble() as it can interpret the string according to the current locale
00589     if (QucsSettings.largeFontSize != LargeFontSizeEdit->text().toDouble(&ok))
00590     {
00591         QucsSettings.largeFontSize = LargeFontSizeEdit->text().toDouble(&ok);
00592         changed = true;
00593     }
00594 
00595     saveApplSettings();  // also sets the small and large font
00596 
00597     if(changed)
00598     {
00599         App->readProjects();
00600         App->slotUpdateTreeview();
00601         App->repaint();
00602     }
00603 
00604     // update the schenatic filelist hash
00605     QucsMain->updatePathList(currentPaths);
00606     QucsMain->updateSchNameHash();
00607     QucsMain->updateSpiceNameHash();
00608 
00609 }
00610 
00611 
00612 // -----------------------------------------------------------
00613 void QucsSettingsDialog::slotFontDialog()
00614 {
00615     bool ok;
00616     QFont tmpFont = QFontDialog::getFont(&ok, Font, this);
00617     if(ok)
00618     {
00619         Font = tmpFont;
00620         FontButton->setText(Font.toString());
00621     }
00622 }
00623 
00624 // -----------------------------------------------------------
00625 void QucsSettingsDialog::slotBGColorDialog()
00626 {
00627     QColor c = QColorDialog::getColor(
00628                    BGColorButton->paletteBackgroundColor(), this);
00629     if(c.isValid())
00630         BGColorButton->setPaletteBackgroundColor(c);
00631 }
00632 
00633 // -----------------------------------------------------------
00634 void QucsSettingsDialog::slotDefaultValues()
00635 {
00636     Font = QFont("Helvetica", 12);
00637     FontButton->setText(Font.toString());
00638     LargeFontSizeEdit->setText(QString::number(16.0));
00639 
00640     LanguageCombo->setCurrentItem(0);
00641     BGColorButton->setPaletteBackgroundColor(QColor(255,250,225));
00642 
00643     ColorComment->setPaletteForegroundColor(Qt::gray);
00644     ColorString->setPaletteForegroundColor(Qt::red);
00645     ColorInteger->setPaletteForegroundColor(Qt::blue);
00646     ColorReal->setPaletteForegroundColor(Qt::darkMagenta);
00647     ColorCharacter->setPaletteForegroundColor(Qt::magenta);
00648     ColorDataType->setPaletteForegroundColor(Qt::darkRed);
00649     ColorAttribute->setPaletteForegroundColor(Qt::darkCyan);
00650     ColorDirective->setPaletteForegroundColor(Qt::darkCyan);
00651     ColorTask->setPaletteForegroundColor(Qt::darkRed);
00652 
00653     undoNumEdit->setText("20");
00654     editorEdit->setText(QucsSettings.BinDir + "qucs");
00655     checkWiring->setChecked(false);
00656     checkLoadFromFutureVersions->setChecked(false);
00657     checkAntiAliasing->setChecked(false);
00658     checkTextAntiAliasing->setChecked(true);
00659 }
00660 
00661 // -----------------------------------------------------------
00662 void QucsSettingsDialog::slotColorComment()
00663 {
00664     QColor c = QColorDialog::getColor(
00665                    ColorComment->paletteForegroundColor(), this);
00666     if(c.isValid())
00667         ColorComment->setPaletteForegroundColor(c);
00668 }
00669 
00670 // -----------------------------------------------------------
00671 void QucsSettingsDialog::slotColorString()
00672 {
00673     QColor c = QColorDialog::getColor(
00674                    ColorString->paletteForegroundColor(), this);
00675     if(c.isValid())
00676         ColorString->setPaletteForegroundColor(c);
00677 }
00678 
00679 // -----------------------------------------------------------
00680 void QucsSettingsDialog::slotColorInteger()
00681 {
00682     QColor c = QColorDialog::getColor(
00683                    ColorInteger->paletteForegroundColor(), this);
00684     if(c.isValid())
00685         ColorInteger->setPaletteForegroundColor(c);
00686 }
00687 
00688 // -----------------------------------------------------------
00689 void QucsSettingsDialog::slotColorReal()
00690 {
00691     QColor c = QColorDialog::getColor(
00692                    ColorReal->paletteForegroundColor(), this);
00693     if(c.isValid())
00694         ColorReal->setPaletteForegroundColor(c);
00695 }
00696 
00697 // -----------------------------------------------------------
00698 void QucsSettingsDialog::slotColorCharacter()
00699 {
00700     QColor c = QColorDialog::getColor(
00701                    ColorCharacter->paletteForegroundColor(), this);
00702     if(c.isValid())
00703         ColorCharacter->setPaletteForegroundColor(c);
00704 }
00705 
00706 // -----------------------------------------------------------
00707 void QucsSettingsDialog::slotColorDataType()
00708 {
00709     QColor c = QColorDialog::getColor(
00710                    ColorDataType->paletteForegroundColor(), this);
00711     if(c.isValid())
00712         ColorDataType->setPaletteForegroundColor(c);
00713 }
00714 
00715 // -----------------------------------------------------------
00716 void QucsSettingsDialog::slotColorAttribute()
00717 {
00718     QColor c = QColorDialog::getColor(
00719                    ColorAttribute->paletteForegroundColor(), this);
00720     if(c.isValid())
00721         ColorAttribute->setPaletteForegroundColor(c);
00722 }
00723 
00724 // -----------------------------------------------------------
00725 void QucsSettingsDialog::slotColorDirective()
00726 {
00727     QColor c = QColorDialog::getColor(
00728                    ColorDirective->paletteForegroundColor(), this);
00729     if(c.isValid())
00730         ColorDirective->setPaletteForegroundColor(c);
00731 }
00732 
00733 // -----------------------------------------------------------
00734 void QucsSettingsDialog::slotColorTask()
00735 {
00736     QColor c = QColorDialog::getColor(
00737                    ColorTask->paletteForegroundColor(), this);
00738     if(c.isValid())
00739         ColorTask->setPaletteForegroundColor(c);
00740 }
00741 
00742 void QucsSettingsDialog::slotTableClicked(int row, int col)
00743 {
00744     Q_UNUSED(col);
00745     Input_Suffix->setText(fileTypesTableWidget->item(row,0)->text());
00746     Input_Program->setText(fileTypesTableWidget->item(row,1)->text());
00747 }
00748 
00749 // -----------------------------------------------------------
00750 // The locations tab slots
00751 
00752 void QucsSettingsDialog::slotHomeDirBrowse()
00753 {
00754     QFileDialog fileDialog( this, tr("Select the home directory"), homeEdit->text() );
00755     fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
00756     fileDialog.setFileMode(QFileDialog::DirectoryOnly);
00757     fileDialog.exec();
00758     homeEdit->setText(fileDialog.selectedFile());
00759 }
00760 
00761 void QucsSettingsDialog::slotAdmsXmlDirBrowse()
00762 {
00763     QFileDialog fileDialog( this, tr("Select the admsXml bin directory"), admsXmlEdit->text() );
00764     fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
00765     fileDialog.setFileMode(QFileDialog::DirectoryOnly);
00766     fileDialog.exec();
00767     admsXmlEdit->setText(fileDialog.selectedFile());
00768 }
00769 
00770 void QucsSettingsDialog::slotAscoDirBrowse()
00771 {
00772     QFileDialog fileDialog( this, tr("Select the ASCO bin directory"), ascoEdit->text() );
00773     fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
00774     fileDialog.setFileMode(QFileDialog::DirectoryOnly);
00775     fileDialog.exec();
00776     ascoEdit->setText(fileDialog.selectedFile());
00777 }
00778 
00779 void QucsSettingsDialog::slotOctaveDirBrowse()
00780 {
00781     QFileDialog fileDialog( this, tr("Select the octave bin directory"), octaveEdit->text() );
00782     fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
00783     fileDialog.setFileMode(QFileDialog::DirectoryOnly);
00784     fileDialog.exec();
00785     octaveEdit->setText(fileDialog.selectedFile());
00786 }
00787 
00790 void QucsSettingsDialog::slotPathTableClicked(int row, int col)
00791 {
00792     Q_UNUSED(row);
00793     Q_UNUSED(col);
00794     //Input_Path->setText(fileTypesTableWidget->item(row,0)->text());
00795 }
00796 
00797 void QucsSettingsDialog::slotAddPath()
00798 {
00799     QFileDialog fileDialog( this, tr("Select a directory"), QucsSettings.QucsWorkDir.canonicalPath());
00800     fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
00801     fileDialog.setFileMode(QFileDialog::DirectoryOnly);
00802 
00803     if (fileDialog.exec())
00804     {
00805         currentPaths.append(fileDialog.selectedFile());
00806         // reconstruct the table again
00807         makePathTable();
00808     }
00809     else
00810     {
00811         // user cancelled
00812     }
00813 }
00814 
00815 void QucsSettingsDialog::slotAddPathWithSubFolders()
00816 {
00817     // open a file dialog to select the top level directory
00818     QFileDialog fileDialog( this, tr("Select a directory"), QucsSettings.QucsWorkDir.canonicalPath());
00819     fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
00820     fileDialog.setFileMode(QFileDialog::DirectoryOnly);
00821 
00822     QString path;
00823     QFileInfo pathfinfo;
00824 
00825     if (fileDialog.exec())
00826     {
00827         // Iterate through the directories
00828         QDirIterator pathIter(fileDialog.selectedFile(), QDirIterator::Subdirectories);
00829         while (pathIter.hasNext())
00830         {
00831             path = pathIter.next();
00832             pathfinfo = pathIter.fileInfo();
00833 
00834             if (pathfinfo.isDir() && !pathfinfo.isSymLink() && !path.endsWith("."))
00835             {
00836                 QDir thispath(path);
00837                 currentPaths.append(thispath.canonicalPath());
00838             }
00839         }
00840         makePathTable();
00841     }
00842     else
00843     {
00844         // user cancelled
00845     }
00846 
00847 
00848 }
00849 
00850 void QucsSettingsDialog::slotRemovePath()
00851 {
00852     //Input_Path->setText(fileTypesTableWidget->item(row,0)->text());
00853     // get the selected items from the table
00854     QList<QTableWidgetItem *> selectedPaths = pathsTableWidget->selectedItems();
00855 
00856     foreach (QTableWidgetItem * item, selectedPaths)
00857     {
00858         QString path = item->text();
00859         //removedPaths.append(path);
00860         int pathind = currentPaths.indexOf(path,0);
00861         if (pathind != -1)
00862         {
00863             currentPaths.removeAt(pathind);
00864         }
00865     }
00866 
00867     makePathTable();
00868 }
00869 
00870 // makePathTable()
00871 //
00872 // Reconstructs the table containing the list of search paths
00873 // in the locations tab
00874 void QucsSettingsDialog::makePathTable()
00875 {
00876     // remove all the paths from the table if present
00877     pathsTableWidget->clearContents();
00878     pathsTableWidget->setRowCount(0);
00879 
00880     // fill listview with the list of paths
00881     foreach (QString pathstr, currentPaths)
00882     {
00883         int row = pathsTableWidget->rowCount();
00884         pathsTableWidget->setRowCount(row+1);
00885         QTableWidgetItem *path = new QTableWidgetItem(pathstr);
00886         path->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
00887         pathsTableWidget->setItem(row, 0, path);
00888     }
00889 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines