File: GlPresenter.cpp

package info (click to toggle)
calligra 1%3A2.4.4-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 290,028 kB
  • sloc: cpp: 1,105,019; xml: 24,940; ansic: 11,807; python: 8,457; perl: 2,792; sh: 1,507; yacc: 1,307; ruby: 1,248; sql: 903; lex: 455; makefile: 89
file content (302 lines) | stat: -rw-r--r-- 8,557 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
 * This file is part of Maemo 5 Office UI for Calligra
 *
 * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
 *
 * Contact: Rahul Das H < h.rahuldas@gmail.com >
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */
#include "GlPresenter.h"
#include <math.h>

#ifdef Q_WS_MAEMO_5
#include <mce/dbus-names.h>
#endif

#include <QDBusMessage>
#include <QDebug>

GLPresenter::GLPresenter(QWidget *parent, int stl, int st, QList <QPixmap> p)
    : QWidget(parent)
{
    keepDisplayOn();
    glbase = new GLWidget(this);
    Q_CHECK_PTR(glbase);
    paused = set = false;
    style = stl;
    s_time = st;
    /*
     * default animation time is 2 seconds ie, 2000 milli seconds
     */
    a_time = 2000;
    c_time = 0;
    delta = 0;
    current_slide = -1;
    pixm = p;
    totalslides = p.count();
    glbase->showFullScreen();
    reverse = done = false;
    forward = true;
    connect(glbase, SIGNAL(paused()), this , SLOT(showpaused()));
    connect(glbase, SIGNAL(next()), this , SLOT(shownext()));
    connect(glbase, SIGNAL(prev()), this , SLOT(showprevious()));
    connect(glbase, SIGNAL(end()), this , SLOT(exitshow()));
    timeline = new QTimeLine(s_time, this);
    Q_CHECK_PTR(timeline);
    timeline->setLoopCount(0);
    timeline->setFrameRange(0, s_time);
    timeline->setUpdateInterval(20); // nearly 50 updates per second
    connect(timeline, SIGNAL(frameChanged(int)), this , SLOT(slideshow()));
    timeline->start();
}

GLPresenter::~GLPresenter()
{
    destroy(true, true);

}

void GLPresenter::keepDisplayOn()
{
#ifdef Q_WS_MAEMO_5
    interface = new QDBusInterface(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, QDBusConnection::systemBus(), this);
    Q_CHECK_PTR(interface);
    QDBusMessage reply = interface->call(MCE_PREVENT_BLANK_REQ);
#endif
}
void GLPresenter::showpaused()
{
    if (!paused) {
        paused = true;
        timeline->setPaused(true);
    } else if (paused) {
        paused = false;
        timeline->resume();
    }
}
void GLPresenter::shownext()
{
    if (current_slide < totalslides - 1) {
        timeline->stop();
        /*
         * reset values for next slide
         */
        glbase->setSlideAngles(0, 0, 0);
        glbase->setSlidePosition(0, 0, 0);
        glbase->setSlideSize(0);
        done = true; forward = true; reverse = false;
        timeline->start();
    }
}
void GLPresenter::showprevious()
{
    if (current_slide > 0) {
        timeline->stop();
        /*
         * reset before previous slide
         */
        glbase->setSlideAngles(0, 0, 0);
        glbase->setSlidePosition(0, 0, 0);
        glbase->setSlideSize(0);
        done = true; forward = true; reverse = false;
        current_slide = current_slide - 2;
        timeline->start();
    }
}
void GLPresenter::exitshow()
{
    close();
}

void GLPresenter::slideshow()
{
    int t = timeline->currentTime();
    if (!done)
        if (current_slide < totalslides - 1) {
            current_slide++;
            glbase->setPixmapSlide(pixm[current_slide]);
            glbase->createSlide();                         //TODO : Adjust for multiple bodies,than for present single object,ie a cube.
            done = true;
        }
    if (t < a_time) animation();
    if (t > a_time) {
        forward = false; reverse = true;
    }
    if (t > (s_time - a_time)) animation();
    /*
     * The animations is reset 100 ms before the actual show time. This is to avoid the visibility of pixmap change from the viewer.
     */
    if (t > (s_time - 100)) {
        forward = true; reverse = false;
        if (current_slide == totalslides - 1)timeline->stop();
    }
    /*
     * watch for the time line end.
     */
    if (t > c_time)
        c_time = t;
    else {
        done = false; c_time = 0;
    }
}

void GLPresenter::animation()
{
    switch (style) {
    case 0 : simpleStyle(); break;
    case 1 : cubicalMoves(); break;
    case 2 : waveMotion(); break;
    case 3 : jumpingSlides(); break;
    }
    glbase->updateGL();
}
//////////////////Transition styles///////////////////

