~ubuntu-branches/ubuntu/vivid/qpdfview/vivid

« back to all changes in this revision

Viewing changes to sources/pageitem.cpp

  • Committer: Package Import Robot
  • Author(s): Benjamin Eltzner
  • Date: 2013-05-26 13:52:50 UTC
  • mfrom: (1.2.8)
  • Revision ID: package-import@ubuntu.com-20130526135250-s1rhw935iqd8fcfs
Tags: 0.4.3-1
* New upstream release.
* Added menu file and fetch xpm icon file in debian folder.

Show diffs side-by-side

added added

removed removed

Lines of Context:
102
102
    return m_boundingRect;
103
103
}
104
104
 
105
 
void PageItem::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget* widget)
 
105
void PageItem::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*)
106
106
{
107
107
    QPixmap pixmap;
108
108
 
142
142
 
143
143
    if(pixmap.isNull())
144
144
    {
145
 
        qreal extent = qMin(0.1 * m_boundingRect.width(), 0.1 * m_boundingRect.height());
146
 
        QRectF rect(m_boundingRect.left() + 0.01 * m_boundingRect.width(), m_boundingRect.top() + 0.01 * m_boundingRect.height(), extent, extent);
 
145
        // progess icon
 
146
 
 
147
        const qreal extent = qMin(0.1 * m_boundingRect.width(), 0.1 * m_boundingRect.height());
 
148
        const QRectF rect(m_boundingRect.left() + 0.01 * m_boundingRect.width(), m_boundingRect.top() + 0.01 * m_boundingRect.height(), extent, extent);
147
149
 
148
150
        s_settings->pageItem().progressIcon().paint(painter, rect.toRect());
149
151
    }
154
156
 
155
157
    if(s_settings->pageItem().decoratePages() && !m_presentationMode)
156
158
    {
157
 
        painter->setPen(QPen(m_invertColors ? Qt::white : Qt::black));
158
159
        painter->drawRect(m_boundingRect);
159
160
    }
160
161
 
167
168
        painter->setTransform(m_normalizedTransform, true);
168
169
        painter->setPen(QPen(Qt::red));
169
170
 
170
 
        foreach(Model::Link* link, m_links)
 
171
        foreach(const Model::Link* link, m_links)
171
172
        {
172
173
            painter->drawPath(link->boundary);
173
174
        }
184
185
        painter->setTransform(m_normalizedTransform, true);
185
186
        painter->setPen(QPen(Qt::blue));
186
187
 
187
 
        foreach(Model::FormField* formField, m_formFields)
 
188
        foreach(const Model::FormField* formField, m_formFields)
188
189
        {
189
190
            painter->drawRect(formField->boundary());
190
191
        }
199
200
        painter->save();
200
201
 
201
202
        painter->setTransform(m_transform, true);
202
 
 
203
 
        QColor highlightColor = widget->palette().color(QPalette::Highlight);
204
 
 
205
 
        highlightColor.setAlpha(127);
206
 
 
207
 
        foreach(QRectF highlight, m_highlights)
 
203
        painter->setPen(QPen(s_settings->pageItem().highlightColor()));
 
204
        painter->setBrush(QBrush(s_settings->pageItem().highlightColor()));
 
205
        painter->setCompositionMode(QPainter::CompositionMode_Multiply);
 
206
 
 
207
        foreach(const QRectF highlight, m_highlights)
208
208
        {
209
 
            painter->fillRect(highlight.normalized(), QBrush(highlightColor));
 
209
            painter->drawRect(highlight.normalized());
210
210
        }
211
211
 
212
212
        painter->restore();
216
216
 
217
217
    if(!m_rubberBand.isNull())
218
218
    {
 
219
        painter->save();
 
220
 
219
221
        QPen pen;
220
 
        pen.setColor(m_invertColors ? Qt::white : Qt::black);
 
222
        pen.setColor(Qt::white);
221
223
        pen.setStyle(Qt::DashLine);
222
224
 
223
225
        painter->setPen(pen);
 
226
        painter->setCompositionMode(QPainter::CompositionMode_Difference);
 
227
 
224
228
        painter->drawRect(m_rubberBand);
 
229
 
 
230
        painter->restore();
225
231
    }
226
232
}
227
233
 
330
336
 
