extract a PixmapPreviewSelector out of the StampAnnotationWidget

svn path=/trunk/playground/graphics/okular/; revision=583857
remotes/origin/KDE/4.0
Pino Toscano 20 years ago
parent 702f234c2a
commit a6dfc76123
  1. 134
      ui/annotationwidgets.cpp
  2. 40
      ui/annotationwidgets.h

@ -22,12 +22,75 @@
#include <qlabel.h> #include <qlabel.h>
#include <qlayout.h> #include <qlayout.h>
#include <qwidget.h> #include <qwidget.h>
#include <kglobal.h>
#include <kiconloader.h> #include <kiconloader.h>
#include <klocale.h> #include <klocale.h>
// local includes // local includes
#include "annotationwidgets.h" #include "annotationwidgets.h"
PixmapPreviewSelector::PixmapPreviewSelector( QWidget * parent )
: QWidget( parent )
{
QHBoxLayout * mainlay = new QHBoxLayout( this );
mainlay->setMargin( 0 );
m_comboItems = new QComboBox( this );
mainlay->addWidget( m_comboItems );
m_iconLabel = new QLabel( this );
mainlay->addWidget( m_iconLabel );
m_iconLabel->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
m_iconLabel->setAlignment( Qt::AlignCenter );
m_iconLabel->setFrameStyle( QFrame::StyledPanel );
setPreviewSize( 32 );
connect( m_comboItems, SIGNAL( currentIndexChanged( const QString& ) ), this, SLOT( iconComboChanged( const QString& ) ) );
connect( m_comboItems, SIGNAL( currentIndexChanged( const QString& ) ), this, SIGNAL( iconChanged( const QString& ) ) );
}
PixmapPreviewSelector::~PixmapPreviewSelector()
{
}
void PixmapPreviewSelector::setIcon( const QString& icon )
{
int id = m_comboItems->findText( icon );
if ( id > -1 )
{
m_comboItems->setCurrentIndex( id );
}
}
QString PixmapPreviewSelector::icon() const
{
return m_icon;
}
void PixmapPreviewSelector::setItems( const QStringList& items )
{
m_comboItems->addItems( items );
setIcon( m_icon );
}
void PixmapPreviewSelector::setPreviewSize( int size )
{
m_previewSize = size;
m_iconLabel->setFixedSize( m_previewSize + 8, m_previewSize + 8 );
iconComboChanged( m_icon );
}
int PixmapPreviewSelector::previewSize() const
{
return m_previewSize;
}
void PixmapPreviewSelector::iconComboChanged( const QString& icon )
{
m_icon = icon;
QPixmap pixmap = KGlobal::iconLoader()->loadIcon( m_icon, K3Icon::NoGroup, m_previewSize );
m_iconLabel->setPixmap( pixmap );
}
AnnotationWidget * AnnotationWidgetFactory::widgetFor( Annotation * ann ) AnnotationWidget * AnnotationWidgetFactory::widgetFor( Annotation * ann )
{ {
switch ( ann->subType() ) switch ( ann->subType() )
@ -60,7 +123,7 @@ Annotation::SubType AnnotationWidget::annotationType()
StampAnnotationWidget::StampAnnotationWidget( Annotation * ann ) StampAnnotationWidget::StampAnnotationWidget( Annotation * ann )
: AnnotationWidget( ann ), m_widget( 0 ), m_iconLabel( 0 ) : AnnotationWidget( ann ), m_widget( 0 ), m_pixmapSelector( 0 )
{ {
m_stampAnn = static_cast< StampAnnotation * >( ann ); m_stampAnn = static_cast< StampAnnotation * >( ann );
} }
@ -77,61 +140,44 @@ QWidget * StampAnnotationWidget::widget()
lay->addWidget( gb ); lay->addWidget( gb );
gb->setTitle( i18n( "Stamp Symbol" ) ); gb->setTitle( i18n( "Stamp Symbol" ) );
QHBoxLayout * gblay = new QHBoxLayout( gb ); QHBoxLayout * gblay = new QHBoxLayout( gb );
QComboBox * cb = new QComboBox( gb ); m_pixmapSelector = new PixmapPreviewSelector( gb );
gblay->addWidget( cb ); gblay->addWidget( m_pixmapSelector );
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 );
QStringList items;
// FIXME!!! use the standard names instead (when we'll have the artwork) // FIXME!!! use the standard names instead (when we'll have the artwork)
cb->addItem( "okular" ); items
cb->addItem( "kmenu" ); << "okular"
cb->addItem( "kttsd" ); << "kmenu"
cb->addItem( "password" ); << "kttsd"
cb->addItem( "Approved" ); << "password";
#if 0 #if 0
cb->addItem( "AsIs" ); << "Approved"
cb->addItem( "Confidential" ); << "AsIs"
cb->addItem( "Departmental" ); << "Confidential"
cb->addItem( "Draft" ); << "Departmental"
cb->addItem( "Experimental" ); << "Draft"
cb->addItem( "Expired" ); << "Experimental"
cb->addItem( "Final" ); << "Expired"
cb->addItem( "ForComment" ); << "Final"
cb->addItem( "ForPublicRelease" ); << "ForComment"
cb->addItem( "NotApproved" ); << "ForPublicRelease"
cb->addItem( "NotForPublicRelease" ); << "NotApproved"
cb->addItem( "Sold" ); << "NotForPublicRelease"
cb->addItem( "TopSecret" ); << "Sold"
<< "TopSecret";
#endif #endif
m_pixmapSelector->setItems( items );
connect( cb, SIGNAL( currentIndexChanged( const QString& ) ), this, SLOT( iconChanged( const QString& ) ) ); m_pixmapSelector->setIcon( m_stampAnn->stampIconName );
m_pixmapSelector->setPreviewSize( 64 );
// fire the event manually
iconChanged( m_stampAnn->stampIconName );
int id = cb->findText( m_currentIcon );
if ( id > -1 )
cb->setCurrentIndex( id );
return m_widget; return m_widget;
} }
void StampAnnotationWidget::applyChanges() void StampAnnotationWidget::applyChanges()
{ {
m_stampAnn->stampIconName = m_currentIcon; m_stampAnn->stampIconName = m_pixmapSelector->icon();
} }
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" #include "annotationwidgets.moc"

