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