00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <gecode/gist/mainwindow.hh>
00039 #include <gecode/gist/preferences.hh>
00040 #include <gecode/gist/nodewidget.hh>
00041 #include <gecode/gist/drawingcursor.hh>
00042
00043 #include <gecode/gist/gecodelogo.hh>
00044
00045 namespace Gecode { namespace Gist {
00046
00047 AboutGist::AboutGist(QWidget* parent) : QDialog(parent) {
00048
00049 Logos logos;
00050 QPixmap myPic;
00051 myPic.loadFromData(logos.logo, logos.logoSize);
00052
00053 QPixmap myPic2;
00054 myPic2.loadFromData(logos.gistLogo, logos.gistLogoSize);
00055 setWindowIcon(myPic2);
00056
00057
00058 setMinimumSize(300, 240);
00059 setMaximumSize(300, 240);
00060 QVBoxLayout* layout = new QVBoxLayout();
00061 QLabel* logo = new QLabel();
00062 logo->setPixmap(myPic);
00063 layout->addWidget(logo, 0, Qt::AlignCenter);
00064 QLabel* aboutLabel =
00065 new QLabel(tr("<h2>Gist</h2>"
00066 "<p><b>The Gecode Interactive Search Tool</b</p> "
00067 "<p>You can find more information about Gecode and Gist "
00068 "at</p>"
00069 "<p><a href='http://www.gecode.org'>www.gecode.org</a>"
00070 "</p"));
00071 aboutLabel->setOpenExternalLinks(true);
00072 aboutLabel->setWordWrap(true);
00073 aboutLabel->setAlignment(Qt::AlignCenter);
00074 layout->addWidget(aboutLabel);
00075 setLayout(layout);
00076 setWindowTitle(tr("About Gist"));
00077 setAttribute(Qt::WA_QuitOnClose, false);
00078 setAttribute(Qt::WA_DeleteOnClose, false);
00079 }
00080
00081 GistMainWindow::GistMainWindow(Space* root, bool bab,
00082 const Options& opt0)
00083 : opt(opt0), aboutGist(this) {
00084 c = new Gist(root,bab,this,opt);
00085 setCentralWidget(c);
00086 setWindowTitle(tr("Gist"));
00087
00088 Logos logos;
00089 QPixmap myPic;
00090 myPic.loadFromData(logos.gistLogo, logos.gistLogoSize);
00091 setWindowIcon(myPic);
00092
00093 resize(500,500);
00094 setMinimumSize(400, 200);
00095
00096 menuBar = new QMenuBar(0);
00097
00098 QMenu* fileMenu = menuBar->addMenu(tr("&File"));
00099 fileMenu->addAction(c->print);
00100 #if QT_VERSION >= 0x040400
00101 fileMenu->addAction(c->exportWholeTreePDF);
00102 #endif
00103 QAction* quitAction = fileMenu->addAction(tr("Quit"));
00104 quitAction->setShortcut(QKeySequence("Ctrl+Q"));
00105 connect(quitAction, SIGNAL(triggered()),
00106 this, SLOT(close()));
00107 QAction* prefAction = fileMenu->addAction(tr("Preferences"));
00108 connect(prefAction, SIGNAL(triggered()), this, SLOT(preferences()));
00109
00110 QMenu* nodeMenu = menuBar->addMenu(tr("&Node"));
00111
00112 inspectNodeMenu = new QMenu("Inspect");
00113 inspectNodeMenu->addAction(c->inspect);
00114 connect(inspectNodeMenu, SIGNAL(aboutToShow()),
00115 this, SLOT(populateInspectors()));
00116
00117 inspectNodeBeforeFPMenu = new QMenu("Inspect before fixpoint");
00118 inspectNodeBeforeFPMenu->addAction(c->inspectBeforeFP);
00119 connect(inspectNodeBeforeFPMenu, SIGNAL(aboutToShow()),
00120 this, SLOT(populateInspectors()));
00121 populateInspectors();
00122
00123 nodeMenu->addMenu(inspectNodeMenu);
00124 nodeMenu->addMenu(inspectNodeBeforeFPMenu);
00125 nodeMenu->addAction(c->compareNode);
00126 nodeMenu->addAction(c->compareNodeBeforeFP);
00127 nodeMenu->addAction(c->setPath);
00128 nodeMenu->addAction(c->inspectPath);
00129 nodeMenu->addAction(c->showNodeStats);
00130 bookmarksMenu = new QMenu("Bookmarks");
00131 bookmarksMenu->addAction(c->bookmarkNode);
00132 connect(bookmarksMenu, SIGNAL(aboutToShow()),
00133 this, SLOT(populateBookmarks()));
00134 nodeMenu->addMenu(bookmarksMenu);
00135 nodeMenu->addSeparator();
00136 nodeMenu->addAction(c->navUp);
00137 nodeMenu->addAction(c->navDown);
00138 nodeMenu->addAction(c->navLeft);
00139 nodeMenu->addAction(c->navRight);
00140 nodeMenu->addAction(c->navRoot);
00141 nodeMenu->addAction(c->navNextSol);
00142 nodeMenu->addAction(c->navPrevSol);
00143 nodeMenu->addSeparator();
00144 nodeMenu->addAction(c->toggleHidden);
00145 nodeMenu->addAction(c->hideFailed);
00146 nodeMenu->addAction(c->unhideAll);
00147 nodeMenu->addAction(c->toggleStop);
00148 nodeMenu->addAction(c->unstopAll);
00149 nodeMenu->addSeparator();
00150 nodeMenu->addAction(c->zoomToFit);
00151 nodeMenu->addAction(c->center);
00152 #if QT_VERSION >= 0x040400
00153 nodeMenu->addAction(c->exportPDF);
00154 #endif
00155
00156 QMenu* searchMenu = menuBar->addMenu(tr("&Search"));
00157 searchMenu->addAction(c->searchNext);
00158 searchMenu->addAction(c->searchAll);
00159 searchMenu->addSeparator();
00160 searchMenu->addAction(c->stop);
00161 searchMenu->addSeparator();
00162 searchMenu->addAction(c->reset);
00163
00164 QMenu* toolsMenu = menuBar->addMenu(tr("&Tools"));
00165 doubleClickInspectorsMenu = new QMenu("Double click Inspectors");
00166 connect(doubleClickInspectorsMenu, SIGNAL(aboutToShow()),
00167 this, SLOT(populateInspectorSelection()));
00168 toolsMenu->addMenu(doubleClickInspectorsMenu);
00169 solutionInspectorsMenu = new QMenu("Solution inspectors");
00170 connect(solutionInspectorsMenu, SIGNAL(aboutToShow()),
00171 this, SLOT(populateInspectorSelection()));
00172 toolsMenu->addMenu(solutionInspectorsMenu);
00173 moveInspectorsMenu = new QMenu("Move inspectors");
00174 connect(moveInspectorsMenu, SIGNAL(aboutToShow()),
00175 this, SLOT(populateInspectorSelection()));
00176 toolsMenu->addMenu(moveInspectorsMenu);
00177 comparatorsMenu = new QMenu("Comparators");
00178 connect(comparatorsMenu, SIGNAL(aboutToShow()),
00179 this, SLOT(populateInspectorSelection()));
00180 toolsMenu->addMenu(comparatorsMenu);
00181
00182 QMenu* helpMenu = menuBar->addMenu(tr("&Help"));
00183 QAction* aboutAction = helpMenu->addAction(tr("About"));
00184 connect(aboutAction, SIGNAL(triggered()),
00185 this, SLOT(about()));
00186
00187
00188 #ifndef Q_WS_MAC
00189 setMenuBar(menuBar);
00190 #endif
00191
00192
00193 QWidget* stw = new QWidget();
00194 QHBoxLayout* hbl = new QHBoxLayout();
00195 hbl->setContentsMargins(0,0,0,0);
00196 wmpLabel = new QLabel("");
00197 hbl->addWidget(wmpLabel);
00198 hbl->addWidget(new QLabel("Depth:"));
00199 depthLabel = new QLabel("0");
00200 hbl->addWidget(depthLabel);
00201 hbl->addWidget(new NodeWidget(SOLVED));
00202 solvedLabel = new QLabel("0");
00203 hbl->addWidget(solvedLabel);
00204 hbl->addWidget(new NodeWidget(FAILED));
00205 failedLabel = new QLabel("0");
00206 hbl->addWidget(failedLabel);
00207 hbl->addWidget(new NodeWidget(BRANCH));
00208 choicesLabel = new QLabel("0");
00209 hbl->addWidget(choicesLabel);
00210 hbl->addWidget(new NodeWidget(UNDETERMINED));
00211 openLabel = new QLabel(" 0");
00212 hbl->addWidget(openLabel);
00213 stw->setLayout(hbl);
00214 statusBar()->addPermanentWidget(stw);
00215
00216 isSearching = false;
00217 statusBar()->showMessage("Ready");
00218
00219 connect(c,SIGNAL(statusChanged(const Statistics&,bool)),
00220 this,SLOT(statusChanged(const Statistics&,bool)));
00221
00222 connect(c,SIGNAL(searchFinished(void)),this,SLOT(close(void)));
00223
00224 preferences(true);
00225 show();
00226 c->reset->trigger();
00227 }
00228
00229 void
00230 GistMainWindow::closeEvent(QCloseEvent* event) {
00231 if (c->finish())
00232 event->accept();
00233 else
00234 event->ignore();
00235 }
00236
00237 void
00238 GistMainWindow::statusChanged(const Statistics& stats, bool finished) {
00239 if (isSearching && finished) {
00240 statusBar()->showMessage("Ready");
00241 isSearching = false;
00242 } else if (!isSearching && !finished) {
00243 statusBar()->showMessage("Searching");
00244 isSearching = true;
00245 }
00246 depthLabel->setNum(stats.maxDepth);
00247 solvedLabel->setNum(stats.solutions);
00248 failedLabel->setNum(stats.failures);
00249 choicesLabel->setNum(stats.choices);
00250 openLabel->setNum(stats.undetermined);
00251 if (stats.wmp)
00252 wmpLabel->setText("WMP");
00253 else
00254 wmpLabel->setText("");
00255 }
00256
00257 void
00258 GistMainWindow::about(void) {
00259 aboutGist.show();
00260 }
00261
00262 void
00263 GistMainWindow::preferences(bool setup) {
00264 PreferencesDialog pd(opt, this);
00265 if (setup) {
00266 c->setAutoZoom(pd.zoom);
00267 }
00268 if (setup || pd.exec() == QDialog::Accepted) {
00269 c->setAutoHideFailed(pd.hideFailed);
00270 c->setRefresh(pd.refresh);
00271 c->setSmoothScrollAndZoom(pd.smoothScrollAndZoom);
00272 c->setRecompDistances(pd.c_d,pd.a_d);
00273 opt.c_d = pd.c_d;
00274 opt.a_d = pd.a_d;
00275 c->setShowCopies(pd.copies);
00276 }
00277 }
00278
00279 void
00280 GistMainWindow::populateInspectorSelection(void) {
00281 doubleClickInspectorsMenu->clear();
00282 doubleClickInspectorsMenu->addActions(
00283 c->doubleClickInspectorGroup->actions());
00284 solutionInspectorsMenu->clear();
00285 solutionInspectorsMenu->addActions(c->solutionInspectorGroup->actions());
00286 moveInspectorsMenu->clear();
00287 moveInspectorsMenu->addActions(c->moveInspectorGroup->actions());
00288 comparatorsMenu->clear();
00289 comparatorsMenu->addActions(c->comparatorGroup->actions());
00290 }
00291
00292 void
00293 GistMainWindow::populateBookmarks(void) {
00294 bookmarksMenu->clear();
00295 bookmarksMenu->addAction(c->bookmarkNode);
00296 bookmarksMenu->addSeparator();
00297 bookmarksMenu->addActions(c->bookmarksGroup->actions());
00298 }
00299
00300 void
00301 GistMainWindow::populateInspectors(void) {
00302 inspectNodeMenu->clear();
00303 inspectNodeMenu->addAction(c->inspect);
00304 inspectNodeMenu->addSeparator();
00305 inspectNodeMenu->addActions(c->inspectGroup->actions());
00306 inspectNodeBeforeFPMenu->clear();
00307 inspectNodeBeforeFPMenu->addAction(c->inspectBeforeFP);
00308 inspectNodeBeforeFPMenu->addSeparator();
00309 inspectNodeBeforeFPMenu->addActions(c->inspectBeforeFPGroup->actions());
00310 }
00311
00312 }}
00313
00314