Annotation properties dialog: Moved color and opacity fields from the dialog to the config widget itself

This patch moves the Color and Opacity fields into the AnnotationWidget
class. This will allow future reuse of the same widget to configure
annotation tools.
Note that AnnotationWidget is no longer abstract: a base
AnnotationWidget object only contains the Color and Opacity fields.
remotes/origin/epub-qtextdoc
Fabio D'Urso 14 years ago
parent 32e0701333
commit 7f97f9c027
  1. 55
      ui/annotationpropertiesdialog.cpp
  2. 4
      ui/annotationpropertiesdialog.h
  3. 68
      ui/annotationwidgets.cpp
  4. 14
      ui/annotationwidgets.h

@ -15,11 +15,9 @@
#include <qlabel.h>
#include <qheaderview.h>
#include <qtextedit.h>
#include <kcolorbutton.h>
#include <kicon.h>
#include <klineedit.h>
#include <klocale.h>
#include <knuminput.h>
#include <kglobal.h>
// local includes
@ -54,43 +52,16 @@ AnnotsPropertiesDialog::AnnotsPropertiesDialog( QWidget *parent, Okular::Documen
QLabel* tmplabel;
//1. Appearance
//BEGIN tab1
QFrame *page = new QFrame( this );
addPage( page, i18n( "&Appearance" ) );
QGridLayout * gridlayout = new QGridLayout( page );
tmplabel = new QLabel( i18n( "&Color:" ), page );
gridlayout->addWidget( tmplabel, 0, 0, Qt::AlignRight );
colorBn = new KColorButton( page );
colorBn->setColor( ann->style().color() );
colorBn->setEnabled( canEditAnnotations );
tmplabel->setBuddy( colorBn );
gridlayout->addWidget( colorBn, 0, 1 );
tmplabel = new QLabel( i18n( "&Opacity:" ), page );
gridlayout->addWidget( tmplabel, 1, 0, Qt::AlignRight );
m_opacity = new KIntNumInput( page );
m_opacity->setRange( 0, 100 );
m_opacity->setValue( (int)( ann->style().opacity() * 100 ) );
m_opacity->setSuffix( i18nc( "Suffix for the opacity level, eg '80 %'", " %" ) );
m_opacity->setEnabled( canEditAnnotations );
tmplabel->setBuddy( m_opacity );
gridlayout->addWidget( m_opacity, 1, 1 );
QWidget * configWidget = 0;
if ( m_annotWidget && ( configWidget = m_annotWidget->styleWidget() ) )
{
gridlayout->addWidget( configWidget, 2, 0, 1, 2 );
configWidget->setEnabled( canEditAnnotations );
}
gridlayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Fixed, QSizePolicy::MinimumExpanding ), 3, 0 );
QWidget *appearanceWidget = m_annotWidget->appearanceWidget();
appearanceWidget->setEnabled( canEditAnnotations );
addPage( appearanceWidget, i18n( "&Appearance" ) );
//END tab1
//BEGIN tab 2
page = new QFrame( this );
QFrame* page = new QFrame( this );
addPage( page, i18n( "&General" ) );
// m_tabitem[1]->setIcon( KIcon( "fonts" ) );
gridlayout = new QGridLayout( page );
QGridLayout* gridlayout = new QGridLayout( page );
tmplabel = new QLabel( i18n( "&Author:" ), page );
AuthorEdit = new KLineEdit( ann->author(), page );
AuthorEdit->setEnabled( canEditAnnotations );
@ -111,20 +82,15 @@ 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() ) )
QWidget * extraWidget = m_annotWidget->extraWidget();
if ( extraWidget )
{
addPage( extraWidget, extraWidget->windowTitle() );
}
//BEGIN connections
connect( colorBn, SIGNAL(changed(QColor)), this, SLOT(setModified()) );
connect( m_opacity, SIGNAL(valueChanged(int)), this, SLOT(setModified()) );
connect( AuthorEdit, SIGNAL(textChanged(QString)), this, SLOT(setModified()) );
if ( m_annotWidget )
{
connect( m_annotWidget, SIGNAL(dataChanged()), this, SLOT(setModified()) );
}
connect( m_annotWidget, SIGNAL(dataChanged()), this, SLOT(setModified()) );
//END
#if 0
@ -200,11 +166,8 @@ void AnnotsPropertiesDialog::slotapply()
m_annot->setAuthor( AuthorEdit->text() );
m_annot->setModificationDate( QDateTime::currentDateTime() );
m_annot->style().setColor( colorBn->color() );
m_annot->style().setOpacity( (double)m_opacity->value() / 100.0 );
if ( m_annotWidget )
m_annotWidget->applyChanges();
m_annotWidget->applyChanges();
m_document->modifyPageAnnotation( m_page, m_annot );

