detailsviewcontainer.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <qcombobox.h>
00025 #include <qframe.h>
00026 #include <qlabel.h>
00027 #include <qlayout.h>
00028 #include <qwidgetstack.h>
00029
00030 #include <kapplication.h>
00031 #include <kdebug.h>
00032 #include <kdialog.h>
00033
00034 #include "look_basic.h"
00035
00036 #include "look_html.h"
00037
00038 #include "detailsviewcontainer.h"
00039
00040 ViewContainer::ViewContainer( QWidget *parent, const char* name )
00041 : QWidget( parent, name ), mCurrentLook( 0 )
00042 {
00043 QBoxLayout *topLayout = new QVBoxLayout( this );
00044 topLayout->setMargin( KDialog::marginHint() );
00045 topLayout->setSpacing( KDialog::spacingHint() );
00046
00047 QBoxLayout *styleLayout = new QHBoxLayout( topLayout );
00048
00049 QLabel *label = new QLabel( i18n("Style:"), this );
00050 styleLayout->addWidget( label );
00051
00052 mStyleCombo = new QComboBox( this );
00053 styleLayout->addWidget( mStyleCombo );
00054
00055 QFrame *frameRuler = new QFrame( this );
00056 frameRuler->setFrameShape( QFrame::HLine );
00057 frameRuler->setFrameShadow( QFrame::Sunken );
00058 topLayout->addWidget( frameRuler );
00059
00060 mDetailsStack = new QWidgetStack( this );
00061 topLayout->addWidget( mDetailsStack, 1 );
00062
00063 registerLooks();
00064
00065 #if 1
00066
00067
00068 label->hide();
00069 mStyleCombo->hide();
00070 frameRuler->hide();
00071 #endif
00072 }
00073
00074 KABBasicLook *ViewContainer::currentLook()
00075 {
00076 return mCurrentLook;
00077 }
00078
00079 void ViewContainer::registerLooks()
00080 {
00081 mLookFactories.append( new KABHtmlViewFactory( mDetailsStack ) );
00082
00083 mStyleCombo->clear();
00084
00085 for ( uint i = 0; i < mLookFactories.count(); ++i )
00086 mStyleCombo->insertItem( mLookFactories.at( i )->description() );
00087
00088 if ( !mLookFactories.isEmpty() )
00089 slotStyleSelected( 0 );
00090 }
00091
00092 void ViewContainer::slotStyleSelected( int index )
00093 {
00094 KConfig *config = kapp->config();
00095 KABC::Addressee addr;
00096
00097 if ( index >= 0 && index < mStyleCombo->count() ) {
00098 if ( mCurrentLook != 0 ) {
00099 mCurrentLook->saveSettings( config );
00100 addr = mCurrentLook->addressee();
00101
00102 delete mCurrentLook;
00103 mCurrentLook = 0;
00104 }
00105
00106 KABLookFactory *factory = mLookFactories.at( index );
00107 kdDebug(5720) << "ViewContainer::slotStyleSelected: "
00108 << "creating look "
00109 << factory->description() << endl;
00110
00111 mCurrentLook = factory->create();
00112 mDetailsStack->raiseWidget( mCurrentLook );
00113
00114 connect( mCurrentLook, SIGNAL( sendEmail( const QString& ) ), this,
00115 SIGNAL( sendEmail( const QString& ) ) );
00116 connect( mCurrentLook, SIGNAL( browse( const QString& ) ), this,
00117 SIGNAL( browse( const QString& ) ) );
00118 }
00119
00120 mCurrentLook->restoreSettings( config );
00121 mCurrentLook->setAddressee( addr );
00122 }
00123
00124 void ViewContainer::setAddressee( const KABC::Addressee& addressee )
00125 {
00126 if ( mCurrentLook != 0 ) {
00127 if ( addressee == mCurrentAddressee )
00128 return;
00129 else {
00130 mCurrentAddressee = addressee;
00131 mCurrentLook->setAddressee( mCurrentAddressee );
00132 }
00133 }
00134 }
00135
00136 KABC::Addressee ViewContainer::addressee()
00137 {
00138 static KABC::Addressee empty;
00139
00140 if ( !mCurrentLook )
00141 return empty;
00142 else
00143 return mCurrentLook->addressee();
00144 }
00145
00146 void ViewContainer::setReadOnly( bool state )
00147 {
00148 if ( mCurrentLook )
00149 mCurrentLook->setReadOnly( state );
00150 }
00151
00152 #include "detailsviewcontainer.moc"
This file is part of the documentation for kaddressbook Library Version 3.2.2.