author | ulf69 <ulf69> | 2004-10-22 03:17:57 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-10-22 03:17:57 (UTC) |
commit | d7ca0e5ca1346116145209b49ae62abeefebdb5f (patch) (unidiff) | |
tree | 29080282472aa29ebe3a8ebd4e47837e18e0b51b /microkde | |
parent | e81c11b59475d934608c7253d2862933d497d1f8 (diff) | |
download | kdepimpi-d7ca0e5ca1346116145209b49ae62abeefebdb5f.zip kdepimpi-d7ca0e5ca1346116145209b49ae62abeefebdb5f.tar.gz kdepimpi-d7ca0e5ca1346116145209b49ae62abeefebdb5f.tar.bz2 |
added include statement to make it buildable on all systems
-rw-r--r-- | microkde/kdeui/kjanuswidget.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/microkde/kdeui/kjanuswidget.cpp b/microkde/kdeui/kjanuswidget.cpp index 7d25854..462c44f 100644 --- a/microkde/kdeui/kjanuswidget.cpp +++ b/microkde/kdeui/kjanuswidget.cpp | |||
@@ -1,1176 +1,1177 @@ | |||
1 | /* This file is part of the KDE Libraries | 1 | /* This file is part of the KDE Libraries |
2 | * Copyright (C) 1999-2000 Espen Sand (espensa@online.no) | 2 | * Copyright (C) 1999-2000 Espen Sand (espensa@online.no) |
3 | * Copyright (C) 2003 Ravikiran Rajagopal (ravi@kde.org) | 3 | * Copyright (C) 2003 Ravikiran Rajagopal (ravi@kde.org) |
4 | * | 4 | * |
5 | * This library is free software; you can redistribute it and/or | 5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Library General Public | 6 | * modify it under the terms of the GNU Library General Public |
7 | * License as published by the Free Software Foundation; either | 7 | * License as published by the Free Software Foundation; either |
8 | * version 2 of the License, or (at your option) any later version. | 8 | * version 2 of the License, or (at your option) any later version. |
9 | * | 9 | * |
10 | * This library is distributed in the hope that it will be useful, | 10 | * This library is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Library General Public License for more details. | 13 | * Library General Public License for more details. |
14 | * | 14 | * |
15 | * You should have received a copy of the GNU Library General Public License | 15 | * You should have received a copy of the GNU Library General Public License |
16 | * along with this library; see the file COPYING.LIB. If not, write to | 16 | * along with this library; see the file COPYING.LIB. If not, write to |
17 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | * Boston, MA 02111-1307, USA. | 18 | * Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <qpixmap.h> | 21 | #include <qpixmap.h> |
22 | #include <qbitmap.h> | 22 | #include <qbitmap.h> |
23 | #include <qlayout.h> | 23 | #include <qlayout.h> |
24 | #include <qlabel.h> | 24 | #include <qlabel.h> |
25 | #include <qwidgetstack.h> | 25 | #include <qwidgetstack.h> |
26 | #include <qtabwidget.h> | 26 | #include <qtabwidget.h> |
27 | #include <qlistview.h> | 27 | #include <qlistview.h> |
28 | #include <qhbox.h> | 28 | #include <qhbox.h> |
29 | #include <qvbox.h> | 29 | #include <qvbox.h> |
30 | #include <qgrid.h> | 30 | #include <qgrid.h> |
31 | #include <qpainter.h> | 31 | #include <qpainter.h> |
32 | #include <qobjectlist.h> | 32 | #include <qobjectlist.h> |
33 | 33 | #include <qstringlist.h> | |
34 | /*US | 34 | /*US |
35 | #include <qbitmap.h> | 35 | #include <qbitmap.h> |
36 | #include <qgrid.h> | 36 | #include <qgrid.h> |
37 | #include <qhbox.h> | 37 | #include <qhbox.h> |
38 | #include <qheader.h> | 38 | #include <qheader.h> |
39 | #include <qlabel.h> | 39 | #include <qlabel.h> |
40 | #include <qlayout.h> | 40 | #include <qlayout.h> |
41 | #include <qobjectlist.h> | 41 | #include <qobjectlist.h> |
42 | #include <qpixmap.h> | 42 | #include <qpixmap.h> |
43 | #include <qsplitter.h> | 43 | #include <qsplitter.h> |
44 | #include <qtabwidget.h> | 44 | #include <qtabwidget.h> |
45 | #include <qvbox.h> | 45 | #include <qvbox.h> |
46 | #include <qwidgetstack.h> | 46 | #include <qwidgetstack.h> |
47 | #include <qpainter.h> | 47 | #include <qpainter.h> |
48 | #include <qstyle.h> | 48 | #include <qstyle.h> |
49 | 49 | ||
50 | #include <kapplication.h> | 50 | #include <kapplication.h> |
51 | #include <klocale.h> | 51 | #include <klocale.h> |
52 | #include <kglobal.h> | 52 | #include <kglobal.h> |
53 | #include <kglobalsettings.h> | 53 | #include <kglobalsettings.h> |
54 | #include <kseparator.h> | 54 | #include <kseparator.h> |
55 | #include <kdebug.h> | 55 | #include <kdebug.h> |
56 | #include "kjanuswidget.h" | 56 | #include "kjanuswidget.h" |
57 | #include <klistview.h> | 57 | #include <klistview.h> |
58 | 58 | ||
59 | */ | 59 | */ |
60 | 60 | ||
61 | #include <kseparator.h> | 61 | #include <kseparator.h> |
62 | #include <kdialog.h> // Access to some static members | 62 | #include <kdialog.h> // Access to some static members |
63 | #include <kdebug.h> | 63 | #include <kdebug.h> |
64 | #include <klistview.h> | 64 | #include <klistview.h> |
65 | 65 | ||
66 | #include "kjanuswidget.h" | 66 | #include "kjanuswidget.h" |
67 | 67 | ||
68 | class KJanusWidget::IconListItem : public QListBoxItem | 68 | class KJanusWidget::IconListItem : public QListBoxItem |
69 | { | 69 | { |
70 | public: | 70 | public: |
71 | IconListItem( QListBox *listbox, const QPixmap &pixmap, | 71 | IconListItem( QListBox *listbox, const QPixmap &pixmap, |
72 | const QString &text ); | 72 | const QString &text ); |
73 | virtual int height( const QListBox *lb ) const; | 73 | virtual int height( const QListBox *lb ) const; |
74 | virtual int width( const QListBox *lb ) const; | 74 | virtual int width( const QListBox *lb ) const; |
75 | int expandMinimumWidth( int width ); | 75 | int expandMinimumWidth( int width ); |
76 | 76 | ||
77 | protected: | 77 | protected: |
78 | const QPixmap &defaultPixmap(); | 78 | const QPixmap &defaultPixmap(); |
79 | void paint( QPainter *painter ); | 79 | void paint( QPainter *painter ); |
80 | 80 | ||
81 | private: | 81 | private: |
82 | QPixmap mPixmap; | 82 | QPixmap mPixmap; |
83 | int mMinimumWidth; | 83 | int mMinimumWidth; |
84 | }; | 84 | }; |
85 | 85 | ||
86 | class KJanusWidget::KJanusWidgetPrivate | 86 | class KJanusWidget::KJanusWidgetPrivate |
87 | { | 87 | { |
88 | public: | 88 | public: |
89 | KJanusWidgetPrivate() : mNextPageIndex(0) { } | 89 | KJanusWidgetPrivate() : mNextPageIndex(0) { } |
90 | 90 | ||
91 | int mNextPageIndex; // The next page index. | 91 | int mNextPageIndex; // The next page index. |
92 | 92 | ||
93 | // Dictionary for multipage modes. | 93 | // Dictionary for multipage modes. |
94 | QMap<int,QWidget*> mIntToPage; | 94 | QMap<int,QWidget*> mIntToPage; |
95 | // Reverse dictionary. Used because showPage() may be performance critical. | 95 | // Reverse dictionary. Used because showPage() may be performance critical. |
96 | QMap<QWidget*,int> mPageToInt; | 96 | QMap<QWidget*,int> mPageToInt; |
97 | // Dictionary of title string associated with page. | 97 | // Dictionary of title string associated with page. |
98 | QMap<int, QString> mIntToTitle; | 98 | QMap<int, QString> mIntToTitle; |
99 | }; | 99 | }; |
100 | 100 | ||
101 | template class QPtrList<QListViewItem>; | 101 | template class QPtrList<QListViewItem>; |
102 | 102 | ||
103 | 103 | ||
104 | KJanusWidget::KJanusWidget( QWidget *parent, const char *name, int face ) | 104 | KJanusWidget::KJanusWidget( QWidget *parent, const char *name, int face ) |
105 | : QWidget( parent, name ), | 105 | : QWidget( parent, name ), |
106 | mValid(false), mPageList(0), | 106 | mValid(false), mPageList(0), |
107 | mTitleList(0), mFace(face), mTitleLabel(0), mActivePageWidget(0), | 107 | mTitleList(0), mFace(face), mTitleLabel(0), mActivePageWidget(0), |
108 | mShowIconsInTreeList(false), d(0) | 108 | mShowIconsInTreeList(false), d(0) |
109 | { | 109 | { |
110 | QVBoxLayout *topLayout = new QVBoxLayout( this ); | 110 | QVBoxLayout *topLayout = new QVBoxLayout( this ); |
111 | if( mFace == TreeList || mFace == IconList ) | 111 | if( mFace == TreeList || mFace == IconList ) |
112 | { | 112 | { |
113 | d = new KJanusWidgetPrivate; | 113 | d = new KJanusWidgetPrivate; |
114 | 114 | ||
115 | QFrame *page = 0; | 115 | QFrame *page = 0; |
116 | if( mFace == TreeList ) | 116 | if( mFace == TreeList ) |
117 | { | 117 | { |
118 | //US | 118 | //US |
119 | qDebug("KJanusWidget::KJanusWidget TreeList not implemented yet"); | 119 | qDebug("KJanusWidget::KJanusWidget TreeList not implemented yet"); |
120 | /*US | 120 | /*US |
121 | QSplitter *splitter = new QSplitter( this ); | 121 | QSplitter *splitter = new QSplitter( this ); |
122 | topLayout->addWidget( splitter, 10 ); | 122 | topLayout->addWidget( splitter, 10 ); |
123 | mTreeListResizeMode = QSplitter::KeepSize; | 123 | mTreeListResizeMode = QSplitter::KeepSize; |
124 | 124 | ||
125 | mTreeList = new KListView( splitter ); | 125 | mTreeList = new KListView( splitter ); |
126 | mTreeList->addColumn( QString::null ); | 126 | mTreeList->addColumn( QString::null ); |
127 | mTreeList->header()->hide(); | 127 | mTreeList->header()->hide(); |
128 | mTreeList->setRootIsDecorated(true); | 128 | mTreeList->setRootIsDecorated(true); |
129 | mTreeList->setSorting( -1 ); | 129 | mTreeList->setSorting( -1 ); |
130 | connect( mTreeList, SIGNAL(selectionChanged()), SLOT(slotShowPage()) ); | 130 | connect( mTreeList, SIGNAL(selectionChanged()), SLOT(slotShowPage()) ); |
131 | connect( mTreeList, SIGNAL(clicked(QListViewItem *)), SLOT(slotItemClicked(QListViewItem *))); | 131 | connect( mTreeList, SIGNAL(clicked(QListViewItem *)), SLOT(slotItemClicked(QListViewItem *))); |
132 | 132 | ||
133 | // | 133 | // |
134 | // Page area. Title at top with a separator below and a pagestack using | 134 | // Page area. Title at top with a separator below and a pagestack using |
135 | // all available space at bottom. | 135 | // all available space at bottom. |
136 | // | 136 | // |
137 | QFrame *p = new QFrame( splitter ); | 137 | QFrame *p = new QFrame( splitter ); |
138 | 138 | ||
139 | QHBoxLayout *hbox = new QHBoxLayout( p, 0, 0 ); | 139 | QHBoxLayout *hbox = new QHBoxLayout( p, 0, 0 ); |
140 | hbox->addSpacing( KDialog::marginHint() ); | 140 | hbox->addSpacing( KDialog::marginHint() ); |
141 | 141 | ||
142 | page = new QFrame( p ); | 142 | page = new QFrame( p ); |
143 | hbox->addWidget( page, 10 ); | 143 | hbox->addWidget( page, 10 ); |
144 | */ | 144 | */ |
145 | } | 145 | } |
146 | else | 146 | else |
147 | { | 147 | { |
148 | QHBoxLayout *hbox = new QHBoxLayout( topLayout ); | 148 | QHBoxLayout *hbox = new QHBoxLayout( topLayout ); |
149 | mIconList = new IconListBox( this ); | 149 | mIconList = new IconListBox( this ); |
150 | 150 | ||
151 | QFont listFont( mIconList->font() ); | 151 | QFont listFont( mIconList->font() ); |
152 | listFont.setBold( true ); | 152 | listFont.setBold( true ); |
153 | mIconList->setFont( listFont ); | 153 | mIconList->setFont( listFont ); |
154 | 154 | ||
155 | mIconList->verticalScrollBar()->installEventFilter( this ); | 155 | mIconList->verticalScrollBar()->installEventFilter( this ); |
156 | hbox->addWidget( mIconList ); | 156 | hbox->addWidget( mIconList ); |
157 | connect( mIconList, SIGNAL(selectionChanged()), SLOT(slotShowPage())); | 157 | connect( mIconList, SIGNAL(selectionChanged()), SLOT(slotShowPage())); |
158 | hbox->addSpacing( KDialog::marginHint() ); | 158 | hbox->addSpacing( KDialog::marginHint() ); |
159 | page = new QFrame( this ); | 159 | page = new QFrame( this ); |
160 | hbox->addWidget( page, 10 ); | 160 | hbox->addWidget( page, 10 ); |
161 | } | 161 | } |
162 | 162 | ||
163 | // | 163 | // |
164 | // Rest of page area. Title at top with a separator below and a | 164 | // Rest of page area. Title at top with a separator below and a |
165 | // pagestack using all available space at bottom. | 165 | // pagestack using all available space at bottom. |
166 | // | 166 | // |
167 | 167 | ||
168 | QVBoxLayout *vbox = new QVBoxLayout( page, 0, KDialog::spacingHint() ); | 168 | QVBoxLayout *vbox = new QVBoxLayout( page, 0, KDialog::spacingHint() ); |
169 | 169 | ||
170 | mTitleLabel = new QLabel( QString::fromLatin1("Empty page"), page, "KJanusWidgetTitleLabel" ); | 170 | mTitleLabel = new QLabel( QString::fromLatin1("Empty page"), page, "KJanusWidgetTitleLabel" ); |
171 | vbox->addWidget( mTitleLabel ); | 171 | vbox->addWidget( mTitleLabel ); |
172 | 172 | ||
173 | QFont titleFont( mTitleLabel->font() ); | 173 | QFont titleFont( mTitleLabel->font() ); |
174 | titleFont.setBold( true ); | 174 | titleFont.setBold( true ); |
175 | mTitleLabel->setFont( titleFont ); | 175 | mTitleLabel->setFont( titleFont ); |
176 | 176 | ||
177 | mTitleSep = new KSeparator( page ); | 177 | mTitleSep = new KSeparator( page ); |
178 | mTitleSep->setFrameStyle( QFrame::HLine|QFrame::Plain ); | 178 | mTitleSep->setFrameStyle( QFrame::HLine|QFrame::Plain ); |
179 | vbox->addWidget( mTitleSep ); | 179 | vbox->addWidget( mTitleSep ); |
180 | 180 | ||
181 | mPageStack = new QWidgetStack( page ); | 181 | mPageStack = new QWidgetStack( page ); |
182 | connect(mPageStack, SIGNAL(aboutToShow(QWidget *)), | 182 | connect(mPageStack, SIGNAL(aboutToShow(QWidget *)), |
183 | SIGNAL(aboutToShowPage(QWidget *))); | 183 | SIGNAL(aboutToShowPage(QWidget *))); |
184 | vbox->addWidget( mPageStack, 10 ); | 184 | vbox->addWidget( mPageStack, 10 ); |
185 | } | 185 | } |
186 | else if( mFace == Tabbed ) | 186 | else if( mFace == Tabbed ) |
187 | { | 187 | { |
188 | d = new KJanusWidgetPrivate; | 188 | d = new KJanusWidgetPrivate; |
189 | 189 | ||
190 | mTabControl = new QTabWidget( this ); | 190 | mTabControl = new QTabWidget( this ); |
191 | mTabControl->setMargin (KDialog::marginHint()); | 191 | mTabControl->setMargin (KDialog::marginHint()); |
192 | topLayout->addWidget( mTabControl, 10 ); | 192 | topLayout->addWidget( mTabControl, 10 ); |
193 | } | 193 | } |
194 | else if( mFace == Swallow ) | 194 | else if( mFace == Swallow ) |
195 | { | 195 | { |
196 | mSwallowPage = new QWidget( this ); | 196 | mSwallowPage = new QWidget( this ); |
197 | topLayout->addWidget( mSwallowPage, 10 ); | 197 | topLayout->addWidget( mSwallowPage, 10 ); |
198 | } | 198 | } |
199 | else | 199 | else |
200 | { | 200 | { |
201 | mFace = Plain; | 201 | mFace = Plain; |
202 | mPlainPage = new QFrame( this ); | 202 | mPlainPage = new QFrame( this ); |
203 | topLayout->addWidget( mPlainPage, 10 ); | 203 | topLayout->addWidget( mPlainPage, 10 ); |
204 | } | 204 | } |
205 | /*US | 205 | /*US |
206 | if ( kapp ) | 206 | if ( kapp ) |
207 | connect(kapp,SIGNAL(kdisplayFontChanged()),SLOT(slotFontChanged())); | 207 | connect(kapp,SIGNAL(kdisplayFontChanged()),SLOT(slotFontChanged())); |
208 | */ | 208 | */ |
209 | mValid = true; | 209 | mValid = true; |
210 | setSwallowedWidget(0); // Set default size if 'mFace' is Swallow. | 210 | setSwallowedWidget(0); // Set default size if 'mFace' is Swallow. |
211 | } | 211 | } |
212 | 212 | ||
213 | 213 | ||
214 | KJanusWidget::~KJanusWidget() | 214 | KJanusWidget::~KJanusWidget() |
215 | { | 215 | { |
216 | 216 | ||
217 | /*US the destroyed signal caused a segmentation fault while closing the dialog and destructing | 217 | /*US the destroyed signal caused a segmentation fault while closing the dialog and destructing |
218 | all pages. Why not just remove all pages in the destructor?? | 218 | all pages. Why not just remove all pages in the destructor?? |
219 | */ | 219 | */ |
220 | // LR we have all subwidgets with parent-child relation | 220 | // LR we have all subwidgets with parent-child relation |
221 | // LR we do not need to delete here anything by the private class | 221 | // LR we do not need to delete here anything by the private class |
222 | /* | 222 | /* |
223 | if( mFace == Tabbed ) | 223 | if( mFace == Tabbed ) |
224 | { | 224 | { |
225 | QMap<QWidget*,int>::Iterator it; | 225 | QMap<QWidget*,int>::Iterator it; |
226 | for (it = d->mPageToInt.begin(); it != d->mPageToInt.end(); ++it) { | 226 | for (it = d->mPageToInt.begin(); it != d->mPageToInt.end(); ++it) { |
227 | QObject*page = (QObject*)it.key(); | 227 | QObject*page = (QObject*)it.key(); |
228 | pageGone(page); | 228 | pageGone(page); |
229 | } | 229 | } |
230 | } | 230 | } |
231 | else | 231 | else |
232 | qDebug("KJanusWidget::~KJanusWidget so far "); | 232 | qDebug("KJanusWidget::~KJanusWidget so far "); |
233 | */ | 233 | */ |
234 | //US end | 234 | //US end |
235 | 235 | ||
236 | delete d; | 236 | delete d; |
237 | 237 | ||
238 | 238 | ||
239 | } | 239 | } |
240 | 240 | ||
241 | 241 | ||
242 | bool KJanusWidget::isValid() const | 242 | bool KJanusWidget::isValid() const |
243 | { | 243 | { |
244 | return( mValid ); | 244 | return( mValid ); |
245 | } | 245 | } |
246 | 246 | ||
247 | 247 | ||
248 | QFrame *KJanusWidget::plainPage() | 248 | QFrame *KJanusWidget::plainPage() |
249 | { | 249 | { |
250 | return( mPlainPage ); | 250 | return( mPlainPage ); |
251 | } | 251 | } |
252 | 252 | ||
253 | 253 | ||
254 | int KJanusWidget::face() const | 254 | int KJanusWidget::face() const |
255 | { | 255 | { |
256 | return( mFace ); | 256 | return( mFace ); |
257 | } | 257 | } |
258 | 258 | ||
259 | QWidget *KJanusWidget::FindParent() | 259 | QWidget *KJanusWidget::FindParent() |
260 | { | 260 | { |
261 | if( mFace == Tabbed ) { | 261 | if( mFace == Tabbed ) { |
262 | return mTabControl; | 262 | return mTabControl; |
263 | } | 263 | } |
264 | else { | 264 | else { |
265 | return this; | 265 | return this; |
266 | } | 266 | } |
267 | } | 267 | } |
268 | 268 | ||
269 | QFrame *KJanusWidget::addPage( const QStringList &items, const QString &header, | 269 | QFrame *KJanusWidget::addPage( const QStringList &items, const QString &header, |
270 | const QPixmap &pixmap ) | 270 | const QPixmap &pixmap ) |
271 | { | 271 | { |
272 | if( mValid == false ) | 272 | if( mValid == false ) |
273 | { | 273 | { |
274 | kdDebug() << "addPage: Invalid object" << endl; | 274 | kdDebug() << "addPage: Invalid object" << endl; |
275 | return( 0 ); | 275 | return( 0 ); |
276 | } | 276 | } |
277 | 277 | ||
278 | QFrame *page = new QFrame( FindParent(), "page" ); | 278 | QFrame *page = new QFrame( FindParent(), "page" ); |
279 | addPageWidget( page, items, header, pixmap ); | 279 | addPageWidget( page, items, header, pixmap ); |
280 | 280 | ||
281 | return page; | 281 | return page; |
282 | } | 282 | } |
283 | 283 | ||
284 | void KJanusWidget::pageGone( QObject *obj ) | 284 | void KJanusWidget::pageGone( QObject *obj ) |
285 | { | 285 | { |
286 | // QObject* obj = (QObject*)sender(); | 286 | // QObject* obj = (QObject*)sender(); |
287 | removePage( static_cast<QWidget*>( obj ) ); | 287 | removePage( static_cast<QWidget*>( obj ) ); |
288 | } | 288 | } |
289 | 289 | ||
290 | void KJanusWidget::slotReopen( QListViewItem * item ) | 290 | void KJanusWidget::slotReopen( QListViewItem * item ) |
291 | { | 291 | { |
292 | if( item ) | 292 | if( item ) |
293 | item->setOpen( true ); | 293 | item->setOpen( true ); |
294 | } | 294 | } |
295 | 295 | ||
296 | QFrame *KJanusWidget::addPage( const QString &itemName, const QString &header, | 296 | QFrame *KJanusWidget::addPage( const QString &itemName, const QString &header, |
297 | const QPixmap &pixmap ) | 297 | const QPixmap &pixmap ) |
298 | { | 298 | { |
299 | |||
299 | QStringList items; | 300 | QStringList items; |
300 | items << itemName; | 301 | items << itemName; |
301 | return addPage(items, header, pixmap); | 302 | return addPage(items, header, pixmap); |
302 | } | 303 | } |
303 | 304 | ||
304 | 305 | ||
305 | 306 | ||
306 | QVBox *KJanusWidget::addVBoxPage( const QStringList &items, | 307 | QVBox *KJanusWidget::addVBoxPage( const QStringList &items, |
307 | const QString &header, | 308 | const QString &header, |
308 | const QPixmap &pixmap ) | 309 | const QPixmap &pixmap ) |
309 | { | 310 | { |
310 | if( mValid == false ) | 311 | if( mValid == false ) |
311 | { | 312 | { |
312 | qDebug("addPage: Invalid object "); | 313 | qDebug("addPage: Invalid object "); |
313 | 314 | ||
314 | return( 0 ); | 315 | return( 0 ); |
315 | } | 316 | } |
316 | 317 | ||
317 | QVBox *page = new QVBox(FindParent() , "vbox_page" ); | 318 | QVBox *page = new QVBox(FindParent() , "vbox_page" ); |
318 | page->setSpacing( KDialog::spacingHintSmall() ); | 319 | page->setSpacing( KDialog::spacingHintSmall() ); |
319 | addPageWidget( page, items, header, pixmap ); | 320 | addPageWidget( page, items, header, pixmap ); |
320 | 321 | ||
321 | return page; | 322 | return page; |
322 | } | 323 | } |
323 | 324 | ||
324 | QVBox *KJanusWidget::addVBoxPage( const QString &itemName, | 325 | QVBox *KJanusWidget::addVBoxPage( const QString &itemName, |
325 | const QString &header, | 326 | const QString &header, |
326 | const QPixmap &pixmap ) | 327 | const QPixmap &pixmap ) |
327 | { | 328 | { |
328 | QStringList items; | 329 | QStringList items; |
329 | items << itemName; | 330 | items << itemName; |
330 | return addVBoxPage(items, header, pixmap); | 331 | return addVBoxPage(items, header, pixmap); |
331 | } | 332 | } |
332 | 333 | ||
333 | QHBox *KJanusWidget::addHBoxPage( const QStringList &items, | 334 | QHBox *KJanusWidget::addHBoxPage( const QStringList &items, |
334 | const QString &header, | 335 | const QString &header, |
335 | const QPixmap &pixmap ) | 336 | const QPixmap &pixmap ) |
336 | { | 337 | { |
337 | if( mValid == false ) { | 338 | if( mValid == false ) { |
338 | kdDebug() << "addPage: Invalid object" << endl; | 339 | kdDebug() << "addPage: Invalid object" << endl; |
339 | return( 0 ); | 340 | return( 0 ); |
340 | } | 341 | } |
341 | 342 | ||
342 | QHBox *page = new QHBox(FindParent(), "hbox_page"); | 343 | QHBox *page = new QHBox(FindParent(), "hbox_page"); |
343 | page->setSpacing( KDialog::spacingHint() ); | 344 | page->setSpacing( KDialog::spacingHint() ); |
344 | addPageWidget( page, items, header, pixmap ); | 345 | addPageWidget( page, items, header, pixmap ); |
345 | 346 | ||
346 | return page; | 347 | return page; |
347 | } | 348 | } |
348 | 349 | ||
349 | QHBox *KJanusWidget::addHBoxPage( const QString &itemName, | 350 | QHBox *KJanusWidget::addHBoxPage( const QString &itemName, |
350 | const QString &header, | 351 | const QString &header, |
351 | const QPixmap &pixmap ) | 352 | const QPixmap &pixmap ) |
352 | { | 353 | { |
353 | QStringList items; | 354 | QStringList items; |
354 | items << itemName; | 355 | items << itemName; |
355 | return addHBoxPage(items, header, pixmap); | 356 | return addHBoxPage(items, header, pixmap); |
356 | } | 357 | } |
357 | 358 | ||
358 | QGrid *KJanusWidget::addGridPage( int n, QGrid::Direction dir, | 359 | QGrid *KJanusWidget::addGridPage( int n, QGrid::Direction dir, |
359 | const QStringList &items, | 360 | const QStringList &items, |
360 | const QString &header, | 361 | const QString &header, |
361 | const QPixmap &pixmap ) | 362 | const QPixmap &pixmap ) |
362 | { | 363 | { |
363 | if( mValid == false ) | 364 | if( mValid == false ) |
364 | { | 365 | { |
365 | kdDebug() << "addPage: Invalid object" << endl; | 366 | kdDebug() << "addPage: Invalid object" << endl; |
366 | return( 0 ); | 367 | return( 0 ); |
367 | } | 368 | } |
368 | 369 | ||
369 | QGrid *page = new QGrid( n, dir, FindParent(), "page" ); | 370 | QGrid *page = new QGrid( n, dir, FindParent(), "page" ); |
370 | page->setSpacing( KDialog::spacingHint() ); | 371 | page->setSpacing( KDialog::spacingHint() ); |
371 | addPageWidget( page, items, header, pixmap ); | 372 | addPageWidget( page, items, header, pixmap ); |
372 | 373 | ||
373 | return page; | 374 | return page; |
374 | } | 375 | } |
375 | 376 | ||
376 | 377 | ||
377 | QGrid *KJanusWidget::addGridPage( int n, QGrid::Direction dir, | 378 | QGrid *KJanusWidget::addGridPage( int n, QGrid::Direction dir, |
378 | const QString &itemName, | 379 | const QString &itemName, |
379 | const QString &header, | 380 | const QString &header, |
380 | const QPixmap &pixmap ) | 381 | const QPixmap &pixmap ) |
381 | { | 382 | { |
382 | QStringList items; | 383 | QStringList items; |
383 | items << itemName; | 384 | items << itemName; |
384 | return addGridPage(n, dir, items, header, pixmap); | 385 | return addGridPage(n, dir, items, header, pixmap); |
385 | } | 386 | } |
386 | 387 | ||
387 | void KJanusWidget::InsertTreeListItem(const QStringList &items, const QPixmap &pixmap, QFrame *page) | 388 | void KJanusWidget::InsertTreeListItem(const QStringList &items, const QPixmap &pixmap, QFrame *page) |
388 | { | 389 | { |
389 | bool isTop = true; | 390 | bool isTop = true; |
390 | QListViewItem *curTop = 0, *child, *last, *newChild; | 391 | QListViewItem *curTop = 0, *child, *last, *newChild; |
391 | unsigned int index = 1; | 392 | unsigned int index = 1; |
392 | QStringList curPath; | 393 | QStringList curPath; |
393 | 394 | ||
394 | for ( QStringList::ConstIterator it = items.begin(); it != items.end(); ++it, index++ ) { | 395 | for ( QStringList::ConstIterator it = items.begin(); it != items.end(); ++it, index++ ) { |
395 | QString name = (*it); | 396 | QString name = (*it); |
396 | bool isPath = ( index != items.count() ); | 397 | bool isPath = ( index != items.count() ); |
397 | 398 | ||
398 | // Find the first child. | 399 | // Find the first child. |
399 | if (isTop) { | 400 | if (isTop) { |
400 | child = mTreeList->firstChild(); | 401 | child = mTreeList->firstChild(); |
401 | } | 402 | } |
402 | else { | 403 | else { |
403 | child = curTop->firstChild(); | 404 | child = curTop->firstChild(); |
404 | } | 405 | } |
405 | 406 | ||
406 | // Now search for a child with the current Name, and if it we doesn't | 407 | // Now search for a child with the current Name, and if it we doesn't |
407 | // find it, then remember the location of the last child. | 408 | // find it, then remember the location of the last child. |
408 | for (last = 0; child && child->text(0) != name ; last = child, child = child->nextSibling()); | 409 | for (last = 0; child && child->text(0) != name ; last = child, child = child->nextSibling()); |
409 | 410 | ||
410 | if (last == 0 && child == 0) { | 411 | if (last == 0 && child == 0) { |
411 | // This node didn't have any children at all, lets just insert the | 412 | // This node didn't have any children at all, lets just insert the |
412 | // new child. | 413 | // new child. |
413 | if (isTop) | 414 | if (isTop) |
414 | newChild = new QListViewItem(mTreeList, name); | 415 | newChild = new QListViewItem(mTreeList, name); |
415 | else | 416 | else |
416 | newChild = new QListViewItem(curTop, name); | 417 | newChild = new QListViewItem(curTop, name); |
417 | 418 | ||
418 | } | 419 | } |
419 | else if (child != 0) { | 420 | else if (child != 0) { |
420 | // we found the given name in this child. | 421 | // we found the given name in this child. |
421 | if (!isPath) { | 422 | if (!isPath) { |
422 | kdDebug() << "The element inserted was already in the TreeList box!" << endl; | 423 | kdDebug() << "The element inserted was already in the TreeList box!" << endl; |
423 | return; | 424 | return; |
424 | } | 425 | } |
425 | else { | 426 | else { |
426 | // Ok we found the folder | 427 | // Ok we found the folder |
427 | newChild = child; | 428 | newChild = child; |
428 | } | 429 | } |
429 | } | 430 | } |
430 | else { | 431 | else { |
431 | // the node had some children, but we didn't find the given name | 432 | // the node had some children, but we didn't find the given name |
432 | if (isTop) | 433 | if (isTop) |
433 | newChild = new QListViewItem(mTreeList, last, name); | 434 | newChild = new QListViewItem(mTreeList, last, name); |
434 | else | 435 | else |
435 | newChild = new QListViewItem(curTop, last, name); | 436 | newChild = new QListViewItem(curTop, last, name); |
436 | } | 437 | } |
437 | 438 | ||
438 | // Now make the element expandable if it is a path component, and make | 439 | // Now make the element expandable if it is a path component, and make |
439 | // ready for next loop | 440 | // ready for next loop |
440 | if (isPath) { | 441 | if (isPath) { |
441 | newChild->setExpandable(true); | 442 | newChild->setExpandable(true); |
442 | curTop = newChild; | 443 | curTop = newChild; |
443 | isTop = false; | 444 | isTop = false; |
444 | curPath << name; | 445 | curPath << name; |
445 | 446 | ||
446 | QString key = curPath.join("_/_"); | 447 | QString key = curPath.join("_/_"); |
447 | if (mFolderIconMap.contains(key)) { | 448 | if (mFolderIconMap.contains(key)) { |
448 | QPixmap p = mFolderIconMap[key]; | 449 | QPixmap p = mFolderIconMap[key]; |
449 | newChild->setPixmap(0,p); | 450 | newChild->setPixmap(0,p); |
450 | } | 451 | } |
451 | } | 452 | } |
452 | else { | 453 | else { |
453 | if (mShowIconsInTreeList) { | 454 | if (mShowIconsInTreeList) { |
454 | newChild->setPixmap(0, pixmap); | 455 | newChild->setPixmap(0, pixmap); |
455 | } | 456 | } |
456 | mTreeListToPageStack.insert(newChild, page); | 457 | mTreeListToPageStack.insert(newChild, page); |
457 | } | 458 | } |
458 | } | 459 | } |
459 | } | 460 | } |
460 | 461 | ||
461 | void KJanusWidget::addPageWidget( QFrame *page, const QStringList &items, | 462 | void KJanusWidget::addPageWidget( QFrame *page, const QStringList &items, |
462 | const QString &header,const QPixmap &pixmap ) | 463 | const QString &header,const QPixmap &pixmap ) |
463 | { | 464 | { |
464 | /*US the following signal causes a segmentation fault while closing the dialog. | 465 | /*US the following signal causes a segmentation fault while closing the dialog. |
465 | Why not just remove all pages in the destructor?? | 466 | Why not just remove all pages in the destructor?? |
466 | */ | 467 | */ |
467 | //US connect(page, SIGNAL(destroyed(QObject*)), this, SLOT(pageGone(QObject*))); | 468 | //US connect(page, SIGNAL(destroyed(QObject*)), this, SLOT(pageGone(QObject*))); |
468 | // we have the SIGNAL(destroyed(QObject*) only in Qt3 | 469 | // we have the SIGNAL(destroyed(QObject*) only in Qt3 |
469 | #ifdef DESKTOP_VERSION | 470 | #ifdef DESKTOP_VERSION |
470 | // connect(page, SIGNAL(destroyed(QObject*)), this, SLOT(pageGone(QObject*))); | 471 | // connect(page, SIGNAL(destroyed(QObject*)), this, SLOT(pageGone(QObject*))); |
471 | #endif | 472 | #endif |
472 | if( mFace == Tabbed ) | 473 | if( mFace == Tabbed ) |
473 | { | 474 | { |
474 | mTabControl->addTab (page, items.last()); | 475 | mTabControl->addTab (page, items.last()); |
475 | d->mIntToPage[d->mNextPageIndex] = static_cast<QWidget*>(page); | 476 | d->mIntToPage[d->mNextPageIndex] = static_cast<QWidget*>(page); |
476 | d->mPageToInt[static_cast<QWidget*>(page)] = d->mNextPageIndex; | 477 | d->mPageToInt[static_cast<QWidget*>(page)] = d->mNextPageIndex; |
477 | d->mNextPageIndex++; | 478 | d->mNextPageIndex++; |
478 | } | 479 | } |
479 | else if( mFace == TreeList || mFace == IconList ) | 480 | else if( mFace == TreeList || mFace == IconList ) |
480 | { | 481 | { |
481 | d->mIntToPage[d->mNextPageIndex] = static_cast<QWidget*>(page); | 482 | d->mIntToPage[d->mNextPageIndex] = static_cast<QWidget*>(page); |
482 | d->mPageToInt[static_cast<QWidget*>(page)] = d->mNextPageIndex; | 483 | d->mPageToInt[static_cast<QWidget*>(page)] = d->mNextPageIndex; |
483 | mPageStack->addWidget( page, 0 ); | 484 | mPageStack->addWidget( page, 0 ); |
484 | 485 | ||
485 | if (items.count() == 0) { | 486 | if (items.count() == 0) { |
486 | kdDebug() << "Invalid QStringList, with zero items" << endl; | 487 | kdDebug() << "Invalid QStringList, with zero items" << endl; |
487 | return; | 488 | return; |
488 | } | 489 | } |
489 | 490 | ||
490 | if( mFace == TreeList ) | 491 | if( mFace == TreeList ) |
491 | { | 492 | { |
492 | InsertTreeListItem(items, pixmap, page); | 493 | InsertTreeListItem(items, pixmap, page); |
493 | } | 494 | } |
494 | else // mFace == IconList | 495 | else // mFace == IconList |
495 | { | 496 | { |
496 | QString itemName = items.last(); | 497 | QString itemName = items.last(); |
497 | IconListItem *item = new IconListItem( mIconList, pixmap, itemName ); | 498 | IconListItem *item = new IconListItem( mIconList, pixmap, itemName ); |
498 | mIconListToPageStack.insert(item, page); | 499 | mIconListToPageStack.insert(item, page); |
499 | mIconList->invalidateHeight(); | 500 | mIconList->invalidateHeight(); |
500 | mIconList->invalidateWidth(); | 501 | mIconList->invalidateWidth(); |
501 | 502 | ||
502 | if (mIconList->isVisible()) | 503 | if (mIconList->isVisible()) |
503 | mIconList->updateWidth(); | 504 | mIconList->updateWidth(); |
504 | } | 505 | } |
505 | 506 | ||
506 | // | 507 | // |
507 | // Make sure the title label is sufficiently wide | 508 | // Make sure the title label is sufficiently wide |
508 | // | 509 | // |
509 | QString lastName = items.last(); | 510 | QString lastName = items.last(); |
510 | const QString &title = (!header.isNull() ? header : lastName); | 511 | const QString &title = (!header.isNull() ? header : lastName); |
511 | QRect r = mTitleLabel->fontMetrics().boundingRect( title ); | 512 | QRect r = mTitleLabel->fontMetrics().boundingRect( title ); |
512 | if( mTitleLabel->minimumWidth() < r.width() ) | 513 | if( mTitleLabel->minimumWidth() < r.width() ) |
513 | { | 514 | { |
514 | mTitleLabel->setMinimumWidth( r.width() ); | 515 | mTitleLabel->setMinimumWidth( r.width() ); |
515 | } | 516 | } |
516 | d->mIntToTitle[d->mNextPageIndex] = title; | 517 | d->mIntToTitle[d->mNextPageIndex] = title; |
517 | if( d->mIntToTitle.count() == 1 ) | 518 | if( d->mIntToTitle.count() == 1 ) |
518 | { | 519 | { |
519 | showPage(0); | 520 | showPage(0); |
520 | } | 521 | } |
521 | d->mNextPageIndex++; | 522 | d->mNextPageIndex++; |
522 | } | 523 | } |
523 | else | 524 | else |
524 | { | 525 | { |
525 | kdDebug() << "KJanusWidget::addPageWidget: can only add a page in Tabbed, TreeList or IconList modes" << endl; | 526 | kdDebug() << "KJanusWidget::addPageWidget: can only add a page in Tabbed, TreeList or IconList modes" << endl; |
526 | } | 527 | } |
527 | 528 | ||
528 | } | 529 | } |
529 | 530 | ||
530 | void KJanusWidget::setFolderIcon(const QStringList &path, const QPixmap &pixmap) | 531 | void KJanusWidget::setFolderIcon(const QStringList &path, const QPixmap &pixmap) |
531 | { | 532 | { |
532 | QString key = path.join("_/_"); | 533 | QString key = path.join("_/_"); |
533 | mFolderIconMap.insert(key,pixmap); | 534 | mFolderIconMap.insert(key,pixmap); |
534 | } | 535 | } |
535 | 536 | ||
536 | 537 | ||
537 | 538 | ||
538 | bool KJanusWidget::setSwallowedWidget( QWidget *widget ) | 539 | bool KJanusWidget::setSwallowedWidget( QWidget *widget ) |
539 | { | 540 | { |
540 | if( mFace != Swallow || mValid == false ) | 541 | if( mFace != Swallow || mValid == false ) |
541 | { | 542 | { |
542 | return( false ); | 543 | return( false ); |
543 | } | 544 | } |
544 | 545 | ||
545 | // | 546 | // |
546 | // Remove current layout and make a new. | 547 | // Remove current layout and make a new. |
547 | // | 548 | // |
548 | if( mSwallowPage->layout() != 0 ) | 549 | if( mSwallowPage->layout() != 0 ) |
549 | { | 550 | { |
550 | delete mSwallowPage->layout(); | 551 | delete mSwallowPage->layout(); |
551 | } | 552 | } |
552 | QGridLayout *gbox = new QGridLayout( mSwallowPage, 1, 1, 0 ); | 553 | QGridLayout *gbox = new QGridLayout( mSwallowPage, 1, 1, 0 ); |
553 | 554 | ||
554 | // | 555 | // |
555 | // Hide old children | 556 | // Hide old children |
556 | // | 557 | // |
557 | QObjectList *l = (QObjectList*)mSwallowPage->children(); // silence please | 558 | QObjectList *l = (QObjectList*)mSwallowPage->children(); // silence please |
558 | for( uint i=0; i < l->count(); i++ ) | 559 | for( uint i=0; i < l->count(); i++ ) |
559 | { | 560 | { |
560 | QObject *o = l->at(i); | 561 | QObject *o = l->at(i); |
561 | if( o->isWidgetType() ) | 562 | if( o->isWidgetType() ) |
562 | { | 563 | { |
563 | ((QWidget*)o)->hide(); | 564 | ((QWidget*)o)->hide(); |
564 | } | 565 | } |
565 | } | 566 | } |
566 | 567 | ||
567 | // | 568 | // |
568 | // Add new child or make default size | 569 | // Add new child or make default size |
569 | // | 570 | // |
570 | if( widget == 0 ) | 571 | if( widget == 0 ) |
571 | { | 572 | { |
572 | gbox->addRowSpacing(0,100); | 573 | gbox->addRowSpacing(0,100); |
573 | gbox->addColSpacing(0,100); | 574 | gbox->addColSpacing(0,100); |
574 | mSwallowPage->setMinimumSize(100,100); | 575 | mSwallowPage->setMinimumSize(100,100); |
575 | } | 576 | } |
576 | else | 577 | else |
577 | { | 578 | { |
578 | if( widget->parent() != mSwallowPage ) | 579 | if( widget->parent() != mSwallowPage ) |
579 | { | 580 | { |
580 | widget->reparent( mSwallowPage, 0, QPoint(0,0) ); | 581 | widget->reparent( mSwallowPage, 0, QPoint(0,0) ); |
581 | } | 582 | } |
582 | gbox->addWidget(widget, 0, 0 ); | 583 | gbox->addWidget(widget, 0, 0 ); |
583 | gbox->activate(); | 584 | gbox->activate(); |
584 | mSwallowPage->setMinimumSize( widget->minimumSize() ); | 585 | mSwallowPage->setMinimumSize( widget->minimumSize() ); |
585 | } | 586 | } |
586 | 587 | ||
587 | return( true ); | 588 | return( true ); |
588 | } | 589 | } |
589 | 590 | ||
590 | bool KJanusWidget::slotShowPage() | 591 | bool KJanusWidget::slotShowPage() |
591 | { | 592 | { |
592 | if( mValid == false ) | 593 | if( mValid == false ) |
593 | { | 594 | { |
594 | return( false ); | 595 | return( false ); |
595 | } | 596 | } |
596 | 597 | ||
597 | if( mFace == TreeList ) | 598 | if( mFace == TreeList ) |
598 | { | 599 | { |
599 | QListViewItem *node = mTreeList->selectedItem(); | 600 | QListViewItem *node = mTreeList->selectedItem(); |
600 | if( node == 0 ) { return( false ); } | 601 | if( node == 0 ) { return( false ); } |
601 | 602 | ||
602 | QWidget *stackItem = mTreeListToPageStack[node]; | 603 | QWidget *stackItem = mTreeListToPageStack[node]; |
603 | // Make sure to call through the virtual function showPage(int) | 604 | // Make sure to call through the virtual function showPage(int) |
604 | return showPage(d->mPageToInt[stackItem]); | 605 | return showPage(d->mPageToInt[stackItem]); |
605 | } | 606 | } |
606 | else if( mFace == IconList ) | 607 | else if( mFace == IconList ) |
607 | { | 608 | { |
608 | QListBoxItem *node = mIconList->item( mIconList->currentItem() ); | 609 | QListBoxItem *node = mIconList->item( mIconList->currentItem() ); |
609 | if( node == 0 ) { return( false ); } | 610 | if( node == 0 ) { return( false ); } |
610 | QWidget *stackItem = mIconListToPageStack[node]; | 611 | QWidget *stackItem = mIconListToPageStack[node]; |
611 | // Make sure to call through the virtual function showPage(int) | 612 | // Make sure to call through the virtual function showPage(int) |
612 | return showPage(d->mPageToInt[stackItem]); | 613 | return showPage(d->mPageToInt[stackItem]); |
613 | } | 614 | } |
614 | 615 | ||
615 | return( false ); | 616 | return( false ); |
616 | } | 617 | } |
617 | 618 | ||
618 | 619 | ||
619 | bool KJanusWidget::showPage( int index ) | 620 | bool KJanusWidget::showPage( int index ) |
620 | { | 621 | { |
621 | if( d == 0 || mValid == false ) | 622 | if( d == 0 || mValid == false ) |
622 | { | 623 | { |
623 | return( false ); | 624 | return( false ); |
624 | } | 625 | } |
625 | else | 626 | else |
626 | { | 627 | { |
627 | return showPage(d->mIntToPage[index]); | 628 | return showPage(d->mIntToPage[index]); |
628 | } | 629 | } |
629 | } | 630 | } |
630 | 631 | ||
631 | 632 | ||
632 | bool KJanusWidget::showPage( QWidget *w ) | 633 | bool KJanusWidget::showPage( QWidget *w ) |
633 | { | 634 | { |
634 | if( w == 0 || mValid == false ) | 635 | if( w == 0 || mValid == false ) |
635 | { | 636 | { |
636 | return( false ); | 637 | return( false ); |
637 | } | 638 | } |
638 | 639 | ||
639 | if( mFace == TreeList || mFace == IconList ) | 640 | if( mFace == TreeList || mFace == IconList ) |
640 | { | 641 | { |
641 | mPageStack->raiseWidget( w ); | 642 | mPageStack->raiseWidget( w ); |
642 | mActivePageWidget = w; | 643 | mActivePageWidget = w; |
643 | 644 | ||
644 | int index = d->mPageToInt[w]; | 645 | int index = d->mPageToInt[w]; |
645 | mTitleLabel->setText( d->mIntToTitle[index] ); | 646 | mTitleLabel->setText( d->mIntToTitle[index] ); |
646 | if( mFace == TreeList ) | 647 | if( mFace == TreeList ) |
647 | { | 648 | { |
648 | QMap<QListViewItem *, QWidget *>::Iterator it; | 649 | QMap<QListViewItem *, QWidget *>::Iterator it; |
649 | for (it = mTreeListToPageStack.begin(); it != mTreeListToPageStack.end(); ++it){ | 650 | for (it = mTreeListToPageStack.begin(); it != mTreeListToPageStack.end(); ++it){ |
650 | QListViewItem *key = it.key(); | 651 | QListViewItem *key = it.key(); |
651 | QWidget *val = it.data(); | 652 | QWidget *val = it.data(); |
652 | if (val == w) { | 653 | if (val == w) { |
653 | mTreeList->setSelected(key, true ); | 654 | mTreeList->setSelected(key, true ); |
654 | break; | 655 | break; |
655 | } | 656 | } |
656 | } | 657 | } |
657 | } | 658 | } |
658 | else | 659 | else |
659 | { | 660 | { |
660 | QMap<QListBoxItem *, QWidget *>::Iterator it; | 661 | QMap<QListBoxItem *, QWidget *>::Iterator it; |
661 | for (it = mIconListToPageStack.begin(); it != mIconListToPageStack.end(); ++it){ | 662 | for (it = mIconListToPageStack.begin(); it != mIconListToPageStack.end(); ++it){ |
662 | QListBoxItem *key = it.key(); | 663 | QListBoxItem *key = it.key(); |
663 | QWidget *val = it.data(); | 664 | QWidget *val = it.data(); |
664 | if (val == w) { | 665 | if (val == w) { |
665 | mIconList->setSelected( key, true ); | 666 | mIconList->setSelected( key, true ); |
666 | break; | 667 | break; |
667 | } | 668 | } |
668 | } | 669 | } |
669 | } | 670 | } |
670 | } | 671 | } |
671 | else if( mFace == Tabbed ) | 672 | else if( mFace == Tabbed ) |
672 | { | 673 | { |
673 | mTabControl->showPage(w); | 674 | mTabControl->showPage(w); |
674 | mActivePageWidget = w; | 675 | mActivePageWidget = w; |
675 | } | 676 | } |
676 | else | 677 | else |
677 | { | 678 | { |
678 | return( false ); | 679 | return( false ); |
679 | } | 680 | } |
680 | 681 | ||
681 | return( true ); | 682 | return( true ); |
682 | } | 683 | } |
683 | 684 | ||
684 | 685 | ||
685 | int KJanusWidget::activePageIndex() const | 686 | int KJanusWidget::activePageIndex() const |
686 | { | 687 | { |
687 | if( mFace == TreeList) { | 688 | if( mFace == TreeList) { |
688 | QListViewItem *node = mTreeList->selectedItem(); | 689 | QListViewItem *node = mTreeList->selectedItem(); |
689 | if( node == 0 ) { return -1; } | 690 | if( node == 0 ) { return -1; } |
690 | QWidget *stackItem = mTreeListToPageStack[node]; | 691 | QWidget *stackItem = mTreeListToPageStack[node]; |
691 | return d->mPageToInt[stackItem]; | 692 | return d->mPageToInt[stackItem]; |
692 | } | 693 | } |
693 | else if (mFace == IconList) { | 694 | else if (mFace == IconList) { |
694 | QListBoxItem *node = mIconList->item( mIconList->currentItem() ); | 695 | QListBoxItem *node = mIconList->item( mIconList->currentItem() ); |
695 | if( node == 0 ) { return( false ); } | 696 | if( node == 0 ) { return( false ); } |
696 | QWidget *stackItem = mIconListToPageStack[node]; | 697 | QWidget *stackItem = mIconListToPageStack[node]; |
697 | return d->mPageToInt[stackItem]; | 698 | return d->mPageToInt[stackItem]; |
698 | } | 699 | } |
699 | else if( mFace == Tabbed ) { | 700 | else if( mFace == Tabbed ) { |
700 | QWidget *widget = mTabControl->currentPage(); | 701 | QWidget *widget = mTabControl->currentPage(); |
701 | return( widget == 0 ? -1 : d->mPageToInt[widget] ); | 702 | return( widget == 0 ? -1 : d->mPageToInt[widget] ); |
702 | } | 703 | } |
703 | else { | 704 | else { |
704 | return( -1 ); | 705 | return( -1 ); |
705 | } | 706 | } |
706 | } | 707 | } |
707 | 708 | ||
708 | 709 | ||
709 | int KJanusWidget::pageIndex( QWidget *widget ) const | 710 | int KJanusWidget::pageIndex( QWidget *widget ) const |
710 | { | 711 | { |
711 | if( widget == 0 ) | 712 | if( widget == 0 ) |
712 | { | 713 | { |
713 | return( -1 ); | 714 | return( -1 ); |
714 | } | 715 | } |
715 | else if( mFace == TreeList || mFace == IconList ) | 716 | else if( mFace == TreeList || mFace == IconList ) |
716 | { | 717 | { |
717 | return( d->mPageToInt[widget] ); | 718 | return( d->mPageToInt[widget] ); |
718 | } | 719 | } |
719 | else if( mFace == Tabbed ) | 720 | else if( mFace == Tabbed ) |
720 | { | 721 | { |
721 | // | 722 | // |
722 | // The user gets the real page widget with addVBoxPage(), addHBoxPage() | 723 | // The user gets the real page widget with addVBoxPage(), addHBoxPage() |
723 | // and addGridPage() but not with addPage() which returns a child of | 724 | // and addGridPage() but not with addPage() which returns a child of |
724 | // the toplevel page. addPage() returns a QFrame so I check for that. | 725 | // the toplevel page. addPage() returns a QFrame so I check for that. |
725 | // | 726 | // |
726 | if( widget->isA("QFrame") ) | 727 | if( widget->isA("QFrame") ) |
727 | { | 728 | { |
728 | return( d->mPageToInt[widget->parentWidget()] ); | 729 | return( d->mPageToInt[widget->parentWidget()] ); |
729 | } | 730 | } |
730 | else | 731 | else |
731 | { | 732 | { |
732 | return( d->mPageToInt[widget] ); | 733 | return( d->mPageToInt[widget] ); |
733 | } | 734 | } |
734 | } | 735 | } |
735 | else | 736 | else |
736 | { | 737 | { |
737 | return( -1 ); | 738 | return( -1 ); |
738 | } | 739 | } |
739 | } | 740 | } |
740 | /*US not yet implemented | 741 | /*US not yet implemented |
741 | void KJanusWidget::slotFontChanged() | 742 | void KJanusWidget::slotFontChanged() |
742 | { | 743 | { |
743 | if( mTitleLabel != 0 ) | 744 | if( mTitleLabel != 0 ) |
744 | { | 745 | { |
745 | mTitleLabel->setFont( KGlobalSettings::generalFont() ); | 746 | mTitleLabel->setFont( KGlobalSettings::generalFont() ); |
746 | QFont titleFont( mTitleLabel->font() ); | 747 | QFont titleFont( mTitleLabel->font() ); |
747 | titleFont.setBold( true ); | 748 | titleFont.setBold( true ); |
748 | mTitleLabel->setFont( titleFont ); | 749 | mTitleLabel->setFont( titleFont ); |
749 | } | 750 | } |
750 | 751 | ||
751 | if( mFace == IconList ) | 752 | if( mFace == IconList ) |
752 | { | 753 | { |
753 | QFont listFont( mIconList->font() ); | 754 | QFont listFont( mIconList->font() ); |
754 | listFont.setBold( true ); | 755 | listFont.setBold( true ); |
755 | mIconList->setFont( listFont ); | 756 | mIconList->setFont( listFont ); |
756 | mIconList->invalidateHeight(); | 757 | mIconList->invalidateHeight(); |
757 | mIconList->invalidateWidth(); | 758 | mIconList->invalidateWidth(); |
758 | } | 759 | } |
759 | } | 760 | } |
760 | */ | 761 | */ |
761 | 762 | ||
762 | // makes the treelist behave like the list of kcontrol | 763 | // makes the treelist behave like the list of kcontrol |
763 | void KJanusWidget::slotItemClicked(QListViewItem *it) | 764 | void KJanusWidget::slotItemClicked(QListViewItem *it) |
764 | { | 765 | { |
765 | if(it && (it->childCount()>0)) | 766 | if(it && (it->childCount()>0)) |
766 | it->setOpen(!it->isOpen()); | 767 | it->setOpen(!it->isOpen()); |
767 | } | 768 | } |
768 | 769 | ||
769 | void KJanusWidget::setFocus() | 770 | void KJanusWidget::setFocus() |
770 | { | 771 | { |
771 | if( mValid == false ) { return; } | 772 | if( mValid == false ) { return; } |
772 | if( mFace == TreeList ) | 773 | if( mFace == TreeList ) |
773 | { | 774 | { |
774 | mTreeList->setFocus(); | 775 | mTreeList->setFocus(); |
775 | } | 776 | } |
776 | if( mFace == IconList ) | 777 | if( mFace == IconList ) |
777 | { | 778 | { |
778 | mIconList->setFocus(); | 779 | mIconList->setFocus(); |
779 | } | 780 | } |
780 | else if( mFace == Tabbed ) | 781 | else if( mFace == Tabbed ) |
781 | { | 782 | { |
782 | mTabControl->setFocus(); | 783 | mTabControl->setFocus(); |
783 | } | 784 | } |
784 | else if( mFace == Swallow ) | 785 | else if( mFace == Swallow ) |
785 | { | 786 | { |
786 | mSwallowPage->setFocus(); | 787 | mSwallowPage->setFocus(); |
787 | } | 788 | } |
788 | else if( mFace == Plain ) | 789 | else if( mFace == Plain ) |
789 | { | 790 | { |
790 | mPlainPage->setFocus(); | 791 | mPlainPage->setFocus(); |
791 | } | 792 | } |
792 | } | 793 | } |
793 | 794 | ||
794 | 795 | ||
795 | QSize KJanusWidget::minimumSizeHint() const | 796 | QSize KJanusWidget::minimumSizeHint() const |
796 | { | 797 | { |
797 | if( mFace == TreeList || mFace == IconList ) | 798 | if( mFace == TreeList || mFace == IconList ) |
798 | { | 799 | { |
799 | QSize s1( KDialog::spacingHint(), KDialog::spacingHint()*2 ); | 800 | QSize s1( KDialog::spacingHint(), KDialog::spacingHint()*2 ); |
800 | QSize s2(0,0); | 801 | QSize s2(0,0); |
801 | QSize s3(0,0); | 802 | QSize s3(0,0); |
802 | QSize s4( mPageStack->sizeHint() ); | 803 | QSize s4( mPageStack->sizeHint() ); |
803 | 804 | ||
804 | if( mFace == TreeList ) | 805 | if( mFace == TreeList ) |
805 | { | 806 | { |
806 | /*US | 807 | /*US |
807 | s1.rwidth() += style().pixelMetric( QStyle::PM_SplitterWidth ); | 808 | s1.rwidth() += style().pixelMetric( QStyle::PM_SplitterWidth ); |
808 | s2 = mTreeList->minimumSize(); | 809 | s2 = mTreeList->minimumSize(); |
809 | */ | 810 | */ |
810 | } | 811 | } |
811 | else | 812 | else |
812 | { | 813 | { |
813 | mIconList->updateMinimumHeight(); | 814 | mIconList->updateMinimumHeight(); |
814 | mIconList->updateWidth(); | 815 | mIconList->updateWidth(); |
815 | s2 = mIconList->minimumSize(); | 816 | s2 = mIconList->minimumSize(); |
816 | } | 817 | } |
817 | 818 | ||
818 | if( mTitleLabel->isVisible() == true ) | 819 | if( mTitleLabel->isVisible() == true ) |
819 | { | 820 | { |
820 | s3 += mTitleLabel->sizeHint(); | 821 | s3 += mTitleLabel->sizeHint(); |
821 | s3.rheight() += mTitleSep->minimumSize().height(); | 822 | s3.rheight() += mTitleSep->minimumSize().height(); |
822 | } | 823 | } |
823 | 824 | ||
824 | // | 825 | // |
825 | // Select the tallest item. It has only effect in IconList mode | 826 | // Select the tallest item. It has only effect in IconList mode |
826 | // | 827 | // |
827 | int h1 = s1.rheight() + s3.rheight() + s4.height(); | 828 | int h1 = s1.rheight() + s3.rheight() + s4.height(); |
828 | int h2 = QMAX( h1, s2.rheight() ); | 829 | int h2 = QMAX( h1, s2.rheight() ); |
829 | 830 | ||
830 | return( QSize( s1.width()+s2.width()+QMAX(s3.width(),s4.width()), h2 ) ); | 831 | return( QSize( s1.width()+s2.width()+QMAX(s3.width(),s4.width()), h2 ) ); |
831 | } | 832 | } |
832 | else if( mFace == Tabbed ) | 833 | else if( mFace == Tabbed ) |
833 | { | 834 | { |
834 | return( mTabControl->sizeHint() ); | 835 | return( mTabControl->sizeHint() ); |
835 | } | 836 | } |
836 | else if( mFace == Swallow ) | 837 | else if( mFace == Swallow ) |
837 | { | 838 | { |
838 | return( mSwallowPage->minimumSize() ); | 839 | return( mSwallowPage->minimumSize() ); |
839 | } | 840 | } |
840 | else if( mFace == Plain ) | 841 | else if( mFace == Plain ) |
841 | { | 842 | { |
842 | return( mPlainPage->sizeHint() ); | 843 | return( mPlainPage->sizeHint() ); |
843 | } | 844 | } |
844 | else | 845 | else |
845 | { | 846 | { |
846 | return( QSize( 100, 100 ) ); // Should never happen though. | 847 | return( QSize( 100, 100 ) ); // Should never happen though. |
847 | } | 848 | } |
848 | 849 | ||
849 | } | 850 | } |
850 | 851 | ||
851 | 852 | ||
852 | QSize KJanusWidget::sizeHint() const | 853 | QSize KJanusWidget::sizeHint() const |
853 | { | 854 | { |
854 | return( minimumSizeHint() ); | 855 | return( minimumSizeHint() ); |
855 | } | 856 | } |
856 | 857 | ||
857 | 858 | ||
858 | void KJanusWidget::setTreeListAutoResize( bool state ) | 859 | void KJanusWidget::setTreeListAutoResize( bool state ) |
859 | { | 860 | { |
860 | if( mFace == TreeList ) | 861 | if( mFace == TreeList ) |
861 | { | 862 | { |
862 | /*US | 863 | /*US |
863 | mTreeListResizeMode = state == false ? | 864 | mTreeListResizeMode = state == false ? |
864 | QSplitter::KeepSize : QSplitter::Stretch; | 865 | QSplitter::KeepSize : QSplitter::Stretch; |
865 | QSplitter *splitter = (QSplitter*)(mTreeList->parentWidget()); | 866 | QSplitter *splitter = (QSplitter*)(mTreeList->parentWidget()); |
866 | splitter->setResizeMode( mTreeList, mTreeListResizeMode ); | 867 | splitter->setResizeMode( mTreeList, mTreeListResizeMode ); |
867 | */ | 868 | */ |
868 | } | 869 | } |
869 | } | 870 | } |
870 | 871 | ||
871 | 872 | ||
872 | void KJanusWidget::setIconListAllVisible( bool state ) | 873 | void KJanusWidget::setIconListAllVisible( bool state ) |
873 | { | 874 | { |
874 | if( mFace == IconList ) | 875 | if( mFace == IconList ) |
875 | { | 876 | { |
876 | mIconList->setShowAll( state ); | 877 | mIconList->setShowAll( state ); |
877 | } | 878 | } |
878 | } | 879 | } |
879 | 880 | ||
880 | void KJanusWidget::setShowIconsInTreeList( bool state ) | 881 | void KJanusWidget::setShowIconsInTreeList( bool state ) |
881 | { | 882 | { |
882 | mShowIconsInTreeList = state; | 883 | mShowIconsInTreeList = state; |
883 | } | 884 | } |
884 | 885 | ||
885 | void KJanusWidget::setRootIsDecorated( bool state ) | 886 | void KJanusWidget::setRootIsDecorated( bool state ) |
886 | { | 887 | { |
887 | if( mFace == TreeList ) { | 888 | if( mFace == TreeList ) { |
888 | mTreeList->setRootIsDecorated(state); | 889 | mTreeList->setRootIsDecorated(state); |
889 | } | 890 | } |
890 | } | 891 | } |
891 | 892 | ||
892 | void KJanusWidget::unfoldTreeList( bool persist ) | 893 | void KJanusWidget::unfoldTreeList( bool persist ) |
893 | { | 894 | { |
894 | if( mFace == TreeList ) | 895 | if( mFace == TreeList ) |
895 | { | 896 | { |
896 | if( persist ) | 897 | if( persist ) |
897 | connect( mTreeList, SIGNAL( collapsed( QListViewItem * ) ), this, SLOT( slotReopen( QListViewItem * ) ) ); | 898 | connect( mTreeList, SIGNAL( collapsed( QListViewItem * ) ), this, SLOT( slotReopen( QListViewItem * ) ) ); |
898 | else | 899 | else |
899 | disconnect( mTreeList, SIGNAL( collapsed( QListViewItem * ) ), this, SLOT( slotReopen( QListViewItem * ) ) ); | 900 | disconnect( mTreeList, SIGNAL( collapsed( QListViewItem * ) ), this, SLOT( slotReopen( QListViewItem * ) ) ); |
900 | 901 | ||
901 | for( QListViewItem * item = mTreeList->firstChild(); item; item = item->itemBelow() ) | 902 | for( QListViewItem * item = mTreeList->firstChild(); item; item = item->itemBelow() ) |
902 | item->setOpen( true ); | 903 | item->setOpen( true ); |
903 | } | 904 | } |
904 | } | 905 | } |
905 | 906 | ||
906 | void KJanusWidget::showEvent( QShowEvent * ) | 907 | void KJanusWidget::showEvent( QShowEvent * ) |
907 | { | 908 | { |
908 | if( mFace == TreeList ) | 909 | if( mFace == TreeList ) |
909 | { | 910 | { |
910 | /*US | 911 | /*US |
911 | QSplitter *splitter = (QSplitter*)(mTreeList->parentWidget()); | 912 | QSplitter *splitter = (QSplitter*)(mTreeList->parentWidget()); |
912 | splitter->setResizeMode( mTreeList, mTreeListResizeMode ); | 913 | splitter->setResizeMode( mTreeList, mTreeListResizeMode ); |
913 | */ | 914 | */ |
914 | } | 915 | } |
915 | } | 916 | } |
916 | 917 | ||
917 | 918 | ||
918 | // | 919 | // |
919 | // 2000-13-02 Espen Sand | 920 | // 2000-13-02 Espen Sand |
920 | // It should be obvious that this eventfilter must only be | 921 | // It should be obvious that this eventfilter must only be |
921 | // be installed on the vertical scrollbar of the mIconList. | 922 | // be installed on the vertical scrollbar of the mIconList. |
922 | // | 923 | // |
923 | bool KJanusWidget::eventFilter( QObject *o, QEvent *e ) | 924 | bool KJanusWidget::eventFilter( QObject *o, QEvent *e ) |
924 | { | 925 | { |
925 | if( e->type() == QEvent::Show ) | 926 | if( e->type() == QEvent::Show ) |
926 | { | 927 | { |
927 | IconListItem *item = (IconListItem*)mIconList->item(0); | 928 | IconListItem *item = (IconListItem*)mIconList->item(0); |
928 | if( item != 0 ) | 929 | if( item != 0 ) |
929 | { | 930 | { |
930 | int lw = item->width( mIconList ); | 931 | int lw = item->width( mIconList ); |
931 | int sw = mIconList->verticalScrollBar()->sizeHint().width(); | 932 | int sw = mIconList->verticalScrollBar()->sizeHint().width(); |
932 | mIconList->setFixedWidth( lw+sw+mIconList->frameWidth()*2 ); | 933 | mIconList->setFixedWidth( lw+sw+mIconList->frameWidth()*2 ); |
933 | } | 934 | } |
934 | } | 935 | } |
935 | else if( e->type() == QEvent::Hide ) | 936 | else if( e->type() == QEvent::Hide ) |
936 | { | 937 | { |
937 | IconListItem *item = (IconListItem*)mIconList->item(0); | 938 | IconListItem *item = (IconListItem*)mIconList->item(0); |
938 | if( item != 0 ) | 939 | if( item != 0 ) |
939 | { | 940 | { |
940 | int lw = item->width( mIconList ); | 941 | int lw = item->width( mIconList ); |
941 | mIconList->setFixedWidth( lw+mIconList->frameWidth()*2 ); | 942 | mIconList->setFixedWidth( lw+mIconList->frameWidth()*2 ); |
942 | } | 943 | } |
943 | } | 944 | } |
944 | return QWidget::eventFilter( o, e ); | 945 | return QWidget::eventFilter( o, e ); |
945 | } | 946 | } |
946 | 947 | ||
947 | 948 | ||
948 | 949 | ||
949 | // | 950 | // |
950 | // Code for the icon list box | 951 | // Code for the icon list box |
951 | // | 952 | // |
952 | 953 | ||
953 | 954 | ||
954 | KJanusWidget::IconListBox::IconListBox( QWidget *parent, const char *name, | 955 | KJanusWidget::IconListBox::IconListBox( QWidget *parent, const char *name, |
955 | WFlags f ) | 956 | WFlags f ) |
956 | :KListBox( parent, name, f ), mShowAll(false), mHeightValid(false), | 957 | :KListBox( parent, name, f ), mShowAll(false), mHeightValid(false), |
957 | mWidthValid(false) | 958 | mWidthValid(false) |
958 | { | 959 | { |
959 | } | 960 | } |
960 | 961 | ||
961 | 962 | ||
962 | void KJanusWidget::IconListBox::updateMinimumHeight() | 963 | void KJanusWidget::IconListBox::updateMinimumHeight() |
963 | { | 964 | { |
964 | if( mShowAll == true && mHeightValid == false ) | 965 | if( mShowAll == true && mHeightValid == false ) |
965 | { | 966 | { |
966 | int h = frameWidth()*2; | 967 | int h = frameWidth()*2; |
967 | for( QListBoxItem *i = item(0); i != 0; i = i->next() ) | 968 | for( QListBoxItem *i = item(0); i != 0; i = i->next() ) |
968 | { | 969 | { |
969 | h += i->height( this ); | 970 | h += i->height( this ); |
970 | } | 971 | } |
971 | setMinimumHeight( h ); | 972 | setMinimumHeight( h ); |
972 | mHeightValid = true; | 973 | mHeightValid = true; |
973 | } | 974 | } |
974 | } | 975 | } |
975 | 976 | ||
976 | 977 | ||
977 | void KJanusWidget::IconListBox::updateWidth() | 978 | void KJanusWidget::IconListBox::updateWidth() |
978 | { | 979 | { |
979 | if( mWidthValid == false ) | 980 | if( mWidthValid == false ) |
980 | { | 981 | { |
981 | int maxWidth = 10; | 982 | int maxWidth = 10; |
982 | for( QListBoxItem *i = item(0); i != 0; i = i->next() ) | 983 | for( QListBoxItem *i = item(0); i != 0; i = i->next() ) |
983 | { | 984 | { |
984 | int w = ((IconListItem *)i)->width(this); | 985 | int w = ((IconListItem *)i)->width(this); |
985 | maxWidth = QMAX( w, maxWidth ); | 986 | maxWidth = QMAX( w, maxWidth ); |
986 | } | 987 | } |
987 | 988 | ||
988 | for( QListBoxItem *i = item(0); i != 0; i = i->next() ) | 989 | for( QListBoxItem *i = item(0); i != 0; i = i->next() ) |
989 | { | 990 | { |
990 | ((IconListItem *)i)->expandMinimumWidth( maxWidth ); | 991 | ((IconListItem *)i)->expandMinimumWidth( maxWidth ); |
991 | } | 992 | } |
992 | 993 | ||
993 | if( verticalScrollBar()->isVisible() ) | 994 | if( verticalScrollBar()->isVisible() ) |
994 | { | 995 | { |
995 | maxWidth += verticalScrollBar()->sizeHint().width(); | 996 | maxWidth += verticalScrollBar()->sizeHint().width(); |
996 | } | 997 | } |
997 | 998 | ||
998 | setFixedWidth( maxWidth + frameWidth()*2 ); | 999 | setFixedWidth( maxWidth + frameWidth()*2 ); |
999 | mWidthValid = true; | 1000 | mWidthValid = true; |
1000 | } | 1001 | } |
1001 | } | 1002 | } |
1002 | 1003 | ||
1003 | 1004 | ||
1004 | void KJanusWidget::IconListBox::invalidateHeight() | 1005 | void KJanusWidget::IconListBox::invalidateHeight() |
1005 | { | 1006 | { |
1006 | mHeightValid = false; | 1007 | mHeightValid = false; |
1007 | } | 1008 | } |
1008 | 1009 | ||
1009 | 1010 | ||
1010 | void KJanusWidget::IconListBox::invalidateWidth() | 1011 | void KJanusWidget::IconListBox::invalidateWidth() |
1011 | { | 1012 | { |
1012 | mWidthValid = false; | 1013 | mWidthValid = false; |
1013 | } | 1014 | } |
1014 | 1015 | ||
1015 | 1016 | ||
1016 | void KJanusWidget::IconListBox::setShowAll( bool showAll ) | 1017 | void KJanusWidget::IconListBox::setShowAll( bool showAll ) |
1017 | { | 1018 | { |
1018 | mShowAll = showAll; | 1019 | mShowAll = showAll; |
1019 | mHeightValid = false; | 1020 | mHeightValid = false; |
1020 | } | 1021 | } |
1021 | 1022 | ||
1022 | 1023 | ||
1023 | 1024 | ||
1024 | KJanusWidget::IconListItem::IconListItem( QListBox *listbox, const QPixmap &pixmap, | 1025 | KJanusWidget::IconListItem::IconListItem( QListBox *listbox, const QPixmap &pixmap, |
1025 | const QString &text ) | 1026 | const QString &text ) |
1026 | : QListBoxItem( listbox ) | 1027 | : QListBoxItem( listbox ) |
1027 | { | 1028 | { |
1028 | mPixmap = pixmap; | 1029 | mPixmap = pixmap; |
1029 | if( mPixmap.isNull() == true ) | 1030 | if( mPixmap.isNull() == true ) |
1030 | { | 1031 | { |
1031 | mPixmap = defaultPixmap(); | 1032 | mPixmap = defaultPixmap(); |
1032 | } | 1033 | } |
1033 | setText( text ); | 1034 | setText( text ); |
1034 | mMinimumWidth = 0; | 1035 | mMinimumWidth = 0; |
1035 | } | 1036 | } |
1036 | 1037 | ||
1037 | 1038 | ||
1038 | int KJanusWidget::IconListItem::expandMinimumWidth( int width ) | 1039 | int KJanusWidget::IconListItem::expandMinimumWidth( int width ) |
1039 | { | 1040 | { |
1040 | mMinimumWidth = QMAX( mMinimumWidth, width ); | 1041 | mMinimumWidth = QMAX( mMinimumWidth, width ); |
1041 | return( mMinimumWidth ); | 1042 | return( mMinimumWidth ); |
1042 | } | 1043 | } |
1043 | 1044 | ||
1044 | 1045 | ||
1045 | const QPixmap &KJanusWidget::IconListItem::defaultPixmap() | 1046 | const QPixmap &KJanusWidget::IconListItem::defaultPixmap() |
1046 | { | 1047 | { |
1047 | static QPixmap *pix=0; | 1048 | static QPixmap *pix=0; |
1048 | if( pix == 0 ) | 1049 | if( pix == 0 ) |
1049 | { | 1050 | { |
1050 | pix = new QPixmap( 32, 32 ); | 1051 | pix = new QPixmap( 32, 32 ); |
1051 | QPainter p( pix ); | 1052 | QPainter p( pix ); |
1052 | p.eraseRect( 0, 0, pix->width(), pix->height() ); | 1053 | p.eraseRect( 0, 0, pix->width(), pix->height() ); |
1053 | p.setPen( Qt::red ); | 1054 | p.setPen( Qt::red ); |
1054 | p.drawRect ( 0, 0, pix->width(), pix->height() ); | 1055 | p.drawRect ( 0, 0, pix->width(), pix->height() ); |
1055 | p.end(); | 1056 | p.end(); |
1056 | 1057 | ||
1057 | QBitmap mask( pix->width(), pix->height(), true); | 1058 | QBitmap mask( pix->width(), pix->height(), true); |
1058 | mask.fill( Qt::black ); | 1059 | mask.fill( Qt::black ); |
1059 | p.begin( &mask ); | 1060 | p.begin( &mask ); |
1060 | p.setPen( Qt::white ); | 1061 | p.setPen( Qt::white ); |
1061 | p.drawRect ( 0, 0, pix->width(), pix->height() ); | 1062 | p.drawRect ( 0, 0, pix->width(), pix->height() ); |
1062 | p.end(); | 1063 | p.end(); |
1063 | 1064 | ||
1064 | pix->setMask( mask ); | 1065 | pix->setMask( mask ); |
1065 | } | 1066 | } |
1066 | return( *pix ); | 1067 | return( *pix ); |
1067 | } | 1068 | } |
1068 | 1069 | ||
1069 | 1070 | ||
1070 | void KJanusWidget::IconListItem::paint( QPainter *painter ) | 1071 | void KJanusWidget::IconListItem::paint( QPainter *painter ) |
1071 | { | 1072 | { |
1072 | QFontMetrics fm = painter->fontMetrics(); | 1073 | QFontMetrics fm = painter->fontMetrics(); |
1073 | //int wt = fm.boundingRect(text()).width(); | 1074 | //int wt = fm.boundingRect(text()).width(); |
1074 | int wp = mPixmap.width(); | 1075 | int wp = mPixmap.width(); |
1075 | int ht = fm.lineSpacing(); | 1076 | int ht = fm.lineSpacing(); |
1076 | int hp = mPixmap.height(); | 1077 | int hp = mPixmap.height(); |
1077 | 1078 | ||
1078 | painter->drawPixmap( (mMinimumWidth-wp)/2, 5, mPixmap ); | 1079 | painter->drawPixmap( (mMinimumWidth-wp)/2, 5, mPixmap ); |
1079 | if( text().isEmpty() == false ) | 1080 | if( text().isEmpty() == false ) |
1080 | { | 1081 | { |
1081 | painter->drawText( 0, hp+7, mMinimumWidth, ht, Qt::AlignCenter, text() ); | 1082 | painter->drawText( 0, hp+7, mMinimumWidth, ht, Qt::AlignCenter, text() ); |
1082 | } | 1083 | } |
1083 | } | 1084 | } |
1084 | 1085 | ||
1085 | int KJanusWidget::IconListItem::height( const QListBox *lb ) const | 1086 | int KJanusWidget::IconListItem::height( const QListBox *lb ) const |
1086 | { | 1087 | { |
1087 | if( text().isEmpty() == true ) | 1088 | if( text().isEmpty() == true ) |
1088 | { | 1089 | { |
1089 | return( mPixmap.height() ); | 1090 | return( mPixmap.height() ); |
1090 | } | 1091 | } |
1091 | else | 1092 | else |
1092 | { | 1093 | { |
1093 | return( mPixmap.height() + lb->fontMetrics().lineSpacing()+10 ); | 1094 | return( mPixmap.height() + lb->fontMetrics().lineSpacing()+10 ); |
1094 | } | 1095 | } |
1095 | } | 1096 | } |
1096 | 1097 | ||
1097 | 1098 | ||
1098 | int KJanusWidget::IconListItem::width( const QListBox *lb ) const | 1099 | int KJanusWidget::IconListItem::width( const QListBox *lb ) const |
1099 | { | 1100 | { |
1100 | int wt = lb->fontMetrics().boundingRect(text()).width()+10; | 1101 | int wt = lb->fontMetrics().boundingRect(text()).width()+10; |
1101 | int wp = mPixmap.width() + 10; | 1102 | int wp = mPixmap.width() + 10; |
1102 | int w = QMAX( wt, wp ); | 1103 | int w = QMAX( wt, wp ); |
1103 | return( QMAX( w, mMinimumWidth ) ); | 1104 | return( QMAX( w, mMinimumWidth ) ); |
1104 | } | 1105 | } |
1105 | 1106 | ||
1106 | 1107 | ||
1107 | void KJanusWidget::virtual_hook( int, void* ) | 1108 | void KJanusWidget::virtual_hook( int, void* ) |
1108 | { /*BASE::virtual_hook( id, data );*/ } | 1109 | { /*BASE::virtual_hook( id, data );*/ } |
1109 | 1110 | ||
1110 | // TODO: In TreeList, if the last child of a node is removed, and there is no corrsponding widget for that node, allow the caller to | 1111 | // TODO: In TreeList, if the last child of a node is removed, and there is no corrsponding widget for that node, allow the caller to |
1111 | // delete the node. | 1112 | // delete the node. |
1112 | void KJanusWidget::removePage( QWidget *page ) | 1113 | void KJanusWidget::removePage( QWidget *page ) |
1113 | { | 1114 | { |
1114 | //US qDebug("KJanusWidget::removePage 1 %lu , %lu, %lu", d, page, &(d->mPageToInt)); | 1115 | //US qDebug("KJanusWidget::removePage 1 %lu , %lu, %lu", d, page, &(d->mPageToInt)); |
1115 | if (!d || !(d->mPageToInt.contains(page))) | 1116 | if (!d || !(d->mPageToInt.contains(page))) |
1116 | { | 1117 | { |
1117 | return; | 1118 | return; |
1118 | } | 1119 | } |
1119 | 1120 | ||
1120 | int index = d->mPageToInt[page]; | 1121 | int index = d->mPageToInt[page]; |
1121 | 1122 | ||
1122 | if ( mFace == TreeList ) | 1123 | if ( mFace == TreeList ) |
1123 | { | 1124 | { |
1124 | QMap<QListViewItem*, QWidget *>::Iterator i; | 1125 | QMap<QListViewItem*, QWidget *>::Iterator i; |
1125 | for( i = mTreeListToPageStack.begin(); i != mTreeListToPageStack.end(); ++i ) | 1126 | for( i = mTreeListToPageStack.begin(); i != mTreeListToPageStack.end(); ++i ) |
1126 | if (i.data()==page) | 1127 | if (i.data()==page) |
1127 | { | 1128 | { |
1128 | delete i.key(); | 1129 | delete i.key(); |
1129 | mPageStack->removeWidget(page); | 1130 | mPageStack->removeWidget(page); |
1130 | mTreeListToPageStack.remove(i); | 1131 | mTreeListToPageStack.remove(i); |
1131 | d->mIntToTitle.remove(index); | 1132 | d->mIntToTitle.remove(index); |
1132 | d->mPageToInt.remove(page); | 1133 | d->mPageToInt.remove(page); |
1133 | d->mIntToPage.remove(index); | 1134 | d->mIntToPage.remove(index); |
1134 | break; | 1135 | break; |
1135 | } | 1136 | } |
1136 | } | 1137 | } |
1137 | else if ( mFace == IconList ) | 1138 | else if ( mFace == IconList ) |
1138 | { | 1139 | { |
1139 | QMap<QListBoxItem*, QWidget *>::Iterator i; | 1140 | QMap<QListBoxItem*, QWidget *>::Iterator i; |
1140 | for( i = mIconListToPageStack.begin(); i != mIconListToPageStack.end(); ++i ) | 1141 | for( i = mIconListToPageStack.begin(); i != mIconListToPageStack.end(); ++i ) |
1141 | if (i.data()==page) | 1142 | if (i.data()==page) |
1142 | { | 1143 | { |
1143 | delete i.key(); | 1144 | delete i.key(); |
1144 | mPageStack->removeWidget(page); | 1145 | mPageStack->removeWidget(page); |
1145 | mIconListToPageStack.remove(i); | 1146 | mIconListToPageStack.remove(i); |
1146 | d->mIntToTitle.remove(index); | 1147 | d->mIntToTitle.remove(index); |
1147 | d->mPageToInt.remove(page); | 1148 | d->mPageToInt.remove(page); |
1148 | d->mIntToPage.remove(index); | 1149 | d->mIntToPage.remove(index); |
1149 | break; | 1150 | break; |
1150 | } | 1151 | } |
1151 | } | 1152 | } |
1152 | else // Tabbed | 1153 | else // Tabbed |
1153 | { | 1154 | { |
1154 | mTabControl->removePage(page); | 1155 | mTabControl->removePage(page); |
1155 | d->mPageToInt.remove(page); | 1156 | d->mPageToInt.remove(page); |
1156 | d->mIntToPage.remove(index); | 1157 | d->mIntToPage.remove(index); |
1157 | } | 1158 | } |
1158 | } | 1159 | } |
1159 | 1160 | ||
1160 | QString KJanusWidget::pageTitle(int index) const | 1161 | QString KJanusWidget::pageTitle(int index) const |
1161 | { | 1162 | { |
1162 | if (!d || !d->mIntToTitle.contains(index)) | 1163 | if (!d || !d->mIntToTitle.contains(index)) |
1163 | return QString::null; | 1164 | return QString::null; |
1164 | else | 1165 | else |
1165 | return d->mIntToTitle[index]; | 1166 | return d->mIntToTitle[index]; |
1166 | } | 1167 | } |
1167 | 1168 | ||
1168 | QWidget *KJanusWidget::pageWidget(int index) const | 1169 | QWidget *KJanusWidget::pageWidget(int index) const |
1169 | { | 1170 | { |
1170 | if (!d || !d->mIntToPage.contains(index)) | 1171 | if (!d || !d->mIntToPage.contains(index)) |
1171 | return 0; | 1172 | return 0; |
1172 | else | 1173 | else |
1173 | return d->mIntToPage[index]; | 1174 | return d->mIntToPage[index]; |
1174 | } | 1175 | } |
1175 | 1176 | ||
1176 | //US #include "kjanuswidget.moc" | 1177 | //US #include "kjanuswidget.moc" |