From cbf3771e86272c10519394627784d6c1088f3a3b Mon Sep 17 00:00:00 2001 From: David Schulz Date: Fri, 23 Nov 2012 11:52:51 +0100 Subject: QtBase: examples/widgets/painting code style Change-Id: I3d3c6f3bae20ac8383279437f8f89c92195a704f Reviewed-by: hjk --- examples/widgets/painting/affine/xform.h | 5 +- examples/widgets/painting/basicdrawing/main.cpp | 4 +- .../widgets/painting/basicdrawing/renderarea.cpp | 4 +- .../widgets/painting/basicdrawing/renderarea.h | 2 +- examples/widgets/painting/basicdrawing/window.cpp | 4 +- examples/widgets/painting/basicdrawing/window.h | 2 +- .../widgets/painting/composition/composition.cpp | 66 +++++----- .../widgets/painting/composition/composition.h | 6 +- examples/widgets/painting/composition/main.cpp | 2 +- .../painting/concentriccircles/circlewidget.cpp | 15 +-- .../painting/concentriccircles/circlewidget.h | 2 +- .../widgets/painting/concentriccircles/main.cpp | 4 +- .../widgets/painting/concentriccircles/window.cpp | 4 +- .../widgets/painting/concentriccircles/window.h | 2 +- examples/widgets/painting/deform/main.cpp | 1 - examples/widgets/painting/deform/pathdeform.cpp | 51 +++----- examples/widgets/painting/deform/pathdeform.h | 11 +- .../widgets/painting/fontsampler/mainwindow.cpp | 28 ++--- examples/widgets/painting/fontsampler/mainwindow.h | 2 +- examples/widgets/painting/gradients/gradients.cpp | 22 +--- examples/widgets/painting/gradients/gradients.h | 10 +- examples/widgets/painting/gradients/main.cpp | 2 +- .../painting/imagecomposition/imagecomposer.cpp | 13 +- .../painting/imagecomposition/imagecomposer.h | 2 +- .../widgets/painting/imagecomposition/main.cpp | 4 +- examples/widgets/painting/painterpaths/main.cpp | 4 +- .../widgets/painting/painterpaths/renderarea.cpp | 7 +- .../widgets/painting/painterpaths/renderarea.h | 2 +- examples/widgets/painting/painterpaths/window.cpp | 39 +++--- examples/widgets/painting/painterpaths/window.h | 2 +- examples/widgets/painting/pathstroke/main.cpp | 1 + .../widgets/painting/pathstroke/pathstroke.cpp | 135 ++++++++++----------- examples/widgets/painting/pathstroke/pathstroke.h | 4 +- .../painting/transformations/renderarea.cpp | 5 +- .../widgets/painting/transformations/renderarea.h | 3 +- .../widgets/painting/transformations/window.cpp | 8 +- examples/widgets/painting/transformations/window.h | 4 +- 37 files changed, 218 insertions(+), 264 deletions(-) (limited to 'examples/widgets/painting') diff --git a/examples/widgets/painting/affine/xform.h b/examples/widgets/painting/affine/xform.h index a0d322c0bc..fff92733a0 100644 --- a/examples/widgets/painting/affine/xform.h +++ b/examples/widgets/painting/affine/xform.h @@ -48,7 +48,10 @@ #include class HoverPoints; -QT_FORWARD_DECLARE_CLASS(QLineEdit) + +QT_BEGIN_NAMESPACE +class QLineEdit; +QT_END_NAMESPACE class XFormView : public ArthurFrame { diff --git a/examples/widgets/painting/basicdrawing/main.cpp b/examples/widgets/painting/basicdrawing/main.cpp index 9c7fef712f..f568b907de 100644 --- a/examples/widgets/painting/basicdrawing/main.cpp +++ b/examples/widgets/painting/basicdrawing/main.cpp @@ -38,10 +38,10 @@ ** ****************************************************************************/ -#include - #include "window.h" +#include + int main(int argc, char *argv[]) { Q_INIT_RESOURCE(basicdrawing); diff --git a/examples/widgets/painting/basicdrawing/renderarea.cpp b/examples/widgets/painting/basicdrawing/renderarea.cpp index 283ffc8349..f8a9cb7b58 100644 --- a/examples/widgets/painting/basicdrawing/renderarea.cpp +++ b/examples/widgets/painting/basicdrawing/renderarea.cpp @@ -38,10 +38,10 @@ ** ****************************************************************************/ -#include - #include "renderarea.h" +#include + //! [0] RenderArea::RenderArea(QWidget *parent) : QWidget(parent) diff --git a/examples/widgets/painting/basicdrawing/renderarea.h b/examples/widgets/painting/basicdrawing/renderarea.h index 67c5a92cf5..775ef62588 100644 --- a/examples/widgets/painting/basicdrawing/renderarea.h +++ b/examples/widgets/painting/basicdrawing/renderarea.h @@ -80,4 +80,4 @@ private: }; //! [0] -#endif +#endif // RENDERAREA_H diff --git a/examples/widgets/painting/basicdrawing/window.cpp b/examples/widgets/painting/basicdrawing/window.cpp index bf01e57b7f..1690ce348b 100644 --- a/examples/widgets/painting/basicdrawing/window.cpp +++ b/examples/widgets/painting/basicdrawing/window.cpp @@ -38,11 +38,11 @@ ** ****************************************************************************/ -#include - #include "renderarea.h" #include "window.h" +#include + //! [0] const int IdRole = Qt::UserRole; //! [0] diff --git a/examples/widgets/painting/basicdrawing/window.h b/examples/widgets/painting/basicdrawing/window.h index c82860051a..8b1f3e62ff 100644 --- a/examples/widgets/painting/basicdrawing/window.h +++ b/examples/widgets/painting/basicdrawing/window.h @@ -84,4 +84,4 @@ private: }; //! [0] -#endif +#endif // WINDOW_H diff --git a/examples/widgets/painting/composition/composition.cpp b/examples/widgets/painting/composition/composition.cpp index fb502bc17d..6759ecc196 100644 --- a/examples/widgets/painting/composition/composition.cpp +++ b/examples/widgets/painting/composition/composition.cpp @@ -162,31 +162,31 @@ CompositionWidget::CompositionWidget(QWidget *parent) #endif QGridLayout *modesLayout = new QGridLayout(modesGroup); - modesLayout->addWidget(rbClear, 0, 0); - modesLayout->addWidget(rbSource, 1, 0); - modesLayout->addWidget(rbDest, 2, 0); - modesLayout->addWidget(rbSourceOver, 3, 0); - modesLayout->addWidget(rbDestOver, 4, 0); - modesLayout->addWidget(rbSourceIn, 5, 0); - modesLayout->addWidget(rbDestIn, 6, 0); - modesLayout->addWidget(rbSourceOut, 7, 0); - modesLayout->addWidget(rbDestOut, 8, 0); - modesLayout->addWidget(rbSourceAtop, 9, 0); - modesLayout->addWidget(rbDestAtop, 10, 0); - modesLayout->addWidget(rbXor, 11, 0); - - modesLayout->addWidget(rbPlus, 0, 1); - modesLayout->addWidget(rbMultiply, 1, 1); - modesLayout->addWidget(rbScreen, 2, 1); - modesLayout->addWidget(rbOverlay, 3, 1); - modesLayout->addWidget(rbDarken, 4, 1); - modesLayout->addWidget(rbLighten, 5, 1); - modesLayout->addWidget(rbColorDodge, 6, 1); - modesLayout->addWidget(rbColorBurn, 7, 1); - modesLayout->addWidget(rbHardLight, 8, 1); - modesLayout->addWidget(rbSoftLight, 9, 1); - modesLayout->addWidget(rbDifference, 10, 1); - modesLayout->addWidget(rbExclusion, 11, 1); + modesLayout->addWidget(rbClear, 0, 0); + modesLayout->addWidget(rbSource, 1, 0); + modesLayout->addWidget(rbDest, 2, 0); + modesLayout->addWidget(rbSourceOver, 3, 0); + modesLayout->addWidget(rbDestOver, 4, 0); + modesLayout->addWidget(rbSourceIn, 5, 0); + modesLayout->addWidget(rbDestIn, 6, 0); + modesLayout->addWidget(rbSourceOut, 7, 0); + modesLayout->addWidget(rbDestOut, 8, 0); + modesLayout->addWidget(rbSourceAtop, 9, 0); + modesLayout->addWidget(rbDestAtop, 10, 0); + modesLayout->addWidget(rbXor, 11, 0); + + modesLayout->addWidget(rbPlus, 0, 1); + modesLayout->addWidget(rbMultiply, 1, 1); + modesLayout->addWidget(rbScreen, 2, 1); + modesLayout->addWidget(rbOverlay, 3, 1); + modesLayout->addWidget(rbDarken, 4, 1); + modesLayout->addWidget(rbLighten, 5, 1); + modesLayout->addWidget(rbColorDodge, 6, 1); + modesLayout->addWidget(rbColorBurn, 7, 1); + modesLayout->addWidget(rbHardLight, 8, 1); + modesLayout->addWidget(rbSoftLight, 9, 1); + modesLayout->addWidget(rbDifference, 10, 1); + modesLayout->addWidget(rbExclusion, 11, 1); QVBoxLayout *circleColorLayout = new QVBoxLayout(circleColorGroup); @@ -345,12 +345,10 @@ void CompositionRenderer::paint(QPainter *painter) if (usesOpenGL()) { int new_pbuf_size = m_pbuffer_size; - if (size().width() > m_pbuffer_size || - size().height() > m_pbuffer_size) + if (size().width() > m_pbuffer_size || size().height() > m_pbuffer_size) new_pbuf_size *= 2; - if (size().width() < m_pbuffer_size/2 && - size().height() < m_pbuffer_size/2) + if (size().width() < m_pbuffer_size/2 && size().height() < m_pbuffer_size/2) new_pbuf_size /= 2; if (!m_pbuffer || new_pbuf_size != m_pbuffer_size) { @@ -488,7 +486,8 @@ void CompositionRenderer::mousePressEvent(QMouseEvent *e) void CompositionRenderer::mouseMoveEvent(QMouseEvent *e) { - if (m_current_object == Circle) setCirclePos(e->pos() + m_offset); + if (m_current_object == Circle) + setCirclePos(e->pos() + m_offset); } void CompositionRenderer::mouseReleaseEvent(QMouseEvent *) @@ -513,10 +512,11 @@ void CompositionRenderer::setCirclePos(const QPointF &pos) m_circle_pos = pos; const QRect newRect = rectangle_around(m_circle_pos).toAlignedRect(); #if defined(QT_OPENGL_SUPPORT) && !defined(QT_OPENGL_ES) - if (usesOpenGL()) + if (usesOpenGL()) { update(); - else + return; + } #endif - update(oldRect | newRect); + update(oldRect | newRect); } diff --git a/examples/widgets/painting/composition/composition.h b/examples/widgets/painting/composition/composition.h index 8090d5034c..d51e0672eb 100644 --- a/examples/widgets/painting/composition/composition.h +++ b/examples/widgets/painting/composition/composition.h @@ -47,8 +47,10 @@ #include #include -QT_FORWARD_DECLARE_CLASS(QPushButton) -QT_FORWARD_DECLARE_CLASS(QRadioButton) +QT_BEGIN_NAMESPACE +class QPushButton; +class QRadioButton; +QT_END_NAMESPACE #ifdef QT_OPENGL_SUPPORT #include diff --git a/examples/widgets/painting/composition/main.cpp b/examples/widgets/painting/composition/main.cpp index 8d5499017b..2e20204630 100644 --- a/examples/widgets/painting/composition/main.cpp +++ b/examples/widgets/painting/composition/main.cpp @@ -46,7 +46,7 @@ #include #endif -int main(int argc, char **argv) +int main(int argc, char *argv[]) { // Q_INIT_RESOURCE(deform); diff --git a/examples/widgets/painting/concentriccircles/circlewidget.cpp b/examples/widgets/painting/concentriccircles/circlewidget.cpp index 8fd134999b..34391f1b51 100644 --- a/examples/widgets/painting/concentriccircles/circlewidget.cpp +++ b/examples/widgets/painting/concentriccircles/circlewidget.cpp @@ -38,10 +38,10 @@ ** ****************************************************************************/ -#include - #include "circlewidget.h" +#include + #include //! [0] @@ -111,13 +111,10 @@ void CircleWidget::paintEvent(QPaintEvent *) if (alpha > 0) { painter.setPen(QPen(QColor(0, diameter / 2, 127, alpha), 3)); - if (floatBased) { - painter.drawEllipse(QRectF(-diameter / 2.0, -diameter / 2.0, - diameter, diameter)); - } else { - painter.drawEllipse(QRect(-diameter / 2, -diameter / 2, - diameter, diameter)); - } + if (floatBased) + painter.drawEllipse(QRectF(-diameter / 2.0, -diameter / 2.0, diameter, diameter)); + else + painter.drawEllipse(QRect(-diameter / 2, -diameter / 2, diameter, diameter)); } } } diff --git a/examples/widgets/painting/concentriccircles/circlewidget.h b/examples/widgets/painting/concentriccircles/circlewidget.h index f9d30a3cea..f2331ec49f 100644 --- a/examples/widgets/painting/concentriccircles/circlewidget.h +++ b/examples/widgets/painting/concentriccircles/circlewidget.h @@ -70,4 +70,4 @@ private: }; //! [0] -#endif +#endif // CIRCLEWIDGET_H diff --git a/examples/widgets/painting/concentriccircles/main.cpp b/examples/widgets/painting/concentriccircles/main.cpp index a244f67d66..903795685f 100644 --- a/examples/widgets/painting/concentriccircles/main.cpp +++ b/examples/widgets/painting/concentriccircles/main.cpp @@ -38,10 +38,10 @@ ** ****************************************************************************/ -#include - #include "window.h" +#include + int main(int argc, char *argv[]) { QApplication app(argc, argv); diff --git a/examples/widgets/painting/concentriccircles/window.cpp b/examples/widgets/painting/concentriccircles/window.cpp index 9fd43f2b10..5f63a0984d 100644 --- a/examples/widgets/painting/concentriccircles/window.cpp +++ b/examples/widgets/painting/concentriccircles/window.cpp @@ -38,11 +38,11 @@ ** ****************************************************************************/ -#include - #include "circlewidget.h" #include "window.h" +#include + //! [0] Window::Window() { diff --git a/examples/widgets/painting/concentriccircles/window.h b/examples/widgets/painting/concentriccircles/window.h index b5741c60fa..3e00d489e5 100644 --- a/examples/widgets/painting/concentriccircles/window.h +++ b/examples/widgets/painting/concentriccircles/window.h @@ -67,4 +67,4 @@ private: }; //! [0] -#endif +#endif // WINDOW_H diff --git a/examples/widgets/painting/deform/main.cpp b/examples/widgets/painting/deform/main.cpp index 370afd7438..8c8b3d24f6 100644 --- a/examples/widgets/painting/deform/main.cpp +++ b/examples/widgets/painting/deform/main.cpp @@ -42,7 +42,6 @@ #include "pathdeform.h" #include -#include int main(int argc, char **argv) { diff --git a/examples/widgets/painting/deform/pathdeform.cpp b/examples/widgets/painting/deform/pathdeform.cpp index 418c5ffd8b..8b27fa2516 100644 --- a/examples/widgets/painting/deform/pathdeform.cpp +++ b/examples/widgets/painting/deform/pathdeform.cpp @@ -53,7 +53,8 @@ #include #include -PathDeformControls::PathDeformControls(QWidget *parent, PathDeformRenderer* renderer, bool smallScreen) +PathDeformControls::PathDeformControls(QWidget *parent, + PathDeformRenderer* renderer, bool smallScreen) : QWidget(parent) { m_renderer = renderer; @@ -64,7 +65,6 @@ PathDeformControls::PathDeformControls(QWidget *parent, PathDeformRenderer* rend layoutForDesktop(); } - void PathDeformControls::layoutForDesktop() { QGroupBox* mainGroup = new QGroupBox(this); @@ -223,8 +223,8 @@ void PathDeformControls::layoutForSmallScreen() mainLayout->addWidget(okButton); mainLayout->addWidget(quitButton); - connect(quitButton, SIGNAL(clicked()), this, SLOT(emitQuitSignal())); - connect(okButton, SIGNAL(clicked()), this, SLOT(emitOkSignal())); + connect(quitButton, SIGNAL(clicked()), this, SIGNAL(quitPressed())); + connect(okButton, SIGNAL(clicked()), this, SIGNAL(okPressed())); connect(radiusSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setRadius(int))); connect(deformSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setIntensity(int))); connect(fontSizeSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setFontSize(int))); @@ -244,14 +244,6 @@ void PathDeformControls::layoutForSmallScreen() m_renderer->setText(tr("Qt")); } - -void PathDeformControls::emitQuitSignal() -{ emit quitPressed(); } - -void PathDeformControls::emitOkSignal() -{ emit okPressed(); } - - PathDeformWidget::PathDeformWidget(QWidget *parent, bool smallScreen) : QWidget(parent) { @@ -293,14 +285,14 @@ void PathDeformWidget::hideControls() void PathDeformWidget::setStyle( QStyle * style ) { QWidget::setStyle(style); - if (m_controls != 0) - { - m_controls->setStyle(style); + if (m_controls == 0) + return; + + m_controls->setStyle(style); - QList widgets = m_controls->findChildren(); - foreach (QWidget *w, widgets) - w->setStyle(style); - } + QList widgets = m_controls->findChildren(); + foreach (QWidget *w, widgets) + w->setStyle(style); } static inline QRect circle_bounds(const QPointF ¢er, qreal radius, qreal compensation) @@ -445,8 +437,6 @@ void PathDeformRenderer::timerEvent(QTimerEvent *e) m_pos += QPointF(dx, dy); - - if (m_pos.x() - m_radius < 0) { m_direction.setX(-m_direction.x()); m_pos.setX(m_radius); @@ -565,7 +555,6 @@ QPainterPath PathDeformRenderer::lensDeform(const QPainterPath &source, const QP return path; } - void PathDeformRenderer::paint(QPainter *painter) { int pad_x = 5; @@ -611,8 +600,6 @@ void PathDeformRenderer::paint(QPainter *painter) } } - - void PathDeformRenderer::setRadius(int radius) { qreal max = qMax(m_radius, (qreal)radius); @@ -620,13 +607,12 @@ void PathDeformRenderer::setRadius(int radius) generateLensPixmap(); if (!m_animated || m_radius < max) { #ifdef QT_OPENGL_SUPPORT - if (usesOpenGL()) { + if (usesOpenGL()){ update(); - } else -#endif - { - update(circle_bounds(m_pos, max, m_fontSize)); + return; } +#endif + update(circle_bounds(m_pos, max, m_fontSize)); } } @@ -637,10 +623,9 @@ void PathDeformRenderer::setIntensity(int intensity) #ifdef QT_OPENGL_SUPPORT if (usesOpenGL()) { update(); - } else -#endif - { - update(circle_bounds(m_pos, m_radius, m_fontSize)); + return; } +#endif + update(circle_bounds(m_pos, m_radius, m_fontSize)); } } diff --git a/examples/widgets/painting/deform/pathdeform.h b/examples/widgets/painting/deform/pathdeform.h index 8e44c4ac4f..8bb2c9667c 100644 --- a/examples/widgets/painting/deform/pathdeform.h +++ b/examples/widgets/painting/deform/pathdeform.h @@ -44,9 +44,9 @@ #include "arthurwidgets.h" -#include #include #include +#include class PathDeformRenderer : public ArthurFrame { @@ -113,8 +113,8 @@ private: QPointF m_offset; QPointF m_direction; QPointF m_mousePress; - bool m_mouseDrag; - bool m_smallScreen; + bool m_mouseDrag; + bool m_smallScreen; }; class PathDeformControls : public QWidget @@ -129,9 +129,6 @@ private: PathDeformRenderer* m_renderer; void layoutForDesktop(); void layoutForSmallScreen(); -private slots: - void emitQuitSignal(); - void emitOkSignal(); }; class PathDeformWidget : public QWidget @@ -139,7 +136,7 @@ class PathDeformWidget : public QWidget Q_OBJECT public: PathDeformWidget(QWidget *parent, bool smallScreen); - void setStyle ( QStyle * style ); + void setStyle (QStyle * style ); private: PathDeformRenderer *m_renderer; diff --git a/examples/widgets/painting/fontsampler/mainwindow.cpp b/examples/widgets/painting/fontsampler/mainwindow.cpp index 42253bd4ae..479c9bac05 100644 --- a/examples/widgets/painting/fontsampler/mainwindow.cpp +++ b/examples/widgets/painting/fontsampler/mainwindow.cpp @@ -52,7 +52,6 @@ MainWindow::MainWindow(QWidget *parent) { setupUi(this); - sampleSizes << 32 << 24 << 16 << 14 << 12 << 8 << 4 << 2 << 1; markedCount = 0; setupFontTree(); @@ -86,10 +85,8 @@ void MainWindow::setupFontTree() QTreeWidgetItem *styleItem = new QTreeWidgetItem(familyItem); styleItem->setText(0, style); styleItem->setCheckState(0, Qt::Unchecked); - styleItem->setData(0, Qt::UserRole, - QVariant(database.weight(family, style))); - styleItem->setData(0, Qt::UserRole + 1, - QVariant(database.italic(family, style))); + styleItem->setData(0, Qt::UserRole, QVariant(database.weight(family, style))); + styleItem->setData(0, Qt::UserRole + 1, QVariant(database.italic(family, style))); } } } @@ -177,13 +174,11 @@ void MainWindow::updateStyles(QTreeWidgetItem *item, int column) else --markedCount; - if (state == Qt::Checked && - parent->checkState(0) == Qt::Unchecked) { + if (state == Qt::Checked && parent->checkState(0) == Qt::Unchecked) { // Mark parent items when child items are checked. parent->setCheckState(0, Qt::Checked); - } else if (state == Qt::Unchecked && - parent->checkState(0) == Qt::Checked) { + } else if (state == Qt::Unchecked && parent->checkState(0) == Qt::Checked) { bool marked = false; for (int row = 0; row < parent->childCount(); ++row) { @@ -343,16 +338,16 @@ void MainWindow::printPage(int index, QPainter *painter, QPrinter *printer) qreal scale = qMin(xScale, yScale); qreal remainingHeight = printer->pageRect().height()/scale - height; - qreal spaceHeight = (remainingHeight/4.0) / (items.count() + 1); - qreal interLineHeight = (remainingHeight/4.0) / (sampleSizes.count() * items.count()); + qreal spaceHeight = (remainingHeight / 4.0) / (items.count() + 1); + qreal interLineHeight = (remainingHeight / 4.0) / (sampleSizes.count() * items.count()); painter->save(); - painter->translate(printer->pageRect().width()/2.0, printer->pageRect().height()/2.0); + painter->translate(printer->pageRect().width() / 2.0, printer->pageRect().height() / 2.0); painter->scale(scale, scale); painter->setBrush(QBrush(Qt::black)); - qreal x = -width/2.0; - qreal y = -height/2.0 - remainingHeight/4.0 + spaceHeight; + qreal x = -width / 2.0; + qreal y = -height / 2.0 - remainingHeight / 4.0 + spaceHeight; foreach (QTreeWidgetItem *item, items) { QString style = item->text(0); @@ -368,8 +363,7 @@ void MainWindow::printPage(int index, QPainter *painter, QPrinter *printer) font.family()).arg(style)); y += rect.height(); painter->setFont(font); - painter->drawText(QPointF(x, y), - QString("%1 %2").arg(family).arg(style)); + painter->drawText(QPointF(x, y), QString("%1 %2").arg(family).arg(style)); y += interLineHeight; } y += spaceHeight; @@ -377,4 +371,4 @@ void MainWindow::printPage(int index, QPainter *painter, QPrinter *printer) painter->restore(); } -#endif +#endif // QT_NO_PRINTER diff --git a/examples/widgets/painting/fontsampler/mainwindow.h b/examples/widgets/painting/fontsampler/mainwindow.h index 7ac5692eb6..d80f174606 100644 --- a/examples/widgets/painting/fontsampler/mainwindow.h +++ b/examples/widgets/painting/fontsampler/mainwindow.h @@ -84,4 +84,4 @@ private: int markedCount; }; -#endif +#endif // MAINWINDOW_H diff --git a/examples/widgets/painting/gradients/gradients.cpp b/examples/widgets/painting/gradients/gradients.cpp index 1474c4ffaf..09985df8fa 100644 --- a/examples/widgets/painting/gradients/gradients.cpp +++ b/examples/widgets/painting/gradients/gradients.cpp @@ -62,7 +62,6 @@ ShadeWidget::ShadeWidget(ShadeType type, QWidget *parent) } else { setAttribute(Qt::WA_NoBackground); - } QPolygonF points; @@ -81,13 +80,11 @@ ShadeWidget::ShadeWidget(ShadeType type, QWidget *parent) connect(m_hoverPoints, SIGNAL(pointsChanged(QPolygonF)), this, SIGNAL(colorsChanged())); } - QPolygonF ShadeWidget::points() const { return m_hoverPoints->points(); } - uint ShadeWidget::colorAt(int x) { generateShade(); @@ -104,7 +101,6 @@ uint ShadeWidget::colorAt(int x) return 0; } - void ShadeWidget::setGradientStops(const QGradientStops &stops) { if (m_shade_type == ARGBShade) { @@ -121,7 +117,6 @@ void ShadeWidget::setGradientStops(const QGradientStops &stops) } } - void ShadeWidget::paintEvent(QPaintEvent *) { generateShade(); @@ -133,7 +128,6 @@ void ShadeWidget::paintEvent(QPaintEvent *) p.drawRect(0, 0, width() - 1, height() - 1); } - void ShadeWidget::generateShade() { if (m_shade.isNull() || m_shade.size() != size()) { @@ -167,11 +161,8 @@ void ShadeWidget::generateShade() p.fillRect(rect(), shade); } } - - } - GradientEditor::GradientEditor(QWidget *parent) : QWidget(parent) { @@ -195,13 +186,11 @@ GradientEditor::GradientEditor(QWidget *parent) connect(m_alpha_shade, SIGNAL(colorsChanged()), this, SLOT(pointsUpdated())); } - inline static bool x_less_than(const QPointF &p1, const QPointF &p2) { return p1.x() < p2.x(); } - void GradientEditor::pointsUpdated() { qreal w = m_alpha_shade->width(); @@ -217,9 +206,9 @@ void GradientEditor::pointsUpdated() qSort(points.begin(), points.end(), x_less_than); - for (int i=0; icolorAt(int(x))) >> 16, (0x0000ff00 & m_green_shade->colorAt(int(x))) >> 8, @@ -237,7 +226,6 @@ void GradientEditor::pointsUpdated() emit gradientStopsChanged(stops); } - static void set_shade_points(const QPolygonF &points, ShadeWidget *shade) { shade->hoverPoints()->setPoints(points); @@ -255,7 +243,7 @@ void GradientEditor::setGradientStops(const QGradientStops &stops) qreal h_blue = m_blue_shade->height(); qreal h_alpha = m_alpha_shade->height(); - for (int i=0; iwidth(), h_red - qRed(color) * h_red / 255); @@ -454,7 +442,6 @@ void GradientWidget::setDefault(int config) m_renderer->setGradientStops(stops); } - GradientRenderer::GradientRenderer(QWidget *parent) : ArthurFrame(parent) { @@ -477,7 +464,6 @@ void GradientRenderer::setGradientStops(const QGradientStops &stops) update(); } - void GradientRenderer::mousePressEvent(QMouseEvent *) { setDescriptionEnabled(false); @@ -503,7 +489,7 @@ void GradientRenderer::paint(QPainter *p) g = QConicalGradient(pts.at(0), angle); } - for (int i=0; i +QT_BEGIN_NAMESPACE +class QRadioButton; +QT_END_NAMESPACE class HoverPoints; @@ -52,6 +54,7 @@ class HoverPoints; class ShadeWidget : public QWidget { Q_OBJECT + public: enum ShadeType { RedShade, @@ -88,6 +91,7 @@ private: class GradientEditor : public QWidget { Q_OBJECT + public: GradientEditor(QWidget *parent); @@ -106,10 +110,10 @@ private: ShadeWidget *m_alpha_shade; }; - class GradientRenderer : public ArthurFrame { Q_OBJECT + public: GradientRenderer(QWidget *parent); void paint(QPainter *p); @@ -139,10 +143,10 @@ private: Qt::BrushStyle m_gradientType; }; - class GradientWidget : public QWidget { Q_OBJECT + public: GradientWidget(QWidget *parent); diff --git a/examples/widgets/painting/gradients/main.cpp b/examples/widgets/painting/gradients/main.cpp index ce179a7312..6ffba86acc 100644 --- a/examples/widgets/painting/gradients/main.cpp +++ b/examples/widgets/painting/gradients/main.cpp @@ -43,7 +43,7 @@ #include -int main(int argc, char **argv) +int main(int argc, char *argv[]) { Q_INIT_RESOURCE(gradients); diff --git a/examples/widgets/painting/imagecomposition/imagecomposer.cpp b/examples/widgets/painting/imagecomposition/imagecomposer.cpp index cc1954d1de..e520cd871a 100644 --- a/examples/widgets/painting/imagecomposition/imagecomposer.cpp +++ b/examples/widgets/painting/imagecomposition/imagecomposer.cpp @@ -38,10 +38,10 @@ ** ****************************************************************************/ -#include - #include "imagecomposer.h" +#include + //! [0] static const QSize resultSize(200, 200); //! [0] @@ -91,10 +91,8 @@ ImageComposer::ImageComposer() //! [3] connect(sourceButton, SIGNAL(clicked()), this, SLOT(chooseSource())); - connect(operatorComboBox, SIGNAL(activated(int)), - this, SLOT(recalculateResult())); - connect(destinationButton, SIGNAL(clicked()), - this, SLOT(chooseDestination())); + connect(operatorComboBox, SIGNAL(activated(int)), this, SLOT(recalculateResult())); + connect(destinationButton, SIGNAL(clicked()), this, SLOT(chooseDestination())); //! [3] //! [4] @@ -128,8 +126,7 @@ void ImageComposer::chooseSource() //! [7] void ImageComposer::chooseDestination() { - chooseImage(tr("Choose Destination Image"), &destinationImage, - destinationButton); + chooseImage(tr("Choose Destination Image"), &destinationImage, destinationButton); } //! [7] diff --git a/examples/widgets/painting/imagecomposition/imagecomposer.h b/examples/widgets/painting/imagecomposition/imagecomposer.h index 6f9d875938..ae2fa9f168 100644 --- a/examples/widgets/painting/imagecomposition/imagecomposer.h +++ b/examples/widgets/painting/imagecomposition/imagecomposer.h @@ -84,4 +84,4 @@ private: }; //! [1] -#endif +#endif // IMAGECOMPOSER_H diff --git a/examples/widgets/painting/imagecomposition/main.cpp b/examples/widgets/painting/imagecomposition/main.cpp index 29ae0cd74c..3e0d509d17 100644 --- a/examples/widgets/painting/imagecomposition/main.cpp +++ b/examples/widgets/painting/imagecomposition/main.cpp @@ -38,10 +38,10 @@ ** ****************************************************************************/ -#include - #include "imagecomposer.h" +#include + //! [0] int main(int argc, char *argv[]) { diff --git a/examples/widgets/painting/painterpaths/main.cpp b/examples/widgets/painting/painterpaths/main.cpp index a244f67d66..903795685f 100644 --- a/examples/widgets/painting/painterpaths/main.cpp +++ b/examples/widgets/painting/painterpaths/main.cpp @@ -38,10 +38,10 @@ ** ****************************************************************************/ -#include - #include "window.h" +#include + int main(int argc, char *argv[]) { QApplication app(argc, argv); diff --git a/examples/widgets/painting/painterpaths/renderarea.cpp b/examples/widgets/painting/painterpaths/renderarea.cpp index ad22f27fe1..e57dd6dafe 100644 --- a/examples/widgets/painting/painterpaths/renderarea.cpp +++ b/examples/widgets/painting/painterpaths/renderarea.cpp @@ -38,10 +38,10 @@ ** ****************************************************************************/ -#include - #include "renderarea.h" +#include + //! [0] RenderArea::RenderArea(const QPainterPath &path, QWidget *parent) : QWidget(parent), path(path) @@ -119,8 +119,7 @@ void RenderArea::paintEvent(QPaintEvent *) painter.translate(-50.0, -50.0); //! [9] //! [10] - painter.setPen(QPen(penColor, penWidth, Qt::SolidLine, Qt::RoundCap, - Qt::RoundJoin)); + painter.setPen(QPen(penColor, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); QLinearGradient gradient(0, 0, 0, 100); gradient.setColorAt(0.0, fillColor1); gradient.setColorAt(1.0, fillColor2); diff --git a/examples/widgets/painting/painterpaths/renderarea.h b/examples/widgets/painting/painterpaths/renderarea.h index 681f7a7930..98327a90b8 100644 --- a/examples/widgets/painting/painterpaths/renderarea.h +++ b/examples/widgets/painting/painterpaths/renderarea.h @@ -77,4 +77,4 @@ private: }; //! [1] -#endif +#endif // RENDERAREA_H diff --git a/examples/widgets/painting/painterpaths/window.cpp b/examples/widgets/painting/painterpaths/window.cpp index 1a29799cd6..e5e427506b 100644 --- a/examples/widgets/painting/painterpaths/window.cpp +++ b/examples/widgets/painting/painterpaths/window.cpp @@ -38,13 +38,13 @@ ** ****************************************************************************/ +#include "renderarea.h" +#include "window.h" + #include #include -#include "renderarea.h" -#include "window.h" - //! [0] const float Pi = 3.14159f; //! [0] @@ -153,13 +153,11 @@ Window::Window() //! [12] fillColor1ComboBox = new QComboBox; populateWithColors(fillColor1ComboBox); - fillColor1ComboBox->setCurrentIndex( - fillColor1ComboBox->findText("mediumslateblue")); + fillColor1ComboBox->setCurrentIndex(fillColor1ComboBox->findText("mediumslateblue")); fillColor2ComboBox = new QComboBox; populateWithColors(fillColor2ComboBox); - fillColor2ComboBox->setCurrentIndex( - fillColor2ComboBox->findText("cornsilk")); + fillColor2ComboBox->setCurrentIndex(fillColor2ComboBox->findText("cornsilk")); fillGradientLabel = new QLabel(tr("&Fill Gradient:")); fillGradientLabel->setBuddy(fillColor1ComboBox); @@ -175,8 +173,7 @@ Window::Window() penColorComboBox = new QComboBox; populateWithColors(penColorComboBox); - penColorComboBox->setCurrentIndex( - penColorComboBox->findText("darkslateblue")); + penColorComboBox->setCurrentIndex(penColorComboBox->findText("darkslateblue")); penColorLabel = new QLabel(tr("Pen &Color:")); penColorLabel->setBuddy(penColorComboBox); @@ -191,20 +188,14 @@ Window::Window() //! [12] //! [16] - connect(fillRuleComboBox, SIGNAL(activated(int)), - this, SLOT(fillRuleChanged())); - connect(fillColor1ComboBox, SIGNAL(activated(int)), - this, SLOT(fillGradientChanged())); - connect(fillColor2ComboBox, SIGNAL(activated(int)), - this, SLOT(fillGradientChanged())); - connect(penColorComboBox, SIGNAL(activated(int)), - this, SLOT(penColorChanged())); + connect(fillRuleComboBox, SIGNAL(activated(int)), this, SLOT(fillRuleChanged())); + connect(fillColor1ComboBox, SIGNAL(activated(int)), this, SLOT(fillGradientChanged())); + connect(fillColor2ComboBox, SIGNAL(activated(int)), this, SLOT(fillGradientChanged())); + connect(penColorComboBox, SIGNAL(activated(int)), this, SLOT(penColorChanged())); for(QList::iterator it = renderAreas.begin(); it != renderAreas.end(); it++) { - connect(penWidthSpinBox, SIGNAL(valueChanged(int)), - *it, SLOT(setPenWidth(int))); - connect(rotationAngleSpinBox, SIGNAL(valueChanged(int)), - *it, SLOT(setRotationAngle(int))); + connect(penWidthSpinBox, SIGNAL(valueChanged(int)), *it, SLOT(setPenWidth(int))); + connect(rotationAngleSpinBox, SIGNAL(valueChanged(int)), *it, SLOT(setRotationAngle(int))); } //! [16] //! [17] @@ -246,7 +237,7 @@ void Window::fillRuleChanged() { Qt::FillRule rule = (Qt::FillRule)currentItemData(fillRuleComboBox).toInt(); - for(QList::iterator it = renderAreas.begin(); it != renderAreas.end(); it++) + for (QList::iterator it = renderAreas.begin(); it != renderAreas.end(); ++it) (*it)->setFillRule(rule); } //! [19] @@ -257,7 +248,7 @@ void Window::fillGradientChanged() QColor color1 = qvariant_cast(currentItemData(fillColor1ComboBox)); QColor color2 = qvariant_cast(currentItemData(fillColor2ComboBox)); - for(QList::iterator it = renderAreas.begin(); it != renderAreas.end(); it++) + for (QList::iterator it = renderAreas.begin(); it != renderAreas.end(); ++it) (*it)->setFillGradient(color1, color2); } //! [20] @@ -267,7 +258,7 @@ void Window::penColorChanged() { QColor color = qvariant_cast(currentItemData(penColorComboBox)); - for(QList::iterator it = renderAreas.begin(); it != renderAreas.end(); it++) + for (QList::iterator it = renderAreas.begin(); it != renderAreas.end(); ++it) (*it)->setPenColor(color); } //! [21] diff --git a/examples/widgets/painting/painterpaths/window.h b/examples/widgets/painting/painterpaths/window.h index 3c0f27ceac..ae98d69352 100644 --- a/examples/widgets/painting/painterpaths/window.h +++ b/examples/widgets/painting/painterpaths/window.h @@ -87,4 +87,4 @@ private: }; //! [2] -#endif +#endif // WINDOW_H diff --git a/examples/widgets/painting/pathstroke/main.cpp b/examples/widgets/painting/pathstroke/main.cpp index 959202b6f6..8e1c263320 100644 --- a/examples/widgets/painting/pathstroke/main.cpp +++ b/examples/widgets/painting/pathstroke/main.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "pathstroke.h" + #include int main(int argc, char **argv) diff --git a/examples/widgets/painting/pathstroke/pathstroke.cpp b/examples/widgets/painting/pathstroke/pathstroke.cpp index 4b71991d04..c11c1e8160 100644 --- a/examples/widgets/painting/pathstroke/pathstroke.cpp +++ b/examples/widgets/painting/pathstroke/pathstroke.cpp @@ -39,9 +39,9 @@ ** ****************************************************************************/ -#include "pathstroke.h" #include "arthurstyle.h" #include "arthurwidgets.h" +#include "pathstroke.h" #include @@ -236,11 +236,9 @@ void PathStrokeControls::layoutForDesktop() // Set up connections - connect(animated, SIGNAL(toggled(bool)), - m_renderer, SLOT(setAnimation(bool))); + connect(animated, SIGNAL(toggled(bool)), m_renderer, SLOT(setAnimation(bool))); - connect(penWidth, SIGNAL(valueChanged(int)), - m_renderer, SLOT(setPenWidth(int))); + connect(penWidth, SIGNAL(valueChanged(int)), m_renderer, SLOT(setPenWidth(int))); connect(showSourceButton, SIGNAL(clicked()), m_renderer, SLOT(showSource())); #ifdef QT_OPENGL_SUPPORT @@ -332,10 +330,14 @@ void PathStrokeControls::layoutForSmallScreens() } void PathStrokeControls::emitQuitSignal() -{ emit quitPressed(); } +{ + emit quitPressed(); +} void PathStrokeControls::emitOkSignal() -{ emit okPressed(); } +{ + emit okPressed(); +} PathStrokeWidget::PathStrokeWidget(bool smallScreen) @@ -362,19 +364,16 @@ PathStrokeWidget::PathStrokeWidget(bool smallScreen) connect(m_controls, SIGNAL(quitPressed()), QApplication::instance(), SLOT(quit())); } - void PathStrokeWidget::showControls() { m_controls->showFullScreen(); } - void PathStrokeWidget::hideControls() { m_controls->hide(); } - void PathStrokeWidget::setStyle( QStyle * style ) { QWidget::setStyle(style); @@ -388,7 +387,6 @@ void PathStrokeWidget::setStyle( QStyle * style ) } } - PathStrokeRenderer::PathStrokeRenderer(QWidget *parent, bool smallScreen) : ArthurFrame(parent) { @@ -420,9 +418,8 @@ void PathStrokeRenderer::paint(QPainter *painter) path.moveTo(m_points.at(0)); if (m_pathMode == LineMode) { - for (int i=1; i(e); - const QList points = event->touchPoints(); - foreach (const QTouchEvent::TouchPoint &touchPoint, points) { - const int id = touchPoint.id(); - switch (touchPoint.state()) { - case Qt::TouchPointPressed: - { - // find the point, move it - QSet activePoints = QSet::fromList(m_fingerPointMapping.values()); - int activePoint = -1; - qreal distance = -1; - const int pointsCount = m_points.size(); - for (int i=0; i::iterator it = m_fingerPointMapping.find(id); - m_points[it.value()] = touchPoint.pos(); - m_fingerPointMapping.erase(it); - } - break; - case Qt::TouchPointMoved: - { - // move the point - const int pointIdx = m_fingerPointMapping.value(id, -1); - if (pointIdx >= 0) - m_points[pointIdx] = touchPoint.pos(); + { + const QTouchEvent *const event = static_cast(e); + const QList points = event->touchPoints(); + foreach (const QTouchEvent::TouchPoint &touchPoint, points) { + const int id = touchPoint.id(); + switch (touchPoint.state()) { + case Qt::TouchPointPressed: + { + // find the point, move it + QSet activePoints = QSet::fromList(m_fingerPointMapping.values()); + int activePoint = -1; + qreal distance = -1; + const int pointsCount = m_points.size(); + for (int i=0; iignore(); - return false; - } else { - if (touchBegin) { - m_wasAnimated = m_timer.isActive(); - setAnimation(false); + if (activePoint != -1) { + m_fingerPointMapping.insert(touchPoint.id(), activePoint); + m_points[activePoint] = touchPoint.pos(); } - update(); - return true; + break; + } + case Qt::TouchPointReleased: + { + // move the point and release + QHash::iterator it = m_fingerPointMapping.find(id); + m_points[it.value()] = touchPoint.pos(); + m_fingerPointMapping.erase(it); + break; + } + case Qt::TouchPointMoved: + { + // move the point + const int pointIdx = m_fingerPointMapping.value(id, -1); + if (pointIdx >= 0) + m_points[pointIdx] = touchPoint.pos(); + break; + } + default: + break; } } + if (m_fingerPointMapping.isEmpty()) { + e->ignore(); + return false; + } else { + if (touchBegin) { + m_wasAnimated = m_timer.isActive(); + setAnimation(false); + } + update(); + return true; + } + } break; case QEvent::TouchEnd: if (m_fingerPointMapping.isEmpty()) { diff --git a/examples/widgets/painting/pathstroke/pathstroke.h b/examples/widgets/painting/pathstroke/pathstroke.h index a4b5b2d86f..6afc271e41 100644 --- a/examples/widgets/painting/pathstroke/pathstroke.h +++ b/examples/widgets/painting/pathstroke/pathstroke.h @@ -43,6 +43,7 @@ #define PATHSTROKE_H #include "arthurwidgets.h" + #include class PathStrokeRenderer : public ArthurFrame @@ -126,6 +127,7 @@ private: class PathStrokeControls : public QWidget { Q_OBJECT + public: PathStrokeControls(QWidget* parent, PathStrokeRenderer* renderer, bool smallScreen); @@ -154,6 +156,7 @@ private slots: class PathStrokeWidget : public QWidget { Q_OBJECT + public: PathStrokeWidget(bool smallScreen); void setStyle ( QStyle * style ); @@ -165,7 +168,6 @@ private: private slots: void showControls(); void hideControls(); - }; #endif // PATHSTROKE_H diff --git a/examples/widgets/painting/transformations/renderarea.cpp b/examples/widgets/painting/transformations/renderarea.cpp index 7a60431d5a..21b0d55a19 100644 --- a/examples/widgets/painting/transformations/renderarea.cpp +++ b/examples/widgets/painting/transformations/renderarea.cpp @@ -38,10 +38,11 @@ ** ****************************************************************************/ -#include - #include "renderarea.h" +#include +#include + //! [0] RenderArea::RenderArea(QWidget *parent) : QWidget(parent) diff --git a/examples/widgets/painting/transformations/renderarea.h b/examples/widgets/painting/transformations/renderarea.h index 61becce995..e163e98ea2 100644 --- a/examples/widgets/painting/transformations/renderarea.h +++ b/examples/widgets/painting/transformations/renderarea.h @@ -41,7 +41,6 @@ #ifndef RENDERAREA_H #define RENDERAREA_H -#include #include #include #include @@ -87,4 +86,4 @@ private: }; //! [2] -#endif +#endif // RENDERAREA_H diff --git a/examples/widgets/painting/transformations/window.cpp b/examples/widgets/painting/transformations/window.cpp index dbbed9fd44..beb9a3e975 100644 --- a/examples/widgets/painting/transformations/window.cpp +++ b/examples/widgets/painting/transformations/window.cpp @@ -38,10 +38,11 @@ ** ****************************************************************************/ -#include - #include "window.h" +#include +#include + //! [0] Window::Window() { @@ -148,8 +149,7 @@ void Window::setupShapes() shapes.append(text); shapes.append(truck); - connect(shapeComboBox, SIGNAL(activated(int)), - this, SLOT(shapeSelected(int))); + connect(shapeComboBox, SIGNAL(activated(int)), this, SLOT(shapeSelected(int))); } //! [7] diff --git a/examples/widgets/painting/transformations/window.h b/examples/widgets/painting/transformations/window.h index 2b288446b8..36edd45b92 100644 --- a/examples/widgets/painting/transformations/window.h +++ b/examples/widgets/painting/transformations/window.h @@ -41,12 +41,12 @@ #ifndef WINDOW_H #define WINDOW_H +#include "renderarea.h" + #include #include #include -#include "renderarea.h" - QT_BEGIN_NAMESPACE class QComboBox; QT_END_NAMESPACE -- cgit v1.2.3