~ubuntu-branches/debian/jessie/qpdfview/jessie

« back to all changes in this revision

Viewing changes to sources/pageitem.cpp

  • Committer: Package Import Robot
  • Author(s): Benjamin Eltzner
  • Date: 2012-11-25 08:31:42 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20121125083142-qj8l8wpijurp3tjc
Tags: 0.3.6-1
* New upstream release.
* Updated description in control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
bool PageItem::s_decoratePages = true;
27
27
bool PageItem::s_decorateLinks = true;
 
28
bool PageItem::s_decorateFormFields = true;
28
29
 
29
30
bool PageItem::s_invertColors = false;
30
31
 
61
62
    s_decorateLinks = decorateLinks;
62
63
}
63
64
 
 
65
bool PageItem::decorateFormFields()
 
66
{
 
67
    return s_decorateFormFields;
 
68
}
 
69
 
 
70
void PageItem::setDecorateFormFields(bool decorateFormFields)
 
71
{
 
72
    s_decorateFormFields = decorateFormFields;
 
73
}
 
74
 
64
75
bool PageItem::invertColors()
65
76
{
66
77
    return s_invertColors;
154
165
        delete annotation;
155
166
    }
156
167
 
 
168
    foreach(Poppler::FormField* formField, m_page->formFields())
 
169
    {
 
170
        if(!formField->isVisible() || formField->isReadOnly())
 
171
        {
 
172
            delete formField;
 
173
            continue;
 
174
        }
 
175
 
 
176
        switch(formField->type())
 
177
        {
 
178
        case Poppler::FormField::FormSignature:
 
179
            delete formField;
 
180
            break;
 
181
        case Poppler::FormField::FormText:
 
182
            switch(static_cast< Poppler::FormFieldText* >(formField)->textType())
 
183
            {
 
184
            case Poppler::FormFieldText::FileSelect:
 
185
                delete formField;
 
186
                break;
 
187
            case Poppler::FormFieldText::Normal:
 
188
            case Poppler::FormFieldText::Multiline:
 
189
                m_formFields.append(formField);
 
190
                break;
 
191
            }
 
192
 
 
193
            break;
 
194
        case Poppler::FormField::FormChoice:
 
195
            m_formFields.append(formField);
 
196
            break;
 
197
        case Poppler::FormField::FormButton:
 
198
            switch(static_cast< Poppler::FormFieldButton* >(formField)->buttonType())
 
199
            {
 
200
            case Poppler::FormFieldButton::Push:
 
201
                delete formField;
 
202
                break;
 
203
            case Poppler::FormFieldButton::CheckBox:
 
204
            case Poppler::FormFieldButton::Radio:
 
205
                m_formFields.append(formField);
 
206
                break;
 
207
            }
 
208
 
 
209
            break;
 
210
        }
 
211
    }
 
212
 
157
213
    prepareGeometry();
158
214
}
159
215
 
234
290
        painter->restore();
235
291
    }
236
292
 
 
293
    // form fields
 
294
 
 
295
    if(s_decorateFormFields)
 
296
    {
 
297
        painter->save();
 
298
 
 
299
        painter->setTransform(m_normalizedTransform, true);
 
300
        painter->setPen(QPen(Qt::blue));
 
301
 
 
302
        foreach(Poppler::FormField* formField, m_formFields)
 
303
        {
 
304
            painter->drawRect(formField->rect().normalized());
 
305
        }
 
306
 
 
307
        painter->restore();
 
308
    }
 
309
 
237
310
    // highlights
238
311
 
239
312
    painter->save();
269
342
    return m_index;
270
343
}
271
344
 
272
 
QSizeF PageItem::size() const
 
345
const QSizeF& PageItem::size() const
273
346
{
274
347
    return m_size;
275
348
}
449
522
{
450
523
    if(m_rubberBandMode == ModifiersMode && event->modifiers() == Qt::NoModifier)
451
524
    {
 
525
        // links
 
526
 
452
527
        foreach(Poppler::Link* link, m_links)
453
528
        {
454
529
            if(m_normalizedTransform.mapRect(link->linkArea().normalized()).contains(event->pos()))
470
545
            }
471
546
        }
472
547
 
 
548
        // annotations
 
549
 
473
550
        foreach(Poppler::Annotation* annotation, m_annotations)
474
551
        {
475
552
            if(m_normalizedTransform.mapRect(annotation->boundary().normalized()).contains(event->pos()))
481
558
            }
482
559
        }
483
560
 
 
561
        // form fields
 
562
 
 
563
        foreach(Poppler::FormField* formField, m_formFields)
 
