author | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
commit | b9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff) | |
tree | 2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /kaddressbook/details/detailsviewcontainer.cpp | |
download | kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2 |
Initial revision
Diffstat (limited to 'kaddressbook/details/detailsviewcontainer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/details/detailsviewcontainer.cpp | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/kaddressbook/details/detailsviewcontainer.cpp b/kaddressbook/details/detailsviewcontainer.cpp new file mode 100644 index 0000000..8f566cf --- a/dev/null +++ b/kaddressbook/details/detailsviewcontainer.cpp | |||
@@ -0,0 +1,171 @@ | |||
1 | /* | ||
2 | This file is part of KAddressBook. | ||
3 | Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org> | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software | ||
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
18 | |||
19 | As a special exception, permission is given to link this program | ||
20 | with any edition of Qt, and distribute the resulting executable, | ||
21 | without including the source code for Qt in the source distribution. | ||
22 | */ | ||
23 | |||
24 | #include <qcombobox.h> | ||
25 | #include <qframe.h> | ||
26 | #include <qlabel.h> | ||
27 | #include <qlayout.h> | ||
28 | #include <qwidgetstack.h> | ||
29 | |||
30 | #include <kapplication.h> | ||
31 | #include <kdebug.h> | ||
32 | #include <kdialog.h> | ||
33 | |||
34 | #include "look_basic.h" | ||
35 | //#include "look_details.h" | ||
36 | #include "look_html.h" | ||
37 | |||
38 | #ifdef KAB_EMBEDDED | ||
39 | #include "kabprefs.h" | ||
40 | #endif //KAB_EMBEDDED | ||
41 | |||
42 | |||
43 | #include "detailsviewcontainer.h" | ||
44 | |||
45 | ViewContainer::ViewContainer( QWidget *parent, const char* name ) | ||
46 | : QWidget( parent, name ), mCurrentLook( 0 ) | ||
47 | { | ||
48 | QBoxLayout *topLayout = new QVBoxLayout( this ); | ||
49 | //topLayout->setMargin( KDialog::marginHint() ); | ||
50 | //topLayout->setSpacing( KDialog::spacingHint() ); | ||
51 | topLayout->setMargin( 0 ); | ||
52 | topLayout->setSpacing( 0 ); | ||
53 | |||
54 | QBoxLayout *styleLayout = new QHBoxLayout( topLayout ); | ||
55 | |||
56 | QLabel *label = new QLabel( i18n("Style:"), this ); | ||
57 | styleLayout->addWidget( label ); | ||
58 | |||
59 | mStyleCombo = new QComboBox( this ); | ||
60 | styleLayout->addWidget( mStyleCombo ); | ||
61 | |||
62 | QFrame *frameRuler = new QFrame( this ); | ||
63 | //US frameRuler->setFrameShape( QFrame::HLine ); | ||
64 | //US frameRuler->setFrameShadow( QFrame::Sunken ); | ||
65 | //US topLayout->addWidget( frameRuler ); | ||
66 | |||
67 | mDetailsStack = new QWidgetStack( this ); | ||
68 | topLayout->addWidget( mDetailsStack, 1 ); | ||
69 | |||
70 | registerLooks(); | ||
71 | |||
72 | #if 1 | ||
73 | // Hide detailed view selection combo box, because we currently have | ||
74 | // only one. Reenable it when there are more detailed views. | ||
75 | label->hide(); | ||
76 | mStyleCombo->hide(); | ||
77 | frameRuler->hide(); | ||
78 | #endif | ||
79 | } | ||
80 | |||
81 | KABBasicLook *ViewContainer::currentLook() | ||
82 | { | ||
83 | return mCurrentLook; | ||
84 | } | ||
85 | |||
86 | void ViewContainer::registerLooks() | ||
87 | { | ||
88 | mLookFactories.append( new KABHtmlViewFactory( mDetailsStack ) ); | ||
89 | // mLookFactories.append( new KABDetailedViewFactory( mDetailsStack ) ); | ||
90 | mStyleCombo->clear(); | ||
91 | |||
92 | for ( uint i = 0; i < mLookFactories.count(); ++i ) | ||
93 | mStyleCombo->insertItem( mLookFactories.at( i )->description() ); | ||
94 | |||
95 | if ( !mLookFactories.isEmpty() ) | ||
96 | slotStyleSelected( 0 ); | ||
97 | } | ||
98 | |||
99 | void ViewContainer::slotStyleSelected( int index ) | ||
100 | { | ||
101 | #ifndef KAB_EMBEDDED | ||
102 | KConfig *config = kapp->config(); | ||
103 | #else //KAB_EMBEDDED | ||
104 | //US I hope I got the same config object as above expected. | ||
105 | KConfig *config = KABPrefs::instance()->getConfig(); | ||
106 | #endif //KAB_EMBEDDED | ||
107 | KABC::Addressee addr; | ||
108 | |||
109 | if ( index >= 0 && index < mStyleCombo->count() ) { | ||
110 | if ( mCurrentLook != 0 ) { | ||
111 | mCurrentLook->saveSettings( config ); | ||
112 | addr = mCurrentLook->addressee(); | ||
113 | |||
114 | delete mCurrentLook; | ||
115 | mCurrentLook = 0; | ||
116 | } | ||
117 | |||
118 | KABLookFactory *factory = mLookFactories.at( index ); | ||
119 | kdDebug(5720) << "ViewContainer::slotStyleSelected: " | ||
120 | << "creating look " | ||
121 | << factory->description() << endl; | ||
122 | |||
123 | mCurrentLook = factory->create(); | ||
124 | mDetailsStack->raiseWidget( mCurrentLook ); | ||
125 | |||
126 | connect( mCurrentLook, SIGNAL( sendEmail( const QString& ) ), this, | ||
127 | SIGNAL( sendEmail( const QString& ) ) ); | ||
128 | connect( mCurrentLook, SIGNAL( browse( const QString& ) ), this, | ||
129 | SIGNAL( browse( const QString& ) ) ); | ||
130 | } | ||
131 | |||
132 | mCurrentLook->restoreSettings( config ); | ||
133 | mCurrentLook->setAddressee( addr ); | ||
134 | } | ||
135 | void ViewContainer::refreshView() | ||
136 | { | ||
137 | if ( mCurrentLook ) | ||
138 | mCurrentLook->setAddressee( mCurrentAddressee ); | ||
139 | } | ||
140 | |||
141 | void ViewContainer::setAddressee( const KABC::Addressee& addressee ) | ||
142 | { | ||
143 | if ( mCurrentLook != 0 ) { | ||
144 | if ( addressee == mCurrentAddressee ) | ||
145 | return; | ||
146 | else { | ||
147 | mCurrentAddressee = addressee; | ||
148 | mCurrentLook->setAddressee( mCurrentAddressee ); | ||
149 | } | ||
150 | } | ||
151 | } | ||
152 | |||
153 | KABC::Addressee ViewContainer::addressee() | ||
154 | { | ||
155 | static KABC::Addressee empty; // do not use! | ||
156 | |||
157 | if ( !mCurrentLook ) | ||
158 | return empty; | ||
159 | else | ||
160 | return mCurrentLook->addressee(); | ||
161 | } | ||
162 | |||
163 | void ViewContainer::setReadOnly( bool state ) | ||
164 | { | ||
165 | if ( mCurrentLook ) | ||
166 | mCurrentLook->setReadOnly( state ); | ||
167 | } | ||
168 | |||
169 | #ifndef KAB_EMBEDDED | ||
170 | #include "detailsviewcontainer.moc" | ||
171 | #endif //KAB_EMBEDDED | ||