// TODO : Bring faster animation.
void GLPresenter::simpleStyle()
{
    QList<float> temp1;
    QList<float> temp2;
    temp1 = glbase->getSlidePosition();
    temp2 = glbase->getSlideSize();
    if (!set) {
        delta = 0;
        /*
         * set slide size to half and locates out side the scree range.
         */
        glbase->setSlideSize(0.5);
        glbase->setSlidePosition(-6, 0, 0);
        set = true;
    }
    if (forward) {
        if (temp1[0] < -0.1)
            glbase->moveSlide(0.4, 0.0, 0.0);
        if (temp1[0] > -0.1 && temp2[0] < 3.95)  // 3.9 is the best fit size for a slide
            glbase->resizeSlide(0.3);
    }
    if (reverse) {
        if (temp2[0] < 1.2)
            glbase->moveSlide(-0.4, 0.0, 0.0);
        if (temp2[0] > 1)
            glbase->resizeSlide(-0.3);
    }
}

void GLPresenter::cubicalMoves()
{
    QList<float> temp1;
    QList<float> temp2;
    temp1 = glbase->getSlideRotation();
    temp2 = glbase->getSlideSize();

    if (forward) {
        if (temp2[0] < 3.9)
            glbase->resizeSlide(0.1);
        if (temp1[0] < 180 || temp1[1] < 180 || temp1[2] < 180) // 180 degree rotation
            glbase->rotateSlide(3, 3, 3);
    }
    if (reverse) {
        if (temp2[0] > 0)
            glbase->resizeSlide(-0.1);
        if (temp1[0] > 0)
            glbase->rotateSlide(-3, -3, -3);
        if (timeline->currentTime() > s_time - 100) {
            set = false;
        }
    }
}

void GLPresenter::waveMotion()
{
    float y;
    float pi = 22 / 7;
    delta = delta + (pi / 10);  //frequency
    y = sin(delta);
    QList<float> temp1;
    QList<float> temp2;
    temp1 = glbase->getSlidePosition();
    temp2 = glbase->getSlideSize();
    if (!set) {
        delta = 0;
        glbase->setSlideSize(0.5);
        glbase->setSlidePosition(-6, -1.5, 0);
        set = true;
    }
    if (forward) {
        if (temp1[0] < -1)
            glbase->moveSlide(0.1, y / 2, 0);   // amplitude
        if (temp1[0] > -1 && temp1[0] != 0) {
            if (temp1[0] < 0.1)glbase->moveSlide(0.09, 0, 0);
            if (temp1[0] > 0.1)glbase->setSlidePosition(0, 0, 0);
        }
        if (temp2[0] < 3.9 && temp1[0] == 0)glbase->resizeSlide(0.5);
    }
    if (reverse) {
        if (temp2[0] > 0.5)glbase->resizeSlide(-0.5);
        if (temp2[0] == 0.5)glbase->moveSlide(0.1, y / 2, 0);
        if (timeline->currentTime() > s_time - 100) {
            set = false; delta = 0;
        }
    }
}

void GLPresenter::jumpingSlides()
{
    float y;
    float pi = 22 / 7;
    delta = delta + (pi / 30);  //frequency
    y = sin(delta);
    if (y > 0)y = (-y);    // half of the cycle is shifted.
    QList<float> temp1;
    QList<float> temp2;
    QList<float> temp12;
    if (!set) {
        delta = 0;
        glbase->setSlideSize(0);
        glbase->setSlidePosition(-5, 3.5, 0);
        glbase->setSlideAngles(10, 30, 0);
        set = true;
    }
    temp1 = glbase->getSlidePosition();
    temp2 = glbase->getSlideSize();
    temp12 = glbase->getSlideRotation();
    if (forward) {
        if (temp1[0] <= 0) {
            glbase->setSlidePosition(temp1[0], 2*y, temp1[2]);
            glbase->resizeSlide(0.01);
            glbase->moveSlide(0.07, -0.01, 0);
        }
        if (temp1[0] > -0.5) {
            if (temp2[0] < 3.9)
                glbase->resizeSlide(0.3);
            glbase->setSlidePosition(0, 0, 0);
            glbase->setSlideAngles(0, 0, 0);
        }
    }
    if (reverse) {
        if (temp2[0] >= 1) glbase->resizeSlide(-0.3);
        if (temp2[0] <= 1) {
            glbase->setSlidePosition(temp1[0], 2*y, temp1[2]);
            glbase->resizeSlide(-0.01);
            glbase->moveSlide(0.07, 0.01, 0);
        }
        if (timeline->currentTime() > s_time - 100) {
            set = false; delta = 0;
        }
    }
}