38 #include <QtGui/QPainter>
40 #include <QPrintDialog>
54 namespace Gecode {
namespace Gist {
59 , mutex(QMutex::Recursive)
60 , layoutMutex(QMutex::Recursive)
62 , compareNodes(false), compareNodesBeforeFP(false)
63 , autoHideFailed(true), autoZoom(false)
64 , refresh(500), refreshPause(0), smoothScrollAndZoom(false)
65 , moveDuringSearch(false)
67 , scrollTimeLine(1000), targetX(0), sourceX(0), targetY(0), sourceY(0)
68 , targetW(0), targetH(0), targetScale(0)
69 , layoutDoneTimerId(0) {
70 QMutexLocker locker(&
mutex);
80 int rootIdx =
na->allocate(rootSpace);
81 assert(rootIdx == 0); (void) rootIdx;
89 setAutoFillBackground(
true);
98 Qt::BlockingQueuedConnection);
100 this, SLOT(inspectSolution(
const Space*)));
102 this, SLOT(inspectSolution(
const Space*)),
103 Qt::BlockingQueuedConnection);
107 Qt::BlockingQueuedConnection);
115 scaleBar =
new QSlider(Qt::Vertical,
this);
116 scaleBar->setObjectName(
"scaleBar");
120 connect(
scaleBar, SIGNAL(valueChanged(
int)),
130 qRegisterMetaType<Statistics>(
"Statistics");
177 comparators.append(QPair<Comparator*,bool>(c,
false));
190 QSize viewport_size =
size();
191 QAbstractScrollArea* sa =
192 static_cast<QAbstractScrollArea*
>(parentWidget()->parentWidget());
195 zoomx = viewport_size.width()/2;
197 zoomy = viewport_size.height()/2;
199 int xoff = (sa->horizontalScrollBar()->value()+zoomx)/
scale;
200 int yoff = (sa->verticalScrollBar()->value()+zoomy)/
scale;
205 scale = (
static_cast<double>(scale0)) / 100.0;
213 sa->horizontalScrollBar()->setRange(0,w-viewport_size.width());
214 sa->verticalScrollBar()->setRange(0,h-viewport_size.height());
215 sa->horizontalScrollBar()->setPageStep(viewport_size.width());
216 sa->verticalScrollBar()->setPageStep(viewport_size.height());
223 sa->horizontalScrollBar()->setValue(xoff-zoomx);
224 sa->verticalScrollBar()->setValue(yoff-zoomy);
232 QMutexLocker locker(&
mutex);
244 QSize viewport_size =
size();
245 QAbstractScrollArea* sa =
246 static_cast<QAbstractScrollArea*
>(parentWidget()->parentWidget());
247 sa->horizontalScrollBar()->setRange(0,w-viewport_size.width());
248 sa->verticalScrollBar()->setRange(0,h-viewport_size.height());
249 sa->horizontalScrollBar()->setPageStep(viewport_size.width());
250 sa->verticalScrollBar()->setPageStep(viewport_size.height());
269 QSize viewport_size =
size();
270 QAbstractScrollArea* sa =
271 static_cast<QAbstractScrollArea*
>(parentWidget()->parentWidget());
272 sa->horizontalScrollBar()->setRange(0,w-viewport_size.width());
273 sa->verticalScrollBar()->setRange(0,h-viewport_size.height());
302 SearcherThread::updateCanvas(
void) {
328 int scale0 =
static_cast<int>(t->
scale*100);
330 QWidget*
p = t->parentWidget();
333 static_cast<double>(p->width()) / (bb.right - bb.left +
336 static_cast<double>(p->height()) /
339 scale0 =
static_cast<int>(
std::min(newXScale, newYScale)*100);
344 double scale = (
static_cast<double>(scale0)) / 100.0;
388 std::stack<SearchItem> stck;
392 static_cast<long unsigned int>(depth+stck.size()));
433 static_cast<long unsigned int>(depth+stck.size()));
457 QMutexLocker locker(&
mutex);
463 QMutexLocker locker(&
mutex);
469 QMutexLocker locker(&
mutex);
478 QMutexLocker locker(&
mutex);
487 QMutexLocker locker(&
mutex);
497 QMutexLocker locker(&
mutex);
506 QMutexLocker locker(&
mutex);
521 int zoomCurrent =
static_cast<int>(scale*100);
540 QWidget* p = parentWidget();
543 static_cast<double>(p->width()) / (bb.
right - bb.
left +
549 int scale0 =
static_cast<int>(
std::min(newXScale, newYScale)*100);
559 int zoomCurrent =
static_cast<int>(scale*100);
560 int targetZoom = scale0;
572 QMutexLocker locker(&
mutex);
583 x =
static_cast<int>((
xtrans+
x)*scale); y =
static_cast<int>(y*
scale);
585 QAbstractScrollArea* sa =
586 static_cast<QAbstractScrollArea*
>(parentWidget()->parentWidget());
588 x -= sa->viewport()->width() / 2;
589 y -= sa->viewport()->height() / 2;
591 sourceX = sa->horizontalScrollBar()->value();
595 sourceY = sa->verticalScrollBar()->value();
600 sa->horizontalScrollBar()->setValue(targetX);
601 sa->verticalScrollBar()->setValue(targetY);
615 QAbstractScrollArea* sa =
616 static_cast<QAbstractScrollArea*
>(parentWidget()->parentWidget());
617 double p =
static_cast<double>(
i)/100.0;
620 sa->horizontalScrollBar()->setValue(
sourceX+static_cast<int>(xdiff));
621 sa->verticalScrollBar()->setValue(
sourceY+static_cast<int>(ydiff));
626 QMutexLocker locker(&
mutex);
633 int failedInspectorType = -1;
634 int failedInspector = -1;
635 bool needCentering =
false;
646 needCentering =
true;
658 failedInspectorType = 0;
671 failedInspectorType = -1;
707 "Something went wrong - probably an incorrect brancher");
717 switch (curSpace->
status()) {
730 if (inspectorNo==-1) {
733 failedInspectorType = 1;
736 failedInspectorType = -1;
740 failedInspectorType = 1;
741 failedInspector = inspectorNo;
743 failedInspectorType = -1;
750 switch (failedInspectorType) {
752 qFatal(
"Exception in move inspector %d: %s.\n Stopping.",
753 failedInspector, e.
what());
756 qFatal(
"Exception in double click inspector %d: %s.\n Stopping.",
757 failedInspector, e.
what());
760 qFatal(
"Exception: %s.\n Stopping.", e.
what());
777 TreeCanvas::inspectSolution(
const Space* s) {
778 int failedInspectorType = -1;
779 int failedInspector = -1;
786 failedInspectorType = 1;
789 failedInspectorType = -1;
793 }
catch (Exception& e) {
794 switch (failedInspectorType) {
796 qFatal(
"Exception in move inspector %d: %s.\n Stopping.",
797 failedInspector, e.what());
800 qFatal(
"Exception in solution inspector %d: %s.\n Stopping.",
801 failedInspector, e.what());
804 qFatal(
"Exception: %s.\n Stopping.", e.what());
818 QMutexLocker locker(&
mutex);
832 int rootIdx =
na->allocate(rootSpace);
833 assert(rootIdx == 0); (void) rootIdx;
851 QMutexLocker locker(&
mutex);
855 QInputDialog::getText(
this,
"Add bookmark",
"Name:",
856 QLineEdit::Normal,
"",&ok);
861 text = QString(
"Node ")+QString().setNum(
bookmarks.size());
876 QMutexLocker locker(&
mutex);
890 QMutexLocker locker(&
mutex);
895 while (nextAlt >= 0) {
906 QMutexLocker locker(&
mutex);
909 setCursor(QCursor(Qt::CrossCursor));
914 QMutexLocker locker(&
mutex);
917 setCursor(QCursor(Qt::CrossCursor));
927 QMutexLocker locker(&
mutex);
940 QMutexLocker locker(&
mutex);
963 QMutexLocker locker(&
mutex);
977 QMutexLocker locker(&
mutex);
991 QMutexLocker locker(&
mutex);
998 QMutexLocker locker(&
mutex);
1016 #if QT_VERSION >= 0x040400
1017 QString filename = QFileDialog::getSaveFileName(
this, tr(
"Export tree as pdf"),
"", tr(
"PDF (*.pdf)"));
1018 if (filename !=
"") {
1019 QPrinter printer(QPrinter::ScreenResolution);
1020 QMutexLocker locker(&
mutex);
1023 printer.setFullPage(
true);
1027 printer.setOutputFileName(filename);
1028 QPainter painter(&printer);
1030 painter.setRenderHint(QPainter::Antialiasing);
1032 QRect pageRect = printer.pageRect();
1034 static_cast<double>(pageRect.width()) / (bb.
right - bb.
left +
1037 static_cast<double>(pageRect.height()) /
1040 double printScale =
std::min(newXScale, newYScale);
1041 painter.scale(printScale,printScale);
1046 QRect clip(0,0,0,0);
1059 #if QT_VERSION >= 0x040400
1060 exportNodePDF(
root);
1066 #if QT_VERSION >= 0x040400
1074 if (QPrintDialog(&printer,
this).exec() == QDialog::Accepted) {
1075 QMutexLocker locker(&
mutex);
1078 QRect pageRect = printer.pageRect();
1080 static_cast<double>(pageRect.width()) / (bb.
right - bb.
left +
1083 static_cast<double>(pageRect.height()) /
1086 double printScale =
std::min(newXScale, newYScale)*100;
1089 if (printScale > 400.0)
1091 printScale = printScale / 100.0;
1093 QPainter painter(&printer);
1094 painter.setRenderHint(QPainter::Antialiasing);
1095 painter.scale(printScale,printScale);
1096 painter.translate(
xtrans, 0);
1097 QRect clip(0,0,0,0);
1107 switch (event->type()) {
1108 case QEvent::ToolTip:
1110 QHelpEvent* he =
static_cast<QHelpEvent*
>(
event);
1115 case QEvent::MouseButtonDblClick:
1116 case QEvent::MouseButtonPress:
1117 case QEvent::MouseButtonRelease:
1118 case QEvent::MouseMove:
1120 QMouseEvent* me =
static_cast<QMouseEvent*
>(
event);
1125 case QEvent::ContextMenu:
1127 QContextMenuEvent* ce =
static_cast<QContextMenuEvent*
>(
event);
1135 QAbstractScrollArea* sa =
1136 static_cast<QAbstractScrollArea*
>(parentWidget()->parentWidget());
1137 int xoff = sa->horizontalScrollBar()->value()/
scale;
1138 int yoff = sa->verticalScrollBar()->value()/
scale;
1143 if (w < sa->viewport()->width())
1144 xoff -= (sa->viewport()->width()-w)/2;
1148 static_cast<int>(x/scale-
xtrans+xoff),
1149 static_cast<int>((y-30)/scale+yoff));
1155 if (
mutex.tryLock()) {
1156 if (event->type() == QEvent::ToolTip) {
1160 QHelpEvent* he =
static_cast<QHelpEvent*
>(
event);
1161 QToolTip::showText(he->globalPos(),
1164 QToolTip::hideText();
1169 return QWidget::event(event);
1181 QPainter painter(
this);
1182 painter.setRenderHint(QPainter::Antialiasing);
1184 QAbstractScrollArea* sa =
1185 static_cast<QAbstractScrollArea*
>(parentWidget()->parentWidget());
1186 int xoff = sa->horizontalScrollBar()->value()/
scale;
1187 int yoff = sa->verticalScrollBar()->value()/
scale;
1192 if (w < sa->viewport()->width())
1193 xoff -= (sa->viewport()->width()-w)/2;
1195 QRect origClip =
event->rect();
1196 painter.translate(0, 30);
1197 painter.scale(scale,scale);
1198 painter.translate(
xtrans-xoff, -yoff);
1199 QRect clip(static_cast<int>(origClip.x()/scale-
xtrans+xoff),
1200 static_cast<int>(origClip.y()/scale+yoff),
1201 static_cast<int>(origClip.width()/
scale),
1202 static_cast<int>(origClip.height()/
scale));
1219 if (
mutex.tryLock()) {
1220 if(event->button() == Qt::LeftButton) {
1236 if (
mutex.tryLock()) {
1252 QAbstractScrollArea* sa =
1253 static_cast<QAbstractScrollArea*
>(parentWidget()->parentWidget());
1255 int w = sa->horizontalScrollBar()->maximum()+e->oldSize().width();
1256 int h = sa->verticalScrollBar()->maximum()+e->oldSize().height();
1258 sa->horizontalScrollBar()->setRange(0,w-e->size().width());
1259 sa->verticalScrollBar()->setRange(0,h-e->size().height());
1260 sa->horizontalScrollBar()->setPageStep(e->size().width());
1261 sa->verticalScrollBar()->setPageStep(e->size().height());
1266 if (event->modifiers() & Qt::ShiftModifier) {
1268 if (event->orientation() == Qt::Vertical && !
autoZoom)
1269 scaleTree(scale*100+ceil(static_cast<double>(event->delta())/4.0),
1270 event->x(),
event->y());
1299 Space* curSpace = NULL;
1302 if (curSpace == NULL)
1307 qFatal(
"Exception in move inspector %d: %s.\n Stopping.",
1320 setCursor(QCursor(Qt::ArrowCursor));
1330 if (
mutex.tryLock()) {
1331 if (event->button() == Qt::LeftButton) {
1337 Space* curSpace = NULL;
1338 Space* compareSpace = NULL;
1341 if (curSpace == NULL) {
1349 switch (compareSpace->
status()) {
1363 comparators[
i].first->compare(*curSpace,*compareSpace);
1365 qFatal(
"Exception in comparator %d: %s.\n Stopping.",
1375 setCursor(QCursor(Qt::ArrowCursor));