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