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