Annotations:

start a basic system for the annotation properties editing. Add a base class that will act as "interface", and a factory to create the right subclass depending on the annotation type.
Adapt the Annotation Properties dialog to interact with the annotation widget.
Add the editing support for Stamp Annotation (but the artwork are missing, grrr)

svn path=/trunk/playground/graphics/okular/; revision=583620
This commit is contained in:
Pino Toscano 2006-09-12 20:21:34 +00:00
parent aabe548eac
commit c3a4b37301
5 changed files with 218 additions and 0 deletions

View file

@ -74,6 +74,7 @@ set(okularpart_SRCS
ui/embeddedfilesdialog.cpp
ui/annotwindow.cpp
ui/annotationpropertiesdialog.cpp
ui/annotationwidgets.cpp
ui/minibar.cpp
ui/newstuff.cpp
ui/pagepainter.cpp

View file

@ -23,6 +23,7 @@
#include "core/page.h"
#include "core/annotations.h"
#include "annotationpropertiesdialog.h"
#include "annotationwidgets.h"
AnnotsPropertiesDialog::AnnotsPropertiesDialog(QWidget *parent,Annotation* ann)
@ -35,6 +36,7 @@ AnnotsPropertiesDialog::AnnotsPropertiesDialog(QWidget *parent,Annotation* ann)
connect( this, SIGNAL( applyClicked() ), this, SLOT( slotapply() ) );
connect( this, SIGNAL( okClicked() ), this, SLOT( slotapply() ) );
m_annotWidget = AnnotationWidgetFactory::widgetFor( ann );
QLabel* tmplabel;
//1. Appearance
@ -62,6 +64,9 @@ AnnotsPropertiesDialog::AnnotsPropertiesDialog(QWidget *parent,Annotation* ann)
tmplabel->setBuddy( m_opacity );
hlay->addWidget( m_opacity );
if ( m_annotWidget )
lay->addWidget( m_annotWidget->widget() );
lay->addItem( new QSpacerItem( 5, 5, QSizePolicy::Fixed, QSizePolicy::Expanding ) );
//END tab1
@ -166,6 +171,9 @@ void AnnotsPropertiesDialog::slotapply()
m_annot->modifyDate=QDateTime::currentDateTime();
m_annot->flags=flagsEdit->text().toInt();
m_annot->style.opacity = (double)m_opacity->value() / 100.0;
if ( m_annotWidget )
m_annotWidget->applyChanges();
}
#include "annotationpropertiesdialog.moc"

View file

@ -16,6 +16,7 @@ class QLineEdit;
class KColorButton;
class KIntNumInput;
class Annotation;
class AnnotationWidget;
class KPDFDocument;
class AnnotsPropertiesDialog : public KPageDialog
@ -36,6 +37,7 @@ private:
*boundaryEdit;
KColorButton *colorBn;
KIntNumInput *m_opacity;
AnnotationWidget *m_annotWidget;
void setCaptionTextbyAnnotType();

137
ui/annotationwidgets.cpp Normal file
View file

