From 5fc6a887c00683251bde2e351890b1d2ab4b27fd Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Fri, 18 Apr 2008 21:37:41 +0000 Subject: [PATCH] Optionally create an extra widget to be shown as third tab in the annotation properties dialog. Use this possibility for file attachment annotations, for showing details about the embedded file. svn path=/trunk/KDE/kdegraphics/okular/; revision=798689 --- ui/annotationpropertiesdialog.cpp | 6 +++ ui/annotationwidgets.cpp | 81 ++++++++++++++++++++++++++++++- ui/annotationwidgets.h | 21 ++++++++ 3 files changed, 107 insertions(+), 1 deletion(-) diff --git a/ui/annotationpropertiesdialog.cpp b/ui/annotationpropertiesdialog.cpp index d880f0cc3..5ec757f07 100644 --- a/ui/annotationpropertiesdialog.cpp +++ b/ui/annotationpropertiesdialog.cpp @@ -112,6 +112,12 @@ AnnotsPropertiesDialog::AnnotsPropertiesDialog( QWidget *parent, Okular::Documen gridlayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Fixed, QSizePolicy::MinimumExpanding ), 3, 0 ); //END tab 2 + QWidget * extraWidget = 0; + if ( m_annotWidget && ( extraWidget = m_annotWidget->extraWidget() ) ) + { + addPage( extraWidget, extraWidget->windowTitle() ); + } + //BEGIN connections connect( colorBn, SIGNAL( changed( const QColor& ) ), this, SLOT( setModified() ) ); connect( m_opacity, SIGNAL( valueChanged( int ) ), this, SLOT( setModified() ) ); diff --git a/ui/annotationwidgets.cpp b/ui/annotationwidgets.cpp index d95942666..164ca4d6f 100644 --- a/ui/annotationwidgets.cpp +++ b/ui/annotationwidgets.cpp @@ -19,12 +19,17 @@ #include #include #include +#include #include #include #include +#include +#include "core/document.h" #include "guiutils.h" +#define FILEATTACH_ICONSIZE 48 + PixmapPreviewSelector::PixmapPreviewSelector( QWidget * parent ) : QWidget( parent ) { @@ -132,6 +137,9 @@ AnnotationWidget * AnnotationWidgetFactory::widgetFor( Okular::Annotation * ann case Okular::Annotation::AGeom: return new GeomAnnotationWidget( ann ); break; + case Okular::Annotation::AFileAttachment: + return new FileAttachmentAnnotationWidget( ann ); + break; // shut up gcc default: ; @@ -142,7 +150,7 @@ AnnotationWidget * AnnotationWidgetFactory::widgetFor( Okular::Annotation * ann AnnotationWidget::AnnotationWidget( Okular::Annotation * ann ) - : QObject(), m_ann( ann ), m_styleWidget( 0 ) + : QObject(), m_ann( ann ), m_styleWidget( 0 ), m_extraWidget( 0 ) { } @@ -164,6 +172,20 @@ QWidget * AnnotationWidget::styleWidget() return m_styleWidget; } +QWidget * AnnotationWidget::extraWidget() +{ + if ( m_extraWidget ) + return m_extraWidget; + + m_extraWidget = createExtraWidget(); + return m_extraWidget; +} + +QWidget * AnnotationWidget::createExtraWidget() +{ + return 0; +} + TextAnnotationWidget::TextAnnotationWidget( Okular::Annotation * ann ) : AnnotationWidget( ann ), m_pixmapSelector( 0 ) @@ -455,4 +477,61 @@ void GeomAnnotationWidget::applyChanges() m_geomAnn->style().setWidth( m_spinSize->value() ); } + + +FileAttachmentAnnotationWidget::FileAttachmentAnnotationWidget( Okular::Annotation * ann ) + : AnnotationWidget( ann ) +{ + m_attachAnn = static_cast< Okular::FileAttachmentAnnotation * >( ann ); +} + +QWidget * FileAttachmentAnnotationWidget::createStyleWidget() +{ + return 0; +} + +QWidget * FileAttachmentAnnotationWidget::createExtraWidget() +{ + QWidget * widget = new QWidget(); + widget->setWindowTitle( i18nc( "'File' as normal file, that can be opened, saved, etc..", "File" ) ); + + Okular::EmbeddedFile *ef = m_attachAnn->embeddedFile(); + const int size = ef->size(); + const QString sizeString = size <= 0 ? i18nc( "Not available size", "N/A" ) : KGlobal::locale()->formatByteSize( size ); + + QGridLayout * lay = new QGridLayout( widget ); + lay->setMargin( 0 ); + QLabel * tmplabel = new QLabel( i18n( "Name: %1", ef->name() ), widget ); + tmplabel->setTextInteractionFlags( Qt::TextSelectableByMouse ); + lay->addWidget( tmplabel, 0, 0 ); + + tmplabel = new QLabel( i18n( "Size: %1", sizeString ), widget ); + tmplabel->setTextInteractionFlags( Qt::TextSelectableByMouse ); + lay->addWidget( tmplabel, 1, 0 ); + + tmplabel = new QLabel( i18n( "Description:" ), widget ); + lay->addWidget( tmplabel, 2, 0 ); + tmplabel = new KSqueezedTextLabel( ef->description(), widget ); + tmplabel->setTextInteractionFlags( Qt::TextSelectableByMouse ); + lay->addWidget( tmplabel, 3, 0, 1, 2 ); + + KMimeType::Ptr mime = KMimeType::findByPath( ef->name(), 0, true ); + if ( mime ) + { + tmplabel = new QLabel( widget ); + tmplabel->setPixmap( KIcon( mime->iconName() ).pixmap( FILEATTACH_ICONSIZE, FILEATTACH_ICONSIZE ) ); + tmplabel->setFixedSize( FILEATTACH_ICONSIZE, FILEATTACH_ICONSIZE ); + lay->addWidget( tmplabel, 0, 1, 3, 1, Qt::AlignTop ); + } + + lay->addItem( new QSpacerItem( 5, 5, QSizePolicy::Fixed, QSizePolicy::MinimumExpanding ), 4, 0 ); + + return widget; +} + +void FileAttachmentAnnotationWidget::applyChanges() +{ +} + + #include "annotationwidgets.moc" diff --git a/ui/annotationwidgets.h b/ui/annotationwidgets.h index fd5a0f5d8..12834459e 100644 --- a/ui/annotationwidgets.h +++ b/ui/annotationwidgets.h @@ -76,6 +76,7 @@ public: virtual Okular::Annotation::SubType annotationType() const; QWidget * styleWidget(); + QWidget * extraWidget(); virtual void applyChanges() = 0; @@ -86,9 +87,11 @@ protected: AnnotationWidget( Okular::Annotation * ann ); virtual QWidget * createStyleWidget() = 0; + virtual QWidget * createExtraWidget(); Okular::Annotation * m_ann; QWidget * m_styleWidget; + QWidget * m_extraWidget; }; class TextAnnotationWidget @@ -188,4 +191,22 @@ private: QDoubleSpinBox * m_spinSize; }; +class FileAttachmentAnnotationWidget + : public AnnotationWidget +{ + Q_OBJECT + +public: + FileAttachmentAnnotationWidget( Okular::Annotation * ann ); + + virtual void applyChanges(); + +protected: + virtual QWidget * createStyleWidget(); + virtual QWidget * createExtraWidget(); + +private: + Okular::FileAttachmentAnnotation * m_attachAnn; +}; + #endif