diff --git a/conf/widgetannottools.cpp b/conf/widgetannottools.cpp index 7898a10e6..e4be577e2 100644 --- a/conf/widgetannottools.cpp +++ b/conf/widgetannottools.cpp @@ -28,6 +28,9 @@ #include #include +#include "core/annotations.h" +#include "ui/annotationwidgets.h" + // Used to store tools' XML description in m_list's items static const int ToolXmlRole = Qt::UserRole; @@ -197,7 +200,7 @@ void WidgetAnnotTools::slotMoveDown( bool ) } NewAnnotToolDialog::NewAnnotToolDialog( QWidget *parent ) - : KDialog( parent ) + : KDialog( parent ), m_stubann( 0 ), m_annotationWidget( 0 ) { setCaption( i18n("Create annotation tool") ); setButtons( Ok | Cancel ); @@ -218,103 +221,32 @@ NewAnnotToolDialog::NewAnnotToolDialog( QWidget *parent ) widgetLayout->addWidget( m_name, 0, 1 ); m_type = new KComboBox( false, widget ); + connect( m_type, SIGNAL( currentIndexChanged(int) ), this, SLOT( slotTypeChanged() ) ); tmplabel = new QLabel( i18n( "&Type:" ), widget ); tmplabel->setBuddy( m_type ); widgetLayout->addWidget( tmplabel, 1, 0, Qt::AlignRight ); widgetLayout->addWidget( m_type, 1, 1 ); - QGroupBox * appearance = new QGroupBox( i18n( "Appearance" ), widget ); - QGridLayout * appearanceLayout = new QGridLayout( appearance ); - - m_color = new KColorButton( appearance ); - tmplabel = new QLabel( i18n( "&Color:" ), appearance ); - m_color->setColor( Qt::green ); - tmplabel->setBuddy( m_color ); - appearanceLayout->addWidget( tmplabel, 0, 0, Qt::AlignRight ); - appearanceLayout->addWidget( m_color, 0, 1 ); - - m_opacity = new KIntNumInput( appearance ); - m_opacity->setRange( 0, 100 ); - m_opacity->setValue( 100 ); - m_opacity->setSuffix( i18nc( "Suffix for the opacity level, eg '80 %'", " %" ) ); - tmplabel = new QLabel( i18n( "&Opacity:" ), appearance ); - tmplabel->setBuddy( m_opacity ); - appearanceLayout->addWidget( tmplabel, 1, 0, Qt::AlignRight ); - appearanceLayout->addWidget( m_opacity, 1, 1 ); - - widgetLayout->addWidget( appearance, 2, 0, 1, 2 ); - -#define TYPE(name, template) \ - m_type->addItem( name, qVariantFromValue(QString( template )) ) - - TYPE( i18n("Note"), - "" - "" - "" - "" - "" ); - TYPE( i18n("Inline Note" ), - "" - "" - "" - "" - "" ); - TYPE( i18n("Freehand Line" ), - "" - "" - "" - "" - "" ); - TYPE( i18n("Straight Line" ), - "" - "" - "" - "" - "" ); - TYPE( i18n("Polygon" ), - "" - "" - "" - "" - "" ); - TYPE( i18n("Highlight" ), - "" - "" - "" - "" - "" ); - TYPE( i18n("Squiggly" ), - "" - "" - "" - "" - "" ); - TYPE( i18n("Underline" ), - "" - "" - "" - "" - "" ); - TYPE( i18n("Strike out" ), - "" - "" - "" - "" - "" ); - TYPE( i18n("Ellipse" ), - "" - "" - "" - "" - "" ); - TYPE( i18n("Rectangle" ), - "" - "" - "" - "" - "" ); - // TODO: Stamp -#undef ADDTYPE + m_appearanceBox = new QGroupBox( i18n( "Appearance" ), widget ); + m_appearanceBox->setLayout( new QVBoxLayout( m_appearanceBox ) ); + widgetLayout->addWidget( m_appearanceBox, 2, 0, 1, 2 ); + + // Populate combobox with annotation types + m_type->addItem( i18n("Note"), QByteArray("note-linked") ); + m_type->addItem( i18n("Inline Note"), QByteArray("note-inline") ); + m_type->addItem( i18n("Freehand Line"), QByteArray("ink") ); + m_type->addItem( i18n("Straight Line"), QByteArray("straight-line") ); + m_type->addItem( i18n("Polygon"), QByteArray("polygon") ); + m_type->addItem( i18n("Text markup"), QByteArray("text-markup") ); + m_type->addItem( i18n("Geometrical shape"), QByteArray("geometrical-shape") ); + m_type->addItem( i18n("Stamp"), QByteArray("stamp") ); + + rebuildAppearanceBox(); +} + +NewAnnotToolDialog::~NewAnnotToolDialog() +{ + delete m_annotationWidget; } QString NewAnnotToolDialog::name() const @@ -324,9 +256,187 @@ QString NewAnnotToolDialog::name() const QString NewAnnotToolDialog::toolXml() const { - const QString templ = m_type->itemData( m_type->currentIndex() ).value(); - const double opacity = (double)m_opacity->value() / 100.0; - return templ.arg( m_color->color().name() ).arg( opacity ); + const QByteArray toolType = m_type->itemData( m_type->currentIndex() ).toByteArray(); + const QString color = m_stubann->style().color().name(); + const double opacity = m_stubann->style().opacity(); + + if ( toolType == "note-linked" ) + { + Okular::TextAnnotation * ta = static_cast( m_stubann ); + Q_UNUSED( ta ); + return QString( "" + "" + "" + "" + "" ).arg( color ).arg( opacity ); + } + else if ( toolType == "note-inline" ) + { + Okular::TextAnnotation * ta = static_cast( m_stubann ); + Q_UNUSED( ta ); + return QString( "" + "" + "" + "" + "" ).arg( color ).arg( opacity ); + } + else if ( toolType == "ink" ) + { + Okular::InkAnnotation * ia = static_cast( m_stubann ); + Q_UNUSED( ia ); + return QString( "" + "" + "" + "" + "").arg( color ).arg( opacity ); + } + else if ( toolType == "straight-line" ) + { + Okular::LineAnnotation * la = static_cast( m_stubann ); + Q_UNUSED( la ); + return QString( "" + "" + "" + "" + "" ).arg( color ).arg( opacity ); + } + else if ( toolType == "polygon" ) + { + Okular::LineAnnotation * la = static_cast( m_stubann ); + Q_UNUSED( la ); + return QString( "" + "" + "" + "" + "" ).arg( color ).arg( opacity ); + } + else if ( toolType == "text-markup" ) + { + Okular::HighlightAnnotation * ha = static_cast( m_stubann ); + + QString toolType, annotationType; + switch ( ha->highlightType() ) + { + case Okular::HighlightAnnotation::Highlight: + toolType = "highlight"; + annotationType = "Highlight"; + break; + case Okular::HighlightAnnotation::Squiggly: + toolType = "squiggly"; + annotationType = "Squiggly"; + break; + case Okular::HighlightAnnotation::Underline: + toolType = "underline"; + annotationType = "Underline"; + break; + case Okular::HighlightAnnotation::StrikeOut: + toolType = "strikeout"; + annotationType = "StrikeOut"; + break; + } + + return QString( "" + "" + "" + "" + "").arg( color ).arg( opacity ) + .arg( toolType ).arg( annotationType ); + } + else if ( toolType == "geometrical-shape" ) + { + Okular::GeomAnnotation * ga = static_cast( m_stubann ); + const bool isCircle = (ga->geometricalType() == Okular::GeomAnnotation::InscribedCircle); + return QString( "" + "" + "" + "" + "").arg( color ).arg( opacity ) + .arg( isCircle ? "ellipse" : "rectangle" ) + .arg( isCircle ? "GeomCircle" : "GeomSquare" ); + } + else if ( toolType == "stamp" ) + { + Okular::StampAnnotation * sa = static_cast( m_stubann ); + return QString( "" + "" + "" + "" + "" ).arg( sa->stampIconName() ); // FIXME: Check bad strings + } + + return QString(); // This should never happen +} + +void NewAnnotToolDialog::rebuildAppearanceBox() +{ + const QByteArray toolType = m_type->itemData( m_type->currentIndex() ).toByteArray(); + + // Delete previous stub annotation, if any + delete m_stubann; + + // Create stub annotation + if ( toolType == "note-linked" ) + { + Okular::TextAnnotation * ta = new Okular::TextAnnotation(); + ta->setTextType( Okular::TextAnnotation::Linked ); + m_stubann = ta; + } + else if ( toolType == "note-inline" ) + { + Okular::TextAnnotation * ta = new Okular::TextAnnotation(); + ta->setTextType( Okular::TextAnnotation::InPlace ); + m_stubann = ta; + } + else if ( toolType == "ink" ) + { + m_stubann = new Okular::InkAnnotation(); + } + else if ( toolType == "straight-line" ) + { + Okular::LineAnnotation * la = new Okular::LineAnnotation(); + la->setLinePoints( QLinkedList() << + Okular::NormalizedPoint(0,0) << + Okular::NormalizedPoint(1,0) ); + m_stubann = la; + } + else if ( toolType == "polygon" ) + { + Okular::LineAnnotation * la = new Okular::LineAnnotation(); + la->setLinePoints( QLinkedList() << + Okular::NormalizedPoint(0,0) << + Okular::NormalizedPoint(1,0) << + Okular::NormalizedPoint(1,1) ); + m_stubann = la; + } + else if ( toolType == "text-markup" ) + { + m_stubann = new Okular::HighlightAnnotation(); + } + else if ( toolType == "geometrical-shape" ) + { + m_stubann = new Okular::GeomAnnotation(); + } + else if ( toolType == "stamp" ) + { + Okular::StampAnnotation * sa = new Okular::StampAnnotation(); + sa->setStampIconName( "okular" ); + m_stubann = sa; + } + + m_stubann->style().setColor( Qt::yellow ); // TODO: Choose default color according to annotation type + + // Remove previous widget (if any) + if ( m_annotationWidget ) + { + delete m_annotationWidget->appearanceWidget(); + delete m_annotationWidget; + } + + m_annotationWidget = AnnotationWidgetFactory::widgetFor( m_stubann ); + m_appearanceBox->layout()->addWidget( m_annotationWidget->appearanceWidget() ); + + // Tell the widget to mirror changes back in the stub annotation + connect( m_annotationWidget, SIGNAL(dataChanged()), m_annotationWidget, SLOT(applyChanges()) ); } void NewAnnotToolDialog::slotNameEdited( const QString &new_name ) @@ -334,4 +444,9 @@ void NewAnnotToolDialog::slotNameEdited( const QString &new_name ) enableButton( Ok, !new_name.isEmpty() ); } +void NewAnnotToolDialog::slotTypeChanged() +{ + rebuildAppearanceBox(); +} + #include "moc_widgetannottools.cpp" diff --git a/conf/widgetannottools.h b/conf/widgetannottools.h index 10a595a4c..a4593c6ad 100644 --- a/conf/widgetannottools.h +++ b/conf/widgetannottools.h @@ -15,10 +15,15 @@ class KLineEdit; class KComboBox; -class KColorButton; -class KIntNumInput; class KPushButton; class QListWidget; +class QGroupBox; +class AnnotationWidget; + +namespace Okular +{ +class Annotation; +} class WidgetAnnotTools : public QWidget { @@ -59,17 +64,23 @@ class NewAnnotToolDialog : public KDialog public: NewAnnotToolDialog( QWidget *parent = 0 ); + ~NewAnnotToolDialog(); QString name() const; QString toolXml() const; private: - KLineEdit * m_name; - KComboBox * m_type; - KColorButton * m_color; - KIntNumInput * m_opacity; + void rebuildAppearanceBox(); + + KLineEdit *m_name; + KComboBox *m_type; + QGroupBox *m_appearanceBox; + + Okular::Annotation *m_stubann; + AnnotationWidget *m_annotationWidget; private slots: void slotNameEdited( const QString &new_name ); + void slotTypeChanged(); }; #endif diff --git a/ui/annotationwidgets.h b/ui/annotationwidgets.h index 55c709abc..1ba344b32 100644 --- a/ui/annotationwidgets.h +++ b/ui/annotationwidgets.h @@ -80,6 +80,7 @@ public: QWidget * appearanceWidget(); QWidget * extraWidget(); +public slots: virtual void applyChanges(); signals: