kaddressbook Library API Documentation

detailsviewcontainer.cpp

00001 #include "detailsviewcontainer.h"
00002 #include "detailsviewcontainer.moc"
00003 
00004 #include <qcombobox.h>
00005 #include <qframe.h>
00006 #include <qlayout.h>
00007 #include <qlabel.h>
00008 #include <qwidgetstack.h>
00009 
00010 #include <kdebug.h>
00011 #include <kapplication.h>
00012 
00013 #include "look_basic.h"
00014 #include "look_details.h"
00015 
00016 ViewContainer::ViewContainer(QWidget *parent, const char* name )
00017     : QWidget(parent, name),
00018       m_look(0)
00019 {
00020     QBoxLayout *topLayout = new QVBoxLayout( this );
00021     topLayout->setMargin( 3 );
00022     topLayout->setSpacing( 3 );
00023 
00024     QBoxLayout *styleLayout = new QHBoxLayout( topLayout );    
00025 
00026     QLabel *tlStyle = new QLabel( i18n("Style:"), this );
00027     styleLayout->addWidget( tlStyle );
00028 
00029     cbStyle = new QComboBox( this );
00030     styleLayout->addWidget( cbStyle );
00031 
00032     QFrame *frameRuler = new QFrame( this );
00033     frameRuler->setFrameShape( QFrame::HLine );
00034     frameRuler->setFrameShadow( QFrame::Sunken );
00035     topLayout->addWidget( frameRuler );
00036 
00037     frameDetails = new QWidgetStack( this );
00038     topLayout->addWidget( frameDetails, 1 );
00039 
00040     registerLooks();
00041 
00042 #if 1
00043     // Hide detailed view selection combo box, because we currently have
00044     // only one. Reenable it when there are more detailed views.
00045     tlStyle->hide();
00046     cbStyle->hide();
00047     frameRuler->hide();
00048 #endif
00049 }
00050 
00051 
00052 KABBasicLook *ViewContainer::look()
00053 {
00054     return m_look;
00055 }
00056 
00057 void ViewContainer::registerLooks()
00058 {
00059     m_lookFactories.append(new KABDetailedViewFactory(frameDetails));
00060     cbStyle->clear();
00061     for(unsigned int i=0; i<m_lookFactories.count(); ++i)
00062     {
00063         cbStyle->insertItem(m_lookFactories.at(i)->description());
00064     }
00065     // selected first look:
00066     if(!m_lookFactories.isEmpty())
00067     {
00068         slotStyleSelected(0);
00069     }
00070 }
00071 
00072 void ViewContainer::slotStyleSelected(int index)
00073 {
00074     KConfig *config;
00075     if(index>=0 && index<cbStyle->count())
00076     {
00077         if(m_look!=0)
00078         {
00079             // WORK_TO_DO: save changes
00080             delete m_look;
00081             m_look=0;
00082         }
00083         KABLookFactory *factory=m_lookFactories.at(index);
00084         kdDebug() << "ViewContainer::slotStyleSelected: "
00085                   << "creating look "
00086                   << factory->description() << endl;
00087         m_look=factory->create();
00088         frameDetails->raiseWidget( m_look );
00089         connect(m_look, SIGNAL(sendEmail(const QString&)), this,
00090                 SIGNAL(sendEmail(const QString&)));
00091         connect(m_look, SIGNAL(browse(const QString&)), this,
00092                 SIGNAL(browse(const QString&)));
00093     }
00094     // WORK_TO_DO: set current entry
00095     // ----- configure the style:
00096     config=kapp->config();
00097     m_look->configure(config);
00098 }
00099 
00100 void ViewContainer::setAddressee(const KABC::Addressee& addressee)
00101 {
00102   if( m_look != 0 ) {
00103     m_look->setEntry(addressee);
00104   }
00105 }
00106 
00107 KABC::Addressee ViewContainer::addressee()
00108 {
00109     static KABC::Addressee empty; // do not use!
00110     if(m_look==0)
00111     {
00112         return empty;
00113     } else {
00114         return m_look->entry();
00115     }
00116 }
00117 
00118 void ViewContainer::setReadonly(bool state)
00119 {
00120     if(m_look!=0)
00121     {
00122         m_look->setReadonly(state);
00123     }
00124 }
00125 
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:40:36 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001