Generated on Mon Nov 30 23:53:19 2009 for Gecode by doxygen 1.6.1

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: 2009-03-04 13:03:28 +0100 (Wed, 04 Mar 2009) $ by $Author: schulte $
00011  *     $Revision: 8359 $
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     smoothScrollAndZoom =
00050       settings.value("smoothScrollAndZoom", true).toBool();
00051 
00052     c_d = opt.c_d;
00053     a_d = opt.a_d;
00054 
00055     hideCheck =
00056       new QCheckBox(tr("Hide failed subtrees automatically"));
00057     hideCheck->setChecked(hideFailed);
00058     zoomCheck =
00059       new QCheckBox(tr("Automatic zoom enabled on start-up"));
00060     zoomCheck->setChecked(zoom);
00061     smoothCheck =
00062       new QCheckBox(tr("Smooth scrolling and zooming"));
00063     smoothCheck->setChecked(smoothScrollAndZoom);
00064 
00065     QPushButton* defButton = new QPushButton(tr("Defaults"));
00066     QPushButton* cancelButton = new QPushButton(tr("Cancel"));
00067     QPushButton* okButton = new QPushButton(tr("Ok"));
00068     okButton->setDefault(true);
00069     QHBoxLayout* buttonLayout = new QHBoxLayout();
00070     buttonLayout->addWidget(defButton);
00071     buttonLayout->addWidget(cancelButton);
00072     buttonLayout->addWidget(okButton);
00073 
00074     connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
00075     connect(defButton, SIGNAL(clicked()), this, SLOT(defaults()));
00076     connect(okButton, SIGNAL(clicked()), this, SLOT(writeBack()));
00077 
00078     QLabel* refreshLabel = new QLabel(tr("Display refresh rate:"));
00079     refreshBox  = new QSpinBox();
00080     refreshBox->setRange(0, 1000000);
00081     refreshBox->setValue(refresh);
00082     refreshBox->setSingleStep(100);
00083     QHBoxLayout* refreshLayout = new QHBoxLayout();
00084     refreshLayout->addWidget(refreshLabel);
00085     refreshLayout->addWidget(refreshBox);
00086 
00087     QVBoxLayout* layout = new QVBoxLayout();
00088     layout->addWidget(hideCheck);
00089     layout->addWidget(zoomCheck);
00090     layout->addWidget(smoothCheck);
00091     layout->addLayout(refreshLayout);
00092 
00093     QTabWidget* tabs = new QTabWidget;
00094     QWidget* page1 = new QWidget;
00095     page1->setLayout(layout);
00096     tabs->addTab(page1, "Drawing");
00097 
00098     QLabel* cdlabel = new QLabel(tr("Commit distance:"));
00099     cdBox  = new QSpinBox();
00100     cdBox->setRange(0, 10000);
00101     cdBox->setValue(c_d);
00102     cdBox->setSingleStep(1);
00103     QHBoxLayout* cdLayout = new QHBoxLayout();
00104     cdLayout->addWidget(cdlabel);
00105     cdLayout->addWidget(cdBox);
00106     QLabel* adlabel = new QLabel(tr("Adaptive distance:"));
00107     adBox  = new QSpinBox();
00108     adBox->setRange(0, 10000);
00109     adBox->setValue(a_d);
00110     adBox->setSingleStep(1);
00111     QHBoxLayout* adLayout = new QHBoxLayout();
00112     adLayout->addWidget(adlabel);
00113     adLayout->addWidget(adBox);
00114     copiesCheck =
00115       new QCheckBox(tr("Show clones in the tree"));
00116     copiesCheck->setChecked(copies);
00117     layout = new QVBoxLayout();
00118     layout->addLayout(cdLayout);
00119     layout->addLayout(adLayout);
00120     layout->addWidget(copiesCheck);
00121     QWidget* page2 = new QWidget;
00122     page2->setLayout(layout);
00123     tabs->addTab(page2, "Search");
00124 
00125     QVBoxLayout* mainLayout = new QVBoxLayout();
00126     mainLayout->addWidget(tabs);
00127     mainLayout->addLayout(buttonLayout);
00128     setLayout(mainLayout);
00129 
00130     setWindowTitle(tr("Preferences"));
00131   }
00132 
00133   void
00134   PreferencesDialog::writeBack(void) {
00135     hideFailed = hideCheck->isChecked();
00136     zoom = zoomCheck->isChecked();
00137     refresh = refreshBox->value();
00138     smoothScrollAndZoom = smoothCheck->isChecked();
00139     copies = copiesCheck->isChecked();
00140     c_d = cdBox->value();
00141     a_d = adBox->value();
00142     QSettings settings("gecode.org", "Gist");
00143     settings.setValue("search/hideFailed", hideFailed);
00144     settings.setValue("search/zoom", zoom);
00145     settings.setValue("search/copies", copies);
00146     settings.setValue("search/refresh", refresh);
00147     settings.setValue("smoothScrollAndZoom", smoothScrollAndZoom);
00148 
00149     accept();
00150   }
00151 
00152   void
00153   PreferencesDialog::defaults(void) {
00154     hideFailed = true;
00155     zoom = false;
00156     refresh = 500;
00157     smoothScrollAndZoom = true;
00158     copies = false;
00159     c_d = 8;
00160     a_d = 2;
00161     hideCheck->setChecked(hideFailed);
00162     zoomCheck->setChecked(zoom);
00163     refreshBox->setValue(refresh);
00164     smoothCheck->setChecked(smoothScrollAndZoom);
00165     copiesCheck->setChecked(copies);
00166   }
00167 
00168 }}
00169 
00170 // STATISTICS: gist-any