• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
kjanuswidget.cpp
1 /* This file is part of the KDE Libraries
2  * Copyright (C) 1999-2000 Espen Sand (espensa@online.no)
3  * Copyright (C) 2003 Ravikiran Rajagopal (ravi@kde.org)
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library 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 GNU
13  * Library General Public License for more details.
14  *
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
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #include <tqbitmap.h>
22 #include <tqgrid.h>
23 #include <tqhbox.h>
24 #include <tqheader.h>
25 #include <tqlabel.h>
26 #include <tqlayout.h>
27 #include <tqobjectlist.h>
28 #include <tqpixmap.h>
29 #include <tqsplitter.h>
30 #include <tqtabwidget.h>
31 #include <tqvbox.h>
32 #include <tqwidgetstack.h>
33 #include <tqpainter.h>
34 #include <tqstyle.h>
35 
36 #include <tdeapplication.h>
37 #include <kdialog.h> // Access to some static members
38 #include <tdelocale.h>
39 #include <tdeglobal.h>
40 #include <tdeglobalsettings.h>
41 #include <kseparator.h>
42 #include <kdebug.h>
43 #include "kjanuswidget.h"
44 #include <tdelistview.h>
45 #include "kpushbutton.h"
46 #include "kguiitem.h"
47 
48 class KJanusWidget::IconListItem : public TQListBoxItem
49 {
50  public:
51  IconListItem( TQListBox *listbox, const TQPixmap &pixmap,
52  const TQString &text );
53  virtual int height( const TQListBox *lb ) const;
54  virtual int width( const TQListBox *lb ) const;
55  int expandMinimumWidth( int width );
56  void highlight( bool erase );
57 
58  protected:
59  const TQPixmap &defaultPixmap();
60  void paint( TQPainter *painter );
61 
62  private:
63  void paintContents( TQPainter *painter );
64 
65  TQPixmap mPixmap;
66  int mMinimumWidth;
67 };
68 
69 class KJanusWidget::KJanusWidgetPrivate
70 {
71 public:
72  KJanusWidgetPrivate() : mNextPageIndex(0), mListFrame( 0 ) { }
73 
74  int mNextPageIndex; // The next page index.
75 
76  // Dictionary for multipage modes.
77  TQMap<int,TQWidget*> mIntToPage;
78  // Reverse dictionary. Used because showPage() may be performance critical.
79  TQMap<TQWidget*,int> mPageToInt;
80  // Dictionary of title string associated with page.
81  TQMap<int, TQString> mIntToTitle;
82 
83  TQWidget * mListFrame;
84  TQSplitter * mSplitter;
85 };
86 
87 template class TQPtrList<TQListViewItem>;
88 
89 
90 KJanusWidget::KJanusWidget( TQWidget *parent, const char *name, int face )
91  : TQWidget( parent, name, 0 ),
92  mValid(false), mPageList(0),
93  mTitleList(0), mFace(face), mTitleLabel(0), mActivePageWidget(0),
94  mShowIconsInTreeList(false), d(0)
95 {
96  TQVBoxLayout *topLayout = new TQVBoxLayout( this );
97 
98  if( mFace == TreeList || mFace == IconList )
99  {
100  d = new KJanusWidgetPrivate;
101  d->mSplitter = 0;
102 
103  TQFrame *page;
104  if( mFace == TreeList )
105  {
106  d->mSplitter = new TQSplitter( this );
107  topLayout->addWidget( d->mSplitter, 10 );
108  mTreeListResizeMode = TQSplitter::KeepSize;
109 
110  d->mListFrame = new TQWidget( d->mSplitter );
111  TQVBoxLayout *dummy = new TQVBoxLayout( d->mListFrame, 0, KDialog::spacingHint() );
112  dummy->setAutoAdd( true );
113  mTreeList = new TDEListView( d->mListFrame );
114  mTreeList->addColumn( TQString::null );
115  mTreeList->header()->hide();
116  mTreeList->setRootIsDecorated(true);
117  mTreeList->setSorting( -1 );
118  connect( mTreeList, TQT_SIGNAL(selectionChanged()), TQT_SLOT(slotShowPage()) );
119  connect( mTreeList, TQT_SIGNAL(clicked(TQListViewItem *)), TQT_SLOT(slotItemClicked(TQListViewItem *)));
120 
121  //
122  // Page area. Title at top with a separator below and a pagestack using
123  // all available space at bottom.
124  //
125  TQFrame *p = new TQFrame( d->mSplitter );
126 
127  TQHBoxLayout *hbox = new TQHBoxLayout( p, 0, 0 );
128 
129  page = new TQFrame( p );
130  hbox->addWidget( page, 10 );
131  }
132  else
133  {
134  TQHBoxLayout *hbox = new TQHBoxLayout( topLayout );
135  d->mListFrame = new TQWidget( this );
136  hbox->addWidget( d->mListFrame );
137 
138  ( new TQVBoxLayout( d->mListFrame, 0, 0 ) )->setAutoAdd( true );
139  mIconList = new IconListBox( d->mListFrame );
140 
141  TQFont listFont( mIconList->font() );
142  listFont.setBold( true );
143  mIconList->setFont( listFont );
144 
145  mIconList->verticalScrollBar()->installEventFilter( this );
146  connect( mIconList, TQT_SIGNAL(selectionChanged()), TQT_SLOT(slotShowPage()));
147  connect( mIconList, TQT_SIGNAL(onItem(TQListBoxItem *)), TQT_SLOT(slotOnItem(TQListBoxItem *)));
148 
149  hbox->addSpacing( KDialog::marginHint() );
150  page = new TQFrame( this );
151  hbox->addWidget( page, 10 );
152  }
153 
154  //
155  // Rest of page area. Title at top with a separator below and a
156  // pagestack using all available space at bottom.
157  //
158 
159  TQVBoxLayout *vbox = new TQVBoxLayout( page, 0, KDialog::spacingHint() );
160 
161  mTitleLabel = new TQLabel( i18n("Empty Page"), page, "KJanusWidgetTitleLabel" );
162  vbox->addWidget( mTitleLabel, 0, TQApplication::reverseLayout() ? AlignRight : AlignLeft );
163 
164  TQFont titleFont( mTitleLabel->font() );
165  titleFont.setBold( true );
166  mTitleLabel->setFont( titleFont );
167 
168  mTitleSep = new KSeparator( page );
169  mTitleSep->setFrameStyle( TQFrame::HLine|TQFrame::Plain );
170  vbox->addWidget( mTitleSep );
171 
172  mPageStack = new TQWidgetStack( page );
173  connect(mPageStack, TQT_SIGNAL(aboutToShow(TQWidget *)),
174  TQT_SIGNAL(aboutToShowPage(TQWidget *)));
175  vbox->addWidget( mPageStack, 10 );
176  }
177  else if( mFace == Tabbed )
178  {
179  d = new KJanusWidgetPrivate;
180 
181  mTabControl = new TQTabWidget( this );
182  mTabControl->setMargin (KDialog::marginHint());
183  connect(mTabControl, TQT_SIGNAL(currentChanged(TQWidget *)),
184  TQT_SIGNAL(aboutToShowPage(TQWidget *)));
185  topLayout->addWidget( mTabControl, 10 );
186  }
187  else if( mFace == Swallow )
188  {
189  mSwallowPage = new TQWidget( this );
190  topLayout->addWidget( mSwallowPage, 10 );
191  }
192  else
193  {
194  mFace = Plain;
195  mPlainPage = new TQFrame( this );
196  topLayout->addWidget( mPlainPage, 10 );
197  }
198 
199  if ( kapp )
200  connect(kapp,TQT_SIGNAL(tdedisplayFontChanged()),TQT_SLOT(slotFontChanged()));
201  mValid = true;
202 
203  setSwallowedWidget(0); // Set default size if 'mFace' is Swallow.
204 }
205 
206 
207 KJanusWidget::~KJanusWidget()
208 {
209  delete d;
210 }
211 
212 
213 bool KJanusWidget::isValid() const
214 {
215  return mValid;
216 }
217 
218 
219 TQFrame *KJanusWidget::plainPage()
220 {
221  return mPlainPage;
222 }
223 
224 
225 int KJanusWidget::face() const
226 {
227  return mFace;
228 }
229 
230 TQWidget *KJanusWidget::FindParent()
231 {
232  if( mFace == Tabbed ) {
233  return mTabControl;
234  }
235  else {
236  return this;
237  }
238 }
239 
240 TQFrame *KJanusWidget::addPage( const TQStringList &items, const TQString &header,
241  const TQPixmap &pixmap )
242 {
243  if( !mValid )
244  {
245  kdDebug() << "addPage: Invalid object" << endl;
246  return 0;
247  }
248 
249  TQFrame *page = new TQFrame( FindParent(), "page" );
250  addPageWidget( page, items, header, pixmap );
251 
252  return page;
253 }
254 
255 void KJanusWidget::pageGone( TQObject *obj )
256 {
257  removePage( TQT_TQWIDGET( obj ) );
258 }
259 
260 void KJanusWidget::slotReopen( TQListViewItem * item )
261 {
262  if( item )
263  item->setOpen( true );
264 }
265 
266 TQFrame *KJanusWidget::addPage( const TQString &itemName, const TQString &header,
267  const TQPixmap &pixmap )
268 {
269  TQStringList items;
270  items << itemName;
271  return addPage(items, header, pixmap);
272 }
273 
274 
275 
276 TQVBox *KJanusWidget::addVBoxPage( const TQStringList &items,
277  const TQString &header,
278  const TQPixmap &pixmap )
279 {
280  if( !mValid )
281  {
282  kdDebug() << "addPage: Invalid object" << endl;
283  return 0;
284  }
285 
286  TQVBox *page = new TQVBox(FindParent() , "page" );
287  page->setSpacing( KDialog::spacingHint() );
288  addPageWidget( page, items, header, pixmap );
289 
290  return page;
291 }
292 
293 TQVBox *KJanusWidget::addVBoxPage( const TQString &itemName,
294  const TQString &header,
295  const TQPixmap &pixmap )
296 {
297  TQStringList items;
298  items << itemName;
299  return addVBoxPage(items, header, pixmap);
300 }
301 
302 TQHBox *KJanusWidget::addHBoxPage( const TQStringList &items,
303  const TQString &header,
304  const TQPixmap &pixmap )
305 {
306  if( !mValid ) {
307  kdDebug() << "addPage: Invalid object" << endl;
308  return 0;
309  }
310 
311  TQHBox *page = new TQHBox(FindParent(), "page");
312  page->setSpacing( KDialog::spacingHint() );
313  addPageWidget( page, items, header, pixmap );
314 
315  return page;
316 }
317 
318 TQHBox *KJanusWidget::addHBoxPage( const TQString &itemName,
319  const TQString &header,
320  const TQPixmap &pixmap )
321 {
322  TQStringList items;
323  items << itemName;
324  return addHBoxPage(items, header, pixmap);
325 }
326 
327 TQGrid *KJanusWidget::addGridPage( int n, Orientation dir,
328  const TQStringList &items,
329  const TQString &header,
330  const TQPixmap &pixmap )
331 {
332  if( !mValid )
333  {
334  kdDebug() << "addPage: Invalid object" << endl;
335  return 0;
336  }
337 
338  TQGrid *page = new TQGrid( n, dir, FindParent(), "page" );
339  page->setSpacing( KDialog::spacingHint() );
340  addPageWidget( page, items, header, pixmap );
341 
342  return page;
343 }
344 
345 
346 TQGrid *KJanusWidget::addGridPage( int n, Orientation dir,
347  const TQString &itemName,
348  const TQString &header,
349  const TQPixmap &pixmap )
350 {
351  TQStringList items;
352  items << itemName;
353  return addGridPage(n, dir, items, header, pixmap);
354 }
355 
356 void KJanusWidget::InsertTreeListItem(const TQStringList &items, const TQPixmap &pixmap, TQFrame *page)
357 {
358  bool isTop = true;
359  TQListViewItem *curTop = 0, *child, *last, *newChild;
360  unsigned int index = 1;
361  TQStringList curPath;
362 
363  for ( TQStringList::ConstIterator it = items.begin(); it != items.end(); ++it, index++ ) {
364  TQString name = (*it);
365  bool isPath = ( index != items.count() );
366 
367  // Find the first child.
368  if (isTop) {
369  child = mTreeList->firstChild();
370  }
371  else {
372  child = curTop->firstChild();
373  }
374 
375  // Now search for a child with the current Name, and if it we doesn't
376  // find it, then remember the location of the last child.
377  for (last = 0; child && child->text(0) != name ; last = child, child = child->nextSibling());
378 
379  if (!last && !child) {
380  // This node didn't have any children at all, lets just insert the
381  // new child.
382  if (isTop)
383  newChild = new TQListViewItem(mTreeList, name);
384  else
385  newChild = new TQListViewItem(curTop, name);
386 
387  }
388  else if (child) {
389  // we found the given name in this child.
390  if (!isPath) {
391  kdDebug() << "The element inserted was already in the TreeList box!" << endl;
392  return;
393  }
394  else {
395  // Ok we found the folder
396  newChild = child;
397  }
398  }
399  else {
400  // the node had some children, but we didn't find the given name
401  if (isTop)
402  newChild = new TQListViewItem(mTreeList, last, name);
403  else
404  newChild = new TQListViewItem(curTop, last, name);
405  }
406 
407  // Now make the element expandable if it is a path component, and make
408  // ready for next loop
409  if (isPath) {
410  newChild->setExpandable(true);
411  curTop = newChild;
412  isTop = false;
413  curPath << name;
414 
415  TQString key = curPath.join("_/_");
416  if (mFolderIconMap.contains(key)) {
417  TQPixmap p = mFolderIconMap[key];
418  newChild->setPixmap(0,p);
419  }
420  }
421  else {
422  if (mShowIconsInTreeList) {
423  newChild->setPixmap(0, pixmap);
424  }
425  mTreeListToPageStack.insert(newChild, page);
426  }
427  }
428 }
429 
430 void KJanusWidget::addPageWidget( TQFrame *page, const TQStringList &items,
431  const TQString &header,const TQPixmap &pixmap )
432 {
433  connect(page, TQT_SIGNAL(destroyed(TQObject*)), TQT_SLOT(pageGone(TQObject*)));
434 
435  if( mFace == Tabbed )
436  {
437  mTabControl->addTab (page, items.last());
438  d->mIntToPage[d->mNextPageIndex] = static_cast<TQWidget*>(page);
439  d->mPageToInt[static_cast<TQWidget*>(page)] = d->mNextPageIndex;
440  d->mNextPageIndex++;
441  }
442  else if( mFace == TreeList || mFace == IconList )
443  {
444  d->mIntToPage[d->mNextPageIndex] = static_cast<TQWidget*>(page);
445  d->mPageToInt[static_cast<TQWidget*>(page)] = d->mNextPageIndex;
446  mPageStack->addWidget( page, 0 );
447 
448  if (items.isEmpty()) {
449  kdDebug() << "Invalid TQStringList, with zero items" << endl;
450  return;
451  }
452 
453  if( mFace == TreeList )
454  {
455  InsertTreeListItem(items, pixmap, page);
456  }
457  else // mFace == IconList
458  {
459  TQString itemName = items.last();
460  IconListItem *item = new IconListItem( mIconList, pixmap, itemName );
461  mIconListToPageStack.insert(item, page);
462  mIconList->invalidateHeight();
463  mIconList->invalidateWidth();
464 
465  if (mIconList->isVisible())
466  mIconList->updateWidth();
467  }
468 
469  //
470  // Make sure the title label is sufficiently wide
471  //
472  TQString lastName = items.last();
473  const TQString &title = (!header.isNull() ? header : lastName);
474  TQRect r = mTitleLabel->fontMetrics().boundingRect( title );
475  if( mTitleLabel->minimumWidth() < r.width() )
476  {
477  mTitleLabel->setMinimumWidth( r.width() );
478  }
479  d->mIntToTitle[d->mNextPageIndex] = title;
480  if( d->mIntToTitle.count() == 1 )
481  {
482  showPage(0);
483  }
484  d->mNextPageIndex++;
485  }
486  else
487  {
488  kdDebug() << "KJanusWidget::addPageWidget: can only add a page in Tabbed, TreeList or IconList modes" << endl;
489  }
490 
491 }
492 
493 void KJanusWidget::setFolderIcon(const TQStringList &path, const TQPixmap &pixmap)
494 {
495  TQString key = path.join("_/_");
496  mFolderIconMap.insert(key,pixmap);
497 }
498 
499 
500 
501 bool KJanusWidget::setSwallowedWidget( TQWidget *widget )
502 {
503  if( mFace != Swallow || !mValid )
504  {
505  return false;
506  }
507 
508  //
509  // Remove current layout and make a new.
510  //
511  delete mSwallowPage->layout();
512 
513  TQGridLayout *gbox = new TQGridLayout( mSwallowPage, 1, 1, 0 );
514 
515  //
516  // Hide old children
517  //
518  TQObjectList l = mSwallowPage->childrenListObject(); // silence please
519  for( uint i=0; i < l.count(); i++ )
520  {
521  TQObject *o = l.at(i);
522  if( o->isWidgetType() )
523  {
524  ((TQWidget*)o)->hide();
525  }
526  }
527 
528  //
529  // Add new child or make default size
530  //
531  if( !widget )
532  {
533  gbox->addRowSpacing(0,100);
534  gbox->addColSpacing(0,100);
535  mSwallowPage->setMinimumSize(100,100);
536  }
537  else
538  {
539  if( TQT_BASE_OBJECT(widget->parent()) != TQT_BASE_OBJECT(mSwallowPage) )
540  {
541  widget->reparent( mSwallowPage, 0, TQPoint(0,0) );
542  }
543  gbox->addWidget(widget, 0, 0 );
544  gbox->activate();
545  mSwallowPage->setMinimumSize( widget->minimumSize() );
546  }
547 
548  return true;
549 }
550 
551 bool KJanusWidget::slotShowPage()
552 {
553  if( !mValid )
554  {
555  return false;
556  }
557 
558  if( mFace == TreeList )
559  {
560  TQListViewItem *node = mTreeList->selectedItem();
561  if( !node ) { return false; }
562 
563  TQWidget *stackItem = mTreeListToPageStack[node];
564  // Make sure to call through the virtual function showPage(int)
565  return showPage(d->mPageToInt[stackItem]);
566  }
567  else if( mFace == IconList )
568  {
569  TQListBoxItem *node = mIconList->item( mIconList->currentItem() );
570  if( !node ) { return false; }
571  TQWidget *stackItem = mIconListToPageStack[node];
572  // Make sure to call through the virtual function showPage(int)
573  return showPage(d->mPageToInt[stackItem]);
574  }
575 
576  return false;
577 }
578 
579 
580 bool KJanusWidget::showPage( int index )
581 {
582  if( !d || !mValid )
583  {
584  return false;
585  }
586  else
587  {
588  return showPage(d->mIntToPage[index]);
589  }
590 }
591 
592 
593 bool KJanusWidget::showPage( TQWidget *w )
594 {
595  if( !w || !mValid )
596  {
597  return false;
598  }
599 
600  if( mFace == TreeList || mFace == IconList )
601  {
602  mPageStack->raiseWidget( w );
603  mActivePageWidget = w;
604 
605  int index = d->mPageToInt[w];
606  mTitleLabel->setText( d->mIntToTitle[index] );
607  if( mFace == TreeList )
608  {
609  TQMap<TQListViewItem *, TQWidget *>::Iterator it;
610  for (it = mTreeListToPageStack.begin(); it != mTreeListToPageStack.end(); ++it){
611  TQListViewItem *key = it.key();
612  TQWidget *val = it.data();
613  if (val == w) {
614  mTreeList->setSelected(key, true );
615  break;
616  }
617  }
618  }
619  else
620  {
621  TQMap<TQListBoxItem *, TQWidget *>::Iterator it;
622  for (it = mIconListToPageStack.begin(); it != mIconListToPageStack.end(); ++it){
623  TQListBoxItem *key = it.key();
624  TQWidget *val = it.data();
625  if (val == w) {
626  mIconList->setSelected( key, true );
627  break;
628  }
629  }
630  }
631  }
632  else if( mFace == Tabbed )
633  {
634  mTabControl->showPage(w);
635  mActivePageWidget = w;
636  }
637  else
638  {
639  return false;
640  }
641 
642  return true;
643 }
644 
645 
646 int KJanusWidget::activePageIndex() const
647 {
648  if( mFace == TreeList) {
649  TQListViewItem *node = mTreeList->selectedItem();
650  if( !node ) { return -1; }
651  TQWidget *stackItem = mTreeListToPageStack[node];
652  return d->mPageToInt[stackItem];
653  }
654  else if (mFace == IconList) {
655  TQListBoxItem *node = mIconList->item( mIconList->currentItem() );
656  if( !node ) { return false; }
657  TQWidget *stackItem = mIconListToPageStack[node];
658  return d->mPageToInt[stackItem];
659  }
660  else if( mFace == Tabbed ) {
661  TQWidget *widget = mTabControl->currentPage();
662  return ( !widget ? -1 : d->mPageToInt[widget] );
663  }
664  else {
665  return -1;
666  }
667 }
668 
669 
670 int KJanusWidget::pageIndex( TQWidget *widget ) const
671 {
672  if( !widget )
673  {
674  return -1;
675  }
676  else if( mFace == TreeList || mFace == IconList )
677  {
678  return d->mPageToInt[widget];
679  }
680  else if( mFace == Tabbed )
681  {
682  //
683  // The user gets the real page widget with addVBoxPage(), addHBoxPage()
684  // and addGridPage() but not with addPage() which returns a child of
685  // the toplevel page. addPage() returns a TQFrame so I check for that.
686  //
687  if( widget->isA(TQFRAME_OBJECT_NAME_STRING) )
688  {
689  return d->mPageToInt[widget->parentWidget()];
690  }
691  else
692  {
693  return d->mPageToInt[widget];
694  }
695  }
696  else
697  {
698  return -1;
699  }
700 }
701 
702 void KJanusWidget::slotFontChanged()
703 {
704  if( mTitleLabel )
705  {
706  mTitleLabel->setFont( TDEGlobalSettings::generalFont() );
707  TQFont titleFont( mTitleLabel->font() );
708  titleFont.setBold( true );
709  mTitleLabel->setFont( titleFont );
710  }
711 
712  if( mFace == IconList )
713  {
714  TQFont listFont( mIconList->font() );
715  listFont.setBold( true );
716  mIconList->setFont( listFont );
717  mIconList->invalidateHeight();
718  mIconList->invalidateWidth();
719  }
720 }
721 
722 // makes the treelist behave like the list of kcontrol
723 void KJanusWidget::slotItemClicked(TQListViewItem *it)
724 {
725  if(it && (it->childCount()>0))
726  it->setOpen(!it->isOpen());
727 }
728 
729 // hack because qt does not support Q_OBJECT in nested classes
730 void KJanusWidget::slotOnItem(TQListBoxItem *qitem)
731 {
732  mIconList->slotOnItem( qitem );
733 }
734 
735 void KJanusWidget::setFocus()
736 {
737  if( !mValid ) { return; }
738  if( mFace == TreeList )
739  {
740  mTreeList->setFocus();
741  }
742  if( mFace == IconList )
743  {
744  mIconList->setFocus();
745  }
746  else if( mFace == Tabbed )
747  {
748  mTabControl->setFocus();
749  }
750  else if( mFace == Swallow )
751  {
752  mSwallowPage->setFocus();
753  }
754  else if( mFace == Plain )
755  {
756  mPlainPage->setFocus();
757  }
758 }
759 
760 
761 TQSize KJanusWidget::minimumSizeHint() const
762 {
763  if( mFace == TreeList || mFace == IconList )
764  {
765  TQSize s1( KDialog::spacingHint(), KDialog::spacingHint()*2 );
766  TQSize s2(0,0);
767  TQSize s3(0,0);
768  TQSize s4( mPageStack->sizeHint() );
769 
770  if( mFace == TreeList )
771  {
772  s1.rwidth() += style().pixelMetric( TQStyle::PM_SplitterWidth );
773  s2 = mTreeList->minimumSize();
774  }
775  else
776  {
777  mIconList->updateMinimumHeight();
778  mIconList->updateWidth();
779  s2 = mIconList->minimumSize();
780  }
781 
782  if( mTitleLabel->isVisible() )
783  {
784  s3 += mTitleLabel->sizeHint();
785  s3.rheight() += mTitleSep->minimumSize().height();
786  }
787 
788  //
789  // Select the tallest item. It has only effect in IconList mode
790  //
791  int h1 = s1.rheight() + s3.rheight() + s4.height();
792  int h2 = TQMAX( h1, s2.rheight() );
793 
794  return TQSize( s1.width()+s2.width()+TQMAX(s3.width(),s4.width()), h2 );
795  }
796  else if( mFace == Tabbed )
797  {
798  return mTabControl->sizeHint();
799  }
800  else if( mFace == Swallow )
801  {
802  return mSwallowPage->minimumSize();
803  }
804  else if( mFace == Plain )
805  {
806  return mPlainPage->sizeHint();
807  }
808  else
809  {
810  return TQSize( 100, 100 ); // Should never happen though.
811  }
812 
813 }
814 
815 
816 TQSize KJanusWidget::sizeHint() const
817 {
818  return minimumSizeHint();
819 }
820 
821 
822 void KJanusWidget::setTreeListAutoResize( bool state )
823 {
824  if( mFace == TreeList )
825  {
826  mTreeListResizeMode = !state ?
827  TQSplitter::KeepSize : TQSplitter::Stretch;
828  if( d->mSplitter )
829  d->mSplitter->setResizeMode( d->mListFrame, mTreeListResizeMode );
830  }
831 }
832 
833 
834 void KJanusWidget::setIconListAllVisible( bool state )
835 {
836  if( mFace == IconList )
837  {
838  mIconList->setShowAll( state );
839  }
840 }
841 
842 void KJanusWidget::setShowIconsInTreeList( bool state )
843 {
844  mShowIconsInTreeList = state;
845 }
846 
847 void KJanusWidget::setRootIsDecorated( bool state )
848 {
849  if( mFace == TreeList ) {
850  mTreeList->setRootIsDecorated(state);
851  }
852 }
853 
854 void KJanusWidget::unfoldTreeList( bool persist )
855 {
856  if( mFace == TreeList )
857  {
858  if( persist )
859  connect( mTreeList, TQT_SIGNAL( collapsed( TQListViewItem * ) ), this, TQT_SLOT( slotReopen( TQListViewItem * ) ) );
860  else
861  disconnect( mTreeList, TQT_SIGNAL( collapsed( TQListViewItem * ) ), this, TQT_SLOT( slotReopen( TQListViewItem * ) ) );
862 
863  for( TQListViewItem * item = mTreeList->firstChild(); item; item = item->itemBelow() )
864  item->setOpen( true );
865  }
866 }
867 
868 void KJanusWidget::addWidgetBelowList( TQWidget * widget )
869 {
870  if( ( mFace == TreeList || mFace == IconList ) && d->mListFrame )
871  {
872  widget->reparent( d->mListFrame, TQPoint() );
873  }
874 }
875 
876 void KJanusWidget::addButtonBelowList( const TQString & text, TQObject * recv, const char * slot )
877 {
878  if( ( mFace == TreeList || mFace == IconList ) && d->mListFrame )
879  {
880  TQPushButton * button = new TQPushButton( text, d->mListFrame, "KJanusWidget::buttonBelowList" );
881  connect( button, TQT_SIGNAL( clicked() ), recv, slot );
882  }
883 }
884 
885 void KJanusWidget::addButtonBelowList( const KGuiItem & item, TQObject * recv, const char * slot )
886 {
887  if( ( mFace == TreeList || mFace == IconList ) && d->mListFrame )
888  {
889  KPushButton * button = new KPushButton( item, d->mListFrame, "KJanusWidget::buttonBelowList" );
890  connect( button, TQT_SIGNAL( clicked() ), recv, slot );
891  }
892 }
893 
894 void KJanusWidget::showEvent( TQShowEvent * )
895 {
896  if( mFace == TreeList )
897  {
898  if( d->mSplitter )
899  d->mSplitter->setResizeMode( d->mListFrame, mTreeListResizeMode );
900  }
901 }
902 
903 
904 //
905 // 2000-13-02 Espen Sand
906 // It should be obvious that this eventfilter must only be
907 // be installed on the vertical scrollbar of the mIconList.
908 //
909 bool KJanusWidget::eventFilter( TQObject *o, TQEvent *e )
910 {
911  if( e->type() == TQEvent::Show )
912  {
913  IconListItem *item = (IconListItem*)mIconList->item(0);
914  if( item )
915  {
916  int lw = item->width( mIconList );
917  int sw = mIconList->verticalScrollBar()->sizeHint().width();
918  mIconList->setFixedWidth( lw+sw+mIconList->frameWidth()*2 );
919  }
920  }
921  else if( e->type() == TQEvent::Hide )
922  {
923  IconListItem *item = (IconListItem*)mIconList->item(0);
924  if( item )
925  {
926  int lw = item->width( mIconList );
927  mIconList->setFixedWidth( lw+mIconList->frameWidth()*2 );
928  }
929  }
930  return TQWidget::eventFilter( o, e );
931 }
932 
933 
934 
935 //
936 // Code for the icon list box
937 //
938 
939 
940 KJanusWidget::IconListBox::IconListBox( TQWidget *parent, const char *name,
941  WFlags f )
942  :TDEListBox( parent, name, f ), mShowAll(false), mHeightValid(false),
943  mWidthValid(false),
944  mOldItem(0)
945 {
946 }
947 
948 void KJanusWidget::IconListBox::updateMinimumHeight()
949 {
950  if( mShowAll && !mHeightValid )
951  {
952  int h = frameWidth()*2;
953  for( TQListBoxItem *i = item(0); i; i = i->next() )
954  {
955  h += i->height( this );
956  }
957  setMinimumHeight( h );
958  mHeightValid = true;
959  }
960 }
961 
962 
963 void KJanusWidget::IconListBox::updateWidth()
964 {
965  if( !mWidthValid )
966  {
967  int maxWidth = 10;
968  for( TQListBoxItem *i = item(0); i; i = i->next() )
969  {
970  int w = ((IconListItem *)i)->width(this);
971  maxWidth = TQMAX( w, maxWidth );
972  }
973 
974  for( TQListBoxItem *i = item(0); i; i = i->next() )
975  {
976  ((IconListItem *)i)->expandMinimumWidth( maxWidth );
977  }
978 
979  if( verticalScrollBar()->isVisible() )
980  {
981  maxWidth += verticalScrollBar()->sizeHint().width();
982  }
983 
984  setFixedWidth( maxWidth + frameWidth()*2 );
985  mWidthValid = true;
986  }
987 }
988 
989 
990 void KJanusWidget::IconListBox::invalidateHeight()
991 {
992  mHeightValid = false;
993 }
994 
995 
996 void KJanusWidget::IconListBox::invalidateWidth()
997 {
998  mWidthValid = false;
999 }
1000 
1001 
1002 void KJanusWidget::IconListBox::setShowAll( bool showAll )
1003 {
1004  mShowAll = showAll;
1005  mHeightValid = false;
1006 }
1007 
1008 
1009 void KJanusWidget::IconListBox::leaveEvent( TQEvent *ev )
1010 {
1011  TDEListBox::leaveEvent( ev );
1012 
1013  if ( mOldItem && !mOldItem->isSelected() )
1014  {
1015  ((KJanusWidget::IconListItem *) mOldItem)->highlight( true );
1016  mOldItem = 0;
1017  }
1018 }
1019 
1020 // hack because qt does not support Q_OBJECT in nested classes
1021 void KJanusWidget::IconListBox::slotOnItem(TQListBoxItem *qitem)
1022 {
1023  TDEListBox::slotOnItem( qitem );
1024 
1025  if ( qitem == mOldItem )
1026  {
1027  return;
1028  }
1029 
1030  if ( mOldItem && !mOldItem->isSelected() )
1031  {
1032  ((KJanusWidget::IconListItem *) mOldItem)->highlight( true );
1033  }
1034 
1035  KJanusWidget::IconListItem *item = dynamic_cast< KJanusWidget::IconListItem * >( qitem );
1036  if ( item && !item->isSelected() )
1037  {
1038  item->highlight( false );
1039  mOldItem = item;
1040  }
1041  else
1042  {
1043  mOldItem = 0;
1044  }
1045 }
1046 
1047 
1048 
1049 KJanusWidget::IconListItem::IconListItem( TQListBox *listbox, const TQPixmap &pixmap,
1050  const TQString &text )
1051  : TQListBoxItem( listbox )
1052 {
1053  mPixmap = pixmap;
1054  if( mPixmap.isNull() )
1055  {
1056  mPixmap = defaultPixmap();
1057  }
1058  setText( text );
1059  setCustomHighlighting( true );
1060  mMinimumWidth = 0;
1061 }
1062 
1063 
1064 int KJanusWidget::IconListItem::expandMinimumWidth( int width )
1065 {
1066  mMinimumWidth = TQMAX( mMinimumWidth, width );
1067  return mMinimumWidth;
1068 }
1069 
1070 
1071 void KJanusWidget::IconListItem::highlight( bool erase )
1072 {
1073  // FIXME: Add configuration option to disable highlighting
1074  // For now, always disable highlighting
1075  erase = true;
1076 
1077  TQRect r = listBox()->itemRect( this );
1078  r.addCoords( 1, 1, -1, -1 );
1079 
1080  TQPainter p( listBox()->viewport() );
1081  p.setClipRegion( r );
1082 
1083  const TQColorGroup &cg = listBox()->colorGroup();
1084  if ( erase )
1085  {
1086  p.setPen( cg.base() );
1087  p.setBrush( cg.base() );
1088  p.drawRect( r );
1089  }
1090  else
1091  {
1092  p.setBrush( cg.highlight().light( 120 ) );
1093  p.drawRect( r );
1094 
1095  p.setPen( cg.highlight().dark( 140 ) );
1096  p.drawRect( r );
1097  }
1098 
1099  p.setPen( cg.foreground() );
1100  p.translate( r.x() - 1, r.y() - 1 );
1101  paintContents( &p );
1102 }
1103 
1104 
1105 const TQPixmap &KJanusWidget::IconListItem::defaultPixmap()
1106 {
1107  static TQPixmap *pix=0;
1108  if( !pix )
1109  {
1110  pix = new TQPixmap( 32, 32 );
1111  TQPainter p( pix );
1112  p.eraseRect( 0, 0, pix->width(), pix->height() );
1113  p.setPen( Qt::red );
1114  p.drawRect ( 0, 0, pix->width(), pix->height() );
1115  p.end();
1116 
1117  TQBitmap mask( pix->width(), pix->height(), true );
1118  mask.fill( Qt::black );
1119  p.begin( &mask );
1120  p.setPen( Qt::white );
1121  p.drawRect ( 0, 0, pix->width(), pix->height() );
1122  p.end();
1123 
1124  pix->setMask( mask );
1125  }
1126  return *pix;
1127 }
1128 
1129 
1130 void KJanusWidget::IconListItem::paint( TQPainter *painter )
1131 {
1132  TQRect itemPaintRegion( listBox()->itemRect( this ) );
1133  TQRect r( 1, 1, itemPaintRegion.width() - 2, itemPaintRegion.height() - 2);
1134 
1135  if ( isSelected() )
1136  {
1137  painter->eraseRect( r );
1138 
1139  painter->save();
1140  painter->setPen( listBox()->colorGroup().highlight().dark( 160 ) );
1141  painter->drawRect( r );
1142  painter->restore();
1143  }
1144 
1145  paintContents( painter );
1146 }
1147 
1148 
1149 void KJanusWidget::IconListItem::paintContents( TQPainter *painter )
1150 {
1151  TQFontMetrics fm = painter->fontMetrics();
1152  int ht = fm.boundingRect( 0, 0, 0, 0, Qt::AlignCenter, text() ).height();
1153  int wp = mPixmap.width();
1154  int hp = mPixmap.height();
1155  painter->drawPixmap( (mMinimumWidth - wp) / 2, 5, mPixmap );
1156 
1157  if( !text().isEmpty() )
1158  {
1159  painter->drawText( 1, hp + 7, mMinimumWidth - 2, ht, Qt::AlignCenter, text() );
1160  }
1161 }
1162 
1163 int KJanusWidget::IconListItem::height( const TQListBox *lb ) const
1164 {
1165  if( text().isEmpty() )
1166  {
1167  return mPixmap.height();
1168  }
1169  else
1170  {
1171  int ht = lb->fontMetrics().boundingRect( 0, 0, 0, 0, Qt::AlignCenter, text() ).height();
1172  return (mPixmap.height() + ht + 10);
1173  }
1174 }
1175 
1176 
1177 int KJanusWidget::IconListItem::width( const TQListBox *lb ) const
1178 {
1179  int wt = lb->fontMetrics().boundingRect( 0, 0, 0, 0, Qt::AlignCenter, text() ).width() + 10;
1180  int wp = mPixmap.width() + 10;
1181  int w = TQMAX( wt, wp );
1182  return TQMAX( w, mMinimumWidth );
1183 }
1184 
1185 
1186 void KJanusWidget::virtual_hook( int, void* )
1187 { /*BASE::virtual_hook( id, data );*/ }
1188 
1189 
1190 // 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
1191 // delete the node.
1192 void KJanusWidget::removePage( TQWidget *page )
1193 {
1194  if (!d || !d->mPageToInt.contains(page))
1195  return;
1196 
1197  int index = d->mPageToInt[page];
1198 
1199  if ( mFace == TreeList )
1200  {
1201  TQMap<TQListViewItem*, TQWidget *>::Iterator i;
1202  for( i = mTreeListToPageStack.begin(); i != mTreeListToPageStack.end(); ++i )
1203  if (i.data()==page)
1204  {
1205  delete i.key();
1206  mPageStack->removeWidget(page);
1207  mTreeListToPageStack.remove(i);
1208  d->mIntToTitle.remove(index);
1209  d->mPageToInt.remove(page);
1210  d->mIntToPage.remove(index);
1211  break;
1212  }
1213  }
1214  else if ( mFace == IconList )
1215  {
1216  TQMap<TQListBoxItem*, TQWidget *>::Iterator i;
1217  for( i = mIconListToPageStack.begin(); i != mIconListToPageStack.end(); ++i )
1218  if (i.data()==page)
1219  {
1220  delete i.key();
1221  mPageStack->removeWidget(page);
1222  mIconListToPageStack.remove(i);
1223  d->mIntToTitle.remove(index);
1224  d->mPageToInt.remove(page);
1225  d->mIntToPage.remove(index);
1226  break;
1227  }
1228  }
1229  else // Tabbed
1230  {
1231  mTabControl->removePage(page);
1232  d->mPageToInt.remove(page);
1233  d->mIntToPage.remove(index);
1234  }
1235 }
1236 
1237 
1238 TQString KJanusWidget::pageTitle(int index) const
1239 {
1240  if (!d || !d->mIntToTitle.contains(index))
1241  return TQString::null;
1242  else
1243  return d->mIntToTitle[index];
1244 }
1245 
1246 
1247 TQWidget *KJanusWidget::pageWidget(int index) const
1248 {
1249  if (!d || !d->mIntToPage.contains(index))
1250  return 0;
1251  else
1252  return d->mIntToPage[index];
1253 }
1254 
1255 #include "kjanuswidget.moc"
KDialog::marginHint
static int marginHint()
Return the number of pixels you shall use between a dialog edge and the outermost widget(s) according...
Definition: kdialog.cpp:104
KJanusWidget::pageTitle
TQString pageTitle(int index) const
Returns the title string associated with a page index in TreeList or IconList mode.
Definition: kjanuswidget.cpp:1238
KPushButton
This is nothing but a TQPushButton with drag-support and KGuiItem support.
Definition: kpushbutton.h:37
KJanusWidget::activePageIndex
virtual int activePageIndex() const
Returns the index of the page that are currently displayed.
Definition: kjanuswidget.cpp:646
KJanusWidget::sizeHint
virtual TQSize sizeHint() const
Returns the recommended size for the widget in order to be displayed properly.
Definition: kjanuswidget.cpp:816
KJanusWidget::pageIndex
virtual int pageIndex(TQWidget *widget) const
Returns the index of a page created with addPage , addVBoxPage , addHBoxPage or addGridPage ...
Definition: kjanuswidget.cpp:670
TDEStdAccel::key
int key(StdAccel) KDE_DEPRECATED
KJanusWidget::showEvent
virtual void showEvent(TQShowEvent *)
Reimplemented to handle the splitter width when the the face is TreeList.
Definition: kjanuswidget.cpp:894
KJanusWidget::setFolderIcon
virtual void setFolderIcon(const TQStringList &path, const TQPixmap &pixmap)
Sets the icon used in TreeList Mode for the given path.
Definition: kjanuswidget.cpp:493
KJanusWidget::setShowIconsInTreeList
virtual void setShowIconsInTreeList(bool state)
This function has only effect in TreeList mode.
Definition: kjanuswidget.cpp:842
kdDebug
kdbgstream kdDebug(int area=0)
KJanusWidget::pageWidget
TQWidget * pageWidget(int index) const
Returns the page widget associated with a page index or null if there is no such page.
Definition: kjanuswidget.cpp:1247
KSeparator
Standard horizontal or vertical separator.
Definition: kseparator.h:33
KJanusWidget::~KJanusWidget
~KJanusWidget()
Destructor.
Definition: kjanuswidget.cpp:207
KJanusWidget::setFocus
virtual void setFocus()
Give the keyboard input focus to the widget.
Definition: kjanuswidget.cpp:735
KJanusWidget::setRootIsDecorated
virtual void setRootIsDecorated(bool state)
This function has only effect in TreeList mode.
Definition: kjanuswidget.cpp:847
KJanusWidget::showPage
virtual bool showPage(int index)
Raises the page which was added by addPage().
Definition: kjanuswidget.cpp:580
tdelocale.h
KDialog::spacingHint
static int spacingHint()
Return the number of pixels you shall use between widgets inside a dialog according to the KDE standa...
Definition: kdialog.cpp:110
KGuiItem
An abstract class for GUI data such as ToolTip and Icon.
Definition: kguiitem.h:38
KJanusWidget::isValid
virtual bool isValid() const
Use this to verify that no memory allocation failed.
Definition: kjanuswidget.cpp:213
KJanusWidget::addHBoxPage
virtual TQHBox * addHBoxPage(const TQString &itemName, const TQString &header=TQString::null, const TQPixmap &pixmap=TQPixmap())
Add a new page when the class is used in TreeList, IconList or Tabbed mode.
Definition: kjanuswidget.cpp:318
TDEGlobalSettings::generalFont
static TQFont generalFont()
KJanusWidget::unfoldTreeList
void unfoldTreeList(bool persist=false)
This function has only effect in TreeList mode.
Definition: kjanuswidget.cpp:854
KJanusWidget::addWidgetBelowList
void addWidgetBelowList(TQWidget *widget)
Add a widget at the bottom of the TreeList/IconList.
Definition: kjanuswidget.cpp:868
KJanusWidget::minimumSizeHint
virtual TQSize minimumSizeHint() const
Returns the minimum size that must be made available for the widget so that UIs can be displayed prop...
Definition: kjanuswidget.cpp:761
TDEListView::setSorting
virtual void setSorting(int column, bool ascending=true)
Reimplemented to remember the current sort column and order.
Definition: tdelistview.cpp:2283
KJanusWidget::TreeList
The TreeList face provides a list in the left area and pages in the right.
Definition: kjanuswidget.h:104
KJanusWidget::addVBoxPage
virtual TQVBox * addVBoxPage(const TQString &item, const TQString &header=TQString::null, const TQPixmap &pixmap=TQPixmap())
Add a new page when the class is used in TreeList, IconList or Tabbed mode.
Definition: kjanuswidget.cpp:293
TDEListView
This Widget extends the functionality of TQListView to honor the system wide settings for Single Clic...
Definition: tdelistview.h:84
TDEListView::addColumn
virtual int addColumn(const TQString &label, int width=-1)
Reimplemented for full width support.
Definition: tdelistview.cpp:2177
KJanusWidget::aboutToShowPage
void aboutToShowPage(TQWidget *page)
This signal is emitted whenever the current page changes.
KJanusWidget::addButtonBelowList
void addButtonBelowList(const TQString &text, TQObject *recv, const char *slot)
Add a button at the bottom of the TreeList/IconList.
Definition: kjanuswidget.cpp:876
KJanusWidget::KJanusWidget
KJanusWidget(TQWidget *parent=0, const char *name=0, int face=Plain)
Constructor where you specify the face.
Definition: kjanuswidget.cpp:90
KJanusWidget::addGridPage
virtual TQGrid * addGridPage(int n, Orientation dir, const TQString &itemName, const TQString &header=TQString::null, const TQPixmap &pixmap=TQPixmap())
Add a new page when the class is used in either TreeList or Tabbed mode.
Definition: kjanuswidget.cpp:346
KJanusWidget::Tabbed
The Tabbed face is a common tabbed widget.
Definition: kjanuswidget.h:111
KJanusWidget::setIconListAllVisible
virtual void setIconListAllVisible(bool state)
This function has only effect in IconList mode.
Definition: kjanuswidget.cpp:834
KJanusWidget::Plain
The Plain face provides an empty widget (TQFrame) where you can place your widgets.
Definition: kjanuswidget.h:117
KJanusWidget::addPage
virtual TQFrame * addPage(const TQString &item, const TQString &header=TQString::null, const TQPixmap &pixmap=TQPixmap())
Add a new page when the class is used in TreeList, IconList or Tabbed mode.
Definition: kjanuswidget.cpp:266
KJanusWidget::setTreeListAutoResize
virtual void setTreeListAutoResize(bool state)
This function has only effect in TreeList mode.
Definition: kjanuswidget.cpp:822
KJanusWidget::removePage
void removePage(TQWidget *page)
Removes a page created with addPage, addVBoxPage, addHBoxPage or addGridPage.
Definition: kjanuswidget.cpp:1192
KJanusWidget::IconList
The IconList face provides an icon list in the left area and pages in the right.
Definition: kjanuswidget.h:133
endl
kndbgstream & endl(kndbgstream &s)
TDEListBox
A variant of TQListBox that honors KDE's system-wide settings.
Definition: tdelistbox.h:40
KJanusWidget::plainPage
virtual TQFrame * plainPage()
Returns the empty widget that is available in Plain mode.
Definition: kjanuswidget.cpp:219
KJanusWidget::Swallow
The Swallow face is provided in order to simplify the usage of existing widgets and to allow changing...
Definition: kjanuswidget.h:125
KJanusWidget::face
virtual int face() const
Returns the face type.
Definition: kjanuswidget.cpp:225
KJanusWidget::setSwallowedWidget
virtual bool setSwallowedWidget(TQWidget *widget)
Defines the widget to be swallowed.
Definition: kjanuswidget.cpp:501
KJanusWidget::eventFilter
virtual bool eventFilter(TQObject *o, TQEvent *e)
This function is used internally when in IconList mode.
Definition: kjanuswidget.cpp:909

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.8.8
This website is maintained by Timothy Pearson.