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