Changeset View
Changeset View
Standalone View
Standalone View
ui/annotationwidgets.cpp
Show All 17 Lines | |||||
18 | #include <qvariant.h> | 18 | #include <qvariant.h> | ||
19 | #include <kcolorbutton.h> | 19 | #include <kcolorbutton.h> | ||
20 | #include <kcombobox.h> | 20 | #include <kcombobox.h> | ||
21 | #include <kfontrequester.h> | 21 | #include <kfontrequester.h> | ||
22 | #include <QIcon> | 22 | #include <QIcon> | ||
23 | #include <kiconloader.h> | 23 | #include <kiconloader.h> | ||
24 | #include <KLocalizedString> | 24 | #include <KLocalizedString> | ||
25 | #include <QDebug> | 25 | #include <QDebug> | ||
26 | #include <QList> | ||||
26 | #include <QMimeDatabase> | 27 | #include <QMimeDatabase> | ||
28 | #include <QPair> | ||||
27 | #include <KFormat> | 29 | #include <KFormat> | ||
28 | 30 | | |||
29 | #include "core/document.h" | 31 | #include "core/document.h" | ||
30 | #include "guiutils.h" | 32 | #include "guiutils.h" | ||
33 | #include "pagepainter.h" | ||||
31 | 34 | | |||
32 | #define FILEATTACH_ICONSIZE 48 | 35 | #define FILEATTACH_ICONSIZE 48 | ||
33 | 36 | | |||
34 | PixmapPreviewSelector::PixmapPreviewSelector( QWidget * parent ) | 37 | PixmapPreviewSelector::PixmapPreviewSelector( QWidget * parent ) | ||
35 | : QWidget( parent ) | 38 | : QWidget( parent ) | ||
36 | { | 39 | { | ||
37 | QHBoxLayout * mainlay = new QHBoxLayout( this ); | 40 | QHBoxLayout * mainlay = new QHBoxLayout( this ); | ||
38 | mainlay->setMargin( 0 ); | 41 | mainlay->setMargin( 0 ); | ||
▲ Show 20 Lines • Show All 486 Lines • ▼ Show 20 Line(s) | 518 | { | |||
525 | gridlay2->addWidget( tmplabel4, 2, 0, Qt::AlignRight ); | 528 | gridlay2->addWidget( tmplabel4, 2, 0, Qt::AlignRight ); | ||
526 | m_startStyleCombo = new QComboBox( widget ); | 529 | m_startStyleCombo = new QComboBox( widget ); | ||
527 | m_endStyleCombo = new QComboBox( widget ); | 530 | m_endStyleCombo = new QComboBox( widget ); | ||
528 | tmplabel3->setBuddy( m_startStyleCombo ); | 531 | tmplabel3->setBuddy( m_startStyleCombo ); | ||
529 | tmplabel4->setBuddy( m_endStyleCombo ); | 532 | tmplabel4->setBuddy( m_endStyleCombo ); | ||
530 | gridlay2->addWidget( m_startStyleCombo, 1, 1, Qt::AlignLeft ); | 533 | gridlay2->addWidget( m_startStyleCombo, 1, 1, Qt::AlignLeft ); | ||
531 | gridlay2->addWidget( m_endStyleCombo, 2, 1, Qt::AlignLeft ); | 534 | gridlay2->addWidget( m_endStyleCombo, 2, 1, Qt::AlignLeft ); | ||
532 | 535 | | |||
533 | for ( const QString &i: { i18n( "Square" ), i18n( "Circle" ), i18n( "Diamond" ), i18n( "Open Arrow" ), i18n( "Closed Arrow" ), | 536 | const QList<QPair<Okular::LineAnnotation::TermStyle, QString>> termStyles | ||
534 | i18n( "None" ), i18n( "Butt" ), i18n( "Right Open Arrow" ), i18n( "Right Closed Arrow" ), i18n( "Slash" ) } ) | | |||
535 | { | 537 | { | ||
536 | m_startStyleCombo->addItem( i ); | 538 | { Okular::LineAnnotation::Square, i18n( "Square" ) }, | ||
537 | m_endStyleCombo->addItem( i ); | 539 | { Okular::LineAnnotation::Circle, i18n( "Circle" ) }, | ||
ngraham: Would it make sense to put all of this in a const variable outside of the loop? | |||||
540 | { Okular::LineAnnotation::Diamond, i18n( "Diamond" ) }, | ||||
541 | { Okular::LineAnnotation::OpenArrow, i18n( "Open Arrow" ) }, | ||||
542 | { Okular::LineAnnotation::ClosedArrow, i18n( "Closed Arrow" ) }, | ||||
543 | { Okular::LineAnnotation::None, i18n( "None" ) }, | ||||
544 | { Okular::LineAnnotation::Butt, i18n( "Butt" ) }, | ||||
545 | { Okular::LineAnnotation::ROpenArrow, i18n( "Right Open Arrow" ) }, | ||||
546 | { Okular::LineAnnotation::RClosedArrow, i18n( "Right Closed Arrow" ) }, | ||||
547 | { Okular::LineAnnotation::Slash, i18n( "Slash" ) } | ||||
548 | }; | ||||
549 | for ( const auto &item: termStyles ) | ||||
550 | { | ||||
551 | const QIcon icon = endStyleIcon( item.first ); | ||||
552 | m_startStyleCombo->addItem( icon, item.second ); | ||||
553 | m_endStyleCombo->addItem( icon, item.second ); | ||||
538 | } | 554 | } | ||
539 | 555 | | |||
540 | m_startStyleCombo->setCurrentIndex( m_lineAnn->lineStartStyle() ); | 556 | m_startStyleCombo->setCurrentIndex( m_lineAnn->lineStartStyle() ); | ||
541 | m_endStyleCombo->setCurrentIndex( m_lineAnn->lineEndStyle() ); | 557 | m_endStyleCombo->setCurrentIndex( m_lineAnn->lineEndStyle() ); | ||
542 | connect( m_startStyleCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &LineAnnotationWidget::dataChanged ); | 558 | connect( m_startStyleCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &LineAnnotationWidget::dataChanged ); | ||
543 | connect( m_endStyleCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &LineAnnotationWidget::dataChanged ); | 559 | connect( m_endStyleCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &LineAnnotationWidget::dataChanged ); | ||
544 | 560 | | |||
545 | } | 561 | } | ||
Show All 39 Lines | 594 | { | |||
585 | { | 601 | { | ||
586 | m_lineAnn->setLineInnerColor( m_innerColor->color() ); | 602 | m_lineAnn->setLineInnerColor( m_innerColor->color() ); | ||
587 | } | 603 | } | ||
588 | } | 604 | } | ||
589 | Q_ASSERT( m_spinSize ); | 605 | Q_ASSERT( m_spinSize ); | ||
590 | m_lineAnn->style().setWidth( m_spinSize->value() ); | 606 | m_lineAnn->style().setWidth( m_spinSize->value() ); | ||
591 | } | 607 | } | ||
592 | 608 | | |||
609 | QIcon LineAnnotationWidget::endStyleIcon( Okular::LineAnnotation::TermStyle endStyle ) { | ||||
610 | const int iconSize { 48 }; | ||||
611 | QImage image { iconSize, iconSize, QImage::Format_ARGB32}; | ||||
612 | image.fill( qRgba(0, 0, 0, 0) ); | ||||
613 | Okular::LineAnnotation prototype; | ||||
614 | prototype.setLinePoints( { { 0, 0.5 }, { 0.65, 0.5 } } ); | ||||
615 | prototype.setLineStartStyle(Okular::LineAnnotation::TermStyle::None); | ||||
616 | prototype.setLineEndStyle( endStyle ); | ||||
617 | prototype.style().setWidth( 4 ); | ||||
618 | prototype.style().setColor( Qt::black ); | ||||
619 | prototype.style().setLineStyle( Okular::Annotation::LineStyle::Solid ); | ||||
620 | prototype.setBoundingRectangle( { 0, 0, 1, 1 } ); | ||||
621 | LineAnnotPainter linepainter { &prototype, { iconSize, iconSize }, 1, QTransform() }; | ||||
622 | linepainter.draw( image ); | ||||
623 | return QIcon( QPixmap::fromImage( image ) ); | ||||
624 | } | ||||
625 | | ||||
593 | 626 | | |||
594 | 627 | | |||
595 | InkAnnotationWidget::InkAnnotationWidget( Okular::Annotation * ann ) | 628 | InkAnnotationWidget::InkAnnotationWidget( Okular::Annotation * ann ) | ||
596 | : AnnotationWidget( ann ) | 629 | : AnnotationWidget( ann ) | ||
597 | { | 630 | { | ||
598 | m_inkAnn = static_cast< Okular::InkAnnotation * >( ann ); | 631 | m_inkAnn = static_cast< Okular::InkAnnotation * >( ann ); | ||
599 | } | 632 | } | ||
600 | 633 | | |||
▲ Show 20 Lines • Show All 276 Lines • Show Last 20 Lines |
Would it make sense to put all of this in a const variable outside of the loop?