564
        {
 
565
            if(m_normalizedTransform.mapRect(formField->rect().normalized()).contains(event->pos()))
 
566
            {
 
567
                setCursor(Qt::PointingHandCursor);
 
568
                QToolTip::showText(event->screenPos(), tr("Edit form field '%1'.").arg(formField->name()));
 
569
 
 
570
                return;
 
571
            }
 
572
        }
 
573
 
484
574
        unsetCursor();
485
575
        QToolTip::hideText();
486
576
    }
522
612
 
523
613
    if(event->modifiers() == Qt::NoModifier && event->button() == Qt::LeftButton)
524
614
    {
525
 
        // links and annotations
 
615
        // links
526
616
 
527
617
        foreach(Poppler::Link* link, m_links)
528
618
        {
529
619
            if(m_normalizedTransform.mapRect(link->linkArea().normalized()).contains(event->pos()))
530
620
            {
531
 
                QApplication::restoreOverrideCursor();
 
621
                unsetCursor();
532
622
 
533
623
                if(link->linkType() == Poppler::Link::Goto)
534
624
                {
553
643
            }
554
644
        }
555
645
 
 
646
        // annotations
 
647
 
556
648
        foreach(Poppler::Annotation* annotation, m_annotations)
557
649
        {
558
650
            if(m_normalizedTransform.mapRect(annotation->boundary().normalized()).contains(event->pos()))
559
651
            {
560
 
                QApplication::restoreOverrideCursor();
 
652
                unsetCursor();
561
653
 
562
654
                editAnnotation(annotation, event->screenPos());
563
655
 
565
657
                return;
566
658
            }
567
659
        }
 
660
 
 
661
        // form fields
 
662
 
 
663
        foreach(Poppler::FormField* formField, m_formFields)
 
664
        {
 
665
            if(m_normalizedTransform.mapRect(formField->rect().normalized()).contains(event->pos()))
 
666
            {
 
667
                unsetCursor();
 
668
 
 
669
                editFormField(formField, event->screenPos());
 
670
 
 
671
                event->accept();
 
672
                return;
 
673
            }
 
674
        }
568
675
    }
569
676
 
570
677
    event->ignore();
625
732
    {
626
733
        if(m_normalizedTransform.mapRect(annotation->boundary().normalized()).contains(event->pos()))
627
734
        {
628
 
            QApplication::restoreOverrideCursor();
 
735
            unsetCursor();
629
736
 
630
737
            removeAnnotation(annotation, event->screenPos());
631
738
 
714
821
 
715
822
    QAction* action = menu->exec(screenPos);
716
823
 
717
 
    if(action != 0)
 
824
    if(action == addTextAction || action == addHighlightAction)
718
825
    {
719
826
        QRectF boundary = m_normalizedTransform.inverted().mapRect(m_rubberBand);
720
827
 
770
877
 
771
878
    Q_UNUSED(screenPos);
772
879
 
 
880
    QMessageBox::information(0, tr("Information"), tr("Version 0.20.1 or higher of the Poppler library is required to add or remove annotations."));
 
881
 
773
882
#endif // HAS_POPPLER_20
774
883
}
775
884
 
802
911
    Q_UNUSED(annotation);
803
912
    Q_UNUSED(screenPos);
804
913
 
 
914
    QMessageBox::information(0, tr("Information"), tr("Version 0.20.1 or higher of the Poppler library is required to add or remove annotations."));
 
915
 
805
916
#endif // HAS_POPPLER_20
806
917
}
807
918
 
815
926
    annotationDialog->show();
816
927
}
817
928
 
 
929
void PageItem::editFormField(Poppler::FormField *formField, const QPoint &screenPos)
 
930
{
 
931
    if(formField->type() == Poppler::FormField::FormText || formField->type() == Poppler::FormField::FormChoice)
 
932
    {
 
933
        FormFieldDialog* formFieldDialog = new FormFieldDialog(m_mutex, formField);
 
934
 
 
935
        formFieldDialog->move(screenPos);
 
936
 
 
937
        formFieldDialog->setAttribute(Qt::WA_DeleteOnClose);
 
938
        formFieldDialog->show();
 
939
 
 
940
        connect(formFieldDialog, SIGNAL(destroyed()), SLOT(refresh()));
 
941
    }
 
942
    else if(formField->type() == Poppler::FormField::FormButton)
 
943
    {
 
944
        Poppler::FormFieldButton* formFieldButton = static_cast< Poppler::FormFieldButton* >(formField);
 
945
 
 
946
        formFieldButton->setState(!formFieldButton->state());
 
947
 
 
948
        refresh();
 
949
    }
 
950
}
 
951
 
818
952
void PageItem::prepareGeometry()
819
953
{
820
954
    m_transform.reset();