demos/composition/composition.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2005-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the demonstration applications of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 #ifndef COMPOSITION_H
00025 #define COMPOSITION_H
00026 
00027 #include "arthurwidgets.h"
00028 
00029 #include <QPainter>
00030 #include <QEvent>
00031 
00032 class QPushButton;
00033 class QRadioButton;
00034 
00035 #ifdef QT_OPENGL_SUPPORT
00036 #include <QtOpenGL>
00037 #endif
00038 
00039 class CompositionWidget : public QWidget
00040 {
00041     Q_OBJECT
00042 
00043 public:
00044     CompositionWidget(QWidget *parent);
00045 
00046 public slots:
00047 void nextMode();
00048 
00049 private:
00050     bool m_cycle_enabled;
00051 
00052     QRadioButton *rbClear;
00053     QRadioButton *rbSource;
00054     QRadioButton *rbDest;
00055     QRadioButton *rbSourceOver;
00056     QRadioButton *rbDestOver;
00057     QRadioButton *rbSourceIn;
00058     QRadioButton *rbDestIn;
00059     QRadioButton *rbSourceOut;
00060     QRadioButton *rbDestOut;
00061     QRadioButton *rbSourceAtop;
00062     QRadioButton *rbDestAtop;
00063     QRadioButton *rbXor;
00064 };
00065 
00066 class CompositionRenderer : public ArthurFrame
00067 {
00068     Q_OBJECT
00069 
00070     enum ObjectType { NoObject, Circle, Rectangle, Image };
00071 
00072     Q_PROPERTY(int circleColor READ circleColor WRITE setCircleColor)
00073     Q_PROPERTY(int circleAlpha READ circleAlpha WRITE setCircleAlpha)
00074     Q_PROPERTY(bool animation READ animationEnabled WRITE setAnimationEnabled)
00075 
00076 public:
00077     CompositionRenderer(QWidget *parent);
00078 
00079     void paint(QPainter *);
00080 
00081     void mousePressEvent(QMouseEvent *);
00082     void mouseMoveEvent(QMouseEvent *);
00083     void mouseReleaseEvent(QMouseEvent *);
00084 
00085     void setCirclePos(const QPointF &pos) { m_circle_pos = pos; update(); }
00086 
00087     QSize sizeHint() const { return QSize(500, 400); }
00088 
00089     bool animationEnabled() const { return m_animation_enabled; }
00090     int circleColor() const { return m_circle_hue; }
00091     int circleAlpha() const { return m_circle_alpha; }
00092 
00093 public slots:
00094 void setClearMode() { m_composition_mode = QPainter::CompositionMode_Clear; update(); }
00095     void setSourceMode() { m_composition_mode = QPainter::CompositionMode_Source; update(); }
00096     void setDestMode() { m_composition_mode = QPainter::CompositionMode_Destination; update(); }
00097     void setSourceOverMode() { m_composition_mode = QPainter::CompositionMode_SourceOver; update(); }
00098     void setDestOverMode() { m_composition_mode = QPainter::CompositionMode_DestinationOver; update(); }
00099     void setSourceInMode() { m_composition_mode = QPainter::CompositionMode_SourceIn; update(); }
00100     void setDestInMode() { m_composition_mode = QPainter::CompositionMode_DestinationIn; update(); }
00101     void setSourceOutMode() { m_composition_mode = QPainter::CompositionMode_SourceOut; update(); }
00102     void setDestOutMode() { m_composition_mode = QPainter::CompositionMode_DestinationOut; update(); }
00103     void setSourceAtopMode() { m_composition_mode = QPainter::CompositionMode_SourceAtop; update(); }
00104     void setDestAtopMode() { m_composition_mode = QPainter::CompositionMode_DestinationAtop; update(); }
00105     void setXorMode() { m_composition_mode = QPainter::CompositionMode_Xor; update(); }
00106 
00107     void setCircleAlpha(int alpha) { m_circle_alpha = alpha; update(); }
00108     void setCircleColor(int hue) { m_circle_hue = hue; update(); }
00109     void setAnimationEnabled(bool enabled) { m_animation_enabled = enabled; update(); }
00110 
00111 private:
00112     void updateCirclePos();
00113     void drawBase(QPainter &p);
00114     void drawSource(QPainter &p);
00115 
00116     QPainter::CompositionMode m_composition_mode;
00117 
00118     QImage m_image;
00119     QImage m_buffer;
00120     QImage m_base_buffer;
00121 
00122     int m_circle_alpha;
00123     int m_circle_hue;
00124 
00125     QPointF m_circle_pos;
00126     QPointF m_offset;
00127 
00128     ObjectType m_current_object;
00129     bool m_animation_enabled;
00130 
00131 #ifdef QT_OPENGL_SUPPORT
00132     QGLPixelBuffer *m_pbuffer;
00133     GLuint m_base_tex;
00134     GLuint m_compositing_tex;
00135     int m_pbuffer_size; // width==height==size of pbuffer
00136     QSize m_previous_size;
00137 #endif
00138 };
00139 
00140 #endif // COMPOSITION_H

Generated on Thu Mar 15 11:52:30 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1