Generated on Sat Feb 7 2015 02:01:19 for Gecode by doxygen 1.8.9.1
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  * Last modified:
10  * $Date: 2012-12-21 01:48:30 +0100 (Fri, 21 Dec 2012) $ by $Author: tack $
11  * $Revision: 13214 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #include <QtGui>
39 #if QT_VERSION >= 0x050000
40 #include <QtWidgets>
41 #endif
42 
43 #include <iostream>
46 
47 namespace Gecode { namespace Gist {
48 
51  : public std::basic_ostream<char, std::char_traits<char> > {
53  class Buf
54  : public std::basic_streambuf<char, std::char_traits<char> > {
55  QString buffer;
56  QTextEdit* editor;
57  public:
58  void flush(void) {
59  QTextBlockFormat bf = editor->textCursor().blockFormat();
60  bf.setBottomMargin(0);
61  editor->textCursor().setBlockFormat(bf);
62  editor->append(buffer);
63  buffer.clear();
64  }
65  virtual int overflow(int v = std::char_traits<char>::eof()) {
66  if (v == '\n') {
67  flush();
68  } else {
69  buffer += (char)v;
70  }
71  return v;
72  }
73  Buf(QTextEdit* e) : editor(e) {}
74  };
75 
76  Buf _buf;
77  public:
78  GistOutputStream(QTextEdit* editor)
79  : std::basic_ostream<char, std::char_traits<char> >(&_buf),
80  _buf(editor) {
81  clear();
82  }
83  void flush(void) {
84  _buf.flush();
85  }
86  };
87 
88  TextOutputI::TextOutputI(const std::string& name, QWidget *parent)
89  : QMainWindow(parent) {
90  Logos logos;
91 
92  QPixmap myPic;
93  myPic.loadFromData(logos.gistLogo, logos.gistLogoSize);
94  setWindowIcon(myPic);
95 
96  QFont font;
97  QString fontFamily("Courier");
98  font.setFamily(fontFamily);
99  font.setFixedPitch(true);
100  font.setPointSize(12);
101 
102 
103  editor = new QTextEdit;
104  editor->setFont(font);
105  editor->setReadOnly(true);
106  editor->setLineWrapMode(QTextEdit::FixedColumnWidth);
107  editor->setLineWrapColumnOrWidth(80);
108  os = new GistOutputStream(editor);
109 
110  QAction* clearText = new QAction("Clear", this);
111  clearText->setShortcut(QKeySequence("Ctrl+K"));
112  this->addAction(clearText);
113  connect(clearText, SIGNAL(triggered()), editor,
114  SLOT(clear()));
115 
116  QAction* closeWindow = new QAction("Close window", this);
117  closeWindow->setShortcut(QKeySequence("Ctrl+W"));
118  this->addAction(closeWindow);
119  connect(closeWindow, SIGNAL(triggered()), this,
120  SLOT(close()));
121 
122  QToolBar* t = addToolBar("Tools");
123  t->setFloatable(false);
124  t->setMovable(false);
125  t->addAction(clearText);
126 
127  stayOnTop = new QAction("Stay on top", this);
128  stayOnTop->setCheckable(true);
129  t->addAction(stayOnTop);
130  connect(stayOnTop, SIGNAL(changed()), this,
131  SLOT(changeStayOnTop()));
132 
133  changeStayOnTop();
134  setCentralWidget(editor);
135  setWindowTitle(QString((std::string("Gist Console: ") + name).c_str()));
136 
137  setAttribute(Qt::WA_QuitOnClose, false);
138  setAttribute(Qt::WA_DeleteOnClose, false);
139  resize(600,300);
140  }
141 
143  delete os;
144  }
145 
146  std::ostream&
148  return *os;
149  }
150 
151  void
153  static_cast<GistOutputStream*>(os)->flush();
154  }
155 
156  void
157  TextOutputI::insertHtml(const QString& s) {
158  QTextBlockFormat bf = editor->textCursor().blockFormat();
159  bf.setBottomMargin(0);
160  editor->textCursor().setBlockFormat(bf);
161  editor->insertHtml(s);
162  editor->ensureCursorVisible();
163  }
164 
166  QPoint p = pos();
167  if (stayOnTop->isChecked()) {
168  setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
169  } else {
170  setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
171  }
172  move(p);
173  show();
174  }
175 
176 }}
177 
178 // STATISTICS: gist-any
NodeType t
Type of node.
Definition: bool-expr.cpp:234
~TextOutputI(void)
Destructor.
Definition: textoutput.cpp:142
bool pos(const View &x)
Test whether x is postive.
Definition: mult.hpp:45
void flush(void)
Flush output.
Definition: textoutput.cpp:152
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Class holding Gecode and Gist logo icons.
Definition: gecodelogo.hh:44
GistOutputStream(QTextEdit *editor)
Definition: textoutput.cpp:78
const unsigned char * gistLogo
A smaller logo used as a window icon.
Definition: gecodelogo.hh:52
const int v[7]
Definition: distinct.cpp:207
std::ostream & getStream(void)
Return stream that prints to the text display.
Definition: textoutput.cpp:147
Gecode toplevel namespace
void insertHtml(const QString &s)
Add html string s to the output.
Definition: textoutput.cpp:157
TextOutputI(const std::string &name, QWidget *parent=0)
Constructor.
Definition: textoutput.cpp:88
const unsigned int gistLogoSize
Size of the smaller logo.
Definition: gecodelogo.hh:54
An outputstream that prints on a QTextEdit.
Definition: textoutput.cpp:50