~ubuntu-docviewer-dev/ubuntu-docviewer-app/lo-viewer

« back to all changes in this revision

Viewing changes to src/plugin/libreofficetoolkit-qml-plugin/loview.cpp

  • Committer: Tarmac
  • Author(s): Roman Shchekin, Stefano Verzegnassi
  • Date: 2015-10-11 19:51:03 UTC
  • mfrom: (172.4.9 reboot-qsg-impress-support)
  • Revision ID: tarmac-20151011195103-st3zu274xl8v8o7h
RenderEngine - impress support.

Approved by Ubuntu Phone Apps Jenkins Bot, Stefano Verzegnassi.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include "twips.h"
21
21
#include "config.h"
22
22
 
23
 
#include <QPainter>
24
23
#include <QImage>
25
24
#include <QTimer>
26
25
#include <QtCore/qmath.h>
36
35
    : QQuickItem(parent)
37
36
    , m_parentFlickable(nullptr)
38
37
    , m_document(nullptr)
 
38
    , m_partsModel(nullptr)
39
39
    , m_zoomFactor(1.0)
40
40
    , m_cacheBuffer(TILE_SIZE * 3)
41
41
    , m_visibleArea(0, 0, 0, 0)
48
48
    connect(this, SIGNAL(parentFlickableChanged()), this, SLOT(updateVisibleRect()));
49
49
    connect(this, SIGNAL(cacheBufferChanged()), this, SLOT(updateVisibleRect()));
50
50
    connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateVisibleRect()));
51
 
    connect(RenderEngine::instance(), SIGNAL(renderFinished(int,QImage)), this, SLOT(renderResultReceived(int,QImage)));
 
51
 
 
52
    connect(RenderEngine::instance(), SIGNAL(renderFinished(int,QImage)),
 
53
            this, SLOT(slotTileRenderFinished(int,QImage)));
 
54
    connect(RenderEngine::instance(), SIGNAL(thumbnailRenderFinished(int,QImage)),
 
55
            this, SLOT(slotThumbnailRenderFinished(int,QImage)));
52
56
}
53
57
 
54
58
// Returns the parent QML Flickable
79
83
 
80
84
void LOView::initializeDocument(const QString &path)
81
85
{
82
 
    if (m_document.data())
83
 
        m_document.data()->disconnect(this);
 
86
    if (m_document)
 
87
        m_document->disconnect(this);
84
88
 
85
89
    m_document = QSharedPointer<LODocument>(new LODocument());
86
90
    m_document->setPath(path);
87
91
 
 
92
    // TODO MOVE
 
93
    m_partsModel = new LOPartsModel(m_document);
 
94
    Q_EMIT partsModelChanged();
 
95
 
 
96
    // --------------------------------------------------
 
97
    QQmlEngine *engine = QQmlEngine::contextForObject(this)->engine();
 
98
    if (engine->imageProvider("lok"))
 
99
        engine->removeImageProvider("lok");
 
100
 
 
101
    m_imageProvider = new LOPartsImageProvider(m_document);
 
102
    engine->addImageProvider("lok", m_imageProvider);
 
103
    // --------------------------------------------------
 
104
 
88
105
    connect(m_document.data(), SIGNAL(currentPartChanged()), this, SLOT(invalidateAllTiles()));
89
106
 
90
107
    Q_EMIT documentChanged();
96
113
    return m_document.data();
97
114
}
98
115
 
 
116
LOPartsModel *LOView::partsModel() const
 
117
{
 
118
    return m_partsModel;
 
119
}
 
120
 
99
121
qreal LOView::zoomFactor() const
100
122
{
101
123
    return m_zoomFactor;
173
195
    return false;
174
196
}
175
197
 
176
 
// Update the size of LOView, according to the size of the loaded document.
177
198
void LOView::updateViewSize()
178
199
{
179
200
    if (!m_document)
184
205
    this->setWidth(Twips::convertTwipsToPixels(docSize.width(), m_zoomFactor));
185
206
    this->setHeight(Twips::convertTwipsToPixels(docSize.height(), m_zoomFactor));
186
207
 
187
 
    // TODO: Consider to use connections to widthChanged and heightChanged
188
 
    this->updateVisibleRect();
 
208
    updateVisibleRect();
189
209
}
190
210
 