331
337
void PageItem::setRotation(Rotation rotation)
332
338
{
333
 
    if(m_rotation != rotation && rotation >= 0 && rotation < NumberOfDirections)
 
339
    if(m_rotation != rotation && rotation >= 0 && rotation < NumberOfRotations)
334
340
    {
335
341
        refresh();
336
342
 
360
366
    update();
361
367
}
362
368
 
363
 
void PageItem::clearHighlights()
364
 
{
365
 
    m_highlights.clear();
366
 
 
367
 
    update();
368
 
}
369
 
 
370
369
void PageItem::startRender(bool prefetch)
371
370
{
372
371
    if(prefetch && s_cache.contains(this))
401
400
 
402
401
    if(image.isNull())
403
402
    {
404
 
        qreal extent = qMin(0.1 * m_boundingRect.width(), 0.1 * m_boundingRect.height());
405
 
        QRectF rect(0.01 * m_boundingRect.width(), 0.01 * m_boundingRect.height(), extent, extent);
 
403
        // error icon
 
404
 
 
405
        const qreal extent = qMin(0.1 * m_boundingRect.width(), 0.1 * m_boundingRect.height());
 
406
        const QRectF rect(0.01 * m_boundingRect.width(), 0.01 * m_boundingRect.height(), extent, extent);
406
407
 
407
408
        image = QImage(qFloor(0.01 * m_boundingRect.width() + extent), qFloor(0.01 * m_boundingRect.height() + extent), QImage::Format_ARGB32);
408
409
        image.fill(Qt::transparent);
413
414
 
414
415
    if(prefetch)
415
416
    {
416
 
        QPixmap pixmap = QPixmap::fromImage(image);
 
417
        QPixmap* pixmap = new QPixmap(QPixmap::fromImage(image));
417
418
 
418
 
        int cost = pixmap.width() * pixmap.height() * pixmap.depth() / 8;
419
 
        s_cache.insert(this, new QPixmap(pixmap), cost);
 
419
        int cost = pixmap->width() * pixmap->height() * pixmap->depth() / 8;
 
420
        s_cache.insert(this, pixmap, cost);
420
421
    }
421
422
    else
422
423
    {
437
438
    {
438
439
        // links
439
440
 
440
 
        foreach(Model::Link* link, m_links)
 
441
        foreach(const Model::Link* link, m_links)
441
442
        {
442
443
            if(m_normalizedTransform.map(link->boundary).contains(event->pos()))
443
444
            {
476
477
 
477
478
        // annotations
478
479
 
479
 
        foreach(Model::Annotation* annotation, m_annotations)
 
480
        foreach(const Model::Annotation* annotation, m_annotations)
480
481
        {
481
482
            if(m_normalizedTransform.mapRect(annotation->boundary()).contains(event->pos()))
482
483
            {
489
490
 
490
491
        // form fields
491
492
 
492
 
        foreach(Model::FormField* formField, m_formFields)
 
493
        foreach(const Model::FormField* formField, m_formFields)
493
494
        {
494
495
            if(m_normalizedTransform.mapRect(formField->boundary()).contains(event->pos()))
495
496
            {
545
546
    {
546
547
        // links
547
548
 
548
 
        foreach(Model::Link* link, m_links)
 
549
        foreach(const Model::Link* link, m_links)
549
550
        {
550
551
            if(m_normalizedTransform.map(link->boundary).contains(event->pos()))
551
552
            {
710
711
{
711
712
    QMenu menu;
712
713
 
713
 
    QAction* copyTextAction = menu.addAction(tr("Copy &text"));
714
 
    QAction* copyImageAction = menu.addAction(tr("Copy &image"));
715
 
    QAction* saveImageToFileAction = menu.addAction(tr("Save image to &file..."));
 
714
    const QAction* copyTextAction = menu.addAction(tr("Copy &text"));
 
715
    const QAction* copyImageAction = menu.addAction(tr("Copy &image"));
 
716
    const QAction* saveImageToFileAction = menu.addAction(tr("Save image to &file..."));
716
717
 
717
 
    QAction* action = menu.exec(screenPos);
 
718
    const QAction* action = menu.exec(screenPos);
718
719
 
719
720
    if(action == copyTextAction)
720
721
    {
721
 
        QString text = m_page->text(m_transform.inverted().mapRect(m_rubberBand));
 
722
        const QString text = m_page->text(m_transform.inverted().mapRect(m_rubberBand));
722
723
 
723
724
        if(!text.isEmpty())
724
725
        {
727
728
    }
728
729
    else if(action == copyImageAction || action == saveImageToFileAction)
729
730
    {
730
 
        QRect rect = m_rubberBand.translated(-m_boundingRect.topLeft()).toRect();
731
 
        QImage image = s_cache.contains(this) ? s_cache.object(this)->copy(rect).toImage() : m_page->render(m_physicalDpiX * m_scaleFactor, m_scaleFactor * m_physicalDpiY, m_rotation, rect);
 
731
        const QRect rect = m_rubberBand.translated(-m_boundingRect.topLeft()).toRect();
 
732
        const QImage image = s_cache.contains(this) ? s_cache.object(this)->copy(rect).toImage() : m_page->render(m_physicalDpiX * m_scaleFactor, m_scaleFactor * m_physicalDpiY, m_rotation, rect);
732
733
 
733
734
        if(!image.isNull())
734
735
        {
738
739
            }
739
740
            else if(action == saveImageToFileAction)
740
741
            {
741
 
                QString fileName = QFileDialog::getSaveFileName(0, tr("Save image to file"), QDir::homePath(), "Portable network graphics (*.png)");
 
742
                const QString fileName = QFileDialog::getSaveFileName(0, tr("Save image to file"), QDir::homePath(), "Portable network graphics (*.png)");
742
743
 
743
744
                if(!image.save(fileName, "PNG"))
744
745
                {
755
756
    {
756
757
        QMenu menu;
757
758
 
758
 
        QAction* addTextAction = menu.addAction(tr("Add &text"));
759
 
        QAction* addHighlightAction = menu.addAction(tr("Add &highlight"));
 
759
        const QAction* addTextAction = menu.addAction(tr("Add &text"));
 
760
        const QAction* addHighlightAction = menu.addAction(tr("Add &highlight"));
760
761
 
761
 
        QAction* action = menu.exec(screenPos);
 
762
        const QAction* action = menu.exec(screenPos);
762
763
 
763
764
        if(action == addTextAction || action == addHighlightAction)
764
765
        {
793
794
    {
794
795
        QMenu menu;
795
796
 
796
 
        QAction* removeAnnotationAction = menu.addAction(tr("&Remove annotation"));
 
797
        const QAction* removeAnnotationAction = menu.addAction(tr("&Remove annotation"));
797
798
 
798
 
        QAction* action = menu.exec(screenPos);
 
799
        const QAction* action = menu.exec(screenPos);
799
800
 
800
801
        if(action == removeAnnotationAction)
801
802
        {
875
876
{
876
877
    setAcceptHoverEvents(false);
877
878
 
878
 
    QFontMetrics fontMetrics = QFontMetrics(QFont());
 
879
    const QFontMetrics fontMetrics = QFontMetrics(QFont());
879
880
 
880
881
    m_textWidth = fontMetrics.width(QString::number(index + 1));
881
882
    m_textHeight = fontMetrics.height();
 
883
 
 
884
    m_current = false;
882
885
}
883
886
 
884
887
QRectF ThumbnailItem::boundingRect() const
890
893
{
891
894
    PageItem::paint(painter, option, widget);
892
895
 
893
 
    QRectF boundingRect = PageItem::boundingRect();
 
896
    const QRectF boundingRect = PageItem::boundingRect();
894
897
 
895
898
    QPointF pos = boundingRect.bottomLeft();
896
899
    pos.rx() += 0.5 * (boundingRect.width() - m_textWidth);
897
900
    pos.ry() += m_textHeight;
898
901
 
899
902
    painter->drawText(pos, QString::number(index() + 1));
 
903
 
 
904
    if(m_current)
 
905
    {
 
906
        painter->save();
 
907
 
 
908
        painter->setCompositionMode(QPainter::CompositionMode_Multiply);
 
909
 
 
910
        painter->fillRect(boundingRect, widget->palette().highlight());
 
911
 
 
912
        painter->restore();
 
913
    }
 
914
}
 
915
 
 
916
bool ThumbnailItem::isCurrent() const
 
917
{
 
918
    return m_current;
 
919
}
 
920
 
 
921
void ThumbnailItem::setCurrent(bool current)
 
922
{
 
923
    if(m_current != current)
 
924
    {
 
925
        m_current = current;
 
926
 
 
927
        update();
 
928
    }
900
929
}
901
930
 
902
931
void ThumbnailItem::mousePressEvent(QGraphicsSceneMouseEvent*)