@ -14,8 +14,6 @@
class QLabel;
class QLineEdit;
class KColorButton;
class KIntNumInput;
class AnnotationWidget;
namespace Okular {
@ -37,8 +35,6 @@ private:
Okular::Annotation* m_annot; //source annotation
//dialog widgets:
QLineEdit *AuthorEdit;
KColorButton *colorBn;
KIntNumInput *m_opacity;
AnnotationWidget *m_annotWidget;
QLabel *m_modifyDateLabel;

@ -22,6 +22,7 @@
#include <kicon.h>
#include <kiconloader.h>
#include <klocale.h>
#include <knuminput.h>
#include <kdebug.h>
#include "core/document.h"
@ -146,13 +147,13 @@ AnnotationWidget * AnnotationWidgetFactory::widgetFor( Okular::Annotation * ann
default:
;
}
// cases not covered yet
return 0;
// cases not covered yet: return a generic widget
return new AnnotationWidget( ann );
}
AnnotationWidget::AnnotationWidget( Okular::Annotation * ann )
: QObject(), m_ann( ann ), m_styleWidget( 0 ), m_extraWidget( 0 )
: QObject(), m_ann( ann ), m_appearanceWidget( 0 ), m_extraWidget( 0 )
{
}
@ -165,13 +166,13 @@ Okular::Annotation::SubType AnnotationWidget::annotationType() const
return m_ann->subType();
}
QWidget * AnnotationWidget::styleWidget()
QWidget * AnnotationWidget::appearanceWidget()
{
if ( m_styleWidget )
return m_styleWidget;
if ( m_appearanceWidget )
return m_appearanceWidget;
m_styleWidget = createStyleWidget();
return m_styleWidget;
m_appearanceWidget = createAppearanceWidget();
return m_appearanceWidget;
}
QWidget * AnnotationWidget::extraWidget()
@ -183,6 +184,50 @@ QWidget * AnnotationWidget::extraWidget()
return m_extraWidget;
}
void AnnotationWidget::applyChanges()
{
m_ann->style().setColor( m_colorBn->color() );
m_ann->style().setOpacity( (double)m_opacity->value() / 100.0 );
}
QWidget * AnnotationWidget::createAppearanceWidget()
{
QWidget * widget = new QWidget();
QGridLayout * gridlayout = new QGridLayout( widget );
QLabel * tmplabel = new QLabel( i18n( "&Color:" ), widget );
gridlayout->addWidget( tmplabel, 0, 0, Qt::AlignRight );
m_colorBn = new KColorButton( widget );
m_colorBn->setColor( m_ann->style().color() );
tmplabel->setBuddy( m_colorBn );
gridlayout->addWidget( m_colorBn, 0, 1 );
tmplabel = new QLabel( i18n( "&Opacity:" ), widget );
gridlayout->addWidget( tmplabel, 1, 0, Qt::AlignRight );
m_opacity = new KIntNumInput( widget );
m_opacity->setRange( 0, 100 );
m_opacity->setValue( (int)( m_ann->style().opacity() * 100 ) );
m_opacity->setSuffix( i18nc( "Suffix for the opacity level, eg '80 %'", " %" ) );
tmplabel->setBuddy( m_opacity );
gridlayout->addWidget( m_opacity, 1, 1 );
QWidget * styleWidget = createStyleWidget();
if ( styleWidget )
gridlayout->addWidget( styleWidget, 2, 0, 1, 2 );
gridlayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Fixed, QSizePolicy::MinimumExpanding ), 3, 0 );
connect( m_colorBn, SIGNAL(changed(QColor)), this, SIGNAL(dataChanged()) );
connect( m_opacity, SIGNAL(valueChanged(int)), this, SIGNAL(dataChanged()) );
return widget;
}
QWidget * AnnotationWidget::createStyleWidget()
{
return 0;
}
QWidget * AnnotationWidget::createExtraWidget()
{
return 0;
@ -238,6 +283,7 @@ QWidget * TextAnnotationWidget::createStyleWidget()
void TextAnnotationWidget::applyChanges()
{
AnnotationWidget::applyChanges();
if ( m_textAnn->textType() == Okular::TextAnnotation::Linked )
{
m_textAnn->setTextIcon( m_pixmapSelector->icon() );
@ -293,6 +339,7 @@ QWidget * StampAnnotationWidget::createStyleWidget()
void StampAnnotationWidget::applyChanges()
{
AnnotationWidget::applyChanges();
m_stampAnn->setStampIconName( m_pixmapSelector->icon() );
}
@ -365,6 +412,7 @@ QWidget * LineAnnotationWidget::createStyleWidget()
void LineAnnotationWidget::applyChanges()
{
AnnotationWidget::applyChanges();
if ( m_lineType == 0 )
{
m_lineAnn->setLineLeadingForwardPoint( m_spinLL->value() );
@ -407,6 +455,7 @@ QWidget * HighlightAnnotationWidget::createStyleWidget()
void HighlightAnnotationWidget::applyChanges()
{
AnnotationWidget::applyChanges();
m_hlAnn->setHighlightType( (Okular::HighlightAnnotation::HighlightType)m_typeCombo->currentIndex() );
}
@ -464,6 +513,7 @@ QWidget * GeomAnnotationWidget::createStyleWidget()
void GeomAnnotationWidget::applyChanges()
{
AnnotationWidget::applyChanges();
m_geomAnn->setGeometricalType( (Okular::GeomAnnotation::GeomType)m_typeCombo->currentIndex() );
if ( !m_useColor->isChecked() )
{
@ -553,6 +603,7 @@ QWidget * FileAttachmentAnnotationWidget::createExtraWidget()
void FileAttachmentAnnotationWidget::applyChanges()
{
AnnotationWidget::applyChanges();
m_attachAnn->setFileIconName( m_pixmapSelector->icon() );
}
@ -608,6 +659,7 @@ QWidget * CaretAnnotationWidget::createStyleWidget()
void CaretAnnotationWidget::applyChanges()
{
AnnotationWidget::applyChanges();
m_caretAnn->setCaretSymbol( caretSymbolFromIcon( m_pixmapSelector->icon() ) );
}

@ -20,6 +20,7 @@ class QDoubleSpinBox;
class QLabel;
class QWidget;
class KColorButton;
class KIntNumInput;
class KFontRequester;
class AnnotationWidget;
@ -71,27 +72,30 @@ class AnnotationWidget
Q_OBJECT
public:
AnnotationWidget( Okular::Annotation * ann );
virtual ~AnnotationWidget();
virtual Okular::Annotation::SubType annotationType() const;
QWidget * styleWidget();
QWidget * appearanceWidget();
QWidget * extraWidget();
virtual void applyChanges() = 0;
virtual void applyChanges();
signals:
void dataChanged();
protected:
AnnotationWidget( Okular::Annotation * ann );
QWidget * createAppearanceWidget();
virtual QWidget * createStyleWidget() = 0;
virtual QWidget * createStyleWidget();
virtual QWidget * createExtraWidget();
Okular::Annotation * m_ann;
QWidget * m_styleWidget;
QWidget * m_appearanceWidget;
QWidget * m_extraWidget;
KColorButton *m_colorBn;
KIntNumInput *m_opacity;
};
class TextAnnotationWidget

Loading…
Cancel
Save