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
remotes/origin/KDE/4.1
Pino Toscano 18 years ago
parent 48058c4743
commit 5fc6a887c0
  1. 6
      ui/annotationpropertiesdialog.cpp
  2. 81
      ui/annotationwidgets.cpp
  3. 21
      ui/annotationwidgets.h

@ -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() ) );

@ -19,12 +19,17 @@
#include <kcolorbutton.h>
#include <kcombobox.h>
#include <kfontrequester.h>
#include <kicon.h>
#include <kiconloader.h>
#include <klocale.h>
#include <kdebug.h>
#include <ksqueezedtextlabel.h>
#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"

@ -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

Loading…
Cancel
Save