00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #ifndef QXTFLOWVIEW_P_H_INCLUDED
00051 #define QXTFLOWVIEW_P_H_INCLUDED
00052
00053
00054 #include "qxtflowview.h"
00055
00056 #define PICTUREFLOW_QT4
00057
00058 #include <QApplication>
00059 #include <QCache>
00060 #include <QHash>
00061 #include <QImage>
00062 #include <QKeyEvent>
00063 #include <QPainter>
00064 #include <QPixmap>
00065 #include <QTimer>
00066 #include <QVector>
00067 #include <QWidget>
00068 #include <QAbstractItemModel>
00069 #include <QPersistentModelIndex>
00070 #include <QList>
00071
00072
00073
00074 typedef long PFreal;
00075 #define PFREAL_SHIFT 10
00076 #define PFREAL_ONE (1 << PFREAL_SHIFT)
00077
00078 #define IANGLE_MAX 1024
00079 #define IANGLE_MASK 1023
00080
00081 inline PFreal fmul(PFreal a, PFreal b)
00082 {
00083 return ((long long)(a))*((long long)(b)) >> PFREAL_SHIFT;
00084 }
00085
00086 inline PFreal fdiv(PFreal num, PFreal den)
00087 {
00088 long long p = (long long)(num) << (PFREAL_SHIFT * 2);
00089 long long q = p / (long long)den;
00090 long long r = q >> PFREAL_SHIFT;
00091
00092 return r;
00093 }
00094
00095 inline PFreal fsin(int iangle)
00096 {
00097
00098 static const PFreal tab[] =
00099 {
00100 3, 103, 202, 300, 394, 485, 571, 652,
00101 726, 793, 853, 904, 947, 980, 1004, 1019,
00102 1023, 1018, 1003, 978, 944, 901, 849, 789,
00103 721, 647, 566, 479, 388, 294, 196, 97,
00104 -4, -104, -203, -301, -395, -486, -572, -653,
00105 -727, -794, -854, -905, -948, -981, -1005, -1020,
00106 -1024, -1019, -1004, -979, -945, -902, -850, -790,
00107 -722, -648, -567, -480, -389, -295, -197, -98,
00108 3
00109 };
00110
00111 while (iangle < 0)
00112 iangle += IANGLE_MAX;
00113 iangle &= IANGLE_MASK;
00114
00115 int i = (iangle >> 4);
00116 PFreal p = tab[i];
00117 PFreal q = tab[(i+1)];
00118 PFreal g = (q - p);
00119 return p + g * (iangle - i*16) / 16;
00120 }
00121
00122 inline PFreal fcos(int iangle)
00123 {
00124 return fsin(iangle + (IANGLE_MAX >> 2));
00125 }
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 struct SlideInfo
00146 {
00147 int slideIndex;
00148 int angle;
00149 PFreal cx;
00150 PFreal cy;
00151 int blend;
00152 };
00153
00154 class QxtFlowViewState
00155 {
00156 public:
00157 QxtFlowViewState();
00158 ~QxtFlowViewState();
00159
00160 void reposition();
00161 void reset();
00162
00163 QRgb backgroundColor;
00164 int slideWidth;
00165 int slideHeight;
00166 QxtFlowView::ReflectionEffect reflectionEffect;
00167 QVector<QImage*> slideImages;
00168
00169 int angle;
00170 int spacing;
00171 PFreal offsetX;
00172 PFreal offsetY;
00173
00174 SlideInfo centerSlide;
00175 QVector<SlideInfo> leftSlides;
00176 QVector<SlideInfo> rightSlides;
00177 int centerIndex;
00178 };
00179
00180 class QxtFlowViewAnimator
00181 {
00182 public:
00183 QxtFlowViewAnimator();
00184 QxtFlowViewState* state;
00185
00186 void start(int slide);
00187 void stop(int slide);
00188 void update();
00189
00190 int target;
00191 int step;
00192 int frame;
00193 QTimer animateTimer;
00194 };
00195
00196 class QxtFlowViewAbstractRenderer
00197 {
00198 public:
00199 QxtFlowViewAbstractRenderer(): state(0), dirty(false), widget(0) {}
00200 virtual ~QxtFlowViewAbstractRenderer() {}
00201
00202 QxtFlowViewState* state;
00203 bool dirty;
00204 QWidget* widget;
00205
00206 virtual void init() = 0;
00207 virtual void paint() = 0;
00208 };
00209
00210 class QxtFlowViewSoftwareRenderer: public QxtFlowViewAbstractRenderer
00211 {
00212 public:
00213 QxtFlowViewSoftwareRenderer();
00214 ~QxtFlowViewSoftwareRenderer();
00215
00216 virtual void init();
00217 virtual void paint();
00218
00219 private:
00220 QSize size;
00221 QRgb bgcolor;
00222 int effect;
00223 QImage buffer;
00224 QVector<PFreal> rays;
00225 QImage* blankSurface;
00226 #ifdef PICTUREFLOW_QT4
00227 QCache<int, QImage> surfaceCache;
00228 QHash<int, QImage*> imageHash;
00229 #endif
00230 #ifdef PICTUREFLOW_QT3
00231 QCache<QImage> surfaceCache;
00232 QMap<int, QImage*> imageHash;
00233 #endif
00234 #ifdef PICTUREFLOW_QT2
00235 QCache<QImage> surfaceCache;
00236 QIntDict<QImage> imageHash;
00237 #endif
00238
00239 void render();
00240 void renderSlides();
00241 QRect renderSlide(const SlideInfo &slide, int col1 = -1, int col2 = -1);
00242 QImage* surface(int slideIndex);
00243 };
00244
00245
00246
00247
00248
00249 class QxtFlowViewPrivate : public QObject
00250 {
00251 Q_OBJECT
00252 public:
00253 QxtFlowViewState* state;
00254 QxtFlowViewAnimator* animator;
00255 QxtFlowViewAbstractRenderer* renderer;
00256 QTimer triggerTimer;
00257 QAbstractItemModel * model;
00258 void setModel(QAbstractItemModel * model);
00259 void clear();
00260 void triggerRender();
00261 void insertSlide(int index, const QImage& image);
00262 void replaceSlide(int index, const QImage& image);
00263 void removeSlide(int index);
00264 void setCurrentIndex(QModelIndex index);
00265 void showSlide(int index);
00266
00267 int picrole;
00268 int textrole;
00269 int piccolumn;
00270 int textcolumn;
00271
00272 void reset();
00273
00274 QList<QPersistentModelIndex> modelmap;
00275 QPersistentModelIndex currentcenter;
00276
00277 QPoint lastgrabpos;
00278 QModelIndex rootindex;
00279
00280 public Q_SLOTS:
00281 void columnsAboutToBeInserted(const QModelIndex & parent, int start, int end);
00282 void columnsAboutToBeRemoved(const QModelIndex & parent, int start, int end);
00283 void columnsInserted(const QModelIndex & parent, int start, int end);
00284 void columnsRemoved(const QModelIndex & parent, int start, int end);
00285 void dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight);
00286 void headerDataChanged(Qt::Orientation orientation, int first, int last);
00287 void layoutAboutToBeChanged();
00288 void layoutChanged();
00289 void modelAboutToBeReset();
00290 void modelReset();
00291 void rowsAboutToBeInserted(const QModelIndex & parent, int start, int end);
00292 void rowsAboutToBeRemoved(const QModelIndex & parent, int start, int end);
00293 void rowsInserted(const QModelIndex & parent, int start, int end);
00294 void rowsRemoved(const QModelIndex & parent, int start, int end);
00295 };
00296
00297
00298 #endif // QXTFLOWVIEW_P_H_INCLUDED