#include <arthurwidgets.h>
Inheritance diagram for ArthurFrame:


Definition at line 48 of file arthurwidgets.h.
Public Slots | |
| void | setPreferImage (bool pi) |
| void | setDescriptionEnabled (bool enabled) |
| void | showSource () |
Signals | |
| void | descriptionEnabledChanged (bool) |
Public Member Functions | |
| ArthurFrame (QWidget *parent) | |
| virtual void | paint (QPainter *) |
| void | paintDescription (QPainter *p) |
| void | loadDescription (const QString &filename) |
| void | setDescription (const QString &htmlDesc) |
| void | loadSourceFile (const QString &fileName) |
| bool | preferImage () const |
Protected Member Functions | |
| void | paintEvent (QPaintEvent *) |
| void | resizeEvent (QResizeEvent *) |
Protected Attributes | |
| QPixmap | m_tile |
| bool | m_show_doc |
| bool | m_prefer_image |
| QTextDocument * | m_document |
| QString | m_sourceFileName |
| ArthurFrame::ArthurFrame | ( | QWidget * | parent | ) |
Definition at line 38 of file arthurwidgets.cpp.
References QGLFormat::defaultFormat(), QPainter::end(), QPixmap::fill(), QPainter::fillRect(), m_document, m_prefer_image, m_show_doc, m_tile, QWidget::QPixmap, QGLFormat::setAlpha(), QGLFormat::setAlphaBufferSize(), QGLFormat::setDefaultFormat(), QGLFormat::setSampleBuffers(), QGLFormat::setStencil(), and Qt::white.
00039 : QWidget(parent) 00040 , m_prefer_image(false) 00041 { 00042 #ifdef QT_OPENGL_SUPPORT 00043 glw = 0; 00044 m_use_opengl = false; 00045 QGLFormat f = QGLFormat::defaultFormat(); 00046 f.setSampleBuffers(true); 00047 f.setStencil(true); 00048 f.setAlpha(true); 00049 f.setAlphaBufferSize(8); 00050 QGLFormat::setDefaultFormat(f); 00051 #endif 00052 m_document = 0; 00053 m_show_doc = false; 00054 00055 m_tile = QPixmap(100, 100); 00056 m_tile.fill(Qt::white); 00057 QPainter pt(&m_tile); 00058 QColor color(240, 240, 240); 00059 pt.fillRect(0, 0, 50, 50, color); 00060 pt.fillRect(50, 50, 50, 50, color); 00061 pt.end(); 00062 00063 // QPalette pal = palette(); 00064 // pal.setBrush(backgroundRole(), m_tile); 00065 // setPalette(pal); 00066 00067 #ifdef Q_WS_X11 00068 QPixmap xRenderPixmap(1, 1); 00069 m_prefer_image = !xRenderPixmap.x11PictureHandle(); 00070 #endif 00071 }
Here is the call graph for this function:

| virtual void ArthurFrame::paint | ( | QPainter * | ) | [inline, virtual] |
| void ArthurFrame::paintDescription | ( | QPainter * | p | ) |
Definition at line 224 of file arthurwidgets.cpp.
References QRect::adjusted(), QPainter::Antialiasing, Qt::black, QAbstractTextDocumentLayout::PaintContext::clip, QTextDocument::documentLayout(), QAbstractTextDocumentLayout::draw(), QPainter::drawRect(), g, QWidget::height(), QRect::height(), Qt::IntersectClip, m_document, Qt::NoPen, QTextDocument::pageSize(), QAbstractTextDocumentLayout::PaintContext::palette, QWidget::palette(), qMax(), QPainter::setBrush(), QPalette::setBrush(), QPainter::setClipRegion(), QTextDocument::setPageSize(), QPainter::setPen(), QPainter::setRenderHint(), QPalette::Text, QRect::topLeft(), QPainter::translate(), Qt::transparent, QRect::width(), QWidget::width(), QSizeF::width(), QRect::x(), and QRect::y().
Referenced by paintEvent().
00225 { 00226 if (!m_document) 00227 return; 00228 00229 int pageWidth = qMax(width() - 100, 100); 00230 int pageHeight = qMax(height() - 100, 100); 00231 if (pageWidth != m_document->pageSize().width()) { 00232 m_document->setPageSize(QSize(pageWidth, pageHeight)); 00233 } 00234 00235 QRect textRect(width() / 2 - pageWidth / 2, 00236 height() / 2 - pageHeight / 2, 00237 pageWidth, 00238 pageHeight); 00239 int pad = 10; 00240 QRect clearRect = textRect.adjusted(-pad, -pad, pad, pad); 00241 painter->setPen(Qt::NoPen); 00242 painter->setBrush(QColor(0, 0, 0, 63)); 00243 int shade = 10; 00244 painter->drawRect(clearRect.x() + clearRect.width() + 1, 00245 clearRect.y() + shade, 00246 shade, 00247 clearRect.height() + 1); 00248 painter->drawRect(clearRect.x() + shade, 00249 clearRect.y() + clearRect.height() + 1, 00250 clearRect.width() - shade + 1, 00251 shade); 00252 00253 painter->setRenderHint(QPainter::Antialiasing, false); 00254 painter->setBrush(QColor(255, 255, 255, 220)); 00255 painter->setPen(Qt::black); 00256 painter->drawRect(clearRect); 00257 00258 painter->setClipRegion(textRect, Qt::IntersectClip); 00259 painter->translate(textRect.topLeft()); 00260 00261 QAbstractTextDocumentLayout::PaintContext ctx; 00262 00263 QLinearGradient g(0, 0, 0, textRect.height()); 00264 g.setColorAt(0, Qt::black); 00265 g.setColorAt(0.9, Qt::black); 00266 g.setColorAt(1, Qt::transparent); 00267 00268 QPalette pal = palette(); 00269 pal.setBrush(QPalette::Text, g); 00270 00271 ctx.palette = pal; 00272 ctx.clip = QRect(0, 0, textRect.width(), textRect.height()); 00273 m_document->documentLayout()->draw(painter, ctx); 00274 }
Here is the call graph for this function:

| void ArthurFrame::loadDescription | ( | const QString & | filename | ) |
Definition at line 206 of file arthurwidgets.cpp.
References QString::arg(), QFile::open(), QIODevice::readAll(), QIODevice::ReadOnly, and setDescription().
Referenced by CompositionWidget::CompositionWidget(), GradientWidget::GradientWidget(), PathDeformWidget::PathDeformWidget(), PathStrokeWidget::PathStrokeWidget(), and XFormWidget::XFormWidget().
00207 { 00208 QFile textFile(fileName); 00209 QString text; 00210 if (!textFile.open(QFile::ReadOnly)) 00211 text = QString("Unable to load resource file: '%1'").arg(fileName); 00212 else 00213 text = textFile.readAll(); 00214 setDescription(text); 00215 }
Here is the call graph for this function:

| void ArthurFrame::setDescription | ( | const QString & | htmlDesc | ) |
Definition at line 218 of file arthurwidgets.cpp.
References m_document, and QTextDocument::setHtml().
Referenced by loadDescription().
00219 { 00220 m_document = new QTextDocument(this); 00221 m_document->setHtml(text); 00222 }
Here is the call graph for this function:

| void ArthurFrame::loadSourceFile | ( | const QString & | fileName | ) |
Definition at line 276 of file arthurwidgets.cpp.
References m_sourceFileName.
Referenced by CompositionWidget::CompositionWidget(), GradientWidget::GradientWidget(), PathDeformWidget::PathDeformWidget(), PathStrokeWidget::PathStrokeWidget(), and XFormWidget::XFormWidget().
00277 { 00278 m_sourceFileName = sourceFile; 00279 }
| bool ArthurFrame::preferImage | ( | ) | const [inline] |
Definition at line 63 of file arthurwidgets.h.
References m_prefer_image.
Referenced by PathDeformRenderer::generateLensPixmap(), PathDeformRenderer::paint(), and paintEvent().
00063 { return m_prefer_image; }
| void ArthurFrame::setPreferImage | ( | bool | pi | ) | [inline, slot] |
Definition at line 70 of file arthurwidgets.h.
References m_prefer_image.
00070 { m_prefer_image = pi; }
| void ArthurFrame::setDescriptionEnabled | ( | bool | enabled | ) | [slot] |
Definition at line 197 of file arthurwidgets.cpp.
References descriptionEnabledChanged(), emit, m_show_doc, and QWidget::update().
Referenced by PathDeformRenderer::mousePressEvent(), GradientRenderer::mousePressEvent(), PathStrokeRenderer::mousePressEvent(), CompositionRenderer::mousePressEvent(), XFormView::mousePressEvent(), and PathDeformWidget::PathDeformWidget().
00198 { 00199 if (m_show_doc != enabled) { 00200 m_show_doc = enabled; 00201 emit descriptionEnabledChanged(m_show_doc); 00202 update(); 00203 } 00204 }
| void ArthurFrame::showSource | ( | ) | [slot] |
Definition at line 281 of file arthurwidgets.cpp.
References QString::append(), QString::arg(), Qt::Dialog, QString::isEmpty(), keywords, m_sourceFileName, QString::mid(), QTextEdit::NoWrap, QObject::objectName(), QFile::open(), QString::prepend(), QIODevice::readAll(), QIODevice::ReadOnly, QString::replace(), QWidget::resize(), QWidget::setAttribute(), QTextEdit::setHtml(), QTextEdit::setLineWrapMode(), QRegExp::setMinimal(), QWidget::setParent(), QWidget::setWindowTitle(), QWidget::show(), and Qt::WA_DeleteOnClose.
00282 { 00283 // Check for existing source 00284 if (qFindChild<QTextBrowser *>(this)) 00285 return; 00286 00287 QString contents; 00288 if (m_sourceFileName.isEmpty()) { 00289 contents = QString("No source for widget: '%1'").arg(objectName()); 00290 } else { 00291 QFile f(m_sourceFileName); 00292 if (!f.open(QFile::ReadOnly)) 00293 contents = QString("Could not open file: '%1'").arg(m_sourceFileName); 00294 else 00295 contents = f.readAll(); 00296 } 00297 00298 contents.replace('&', "&"); 00299 contents.replace('<', "<"); 00300 contents.replace('>', ">"); 00301 00302 QStringList keywords; 00303 keywords << "for " << "if " << "switch " << " int " << "#include " << "const" 00304 << "void " << "uint " << "case " << "double " << "#define " << "static" 00305 << "new" << "this"; 00306 00307 foreach (QString keyword, keywords) 00308 contents.replace(keyword, QLatin1String("<font color=olive>") + keyword + QLatin1String("</font>")); 00309 contents.replace("(int ", "(<font color=olive><b>int </b></font>"); 00310 00311 QStringList ppKeywords; 00312 ppKeywords << "#ifdef" << "#ifndef" << "#if" << "#endif" << "#else"; 00313 00314 foreach (QString keyword, ppKeywords) 00315 contents.replace(keyword, QLatin1String("<font color=navy>") + keyword + QLatin1String("</font>")); 00316 00317 contents.replace(QRegExp("(\\d\\d?)"), QLatin1String("<font color=navy>\\1</font>")); 00318 00319 QRegExp commentRe("(//.+)\\n"); 00320 commentRe.setMinimal(true); 00321 contents.replace(commentRe, QLatin1String("<font color=red>\\1</font>\n")); 00322 00323 QRegExp stringLiteralRe("(\".+\")"); 00324 stringLiteralRe.setMinimal(true); 00325 contents.replace(stringLiteralRe, QLatin1String("<font color=green>\\1</font>")); 00326 00327 QString html = contents; 00328 html.prepend("<html><pre>"); 00329 html.append("</pre></html>"); 00330 00331 QTextBrowser *sourceViewer = new QTextBrowser(0); 00332 sourceViewer->setWindowTitle("Source: " + m_sourceFileName.mid(5)); 00333 sourceViewer->setParent(this, Qt::Dialog); 00334 sourceViewer->setAttribute(Qt::WA_DeleteOnClose); 00335 sourceViewer->setLineWrapMode(QTextEdit::NoWrap); 00336 sourceViewer->setHtml(html); 00337 sourceViewer->resize(600, 600); 00338 sourceViewer->show(); 00339 }
| void ArthurFrame::descriptionEnabledChanged | ( | bool | ) | [signal] |
Referenced by setDescriptionEnabled().
| void ArthurFrame::paintEvent | ( | QPaintEvent * | e | ) | [protected, virtual] |
This event handler can be reimplemented in a subclass to receive paint events which are passed in the event parameter.
A paint event is a request to repaint all or part of the widget. It can happen as a result of repaint() or update(), or because the widget was obscured and has now been uncovered, or for many other reasons.
Many widgets can simply repaint their entire surface when asked to, but some slow widgets need to optimize by painting only the requested region: QPaintEvent::region(). This speed optimization does not change the result, as painting is clipped to that region during event processing. QListView and QTableView do this, for example.
Qt also tries to speed up painting by merging multiple paint events into one. When update() is called several times or the window system sends several paint events, Qt merges these events into one event with a larger region (see QRegion::united()). repaint() does not permit this optimization, so we suggest using update() whenever possible.
When the paint event occurs, the update region has normally been erased, so that you're painting on the widget's background.
The background can be set using setBackgroundRole() and setPalette().
From Qt 4.0, QWidget automatically double-buffers its painting, so there's no need to write double-buffering code in paintEvent() to avoid flicker.
Note: Under X11 it is possible to toggle the global double buffering by calling qt_x11_set_global_double_buffer(). Example usage:
...
extern void qt_x11_set_global_double_buffer(bool);
qt_x11_set_global_double_buffer(false);
...
Reimplemented from QWidget.
Definition at line 94 of file arthurwidgets.cpp.
References QPainter::Antialiasing, QPainterPath::arcTo(), QPalette::Background, QWidget::backgroundRole(), QPainter::begin(), QRect::bottom(), QPalette::brush(), QPainterPath::closeSubpath(), QPalette::color(), QPainter::drawTiledPixmap(), QPainter::fillRect(), QImage::Format_RGB32, QWidget::height(), QObject::inherits(), Qt::IntersectClip, left(), level, m_show_doc, m_tile, QPainterPath::moveTo(), Qt::NoBrush, o, paint(), paintDescription(), QWidget::palette(), preferImage(), QPaintEvent::rect(), QWidget::rect(), QPainter::restore(), right(), QRect::right(), QPainter::save(), QPainter::setClipPath(), QPainter::setClipRect(), QPainter::setRenderHint(), QImage::size(), QWidget::size(), QWidget::width(), QRect::x(), and QRect::y().
00095 { 00096 static QImage *static_image = 0; 00097 QPainter painter; 00098 if (preferImage() 00099 #ifdef QT_OPENGL_SUPPORT 00100 && !m_use_opengl 00101 #endif 00102 ) { 00103 if (!static_image) { 00104 static_image = new QImage(size(), QImage::Format_RGB32); 00105 } else if (static_image->size() != size()) { 00106 delete static_image; 00107 static_image = new QImage(size(), QImage::Format_RGB32); 00108 } 00109 painter.begin(static_image); 00110 00111 int o = 10; 00112 00113 QBrush bg = palette().brush(QPalette::Background); 00114 painter.fillRect(0, 0, o, o, bg); 00115 painter.fillRect(width() - o, 0, o, o, bg); 00116 painter.fillRect(0, height() - o, o, o, bg); 00117 painter.fillRect(width() - o, height() - o, o, o, bg); 00118 } else { 00119 #ifdef QT_OPENGL_SUPPORT 00120 if (m_use_opengl) { 00121 painter.begin(glw); 00122 painter.fillRect(QRectF(0, 0, glw->width(), glw->height()), palette().color(backgroundRole())); 00123 } else { 00124 painter.begin(this); 00125 } 00126 #else 00127 painter.begin(this); 00128 #endif 00129 } 00130 00131 painter.setClipRect(e->rect()); 00132 00133 painter.setRenderHint(QPainter::Antialiasing); 00134 00135 QPainterPath clipPath; 00136 00137 QRect r = rect(); 00138 double left = r.x() + 1; 00139 double top = r.y() + 1; 00140 double right = r.right(); 00141 double bottom = r.bottom(); 00142 double radius2 = 8 * 2; 00143 00144 clipPath.moveTo(right - radius2, top); 00145 clipPath.arcTo(right - radius2, top, radius2, radius2, 90, -90); 00146 clipPath.arcTo(right - radius2, bottom - radius2, radius2, radius2, 0, -90); 00147 clipPath.arcTo(left, bottom - radius2, radius2, radius2, 270, -90); 00148 clipPath.arcTo(left, top, radius2, radius2, 180, -90); 00149 clipPath.closeSubpath(); 00150 00151 painter.save(); 00152 painter.setClipPath(clipPath, Qt::IntersectClip); 00153 00154 painter.drawTiledPixmap(rect(), m_tile); 00155 00156 // client painting 00157 00158 paint(&painter); 00159 00160 painter.restore(); 00161 00162 painter.save(); 00163 if (m_show_doc) 00164 paintDescription(&painter); 00165 painter.restore(); 00166 00167 int level = 180; 00168 painter.setPen(QPen(QColor(level, level, level), 2)); 00169 painter.setBrush(Qt::NoBrush); 00170 painter.drawPath(clipPath); 00171 00172 if (preferImage() 00173 #ifdef QT_OPENGL_SUPPORT 00174 && !m_use_opengl 00175 #endif 00176 ) { 00177 painter.end(); 00178 painter.begin(this); 00179 painter.drawImage(e->rect(), *static_image, e->rect()); 00180 } 00181 00182 #ifdef QT_OPENGL_SUPPORT 00183 if (m_use_opengl && (inherits("PathDeformRenderer") || inherits("PathStrokeRenderer") || inherits("CompositionRenderer") || m_show_doc)) 00184 glw->swapBuffers(); 00185 #endif 00186 }
Here is the call graph for this function:

| void ArthurFrame::resizeEvent | ( | QResizeEvent * | e | ) | [protected, virtual] |
This event handler can be reimplemented in a subclass to receive widget resize events which are passed in the event parameter. When resizeEvent() is called, the widget already has its new geometry. The old size is accessible through QResizeEvent::oldSize().
The widget will be erased and receive a paint event immediately after processing the resize event. No drawing need be (or should be) done inside this handler.
Reimplemented from QWidget.
Definition at line 188 of file arthurwidgets.cpp.
References QSize::height(), QWidget::resizeEvent(), QResizeEvent::size(), and QSize::width().
Referenced by XFormView::resizeEvent().
00189 { 00190 #ifdef QT_OPENGL_SUPPORT 00191 if (glw) 00192 glw->setGeometry(0, 0, e->size().width()-1, e->size().height()-1); 00193 #endif 00194 QWidget::resizeEvent(e); 00195 }
Here is the call graph for this function:

QPixmap ArthurFrame::m_tile [protected] |
bool ArthurFrame::m_show_doc [protected] |
Definition at line 92 of file arthurwidgets.h.
Referenced by ArthurFrame(), paintEvent(), and setDescriptionEnabled().
bool ArthurFrame::m_prefer_image [protected] |
Definition at line 93 of file arthurwidgets.h.
Referenced by ArthurFrame(), preferImage(), and setPreferImage().
QTextDocument* ArthurFrame::m_document [protected] |
Definition at line 94 of file arthurwidgets.h.
Referenced by ArthurFrame(), paintDescription(), and setDescription().
QString ArthurFrame::m_sourceFileName [protected] |
1.5.1