Generated on Fri Aug 31 2012 16:20:44 for Gecode by doxygen 1.8.1.2
preferences.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Guido Tack <tack@gecode.org>
5  *
6  * Copyright:
7  * Guido Tack, 2007
8  *
9  * Last modified:
10  * $Date: 2010-08-12 18:29:27 +1000 (Thu, 12 Aug 2010) $ by $Author: tack $
11  * $Revision: 11346 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
39 
40 namespace Gecode { namespace Gist {
41 
43  : QDialog(parent) {
44  QSettings settings("gecode.org", "Gist");
45  hideFailed = settings.value("search/hideFailed", true).toBool();
46  zoom = settings.value("search/zoom", false).toBool();
47  copies = settings.value("search/copies", false).toBool();
48  refresh = settings.value("search/refresh", 500).toInt();
49  refreshPause = settings.value("search/refreshPause", 0).toInt();
51  settings.value("smoothScrollAndZoom", true).toBool();
52 
53  c_d = opt.c_d;
54  a_d = opt.a_d;
55 
56  hideCheck =
57  new QCheckBox(tr("Hide failed subtrees automatically"));
58  hideCheck->setChecked(hideFailed);
59  zoomCheck =
60  new QCheckBox(tr("Automatic zoom enabled on start-up"));
61  zoomCheck->setChecked(zoom);
62  smoothCheck =
63  new QCheckBox(tr("Smooth scrolling and zooming"));
64  smoothCheck->setChecked(smoothScrollAndZoom);
65 
66  QPushButton* defButton = new QPushButton(tr("Defaults"));
67  QPushButton* cancelButton = new QPushButton(tr("Cancel"));
68  QPushButton* okButton = new QPushButton(tr("Ok"));
69  okButton->setDefault(true);
70  QHBoxLayout* buttonLayout = new QHBoxLayout();
71  buttonLayout->addWidget(defButton);
72  buttonLayout->addWidget(cancelButton);
73  buttonLayout->addWidget(okButton);
74 
75  connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
76  connect(defButton, SIGNAL(clicked()), this, SLOT(defaults()));
77  connect(okButton, SIGNAL(clicked()), this, SLOT(writeBack()));
78 
79  QLabel* refreshLabel = new QLabel(tr("Display refresh rate:"));
80  refreshBox = new QSpinBox();
81  refreshBox->setRange(0, 1000000);
82  refreshBox->setValue(refresh);
83  refreshBox->setSingleStep(100);
84  QHBoxLayout* refreshLayout = new QHBoxLayout();
85  refreshLayout->addWidget(refreshLabel);
86  refreshLayout->addWidget(refreshBox);
87 
88  slowBox =
89  new QCheckBox(tr("Slow down search"));
90  slowBox->setChecked(refreshPause > 0);
91 
92  refreshBox->setEnabled(refreshPause == 0);
93 
94  connect(slowBox, SIGNAL(stateChanged(int)), this,
95  SLOT(toggleSlow(int)));
96 
97  QVBoxLayout* layout = new QVBoxLayout();
98  layout->addWidget(hideCheck);
99  layout->addWidget(zoomCheck);
100  layout->addWidget(smoothCheck);
101  layout->addLayout(refreshLayout);
102  layout->addWidget(slowBox);
103 
104  QTabWidget* tabs = new QTabWidget;
105  QWidget* page1 = new QWidget;
106  page1->setLayout(layout);
107  tabs->addTab(page1, "Drawing");
108 
109  QLabel* cdlabel = new QLabel(tr("Commit distance:"));
110  cdBox = new QSpinBox();
111  cdBox->setRange(0, 10000);
112  cdBox->setValue(c_d);
113  cdBox->setSingleStep(1);
114  QHBoxLayout* cdLayout = new QHBoxLayout();
115  cdLayout->addWidget(cdlabel);
116  cdLayout->addWidget(cdBox);
117  QLabel* adlabel = new QLabel(tr("Adaptive distance:"));
118  adBox = new QSpinBox();
119  adBox->setRange(0, 10000);
120  adBox->setValue(a_d);
121  adBox->setSingleStep(1);
122  QHBoxLayout* adLayout = new QHBoxLayout();
123  adLayout->addWidget(adlabel);
124  adLayout->addWidget(adBox);
125  copiesCheck =
126  new QCheckBox(tr("Show clones in the tree"));
127  copiesCheck->setChecked(copies);
128  layout = new QVBoxLayout();
129  layout->addLayout(cdLayout);
130  layout->addLayout(adLayout);
131  layout->addWidget(copiesCheck);
132  QWidget* page2 = new QWidget;
133  page2->setLayout(layout);
134  tabs->addTab(page2, "Search");
135 
136  QVBoxLayout* mainLayout = new QVBoxLayout();
137  mainLayout->addWidget(tabs);
138  mainLayout->addLayout(buttonLayout);
139  setLayout(mainLayout);
140 
141  setWindowTitle(tr("Preferences"));
142  }
143 
144  void
146  hideFailed = hideCheck->isChecked();
147  zoom = zoomCheck->isChecked();
148  refresh = refreshBox->value();
149  refreshPause = slowBox->isChecked() ? 200 : 0;
150  smoothScrollAndZoom = smoothCheck->isChecked();
151  copies = copiesCheck->isChecked();
152  c_d = cdBox->value();
153  a_d = adBox->value();
154  QSettings settings("gecode.org", "Gist");
155  settings.setValue("search/hideFailed", hideFailed);
156  settings.setValue("search/zoom", zoom);
157  settings.setValue("search/copies", copies);
158  settings.setValue("search/refresh", refresh);
159  settings.setValue("search/refreshPause", refreshPause);
160  settings.setValue("smoothScrollAndZoom", smoothScrollAndZoom);
161 
162  accept();
163  }
164 
165  void
167  hideFailed = true;
168  zoom = false;
169  refresh = 500;
170  refreshPause = 0;
171  smoothScrollAndZoom = true;
172  copies = false;
173  c_d = 8;
174  a_d = 2;
175  hideCheck->setChecked(hideFailed);
176  zoomCheck->setChecked(zoom);
177  refreshBox->setValue(refresh);
178  slowBox->setChecked(refreshPause > 0);
179  smoothCheck->setChecked(smoothScrollAndZoom);
180  copiesCheck->setChecked(copies);
181  }
182 
183  void
185  refreshBox->setEnabled(state != Qt::Checked);
186  }
187 
188 }}
189 
190 // STATISTICS: gist-any