Diffstat (limited to 'libopie2/qt3/opieui/ojanuswidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/qt3/opieui/ojanuswidget.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/libopie2/qt3/opieui/ojanuswidget.cpp b/libopie2/qt3/opieui/ojanuswidget.cpp index 0a037ff..063e393 100644 --- a/libopie2/qt3/opieui/ojanuswidget.cpp +++ b/libopie2/qt3/opieui/ojanuswidget.cpp @@ -1,291 +1,291 @@ /* This file is part of the Opie Project Originally part of the KDE project (C) 1999-2000 Espen Sand (espensa@online.no) =. .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* QT */ #include <qbitmap.h> #include <qgrid.h> #include <qhbox.h> #include <qheader.h> #include <qlabel.h> #include <qlayout.h> #include <qobjectlist.h> #include <qpixmap.h> #include <qlistview.h> #include <qsplitter.h> #include <qtabwidget.h> #include <qvbox.h> #include <qwidgetstack.h> #include <qpainter.h> #include <qtimer.h> #include <qstyle.h> /* OPIE */ #include <opie2/odialog.h> #include <opie2/oseparator.h> #include <opie2/ojanuswidget.h> /*====================================================================================== * IconListItem *======================================================================================*/ class OJanusWidget::IconListItem : public QListBoxItem { public: IconListItem( QListBox *listbox, const QPixmap &pixmap, const QString &text ); virtual int height( const QListBox *lb ) const; virtual int width( const QListBox *lb ) const; int expandMinimumWidth( int width ); protected: const QPixmap &defaultPixmap(); void paint( QPainter *painter ); private: QPixmap mPixmap; int mMinimumWidth; }; template class QPtrList<QListViewItem>; /*====================================================================================== * OJanusWidget *======================================================================================*/ OJanusWidget::OJanusWidget( QWidget *parent, const char *name, int face ) : QWidget( parent, name, 0 ), mValid(false), mPageList(0), mTitleList(0), mFace(face), mTitleLabel(0), mActivePageWidget(0), mShowIconsInTreeList(false), d(0) { QVBoxLayout *topLayout = new QVBoxLayout( this ); if( mFace == TreeList || mFace == IconList ) { mPageList = new QPtrList<QWidget>; mTitleList = new QStringList(); QFrame *page; if( mFace == TreeList ) { QSplitter *splitter = new QSplitter( this ); topLayout->addWidget( splitter, 10 ); mTreeListResizeMode = QSplitter::KeepSize; mTreeList = new QListView( splitter ); mTreeList->addColumn( QString::fromLatin1("") ); mTreeList->header()->hide(); mTreeList->setRootIsDecorated(true); mTreeList->setSorting( -1 ); connect( mTreeList, SIGNAL(selectionChanged()), SLOT(slotShowPage()) ); - connect( mTreeList, SIGNAL(clicked(QListViewItem *)), SLOT(slotItemClicked(QListViewItem *))); + connect( mTreeList, SIGNAL(clicked(QListViewItem*)), SLOT(slotItemClicked(QListViewItem*))); // // Page area. Title at top with a separator below and a pagestack using // all available space at bottom. // QFrame *p = new QFrame( splitter ); QHBoxLayout *hbox = new QHBoxLayout( p, 0, 0 ); hbox->addSpacing( ODialog::spacingHint() ); page = new QFrame( p ); hbox->addWidget( page, 10 ); } else { QHBoxLayout *hbox = new QHBoxLayout( topLayout ); mIconList = new IconListBox( this ); QFont listFont( mIconList->font() ); listFont.setBold( true ); mIconList->setFont( listFont ); mIconList->verticalScrollBar()->installEventFilter( this ); hbox->addWidget( mIconList ); connect( mIconList, SIGNAL(selectionChanged()), SLOT(slotShowPage())); hbox->addSpacing( ODialog::spacingHint() ); page = new QFrame( this ); hbox->addWidget( page, 10 ); } // // Rest of page area. Title at top with a separator below and a // pagestack using all available space at bottom. // QVBoxLayout *vbox = new QVBoxLayout( page, 0, ODialog::spacingHint() ); mTitleLabel = new QLabel( QString::fromLatin1("Empty page"), page, "OJanusWidgetTitleLabel" ); vbox->addWidget( mTitleLabel ); QFont titleFont( mTitleLabel->font() ); titleFont.setBold( true ); mTitleLabel->setFont( titleFont ); mTitleSep = new OSeparator( page ); mTitleSep->setFrameStyle( QFrame::HLine|QFrame::Plain ); vbox->addWidget( mTitleSep ); mPageStack = new QWidgetStack( page ); - connect(mPageStack, SIGNAL(aboutToShow(QWidget *)), - this, SIGNAL(aboutToShowPage(QWidget *))); + connect(mPageStack, SIGNAL(aboutToShow(QWidget*)), + this, SIGNAL(aboutToShowPage(QWidget*))); vbox->addWidget( mPageStack, 10 ); } else if( mFace == Tabbed ) { mPageList = new QPtrList<QWidget>; mTabControl = new QTabWidget( this ); mTabControl->setMargin (ODialog::marginHint()); topLayout->addWidget( mTabControl, 10 ); } else if( mFace == Swallow ) { mSwallowPage = new QWidget( this ); topLayout->addWidget( mSwallowPage, 10 ); } else { mFace = Plain; mPlainPage = new QFrame( this ); topLayout->addWidget( mPlainPage, 10 ); } /* FIXME: Revise for Opie if ( kapp ) connect(kapp,SIGNAL(kdisplayFontChanged()),SLOT(slotFontChanged())); */ mValid = true; setSwallowedWidget(0); // Set default size if 'mFace' is Swallow. } OJanusWidget::~OJanusWidget() { delete mPageList; mPageList = 0; delete mTitleList; mTitleList = 0; } bool OJanusWidget::isValid() const { return( mValid ); } QFrame *OJanusWidget::plainPage() { return( mPlainPage ); } int OJanusWidget::face() const { return( mFace ); } QWidget *OJanusWidget::FindParent() { if( mFace == Tabbed ) { return mTabControl; } else { return this; } } QFrame *OJanusWidget::addPage( const QStringList &items, const QString &header, const QPixmap &pixmap ) { if( mValid == false ) { qDebug( "addPage: Invalid object" ); return( 0 ); } QFrame *page = new QFrame( FindParent(), "page" ); addPageWidget( page, items, header, pixmap ); return page; } void OJanusWidget::pageGone( QObject *obj ) { removePage( static_cast<QWidget*>( obj ) ); } void OJanusWidget::slotReopen( QListViewItem * item ) { if( item ) item->setOpen( true ); } QFrame *OJanusWidget::addPage( const QString &itemName, const QString &header, const QPixmap &pixmap ) { QStringList items; items << itemName; return addPage(items, header, pixmap); } QVBox *OJanusWidget::addVBoxPage( const QStringList &items, const QString &header, const QPixmap &pixmap ) { if( mValid == false ) { qDebug( "addPage: Invalid object" ); return( 0 ); } QVBox *page = new QVBox(FindParent() , "page" ); page->setSpacing( ODialog::spacingHint() ); addPageWidget( page, items, header, pixmap ); return page; } QVBox *OJanusWidget::addVBoxPage( const QString &itemName, const QString &header, const QPixmap &pixmap ) { QStringList items; items << itemName; @@ -738,259 +738,259 @@ void OJanusWidget::slotItemClicked(QListViewItem *it) void OJanusWidget::setFocus() { if( mValid == false ) { return; } if( mFace == TreeList ) { mTreeList->setFocus(); } if( mFace == IconList ) { mIconList->setFocus(); } else if( mFace == Tabbed ) { mTabControl->setFocus(); } else if( mFace == Swallow ) { mSwallowPage->setFocus(); } else if( mFace == Plain ) { mPlainPage->setFocus(); } } QSize OJanusWidget::minimumSizeHint() const { if( mFace == TreeList || mFace == IconList ) { QSize s1( ODialog::spacingHint(), ODialog::spacingHint()*2 ); QSize s2(0,0); QSize s3(0,0); QSize s4( mPageStack->sizeHint() ); if( mFace == TreeList ) { #if QT_VERSION < 300 s1.rwidth() += style().splitterWidth(); #else s1.rwidth() += style().pixelMetric( QStyle::PM_SplitterWidth ); #endif s2 = mTreeList->minimumSize(); } else { mIconList->updateMinimumHeight(); mIconList->updateWidth(); s2 = mIconList->minimumSize(); } if( mTitleLabel->isVisible() == true ) { s3 += mTitleLabel->sizeHint(); s3.rheight() += mTitleSep->minimumSize().height(); } // // Select the tallest item. It has only effect in IconList mode // int h1 = s1.rheight() + s3.rheight() + s4.height(); int h2 = QMAX( h1, s2.rheight() ); return( QSize( s1.width()+s2.width()+QMAX(s3.width(),s4.width()), h2 ) ); } else if( mFace == Tabbed ) { return( mTabControl->sizeHint() ); } else if( mFace == Swallow ) { return( mSwallowPage->minimumSize() ); } else if( mFace == Plain ) { return( mPlainPage->sizeHint() ); } else { return( QSize( 100, 100 ) ); // Should never happen though. } } QSize OJanusWidget::sizeHint() const { return( minimumSizeHint() ); } void OJanusWidget::setTreeListAutoResize( bool state ) { if( mFace == TreeList ) { mTreeListResizeMode = state == false ? QSplitter::KeepSize : QSplitter::Stretch; QSplitter *splitter = (QSplitter*)(mTreeList->parentWidget()); splitter->setResizeMode( mTreeList, mTreeListResizeMode ); } } void OJanusWidget::setIconListAllVisible( bool state ) { if( mFace == IconList ) { mIconList->setShowAll( state ); } } void OJanusWidget::setShowIconsInTreeList( bool state ) { mShowIconsInTreeList = state; } void OJanusWidget::setRootIsDecorated( bool state ) { if( mFace == TreeList ) { mTreeList->setRootIsDecorated(state); } } void OJanusWidget::unfoldTreeList( bool persist ) { if( mFace == TreeList ) { if( persist ) - connect( mTreeList, SIGNAL( collapsed( QListViewItem * ) ), this, SLOT( slotReopen( QListViewItem * ) ) ); + connect( mTreeList, SIGNAL( collapsed(QListViewItem*) ), this, SLOT( slotReopen(QListViewItem*) ) ); else - disconnect( mTreeList, SIGNAL( collapsed( QListViewItem * ) ), this, SLOT( slotReopen( QListViewItem * ) ) ); + disconnect( mTreeList, SIGNAL( collapsed(QListViewItem*) ), this, SLOT( slotReopen(QListViewItem*) ) ); for( QListViewItem * item = mTreeList->firstChild(); item; item = item->itemBelow() ) item->setOpen( true ); } } void OJanusWidget::showEvent( QShowEvent * ) { if( mFace == TreeList ) { QSplitter *splitter = (QSplitter*)(mTreeList->parentWidget()); splitter->setResizeMode( mTreeList, mTreeListResizeMode ); } } // // 2000-13-02 Espen Sand // It should be obvious that this eventfilter must only be // be installed on the vertical scrollbar of the mIconList. // bool OJanusWidget::eventFilter( QObject *o, QEvent *e ) { if( e->type() == QEvent::Show ) { IconListItem *item = (IconListItem*)mIconList->item(0); if( item != 0 ) { int lw = item->width( mIconList ); int sw = mIconList->verticalScrollBar()->sizeHint().width(); mIconList->setFixedWidth( lw+sw+mIconList->frameWidth()*2 ); } } else if( e->type() == QEvent::Hide ) { IconListItem *item = (IconListItem*)mIconList->item(0); if( item != 0 ) { int lw = item->width( mIconList ); mIconList->setFixedWidth( lw+mIconList->frameWidth()*2 ); } } return QWidget::eventFilter( o, e ); } // // Code for the icon list box // OJanusWidget::IconListBox::IconListBox( QWidget *parent, const char *name, WFlags f ) :QListBox( parent, name, f ), mShowAll(false), mHeightValid(false), mWidthValid(false) { } void OJanusWidget::IconListBox::updateMinimumHeight() { if( mShowAll == true && mHeightValid == false ) { int h = frameWidth()*2; for( QListBoxItem *i = item(0); i != 0; i = i->next() ) { h += i->height( this ); } setMinimumHeight( h ); mHeightValid = true; } } void OJanusWidget::IconListBox::updateWidth() { if( mWidthValid == false ) { int maxWidth = 10; for( QListBoxItem *i = item(0); i != 0; i = i->next() ) { int w = ((IconListItem *)i)->width(this); maxWidth = QMAX( w, maxWidth ); } for( QListBoxItem *i = item(0); i != 0; i = i->next() ) { ((IconListItem *)i)->expandMinimumWidth( maxWidth ); } if( verticalScrollBar()->isVisible() ) { maxWidth += verticalScrollBar()->sizeHint().width(); } setFixedWidth( maxWidth + frameWidth()*2 ); mWidthValid = true; } } void OJanusWidget::IconListBox::invalidateHeight() { mHeightValid = false; } void OJanusWidget::IconListBox::invalidateWidth() { mWidthValid = false; } void OJanusWidget::IconListBox::setShowAll( bool showAll ) { mShowAll = showAll; mHeightValid = false; } OJanusWidget::IconListItem::IconListItem( QListBox *listbox, const QPixmap &pixmap, const QString &text ) : QListBoxItem( listbox ) { mPixmap = pixmap; if( mPixmap.isNull() == true ) |