191
 
// Update the informations of the currently visible area of the parent
192
 
// Flickable, then generate/delete all the required tiles, according to these
193
 
// informations.
194
211
void LOView::updateVisibleRect()
195
212
{
196
213
    if (!m_parentFlickable)
228
245
                          m_parentFlickable->height());
229
246
 
230
247
    // Update information about the buffer area
231
 
    m_bufferArea.setRect(qMax(0, m_visibleArea.x() - this->cacheBuffer()),
232
 
                         qMax(0, m_visibleArea.y() - this->cacheBuffer()),
233
 
                         qMin(int(this->width() - m_bufferArea.x()), m_visibleArea.width() + (this->cacheBuffer() * 2)),
234
 
                         qMin(int(this->height() - m_bufferArea.y()), m_visibleArea.height() + (this->cacheBuffer() * 2)));
 
248
    m_bufferArea.setRect(qMax(0, m_visibleArea.x() - m_cacheBuffer),
 
249
                         qMax(0, m_visibleArea.y() - m_cacheBuffer),
 
250
                         qMin(int(this->width() - m_bufferArea.x()), m_visibleArea.width() + (m_cacheBuffer * 2)),
 
251
                         qMin(int(this->height() - m_bufferArea.y()), m_visibleArea.height() + (m_cacheBuffer * 2)));
235
252
 
236
253
    // Delete tiles that are outside the loading area
237
254
    if (!m_tiles.isEmpty()) {
300
317
    }
301
318
}
302
319
 
303
 
// FIXME: Just for the moment. In zoom branch we have all we need :)
304
320
void LOView::invalidateAllTiles()
305
321
{
306
322
    clearView();
314
330
        qDebug() << "Creating tile indexed as" << index;
315
331
#endif
316
332
 
317
 
        auto tile = new SGTileItem(rect, m_zoomFactor, this);
 
333
        auto tile = new SGTileItem(rect, m_zoomFactor, RenderEngine::getNextId(), this);
318
334
        m_tiles.insert(index, tile);
319
 
        RenderEngine::instance()->enqueueTask(m_document, rect, m_zoomFactor, tile->id());
 
335
        RenderEngine::instance()->enqueueTask(m_document, m_document->currentPart(), rect, m_zoomFactor, tile->id());
320
336
    }
321
337
#ifdef DEBUG_VERBOSE
322
338
    else {
331
347
        m_updateTimer.start(20);
332
348
}
333
349
 
334
 
void LOView::renderResultReceived(int id, QImage img)
 
350
void LOView::slotTileRenderFinished(int id, QImage img)
335
351
{
336
352
    for (auto i = m_tiles.begin(); i != m_tiles.end(); ++i) {
337
353
        SGTileItem* sgtile = i.value();
342
358
    }
343
359
}
344
360
 
 
361
void LOView::slotThumbnailRenderFinished(int id, QImage img)
 
362
{
 
363
    if (!m_imageProvider->m_images.contains(id))
 
364
        m_imageProvider->m_images.insert(id, img);
 
365
    m_partsModel->notifyAboutChanges(id);
 
366
}
 
367
 
345
368
void LOView::clearView()
346
369
{
347
370
    for (auto i = m_tiles.begin(); i != m_tiles.end(); ++i)
352
375
 
353
376
LOView::~LOView()
354
377
{
355
 
    disconnect(RenderEngine::instance(), SIGNAL(renderFinished(int,QImage)), this, SLOT(renderResultReceived(int,QImage)));
 
378
    delete m_partsModel;
 
379
 
 
380
    disconnect(RenderEngine::instance(), SIGNAL(renderFinished(int,QImage)),
 
381
               this, SLOT(slotTileRenderFinished(int,QImage)));
 
382
    disconnect(RenderEngine::instance(), SIGNAL(thumbnailRenderFinished(int,QImage)),
 
383
               this, SLOT(slotThumbnailRenderFinished(int,QImage)));
356
384
 
357
385
    // Remove all tasks from rendering queue.
358
386
    for (auto i = m_tiles.begin(); i != m_tiles.end(); ++i)