43 #include <QApplication>
45 #include <QPainterPath>
46 #include <QPixmapCache>
48 #include <QTextDocument>
49 #include <QAbstractTextDocumentLayout>
51 #include <QTextBrowser>
54 extern QPixmap
cached(
const QString &img);
58 , m_prefer_image(false)
60 #ifdef QT_OPENGL_SUPPORT
63 QGLFormat f = QGLFormat::defaultFormat();
64 f.setSampleBuffers(
true);
67 f.setAlphaBufferSize(8);
68 QGLFormat::setDefaultFormat(f);
73 m_tile = QPixmap(128, 128);
76 QColor color(230, 230, 230);
77 pt.fillRect(0, 0, 64, 64, color);
78 pt.fillRect(64, 64, 64, 64, color);
87 #ifdef QT_OPENGL_SUPPORT
88 void ArthurFrame::enableOpenGL(
bool use_opengl)
90 if (m_use_opengl == use_opengl)
93 if (!glw && use_opengl) {
95 glw->setAutoFillBackground(
false);
96 glw->disableAutoBufferSwap();
97 QApplication::postEvent(
this,
new QResizeEvent(size(), size()));
100 m_use_opengl = use_opengl;
114 static QImage *static_image = 0;
117 #ifdef QT_OPENGL_SUPPORT
121 if (!static_image || static_image->size() != size()) {
123 static_image =
new QImage(size(), QImage::Format_RGB32);
125 painter.begin(static_image);
129 QBrush bg = palette().brush(QPalette::Background);
130 painter.fillRect(0, 0, o, o, bg);
131 painter.fillRect(width() - o, 0, o, o, bg);
132 painter.fillRect(0, height() - o, o, o, bg);
133 painter.fillRect(width() - o, height() - o, o, o, bg);
135 #ifdef QT_OPENGL_SUPPORT
138 painter.fillRect(QRectF(0, 0, glw->width(), glw->height()), palette().color(backgroundRole()));
147 painter.setClipRect(e->rect());
149 painter.setRenderHint(QPainter::Antialiasing);
151 QPainterPath clipPath;
154 qreal left = r.x() + 1;
155 qreal top = r.y() + 1;
156 qreal right = r.right();
157 qreal bottom = r.bottom();
158 qreal radius2 = 8 * 2;
160 clipPath.moveTo(right - radius2, top);
161 clipPath.arcTo(right - radius2, top, radius2, radius2, 90, -90);
162 clipPath.arcTo(right - radius2, bottom - radius2, radius2, radius2, 0, -90);
163 clipPath.arcTo(left, bottom - radius2, radius2, radius2, 270, -90);
164 clipPath.arcTo(left, top, radius2, radius2, 180, -90);
165 clipPath.closeSubpath();
168 painter.setClipPath(clipPath, Qt::IntersectClip);
170 painter.drawTiledPixmap(rect(),
m_tile);
184 painter.setPen(QPen(QColor(level, level, level), 2));
185 painter.setBrush(Qt::NoBrush);
186 painter.drawPath(clipPath);
189 #ifdef QT_OPENGL_SUPPORT
195 painter.drawImage(e->rect(), *static_image, e->rect());
198 #ifdef QT_OPENGL_SUPPORT
199 if (m_use_opengl && (inherits(
"PathDeformRenderer") || inherits(
"PathStrokeRenderer") || inherits(
"CompositionRenderer") ||
m_show_doc))
206 #ifdef QT_OPENGL_SUPPORT
208 glw->setGeometry(0, 0, e->size().width()-1, e->size().height()-1);
210 QWidget::resizeEvent(e);
224 QFile textFile(fileName);
226 if (!textFile.open(QFile::ReadOnly))
227 text = QString(
"Unable to load resource file: '%1'").arg(fileName);
229 text = textFile.readAll();
245 int pageWidth = qMax(width() - 100, 100);
246 int pageHeight = qMax(height() - 100, 100);
247 if (pageWidth !=
m_document->pageSize().width()) {
248 m_document->setPageSize(QSize(pageWidth, pageHeight));
251 QRect textRect(width() / 2 - pageWidth / 2,
252 height() / 2 - pageHeight / 2,
256 QRect clearRect = textRect.adjusted(-pad, -pad, pad, pad);
257 painter->setPen(Qt::NoPen);
258 painter->setBrush(QColor(0, 0, 0, 63));
260 painter->drawRect(clearRect.x() + clearRect.width() + 1,
261 clearRect.y() + shade,
263 clearRect.height() + 1);
264 painter->drawRect(clearRect.x() + shade,
265 clearRect.y() + clearRect.height() + 1,
266 clearRect.width() - shade + 1,
269 painter->setRenderHint(QPainter::Antialiasing,
false);
270 painter->setBrush(QColor(255, 255, 255, 220));
271 painter->setPen(Qt::black);
272 painter->drawRect(clearRect);
274 painter->setClipRegion(textRect, Qt::IntersectClip);
275 painter->translate(textRect.topLeft());
277 QAbstractTextDocumentLayout::PaintContext ctx;
279 QLinearGradient g(0, 0, 0, textRect.height());
280 g.setColorAt(0, Qt::black);
281 g.setColorAt(0.9, Qt::black);
282 g.setColorAt(1, Qt::transparent);
284 QPalette pal = palette();
285 pal.setBrush(QPalette::Text, g);
288 ctx.clip = QRect(0, 0, textRect.width(), textRect.height());
289 m_document->documentLayout()->draw(painter, ctx);
300 if (findChild<QTextBrowser *>())
305 contents = QString(
"No source for widget: '%1'").arg(objectName());
308 if (!f.open(QFile::ReadOnly))
311 contents = f.readAll();
314 contents.replace(
'&',
"&");
315 contents.replace(
'<',
"<");
316 contents.replace(
'>',
">");
318 QStringList keywords;
319 keywords <<
"for " <<
"if " <<
"switch " <<
" int " <<
"#include " <<
"const"
320 <<
"void " <<
"uint " <<
"case " <<
"double " <<
"#define " <<
"static"
323 foreach (QString keyword, keywords)
324 contents.replace(keyword, QLatin1String(
"<font color=olive>") + keyword + QLatin1String(
"</font>"));
325 contents.replace(
"(int ",
"(<font color=olive><b>int </b></font>");
327 QStringList ppKeywords;
328 ppKeywords <<
"#ifdef" <<
"#ifndef" <<
"#if" <<
"#endif" <<
"#else";
330 foreach (QString keyword, ppKeywords)
331 contents.replace(keyword, QLatin1String(
"<font color=navy>") + keyword + QLatin1String(
"</font>"));
333 contents.replace(QRegExp(
"(\\d\\d?)"), QLatin1String(
"<font color=navy>\\1</font>"));
335 QRegExp commentRe(
"(//.+)\\n");
336 commentRe.setMinimal(
true);
337 contents.replace(commentRe, QLatin1String(
"<font color=red>\\1</font>\n"));
339 QRegExp stringLiteralRe(
"(\".+\")");
340 stringLiteralRe.setMinimal(
true);
341 contents.replace(stringLiteralRe, QLatin1String(
"<font color=green>\\1</font>"));
343 QString html = contents;
344 html.prepend(
"<html><pre>");
345 html.append(
"</pre></html>");
347 QTextBrowser *sourceViewer =
new QTextBrowser(0);
349 sourceViewer->setParent(
this, Qt::Dialog);
350 sourceViewer->setAttribute(Qt::WA_DeleteOnClose);
351 sourceViewer->setLineWrapMode(QTextEdit::NoWrap);
352 sourceViewer->setHtml(html);
353 sourceViewer->resize(600, 600);
354 sourceViewer->show();