@ -10,12 +10,46 @@
#ifndef _ANNOTATIONWIDGETS_H_ #ifndef _ANNOTATIONWIDGETS_H_
#define _ANNOTATIONWIDGETS_H_ #define _ANNOTATIONWIDGETS_H_
#include <qwidget.h>
#include "core/annotations.h" #include "core/annotations.h"
class QComboBox;
class QLabel; class QLabel;
class QWidget; class QWidget;
class AnnotationWidget; class AnnotationWidget;
class PixmapPreviewSelector
: public QWidget
{
Q_OBJECT
public:
explicit PixmapPreviewSelector( QWidget * parent = 0 );
virtual ~PixmapPreviewSelector();
void setIcon( const QString& icon );
QString icon() const;
void setItems( const QStringList& items );
void setPreviewSize( int size );
int previewSize() const;
signals:
void iconChanged( const QString& );
private slots:
void iconComboChanged( const QString& icon );
private:
QString m_icon;
QLabel * m_iconLabel;
QComboBox * m_comboItems;
int m_previewSize;
};
/** /**
* A factory to create AnnotationWidget's. * A factory to create AnnotationWidget's.
*/ */
@ -57,14 +91,10 @@ public:
virtual void applyChanges(); virtual void applyChanges();
private slots:
void iconChanged( const QString& );
private: private:
StampAnnotation * m_stampAnn; StampAnnotation * m_stampAnn;
QWidget * m_widget; QWidget * m_widget;
QLabel * m_iconLabel; PixmapPreviewSelector * m_pixmapSelector;
QString m_currentIcon;
}; };
#endif #endif

Loading…
Cancel
Save