Generated on Fri Jan 10 2020 11:38:25 for Gecode by doxygen 1.8.16
textoutput.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, 2006
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 
34 #include <QtGui>
35 #if QT_VERSION >= 0x050000
36 #include <QtWidgets>
37 #endif
38 
39 #include <iostream>
42 
43 namespace Gecode { namespace Gist {
44 
47  : public std::basic_ostream<char, std::char_traits<char> > {
49  class Buf
50  : public std::basic_streambuf<char, std::char_traits<char> > {
51  QString buffer;
52  QTextEdit* editor;
53  public:
54  void flush(void) {
55  QTextBlockFormat bf = editor->textCursor().blockFormat();
56  bf.setBottomMargin(0);
57  editor->textCursor().setBlockFormat(bf);
58  editor->append(buffer);
59  buffer.clear();
60  }
61  virtual int overflow(int v = std::char_traits<char>::eof()) {
62  if (v == '\n') {
63  flush();
64  } else {
65  buffer += (char)v;
66  }
67  return v;
68  }
69  Buf(QTextEdit* e) : editor(e) {}
70  };
71 
72  Buf _buf;
73  public:
74  GistOutputStream(QTextEdit* editor)
75  : std::basic_ostream<char, std::char_traits<char> >(&_buf),
76  _buf(editor) {
77  clear();
78  }
79  void flush(void) {
80  _buf.flush();
81  }
82  };
83 
84  TextOutputI::TextOutputI(const std::string& name, QWidget *parent)
85  : QMainWindow(parent) {
86  Logos logos;
87 
88  QPixmap myPic;
89  myPic.loadFromData(logos.gistLogo, logos.gistLogoSize);
90  setWindowIcon(myPic);
91 
92  QFont font;
93  QString fontFamily("Courier");
94  font.setFamily(fontFamily);
95  font.setFixedPitch(true);
96  font.setPointSize(12);
97 
98 
99  editor = new QTextEdit;
100  editor->setFont(font);
101  editor->setReadOnly(true);
102  editor->setLineWrapMode(QTextEdit::FixedColumnWidth);
103  editor->setLineWrapColumnOrWidth(80);
104  os = new GistOutputStream(editor);
105 
106  QAction* clearText = new QAction("Clear", this);
107  clearText->setShortcut(QKeySequence("Ctrl+K"));
108  this->addAction(clearText);
109  connect(clearText, SIGNAL(triggered()), editor,
110  SLOT(clear()));
111 
112  QAction* closeWindow = new QAction("Close window", this);
113  closeWindow->setShortcut(QKeySequence("Ctrl+W"));
114  this->addAction(closeWindow);
115  connect(closeWindow, SIGNAL(triggered()), this,
116  SLOT(close()));
117 
118  QToolBar* t = addToolBar("Tools");
119  t->setFloatable(false);
120  t->setMovable(false);
121  t->addAction(clearText);
122 
123  stayOnTop = new QAction("Stay on top", this);
124  stayOnTop->setCheckable(true);
125  t->addAction(stayOnTop);
126  connect(stayOnTop, SIGNAL(changed()), this,
127  SLOT(changeStayOnTop()));
128 
129  changeStayOnTop();
130  setCentralWidget(editor);
131  setWindowTitle(QString((std::string("Gist Console: ") + name).c_str()));
132 
133  setAttribute(Qt::WA_QuitOnClose, false);
134  setAttribute(Qt::WA_DeleteOnClose, false);
135  resize(600,300);
136  }
137 
139  delete os;
140  }
141 
142  std::ostream&
144  return *os;
145  }
146 
147  void
149  static_cast<GistOutputStream*>(os)->flush();
150  }
151 
152  void
153  TextOutputI::insertHtml(const QString& s) {
154  QTextBlockFormat bf = editor->textCursor().blockFormat();
155  bf.setBottomMargin(0);
156  editor->textCursor().setBlockFormat(bf);
157  editor->insertHtml(s);
158  editor->ensureCursorVisible();
159  }
160 
162  QPoint p = pos();
163  if (stayOnTop->isChecked()) {
164  setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
165  } else {
166  setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
167  }
168  move(p);
169  show();
170  }
171 
172 }}
173 
174 // STATISTICS: gist-any
const unsigned int gistLogoSize
Size of the smaller logo.
Definition: gecodelogo.hh:50
~TextOutputI(void)
Destructor.
Definition: textoutput.cpp:138
Class holding Gecode and Gist logo icons.
Definition: gecodelogo.hh:40
NodeType t
Type of node.
Definition: bool-expr.cpp:230
void flush(void)
Flush output.
Definition: textoutput.cpp:148
void flush(void)
Definition: textoutput.cpp:79
Gecode toplevel namespace
GistOutputStream(QTextEdit *editor)
Definition: textoutput.cpp:74
const unsigned char * gistLogo
A smaller logo used as a window icon.
Definition: gecodelogo.hh:48
void changeStayOnTop(void)
Definition: textoutput.cpp:161
An outputstream that prints on a QTextEdit.
Definition: textoutput.cpp:46
bool overflow(Term *t, int n, FloatVal c)
Definition: post.cpp:64
const int v[7]
Definition: distinct.cpp:259
std::ostream & getStream(void)
Return stream that prints to the text display.
Definition: textoutput.cpp:143
Definition: flatzinc.cpp:52
void insertHtml(const QString &s)
Add html string s to the output.
Definition: textoutput.cpp:153
bool pos(const View &x)
Test whether x is postive.
Definition: mult.hpp:41
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
TextOutputI(const std::string &name, QWidget *parent=0)
Constructor.
Definition: textoutput.cpp:84