@ -0,0 +1,137 @@
/***************************************************************************
* Copyright (C) 2006 by Pino Toscano <pino@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
// qt/kde includes
/*
#include <qframe.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qheaderview.h>
#include <kcolorbutton.h>
#include <kicon.h>
#include <knuminput.h>
*/
#include <qcombobox.h>
#include <qgroupbox.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qwidget.h>
#include <kiconloader.h>
#include <klocale.h>
// local includes
#include "annotationwidgets.h"
AnnotationWidget * AnnotationWidgetFactory::widgetFor( Annotation * ann )
{
switch ( ann->subType() )
{
case Annotation::AStamp:
return new StampAnnotationWidget( ann );
break;
// shut up gcc
default:
;
}
// cases not covered yet
return 0;
}
AnnotationWidget::AnnotationWidget( Annotation * ann )
: QObject(), m_ann( ann )
{
}
AnnotationWidget::~AnnotationWidget()
{
}
Annotation::SubType AnnotationWidget::annotationType()
{
return m_ann->subType();
}
StampAnnotationWidget::StampAnnotationWidget( Annotation * ann )
: AnnotationWidget( ann ), m_widget( 0 ), m_iconLabel( 0 )
{
m_stampAnn = static_cast< StampAnnotation * >( ann );
}
QWidget * StampAnnotationWidget::widget()
{
if ( m_widget )
return m_widget;
m_widget = new QWidget();
QVBoxLayout * lay = new QVBoxLayout( m_widget );
lay->setMargin( 0 );
QGroupBox * gb = new QGroupBox( m_widget );
lay->addWidget( gb );
gb->setTitle( i18n( "Stamp Symbol" ) );
QHBoxLayout * gblay = new QHBoxLayout( gb );
QComboBox * cb = new QComboBox( gb );
gblay->addWidget( cb );
m_iconLabel = new QLabel( gb );
gblay->addWidget( m_iconLabel );
m_iconLabel->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
m_iconLabel->setFixedSize( 40, 40 );
m_iconLabel->setAlignment( Qt::AlignCenter );
m_iconLabel->setFrameStyle( QFrame::StyledPanel );
// FIXME!!! use the standard names instead (when we'll have the artwork)
cb->addItem( "okular" );
cb->addItem( "kmenu" );
cb->addItem( "kttsd" );
cb->addItem( "password" );
cb->addItem( "Approved" );
#if 0
cb->addItem( "AsIs" );
cb->addItem( "Confidential" );
cb->addItem( "Departmental" );
cb->addItem( "Draft" );
cb->addItem( "Experimental" );
cb->addItem( "Expired" );
cb->addItem( "Final" );
cb->addItem( "ForComment" );
cb->addItem( "ForPublicRelease" );
cb->addItem( "NotApproved" );
cb->addItem( "NotForPublicRelease" );
cb->addItem( "Sold" );
cb->addItem( "TopSecret" );
#endif
connect( cb, SIGNAL( currentIndexChanged( const QString& ) ), this, SLOT( iconChanged( const QString& ) ) );
// fire the event manually
iconChanged( m_stampAnn->stampIconName );
int id = cb->findText( m_currentIcon );
if ( id > -1 )
cb->setCurrentIndex( id );
return m_widget;
}
void StampAnnotationWidget::applyChanges()
{
m_stampAnn->stampIconName = m_currentIcon;
}
void StampAnnotationWidget::iconChanged( const QString& icon )
{
if ( !m_iconLabel ) return;
m_currentIcon = icon;
QPixmap pixmap = DesktopIcon( icon, 32 );
m_iconLabel->setPixmap( pixmap );
}
#include "annotationwidgets.moc"

70
ui/annotationwidgets.h Normal file
View file

@ -0,0 +1,70 @@
/***************************************************************************
* Copyright (C) 2006 by Pino Toscano <pino@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef _ANNOTATIONWIDGETS_H_
#define _ANNOTATIONWIDGETS_H_
#include "core/annotations.h"
class QLabel;
class QWidget;
class AnnotationWidget;
/**
* A factory to create AnnotationWidget's.
*/
class AnnotationWidgetFactory
{
public:
static AnnotationWidget * widgetFor( Annotation * ann );
};
class AnnotationWidget
: public QObject
{
Q_OBJECT
public:
virtual ~AnnotationWidget();
virtual Annotation::SubType annotationType();
virtual QWidget * widget() = 0;
virtual void applyChanges() = 0;
protected:
AnnotationWidget( Annotation * ann );
Annotation * m_ann;
};
class StampAnnotationWidget
: public AnnotationWidget
{
Q_OBJECT
public:
StampAnnotationWidget( Annotation * ann );
virtual QWidget * widget();
virtual void applyChanges();
private slots:
void iconChanged( const QString& );
private:
StampAnnotation * m_stampAnn;
QWidget * m_widget;
QLabel * m_iconLabel;
QString m_currentIcon;
};
#endif