preferences.cpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Guido Tack <tack@gecode.org>
*
* Copyright:
* Guido Tack, 2007
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include <gecode/gist/preferences.hh>
namespace Gecode { namespace Gist {
PreferencesDialog::PreferencesDialog(const Options& opt, QWidget *parent)
: QDialog(parent) {
QSettings settings("gecode.org", "Gist");
hideFailed = settings.value("search/hideFailed", true).toBool();
zoom = settings.value("search/zoom", false).toBool();
copies = settings.value("search/copies", false).toBool();
refresh = settings.value("search/refresh", 500).toInt();
refreshPause = settings.value("search/refreshPause", 0).toInt();
smoothScrollAndZoom =
settings.value("smoothScrollAndZoom", true).toBool();
moveDuringSearch = false;
c_d = opt.c_d;
a_d = opt.a_d;
hideCheck =
new QCheckBox(tr("Hide failed subtrees automatically"));
hideCheck->setChecked(hideFailed);
zoomCheck =
new QCheckBox(tr("Automatic zoom enabled on start-up"));
zoomCheck->setChecked(zoom);
smoothCheck =
new QCheckBox(tr("Smooth scrolling and zooming"));
smoothCheck->setChecked(smoothScrollAndZoom);
QPushButton* defButton = new QPushButton(tr("Defaults"));
QPushButton* cancelButton = new QPushButton(tr("Cancel"));
QPushButton* okButton = new QPushButton(tr("Ok"));
okButton->setDefault(true);
QHBoxLayout* buttonLayout = new QHBoxLayout();
buttonLayout->addWidget(defButton);
buttonLayout->addWidget(cancelButton);
buttonLayout->addWidget(okButton);
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
connect(defButton, SIGNAL(clicked()), this, SLOT(defaults()));
connect(okButton, SIGNAL(clicked()), this, SLOT(writeBack()));
QLabel* refreshLabel = new QLabel(tr("Display refresh rate:"));
refreshBox = new QSpinBox();
refreshBox->setRange(0, 1000000);
refreshBox->setValue(refresh);
refreshBox->setSingleStep(100);
QHBoxLayout* refreshLayout = new QHBoxLayout();
refreshLayout->addWidget(refreshLabel);
refreshLayout->addWidget(refreshBox);
slowBox =
new QCheckBox(tr("Slow down search"));
slowBox->setChecked(refreshPause > 0);
refreshBox->setEnabled(refreshPause == 0);
connect(slowBox, SIGNAL(stateChanged(int)), this,
SLOT(toggleSlow(int)));
moveDuringSearchBox =
new QCheckBox(tr("Move cursor during search"));
moveDuringSearchBox->setChecked(moveDuringSearch);
QVBoxLayout* layout = new QVBoxLayout();
layout->addWidget(hideCheck);
layout->addWidget(zoomCheck);
layout->addWidget(smoothCheck);
layout->addLayout(refreshLayout);
layout->addWidget(slowBox);
layout->addWidget(moveDuringSearchBox);
QTabWidget* tabs = new QTabWidget;
QWidget* page1 = new QWidget;
page1->setLayout(layout);
tabs->addTab(page1, "Drawing");
QLabel* cdlabel = new QLabel(tr("Commit distance:"));
cdBox = new QSpinBox();
cdBox->setRange(0, 10000);
cdBox->setValue(c_d);
cdBox->setSingleStep(1);
QHBoxLayout* cdLayout = new QHBoxLayout();
cdLayout->addWidget(cdlabel);
cdLayout->addWidget(cdBox);
QLabel* adlabel = new QLabel(tr("Adaptive distance:"));
adBox = new QSpinBox();
adBox->setRange(0, 10000);
adBox->setValue(a_d);
adBox->setSingleStep(1);
QHBoxLayout* adLayout = new QHBoxLayout();
adLayout->addWidget(adlabel);
adLayout->addWidget(adBox);
copiesCheck =
new QCheckBox(tr("Show clones in the tree"));
copiesCheck->setChecked(copies);
layout = new QVBoxLayout();
layout->addLayout(cdLayout);
layout->addLayout(adLayout);
layout->addWidget(copiesCheck);
QWidget* page2 = new QWidget;
page2->setLayout(layout);
tabs->addTab(page2, "Search");
QVBoxLayout* mainLayout = new QVBoxLayout();
mainLayout->addWidget(tabs);
mainLayout->addLayout(buttonLayout);
setLayout(mainLayout);
setWindowTitle(tr("Preferences"));
}
void
PreferencesDialog::writeBack(void) {
hideFailed = hideCheck->isChecked();
zoom = zoomCheck->isChecked();
refresh = refreshBox->value();
refreshPause = slowBox->isChecked() ? 200 : 0;
moveDuringSearch = moveDuringSearchBox->isChecked();
smoothScrollAndZoom = smoothCheck->isChecked();
copies = copiesCheck->isChecked();
c_d = cdBox->value();
a_d = adBox->value();
QSettings settings("gecode.org", "Gist");
settings.setValue("search/hideFailed", hideFailed);
settings.setValue("search/zoom", zoom);
settings.setValue("search/copies", copies);
settings.setValue("search/refresh", refresh);
settings.setValue("search/refreshPause", refreshPause);
settings.setValue("smoothScrollAndZoom", smoothScrollAndZoom);
accept();
}
void
PreferencesDialog::defaults(void) {
hideFailed = true;
zoom = false;
refresh = 500;
refreshPause = 0;
smoothScrollAndZoom = true;
moveDuringSearch = false;
copies = false;
c_d = 8;
a_d = 2;
hideCheck->setChecked(hideFailed);
zoomCheck->setChecked(zoom);
refreshBox->setValue(refresh);
slowBox->setChecked(refreshPause > 0);
smoothCheck->setChecked(smoothScrollAndZoom);
copiesCheck->setChecked(copies);
moveDuringSearchBox->setChecked(moveDuringSearch);
}
void
PreferencesDialog::toggleSlow(int state) {
refreshBox->setEnabled(state != Qt::Checked);
}
}}
// STATISTICS: gist-any
Gecode::Gist::Options
Options for Gist
Definition gist.hh:234
Gecode::Gist::PreferencesDialog::adBox
QSpinBox * adBox
Definition preferences.hh:60
Gecode::Gist::PreferencesDialog::writeBack
void writeBack(void)
Write settings.
Definition preferences.cpp:147
Gecode::Gist::PreferencesDialog::smoothCheck
QCheckBox * smoothCheck
Definition preferences.hh:54
Gecode::Gist::PreferencesDialog::toggleSlow
void toggleSlow(int state)
Toggle slow down setting.
Definition preferences.cpp:189
Gecode::Gist::PreferencesDialog::hideFailed
bool hideFailed
Whether to automatically hide failed subtrees during search.
Definition preferences.hh:73
Gecode::Gist::PreferencesDialog::slowBox
QCheckBox * slowBox
Definition preferences.hh:57
Gecode::Gist::PreferencesDialog::c_d
int c_d
The copying distance.
Definition preferences.hh:88
Gecode::Gist::PreferencesDialog::moveDuringSearch
bool moveDuringSearch
Whether to move cursor during search.
Definition preferences.hh:85
Gecode::Gist::PreferencesDialog::defaults
void defaults(void)
Reset to defaults.
Definition preferences.cpp:169
Gecode::Gist::PreferencesDialog::a_d
int a_d
The adaptive recomputation distance.
Definition preferences.hh:90
Gecode::Gist::PreferencesDialog::smoothScrollAndZoom
bool smoothScrollAndZoom
Whether to use smooth scrolling and zooming.
Definition preferences.hh:83
Gecode::Gist::PreferencesDialog::zoom
bool zoom
Whether to automatically zoom during search.
Definition preferences.hh:75
Gecode::Gist::PreferencesDialog::zoomCheck
QCheckBox * zoomCheck
Definition preferences.hh:53
Gecode::Gist::PreferencesDialog::PreferencesDialog
PreferencesDialog(const Options &opt, QWidget *parent=0)
Constructor.
Definition preferences.cpp:38
Gecode::Gist::PreferencesDialog::copies
bool copies
Whether to show where copies are in the tree.
Definition preferences.hh:77
Gecode::Gist::PreferencesDialog::refreshBox
QSpinBox * refreshBox
Definition preferences.hh:56
Gecode::Gist::PreferencesDialog::cdBox
QSpinBox * cdBox
Definition preferences.hh:59
Gecode::Gist::PreferencesDialog::hideCheck
QCheckBox * hideCheck
Definition preferences.hh:52
Gecode::Gist::PreferencesDialog::moveDuringSearchBox
QCheckBox * moveDuringSearchBox
Definition preferences.hh:58
Gecode::Gist::PreferencesDialog::copiesCheck
QCheckBox * copiesCheck
Definition preferences.hh:55
Gecode::Gist::PreferencesDialog::refresh
int refresh
How often to refresh the display during search.
Definition preferences.hh:79
Gecode::Gist::PreferencesDialog::refreshPause
int refreshPause
Milliseconds to wait after each refresh (to slow down search).
Definition preferences.hh:81
Gecode::Gist
The Gecode Interactive Search Tool.
Gecode
Gecode toplevel namespace
preferences.hh