Generated on Fri Oct 19 11:25:00 2018 for Gecode by doxygen 1.6.3

preferences.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 2007
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  * Permission is hereby granted, free of charge, to any person obtaining
00014  * a copy of this software and associated documentation files (the
00015  * "Software"), to deal in the Software without restriction, including
00016  * without limitation the rights to use, copy, modify, merge, publish,
00017  * distribute, sublicense, and/or sell copies of the Software, and to
00018  * permit persons to whom the Software is furnished to do so, subject to
00019  * the following conditions:
00020  *
00021  * The above copyright notice and this permission notice shall be
00022  * included in all copies or substantial portions of the Software.
00023  *
00024  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 #include <gecode/gist/preferences.hh>
00035 
00036 namespace Gecode { namespace Gist {
00037 
00038   PreferencesDialog::PreferencesDialog(const Options& opt, QWidget *parent)
00039   : QDialog(parent) {
00040     QSettings settings("gecode.org", "Gist");
00041     hideFailed = settings.value("search/hideFailed", true).toBool();
00042     zoom = settings.value("search/zoom", false).toBool();
00043     copies = settings.value("search/copies", false).toBool();
00044     refresh = settings.value("search/refresh", 500).toInt();
00045     refreshPause = settings.value("search/refreshPause", 0).toInt();
00046     smoothScrollAndZoom =
00047       settings.value("smoothScrollAndZoom", true).toBool();
00048     moveDuringSearch = false;
00049 
00050     c_d = opt.c_d;
00051     a_d = opt.a_d;
00052 
00053     hideCheck =
00054       new QCheckBox(tr("Hide failed subtrees automatically"));
00055     hideCheck->setChecked(hideFailed);
00056     zoomCheck =
00057       new QCheckBox(tr("Automatic zoom enabled on start-up"));
00058     zoomCheck->setChecked(zoom);
00059     smoothCheck =
00060       new QCheckBox(tr("Smooth scrolling and zooming"));
00061     smoothCheck->setChecked(smoothScrollAndZoom);
00062 
00063     QPushButton* defButton = new QPushButton(tr("Defaults"));
00064     QPushButton* cancelButton = new QPushButton(tr("Cancel"));
00065     QPushButton* okButton = new QPushButton(tr("Ok"));
00066     okButton->setDefault(true);
00067     QHBoxLayout* buttonLayout = new QHBoxLayout();
00068     buttonLayout->addWidget(defButton);
00069     buttonLayout->addWidget(cancelButton);
00070     buttonLayout->addWidget(okButton);
00071 
00072     connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
00073     connect(defButton, SIGNAL(clicked()), this, SLOT(defaults()));
00074     connect(okButton, SIGNAL(clicked()), this, SLOT(writeBack()));
00075 
00076     QLabel* refreshLabel = new QLabel(tr("Display refresh rate:"));
00077     refreshBox  = new QSpinBox();
00078     refreshBox->setRange(0, 1000000);
00079     refreshBox->setValue(refresh);
00080     refreshBox->setSingleStep(100);
00081     QHBoxLayout* refreshLayout = new QHBoxLayout();
00082     refreshLayout->addWidget(refreshLabel);
00083     refreshLayout->addWidget(refreshBox);
00084 
00085     slowBox =
00086       new QCheckBox(tr("Slow down search"));
00087     slowBox->setChecked(refreshPause > 0);
00088 
00089     refreshBox->setEnabled(refreshPause == 0);
00090 
00091     connect(slowBox, SIGNAL(stateChanged(int)), this,
00092                      SLOT(toggleSlow(int)));
00093 
00094     moveDuringSearchBox =
00095       new QCheckBox(tr("Move cursor during search"));
00096     moveDuringSearchBox->setChecked(moveDuringSearch);
00097 
00098     QVBoxLayout* layout = new QVBoxLayout();
00099     layout->addWidget(hideCheck);
00100     layout->addWidget(zoomCheck);
00101     layout->addWidget(smoothCheck);
00102     layout->addLayout(refreshLayout);
00103     layout->addWidget(slowBox);
00104     layout->addWidget(moveDuringSearchBox);
00105 
00106     QTabWidget* tabs = new QTabWidget;
00107     QWidget* page1 = new QWidget;
00108     page1->setLayout(layout);
00109     tabs->addTab(page1, "Drawing");
00110 
00111     QLabel* cdlabel = new QLabel(tr("Commit distance:"));
00112     cdBox  = new QSpinBox();
00113     cdBox->setRange(0, 10000);
00114     cdBox->setValue(c_d);
00115     cdBox->setSingleStep(1);
00116     QHBoxLayout* cdLayout = new QHBoxLayout();
00117     cdLayout->addWidget(cdlabel);
00118     cdLayout->addWidget(cdBox);
00119     QLabel* adlabel = new QLabel(tr("Adaptive distance:"));
00120     adBox  = new QSpinBox();
00121     adBox->setRange(0, 10000);
00122     adBox->setValue(a_d);
00123     adBox->setSingleStep(1);
00124     QHBoxLayout* adLayout = new QHBoxLayout();
00125     adLayout->addWidget(adlabel);
00126     adLayout->addWidget(adBox);
00127     copiesCheck =
00128       new QCheckBox(tr("Show clones in the tree"));
00129     copiesCheck->setChecked(copies);
00130     layout = new QVBoxLayout();
00131     layout->addLayout(cdLayout);
00132     layout->addLayout(adLayout);
00133     layout->addWidget(copiesCheck);
00134     QWidget* page2 = new QWidget;
00135     page2->setLayout(layout);
00136     tabs->addTab(page2, "Search");
00137 
00138     QVBoxLayout* mainLayout = new QVBoxLayout();
00139     mainLayout->addWidget(tabs);
00140     mainLayout->addLayout(buttonLayout);
00141     setLayout(mainLayout);
00142 
00143     setWindowTitle(tr("Preferences"));
00144   }
00145 
00146   void
00147   PreferencesDialog::writeBack(void) {
00148     hideFailed = hideCheck->isChecked();
00149     zoom = zoomCheck->isChecked();
00150     refresh = refreshBox->value();
00151     refreshPause = slowBox->isChecked() ? 200 : 0;
00152     moveDuringSearch = moveDuringSearchBox->isChecked();
00153     smoothScrollAndZoom = smoothCheck->isChecked();
00154     copies = copiesCheck->isChecked();
00155     c_d = cdBox->value();
00156     a_d = adBox->value();
00157     QSettings settings("gecode.org", "Gist");
00158     settings.setValue("search/hideFailed", hideFailed);
00159     settings.setValue("search/zoom", zoom);
00160     settings.setValue("search/copies", copies);
00161     settings.setValue("search/refresh", refresh);
00162     settings.setValue("search/refreshPause", refreshPause);
00163     settings.setValue("smoothScrollAndZoom", smoothScrollAndZoom);
00164 
00165     accept();
00166   }
00167 
00168   void
00169   PreferencesDialog::defaults(void) {
00170     hideFailed = true;
00171     zoom = false;
00172     refresh = 500;
00173     refreshPause = 0;
00174     smoothScrollAndZoom = true;
00175     moveDuringSearch = false;
00176     copies = false;
00177     c_d = 8;
00178     a_d = 2;
00179     hideCheck->setChecked(hideFailed);
00180     zoomCheck->setChecked(zoom);
00181     refreshBox->setValue(refresh);
00182     slowBox->setChecked(refreshPause > 0);
00183     smoothCheck->setChecked(smoothScrollAndZoom);
00184     copiesCheck->setChecked(copies);
00185     moveDuringSearchBox->setChecked(moveDuringSearch);
00186   }
00187 
00188   void
00189   PreferencesDialog::toggleSlow(int state) {
00190     refreshBox->setEnabled(state != Qt::Checked);
00191   }
00192 
00193 }}
00194 
00195 // STATISTICS: gist-any