You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1256 lines
30 KiB
1256 lines
30 KiB
15 years ago
|
/* This file is part of the KDE Libraries
|
||
|
* Copyright (C) 1999-2000 Espen Sand (espensa@online.no)
|
||
|
* Copyright (C) 2003 Ravikiran Rajagopal (ravi@kde.org)
|
||
|
*
|
||
|
* This library is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU Library General Public
|
||
|
* License as published by the Free Software Foundation; either
|
||
|
* version 2 of the License, or (at your option) any later version.
|
||
|
*
|
||
|
* This library 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., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
15 years ago
|
#include <tqbitmap.h>
|
||
|
#include <tqgrid.h>
|
||
|
#include <tqhbox.h>
|
||
|
#include <tqheader.h>
|
||
|
#include <tqlabel.h>
|
||
|
#include <tqlayout.h>
|
||
|
#include <tqobjectlist.h>
|
||
|
#include <tqpixmap.h>
|
||
|
#include <tqsplitter.h>
|
||
|
#include <tqtabwidget.h>
|
||
|
#include <tqvbox.h>
|
||
|
#include <tqwidgetstack.h>
|
||
|
#include <tqpainter.h>
|
||
|
#include <tqstyle.h>
|
||
15 years ago
|
|
||
|
#include <kapplication.h>
|
||
|
#include <kdialog.h> // Access to some static members
|
||
|
#include <klocale.h>
|
||
|
#include <kglobal.h>
|
||
|
#include <kglobalsettings.h>
|
||
|
#include <kseparator.h>
|
||
|
#include <kdebug.h>
|
||
|
#include "kjanuswidget.h"
|
||
|
#include <klistview.h>
|
||
|
#include "kpushbutton.h"
|
||
|
#include "kguiitem.h"
|
||
|
|
||
14 years ago
|
class KJanusWidget::IconListItem : public TQListBoxItem
|
||
15 years ago
|
{
|
||
|
public:
|
||
15 years ago
|
IconListItem( TQListBox *listbox, const TQPixmap &pixmap,
|
||
14 years ago
|
const TQString &text );
|
||
15 years ago
|
virtual int height( const TQListBox *lb ) const;
|
||
|
virtual int width( const TQListBox *lb ) const;
|
||
15 years ago
|
int expandMinimumWidth( int width );
|
||
14 years ago
|
void highlight( bool erase );
|
||
15 years ago
|
|
||
|
protected:
|
||
15 years ago
|
const TQPixmap &defaultPixmap();
|
||
|
void paint( TQPainter *painter );
|
||
14 years ago
|
|
||
15 years ago
|
private:
|
||
14 years ago
|
void paintContents( TQPainter *painter );
|
||
|
|
||
15 years ago
|
TQPixmap mPixmap;
|
||
15 years ago
|
int mMinimumWidth;
|
||
|
};
|
||
|
|
||
|
class KJanusWidget::KJanusWidgetPrivate
|
||
|
{
|
||
|
public:
|
||
|
KJanusWidgetPrivate() : mNextPageIndex(0), mListFrame( 0 ) { }
|
||
|
|
||
|
int mNextPageIndex; // The next page index.
|
||
|
|
||
|
// Dictionary for multipage modes.
|
||
15 years ago
|
TQMap<int,TQWidget*> mIntToPage;
|
||
15 years ago
|
// Reverse dictionary. Used because showPage() may be performance critical.
|
||
15 years ago
|
TQMap<TQWidget*,int> mPageToInt;
|
||
15 years ago
|
// Dictionary of title string associated with page.
|
||
15 years ago
|
TQMap<int, TQString> mIntToTitle;
|
||
15 years ago
|
|
||
15 years ago
|
TQWidget * mListFrame;
|
||
|
TQSplitter * mSplitter;
|
||
15 years ago
|
};
|
||
|
|
||
15 years ago
|
template class TQPtrList<TQListViewItem>;
|
||
15 years ago
|
|
||
|
|
||
15 years ago
|
KJanusWidget::KJanusWidget( TQWidget *parent, const char *name, int face )
|
||
|
: TQWidget( parent, name, 0 ),
|
||
15 years ago
|
mValid(false), mPageList(0),
|
||
|
mTitleList(0), mFace(face), mTitleLabel(0), mActivePageWidget(0),
|
||
|
mShowIconsInTreeList(false), d(0)
|
||
|
{
|
||
15 years ago
|
TQVBoxLayout *topLayout = new TQVBoxLayout( this );
|
||
15 years ago
|
|
||
|
if( mFace == TreeList || mFace == IconList )
|
||
|
{
|
||
|
d = new KJanusWidgetPrivate;
|
||
|
d->mSplitter = 0;
|
||
|
|
||
15 years ago
|
TQFrame *page;
|
||
15 years ago
|
if( mFace == TreeList )
|
||
|
{
|
||
15 years ago
|
d->mSplitter = new TQSplitter( this );
|
||
15 years ago
|
topLayout->addWidget( d->mSplitter, 10 );
|
||
15 years ago
|
mTreeListResizeMode = TQSplitter::KeepSize;
|
||
15 years ago
|
|
||
15 years ago
|
d->mListFrame = new TQWidget( d->mSplitter );
|
||
|
TQVBoxLayout *dummy = new TQVBoxLayout( d->mListFrame, 0, KDialog::spacingHint() );
|
||
15 years ago
|
dummy->setAutoAdd( true );
|
||
|
mTreeList = new KListView( d->mListFrame );
|
||
15 years ago
|
mTreeList->addColumn( TQString::null );
|
||
15 years ago
|
mTreeList->header()->hide();
|
||
|
mTreeList->setRootIsDecorated(true);
|
||
|
mTreeList->setSorting( -1 );
|
||
15 years ago
|
connect( mTreeList, TQT_SIGNAL(selectionChanged()), TQT_SLOT(slotShowPage()) );
|
||
|
connect( mTreeList, TQT_SIGNAL(clicked(TQListViewItem *)), TQT_SLOT(slotItemClicked(TQListViewItem *)));
|
||
15 years ago
|
|
||
|
//
|
||
|
// Page area. Title at top with a separator below and a pagestack using
|
||
|
// all available space at bottom.
|
||
|
//
|
||
15 years ago
|
TQFrame *p = new TQFrame( d->mSplitter );
|
||
15 years ago
|
|
||
15 years ago
|
TQHBoxLayout *hbox = new TQHBoxLayout( p, 0, 0 );
|
||
15 years ago
|
|
||
15 years ago
|
page = new TQFrame( p );
|
||
15 years ago
|
hbox->addWidget( page, 10 );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
15 years ago
|
TQHBoxLayout *hbox = new TQHBoxLayout( topLayout );
|
||
|
d->mListFrame = new TQWidget( this );
|
||
15 years ago
|
hbox->addWidget( d->mListFrame );
|
||
|
|
||
15 years ago
|
( new TQVBoxLayout( d->mListFrame, 0, 0 ) )->setAutoAdd( true );
|
||
15 years ago
|
mIconList = new IconListBox( d->mListFrame );
|
||
|
|
||
15 years ago
|
TQFont listFont( mIconList->font() );
|
||
15 years ago
|
listFont.setBold( true );
|
||
|
mIconList->setFont( listFont );
|
||
|
|
||
|
mIconList->verticalScrollBar()->installEventFilter( this );
|
||
15 years ago
|
connect( mIconList, TQT_SIGNAL(selectionChanged()), TQT_SLOT(slotShowPage()));
|
||
14 years ago
|
connect( mIconList, TQT_SIGNAL(onItem(TQListBoxItem *)), TQT_SLOT(slotOnItem(TQListBoxItem *)));
|
||
|
|
||
15 years ago
|
hbox->addSpacing( KDialog::marginHint() );
|
||
15 years ago
|
page = new TQFrame( this );
|
||
15 years ago
|
hbox->addWidget( page, 10 );
|
||
|
}
|
||
|
|
||
|
//
|
||
|
// Rest of page area. Title at top with a separator below and a
|
||
|
// pagestack using all available space at bottom.
|
||
|
//
|
||
|
|
||
15 years ago
|
TQVBoxLayout *vbox = new TQVBoxLayout( page, 0, KDialog::spacingHint() );
|
||
15 years ago
|
|
||
15 years ago
|
mTitleLabel = new TQLabel( i18n("Empty Page"), page, "KJanusWidgetTitleLabel" );
|
||
|
vbox->addWidget( mTitleLabel, 0, TQApplication::reverseLayout() ? AlignRight : AlignLeft );
|
||
15 years ago
|
|
||
15 years ago
|
TQFont titleFont( mTitleLabel->font() );
|
||
15 years ago
|
titleFont.setBold( true );
|
||
|
mTitleLabel->setFont( titleFont );
|
||
|
|
||
|
mTitleSep = new KSeparator( page );
|
||
15 years ago
|
mTitleSep->setFrameStyle( TQFrame::HLine|TQFrame::Plain );
|
||
15 years ago
|
vbox->addWidget( mTitleSep );
|
||
|
|
||
15 years ago
|
mPageStack = new TQWidgetStack( page );
|
||
|
connect(mPageStack, TQT_SIGNAL(aboutToShow(TQWidget *)),
|
||
|
TQT_SIGNAL(aboutToShowPage(TQWidget *)));
|
||
15 years ago
|
vbox->addWidget( mPageStack, 10 );
|
||
|
}
|
||
|
else if( mFace == Tabbed )
|
||
|
{
|
||
|
d = new KJanusWidgetPrivate;
|
||
|
|
||
15 years ago
|
mTabControl = new TQTabWidget( this );
|
||
15 years ago
|
mTabControl->setMargin (KDialog::marginHint());
|
||
15 years ago
|
connect(mTabControl, TQT_SIGNAL(currentChanged(TQWidget *)),
|
||
|
TQT_SIGNAL(aboutToShowPage(TQWidget *)));
|
||
15 years ago
|
topLayout->addWidget( mTabControl, 10 );
|
||
|
}
|
||
|
else if( mFace == Swallow )
|
||
|
{
|
||
15 years ago
|
mSwallowPage = new TQWidget( this );
|
||
15 years ago
|
topLayout->addWidget( mSwallowPage, 10 );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
mFace = Plain;
|
||
15 years ago
|
mPlainPage = new TQFrame( this );
|
||
15 years ago
|
topLayout->addWidget( mPlainPage, 10 );
|
||
|
}
|
||
|
|
||
|
if ( kapp )
|
||
15 years ago
|
connect(kapp,TQT_SIGNAL(kdisplayFontChanged()),TQT_SLOT(slotFontChanged()));
|
||
15 years ago
|
mValid = true;
|
||
|
|
||
|
setSwallowedWidget(0); // Set default size if 'mFace' is Swallow.
|
||
|
}
|
||
|
|
||
|
|
||
|
KJanusWidget::~KJanusWidget()
|
||
|
{
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool KJanusWidget::isValid() const
|
||
|
{
|
||
|
return mValid;
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
TQFrame *KJanusWidget::plainPage()
|
||
15 years ago
|
{
|
||
|
return mPlainPage;
|
||
|
}
|
||
|
|
||
|
|
||
|
int KJanusWidget::face() const
|
||
|
{
|
||
|
return mFace;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQWidget *KJanusWidget::FindParent()
|
||
15 years ago
|
{
|
||
|
if( mFace == Tabbed ) {
|
||
|
return mTabControl;
|
||
|
}
|
||
|
else {
|
||
|
return this;
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
TQFrame *KJanusWidget::addPage( const TQStringList &items, const TQString &header,
|
||
|
const TQPixmap &pixmap )
|
||
15 years ago
|
{
|
||
|
if( !mValid )
|
||
|
{
|
||
|
kdDebug() << "addPage: Invalid object" << endl;
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQFrame *page = new TQFrame( FindParent(), "page" );
|
||
15 years ago
|
addPageWidget( page, items, header, pixmap );
|
||
|
|
||
|
return page;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KJanusWidget::pageGone( TQObject *obj )
|
||
15 years ago
|
{
|
||
14 years ago
|
removePage( TQT_TQWIDGET( obj ) );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void KJanusWidget::slotReopen( TQListViewItem * item )
|
||
15 years ago
|
{
|
||
|
if( item )
|
||
|
item->setOpen( true );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQFrame *KJanusWidget::addPage( const TQString &itemName, const TQString &header,
|
||
14 years ago
|
const TQPixmap &pixmap )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQStringList items;
|
||
15 years ago
|
items << itemName;
|
||
|
return addPage(items, header, pixmap);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
15 years ago
|
TQVBox *KJanusWidget::addVBoxPage( const TQStringList &items,
|
||
14 years ago
|
const TQString &header,
|
||
|
const TQPixmap &pixmap )
|
||
15 years ago
|
{
|
||
|
if( !mValid )
|
||
|
{
|
||
|
kdDebug() << "addPage: Invalid object" << endl;
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQVBox *page = new TQVBox(FindParent() , "page" );
|
||
15 years ago
|
page->setSpacing( KDialog::spacingHint() );
|
||
|
addPageWidget( page, items, header, pixmap );
|
||
|
|
||
|
return page;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQVBox *KJanusWidget::addVBoxPage( const TQString &itemName,
|
||
|
const TQString &header,
|
||
|
const TQPixmap &pixmap )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQStringList items;
|
||
15 years ago
|
items << itemName;
|
||
|
return addVBoxPage(items, header, pixmap);
|
||
|
}
|
||
|
|
||
15 years ago
|
TQHBox *KJanusWidget::addHBoxPage( const TQStringList &items,
|
||
|
const TQString &header,
|
||
|
const TQPixmap &pixmap )
|
||
15 years ago
|
{
|
||
|
if( !mValid ) {
|
||
|
kdDebug() << "addPage: Invalid object" << endl;
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQHBox *page = new TQHBox(FindParent(), "page");
|
||
15 years ago
|
page->setSpacing( KDialog::spacingHint() );
|
||
|
addPageWidget( page, items, header, pixmap );
|
||
|
|
||
|
return page;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQHBox *KJanusWidget::addHBoxPage( const TQString &itemName,
|
||
|
const TQString &header,
|
||
|
const TQPixmap &pixmap )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQStringList items;
|
||
15 years ago
|
items << itemName;
|
||
|
return addHBoxPage(items, header, pixmap);
|
||
|
}
|
||
|
|
||
15 years ago
|
TQGrid *KJanusWidget::addGridPage( int n, Orientation dir,
|
||
|
const TQStringList &items,
|
||
|
const TQString &header,
|
||
|
const TQPixmap &pixmap )
|
||
15 years ago
|
{
|
||
|
if( !mValid )
|
||
|
{
|
||
|
kdDebug() << "addPage: Invalid object" << endl;
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQGrid *page = new TQGrid( n, dir, FindParent(), "page" );
|
||
15 years ago
|
page->setSpacing( KDialog::spacingHint() );
|
||
|
addPageWidget( page, items, header, pixmap );
|
||
|
|
||
|
return page;
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
TQGrid *KJanusWidget::addGridPage( int n, Orientation dir,
|
||
|
const TQString &itemName,
|
||
|
const TQString &header,
|
||
|
const TQPixmap &pixmap )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQStringList items;
|
||
15 years ago
|
items << itemName;
|
||
|
return addGridPage(n, dir, items, header, pixmap);
|
||
|
}
|
||
|
|
||
15 years ago
|
void KJanusWidget::InsertTreeListItem(const TQStringList &items, const TQPixmap &pixmap, TQFrame *page)
|
||
15 years ago
|
{
|
||
|
bool isTop = true;
|
||
15 years ago
|
TQListViewItem *curTop = 0, *child, *last, *newChild;
|
||
15 years ago
|
unsigned int index = 1;
|
||
15 years ago
|
TQStringList curPath;
|
||
15 years ago
|
|
||
15 years ago
|
for ( TQStringList::ConstIterator it = items.begin(); it != items.end(); ++it, index++ ) {
|
||
|
TQString name = (*it);
|
||
15 years ago
|
bool isPath = ( index != items.count() );
|
||
|
|
||
|
// Find the first child.
|
||
|
if (isTop) {
|
||
|
child = mTreeList->firstChild();
|
||
|
}
|
||
|
else {
|
||
|
child = curTop->firstChild();
|
||
|
}
|
||
|
|
||
|
// Now search for a child with the current Name, and if it we doesn't
|
||
14 years ago
|
// find it, then remember the location of the last child.
|
||
15 years ago
|
for (last = 0; child && child->text(0) != name ; last = child, child = child->nextSibling());
|
||
|
|
||
|
if (!last && !child) {
|
||
|
// This node didn't have any children at all, lets just insert the
|
||
|
// new child.
|
||
|
if (isTop)
|
||
15 years ago
|
newChild = new TQListViewItem(mTreeList, name);
|
||
15 years ago
|
else
|
||
15 years ago
|
newChild = new TQListViewItem(curTop, name);
|
||
15 years ago
|
|
||
|
}
|
||
|
else if (child) {
|
||
|
// we found the given name in this child.
|
||
|
if (!isPath) {
|
||
|
kdDebug() << "The element inserted was already in the TreeList box!" << endl;
|
||
|
return;
|
||
|
}
|
||
|
else {
|
||
|
// Ok we found the folder
|
||
|
newChild = child;
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
14 years ago
|
// the node had some children, but we didn't find the given name
|
||
15 years ago
|
if (isTop)
|
||
15 years ago
|
newChild = new TQListViewItem(mTreeList, last, name);
|
||
15 years ago
|
else
|
||
15 years ago
|
newChild = new TQListViewItem(curTop, last, name);
|
||
15 years ago
|
}
|
||
|
|
||
|
// Now make the element expandable if it is a path component, and make
|
||
|
// ready for next loop
|
||
|
if (isPath) {
|
||
|
newChild->setExpandable(true);
|
||
|
curTop = newChild;
|
||
|
isTop = false;
|
||
|
curPath << name;
|
||
|
|
||
15 years ago
|
TQString key = curPath.join("_/_");
|
||
13 years ago
|
if (mFolderIconMap.contains(key)) {
|
||
15 years ago
|
TQPixmap p = mFolderIconMap[key];
|
||
15 years ago
|
newChild->setPixmap(0,p);
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
if (mShowIconsInTreeList) {
|
||
|
newChild->setPixmap(0, pixmap);
|
||
|
}
|
||
|
mTreeListToPageStack.insert(newChild, page);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KJanusWidget::addPageWidget( TQFrame *page, const TQStringList &items,
|
||
|
const TQString &header,const TQPixmap &pixmap )
|
||
15 years ago
|
{
|
||
15 years ago
|
connect(page, TQT_SIGNAL(destroyed(TQObject*)), TQT_SLOT(pageGone(TQObject*)));
|
||
15 years ago
|
|
||
|
if( mFace == Tabbed )
|
||
|
{
|
||
|
mTabControl->addTab (page, items.last());
|
||
15 years ago
|
d->mIntToPage[d->mNextPageIndex] = static_cast<TQWidget*>(page);
|
||
|
d->mPageToInt[static_cast<TQWidget*>(page)] = d->mNextPageIndex;
|
||
15 years ago
|
d->mNextPageIndex++;
|
||
|
}
|
||
|
else if( mFace == TreeList || mFace == IconList )
|
||
|
{
|
||
15 years ago
|
d->mIntToPage[d->mNextPageIndex] = static_cast<TQWidget*>(page);
|
||
|
d->mPageToInt[static_cast<TQWidget*>(page)] = d->mNextPageIndex;
|
||
15 years ago
|
mPageStack->addWidget( page, 0 );
|
||
|
|
||
|
if (items.isEmpty()) {
|
||
15 years ago
|
kdDebug() << "Invalid TQStringList, with zero items" << endl;
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
if( mFace == TreeList )
|
||
|
{
|
||
|
InsertTreeListItem(items, pixmap, page);
|
||
|
}
|
||
|
else // mFace == IconList
|
||
|
{
|
||
15 years ago
|
TQString itemName = items.last();
|
||
15 years ago
|
IconListItem *item = new IconListItem( mIconList, pixmap, itemName );
|
||
|
mIconListToPageStack.insert(item, page);
|
||
14 years ago
|
mIconList->invalidateHeight();
|
||
|
mIconList->invalidateWidth();
|
||
15 years ago
|
|
||
|
if (mIconList->isVisible())
|
||
|
mIconList->updateWidth();
|
||
|
}
|
||
|
|
||
|
//
|
||
|
// Make sure the title label is sufficiently wide
|
||
|
//
|
||
15 years ago
|
TQString lastName = items.last();
|
||
|
const TQString &title = (!header.isNull() ? header : lastName);
|
||
|
TQRect r = mTitleLabel->fontMetrics().boundingRect( title );
|
||
15 years ago
|
if( mTitleLabel->minimumWidth() < r.width() )
|
||
|
{
|
||
|
mTitleLabel->setMinimumWidth( r.width() );
|
||
|
}
|
||
|
d->mIntToTitle[d->mNextPageIndex] = title;
|
||
|
if( d->mIntToTitle.count() == 1 )
|
||
|
{
|
||
|
showPage(0);
|
||
|
}
|
||
|
d->mNextPageIndex++;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
kdDebug() << "KJanusWidget::addPageWidget: can only add a page in Tabbed, TreeList or IconList modes" << endl;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
15 years ago
|
void KJanusWidget::setFolderIcon(const TQStringList &path, const TQPixmap &pixmap)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString key = path.join("_/_");
|
||
15 years ago
|
mFolderIconMap.insert(key,pixmap);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
15 years ago
|
bool KJanusWidget::setSwallowedWidget( TQWidget *widget )
|
||
15 years ago
|
{
|
||
|
if( mFace != Swallow || !mValid )
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
//
|
||
14 years ago
|
// Remove current layout and make a new.
|
||
15 years ago
|
//
|
||
14 years ago
|
delete mSwallowPage->layout();
|
||
15 years ago
|
|
||
15 years ago
|
TQGridLayout *gbox = new TQGridLayout( mSwallowPage, 1, 1, 0 );
|
||
15 years ago
|
|
||
|
//
|
||
|
// Hide old children
|
||
|
//
|
||
14 years ago
|
TQObjectList l = mSwallowPage->childrenListObject(); // silence please
|
||
|
for( uint i=0; i < l.count(); i++ )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQObject *o = l.tqat(i);
|
||
15 years ago
|
if( o->isWidgetType() )
|
||
|
{
|
||
15 years ago
|
((TQWidget*)o)->hide();
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
//
|
||
|
// Add new child or make default size
|
||
|
//
|
||
|
if( !widget )
|
||
|
{
|
||
|
gbox->addRowSpacing(0,100);
|
||
|
gbox->addColSpacing(0,100);
|
||
|
mSwallowPage->setMinimumSize(100,100);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
13 years ago
|
if( TQT_BASE_OBJECT(widget->parent()) != TQT_BASE_OBJECT(mSwallowPage) )
|
||
15 years ago
|
{
|
||
15 years ago
|
widget->reparent( mSwallowPage, 0, TQPoint(0,0) );
|
||
15 years ago
|
}
|
||
|
gbox->addWidget(widget, 0, 0 );
|
||
|
gbox->activate();
|
||
14 years ago
|
mSwallowPage->setMinimumSize( widget->tqminimumSize() );
|
||
15 years ago
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool KJanusWidget::slotShowPage()
|
||
|
{
|
||
|
if( !mValid )
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
if( mFace == TreeList )
|
||
|
{
|
||
15 years ago
|
TQListViewItem *node = mTreeList->selectedItem();
|
||
15 years ago
|
if( !node ) { return false; }
|
||
|
|
||
15 years ago
|
TQWidget *stackItem = mTreeListToPageStack[node];
|
||
15 years ago
|
// Make sure to call through the virtual function showPage(int)
|
||
|
return showPage(d->mPageToInt[stackItem]);
|
||
|
}
|
||
|
else if( mFace == IconList )
|
||
|
{
|
||
15 years ago
|
TQListBoxItem *node = mIconList->item( mIconList->currentItem() );
|
||
15 years ago
|
if( !node ) { return false; }
|
||
15 years ago
|
TQWidget *stackItem = mIconListToPageStack[node];
|
||
15 years ago
|
// Make sure to call through the virtual function showPage(int)
|
||
|
return showPage(d->mPageToInt[stackItem]);
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool KJanusWidget::showPage( int index )
|
||
|
{
|
||
|
if( !d || !mValid )
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return showPage(d->mIntToPage[index]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
bool KJanusWidget::showPage( TQWidget *w )
|
||
15 years ago
|
{
|
||
|
if( !w || !mValid )
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
if( mFace == TreeList || mFace == IconList )
|
||
|
{
|
||
|
mPageStack->raiseWidget( w );
|
||
|
mActivePageWidget = w;
|
||
|
|
||
|
int index = d->mPageToInt[w];
|
||
|
mTitleLabel->setText( d->mIntToTitle[index] );
|
||
|
if( mFace == TreeList )
|
||
|
{
|
||
15 years ago
|
TQMap<TQListViewItem *, TQWidget *>::Iterator it;
|
||
15 years ago
|
for (it = mTreeListToPageStack.begin(); it != mTreeListToPageStack.end(); ++it){
|
||
15 years ago
|
TQListViewItem *key = it.key();
|
||
|
TQWidget *val = it.data();
|
||
15 years ago
|
if (val == w) {
|
||
|
mTreeList->setSelected(key, true );
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
15 years ago
|
TQMap<TQListBoxItem *, TQWidget *>::Iterator it;
|
||
15 years ago
|
for (it = mIconListToPageStack.begin(); it != mIconListToPageStack.end(); ++it){
|
||
15 years ago
|
TQListBoxItem *key = it.key();
|
||
|
TQWidget *val = it.data();
|
||
15 years ago
|
if (val == w) {
|
||
|
mIconList->setSelected( key, true );
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else if( mFace == Tabbed )
|
||
|
{
|
||
|
mTabControl->showPage(w);
|
||
|
mActivePageWidget = w;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
|
int KJanusWidget::activePageIndex() const
|
||
|
{
|
||
|
if( mFace == TreeList) {
|
||
15 years ago
|
TQListViewItem *node = mTreeList->selectedItem();
|
||
15 years ago
|
if( !node ) { return -1; }
|
||
15 years ago
|
TQWidget *stackItem = mTreeListToPageStack[node];
|
||
15 years ago
|
return d->mPageToInt[stackItem];
|
||
|
}
|
||
|
else if (mFace == IconList) {
|
||
15 years ago
|
TQListBoxItem *node = mIconList->item( mIconList->currentItem() );
|
||
15 years ago
|
if( !node ) { return false; }
|
||
15 years ago
|
TQWidget *stackItem = mIconListToPageStack[node];
|
||
15 years ago
|
return d->mPageToInt[stackItem];
|
||
|
}
|
||
|
else if( mFace == Tabbed ) {
|
||
15 years ago
|
TQWidget *widget = mTabControl->currentPage();
|
||
15 years ago
|
return ( !widget ? -1 : d->mPageToInt[widget] );
|
||
|
}
|
||
|
else {
|
||
|
return -1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
int KJanusWidget::pageIndex( TQWidget *widget ) const
|
||
15 years ago
|
{
|
||
|
if( !widget )
|
||
|
{
|
||
|
return -1;
|
||
|
}
|
||
|
else if( mFace == TreeList || mFace == IconList )
|
||
|
{
|
||
|
return d->mPageToInt[widget];
|
||
|
}
|
||
|
else if( mFace == Tabbed )
|
||
|
{
|
||
|
//
|
||
|
// The user gets the real page widget with addVBoxPage(), addHBoxPage()
|
||
|
// and addGridPage() but not with addPage() which returns a child of
|
||
15 years ago
|
// the toplevel page. addPage() returns a TQFrame so I check for that.
|
||
15 years ago
|
//
|
||
14 years ago
|
if( widget->isA(TQFRAME_OBJECT_NAME_STRING) )
|
||
15 years ago
|
{
|
||
14 years ago
|
return d->mPageToInt[widget->parentWidget()];
|
||
15 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
return d->mPageToInt[widget];
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return -1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KJanusWidget::slotFontChanged()
|
||
|
{
|
||
|
if( mTitleLabel )
|
||
|
{
|
||
|
mTitleLabel->setFont( KGlobalSettings::generalFont() );
|
||
15 years ago
|
TQFont titleFont( mTitleLabel->font() );
|
||
15 years ago
|
titleFont.setBold( true );
|
||
|
mTitleLabel->setFont( titleFont );
|
||
|
}
|
||
|
|
||
|
if( mFace == IconList )
|
||
|
{
|
||
15 years ago
|
TQFont listFont( mIconList->font() );
|
||
15 years ago
|
listFont.setBold( true );
|
||
|
mIconList->setFont( listFont );
|
||
14 years ago
|
mIconList->invalidateHeight();
|
||
|
mIconList->invalidateWidth();
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
// makes the treelist behave like the list of kcontrol
|
||
15 years ago
|
void KJanusWidget::slotItemClicked(TQListViewItem *it)
|
||
15 years ago
|
{
|
||
|
if(it && (it->childCount()>0))
|
||
|
it->setOpen(!it->isOpen());
|
||
|
}
|
||
|
|
||
14 years ago
|
// hack because qt does not support Q_OBJECT in nested classes
|
||
|
void KJanusWidget::slotOnItem(TQListBoxItem *qitem)
|
||
|
{
|
||
|
mIconList->slotOnItem( qitem );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KJanusWidget::setFocus()
|
||
|
{
|
||
|
if( !mValid ) { 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();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
TQSize KJanusWidget::tqminimumSizeHint() const
|
||
15 years ago
|
{
|
||
|
if( mFace == TreeList || mFace == IconList )
|
||
|
{
|
||
15 years ago
|
TQSize s1( KDialog::spacingHint(), KDialog::spacingHint()*2 );
|
||
|
TQSize s2(0,0);
|
||
|
TQSize s3(0,0);
|
||
14 years ago
|
TQSize s4( mPageStack->tqsizeHint() );
|
||
15 years ago
|
|
||
|
if( mFace == TreeList )
|
||
|
{
|
||
14 years ago
|
s1.rwidth() += tqstyle().tqpixelMetric( TQStyle::PM_SplitterWidth );
|
||
|
s2 = mTreeList->tqminimumSize();
|
||
15 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
mIconList->updateMinimumHeight();
|
||
|
mIconList->updateWidth();
|
||
14 years ago
|
s2 = mIconList->tqminimumSize();
|
||
15 years ago
|
}
|
||
|
|
||
|
if( mTitleLabel->isVisible() )
|
||
|
{
|
||
14 years ago
|
s3 += mTitleLabel->tqsizeHint();
|
||
|
s3.rheight() += mTitleSep->tqminimumSize().height();
|
||
15 years ago
|
}
|
||
|
|
||
|
//
|
||
|
// 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() );
|
||
|
|
||
15 years ago
|
return TQSize( s1.width()+s2.width()+QMAX(s3.width(),s4.width()), h2 );
|
||
15 years ago
|
}
|
||
|
else if( mFace == Tabbed )
|
||
|
{
|
||
14 years ago
|
return mTabControl->tqsizeHint();
|
||
15 years ago
|
}
|
||
|
else if( mFace == Swallow )
|
||
|
{
|
||
14 years ago
|
return mSwallowPage->tqminimumSize();
|
||
15 years ago
|
}
|
||
|
else if( mFace == Plain )
|
||
|
{
|
||
14 years ago
|
return mPlainPage->tqsizeHint();
|
||
15 years ago
|
}
|
||
|
else
|
||
|
{
|
||
15 years ago
|
return TQSize( 100, 100 ); // Should never happen though.
|
||
15 years ago
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
TQSize KJanusWidget::tqsizeHint() const
|
||
15 years ago
|
{
|
||
14 years ago
|
return tqminimumSizeHint();
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
void KJanusWidget::setTreeListAutoResize( bool state )
|
||
|
{
|
||
|
if( mFace == TreeList )
|
||
|
{
|
||
|
mTreeListResizeMode = !state ?
|
||
15 years ago
|
TQSplitter::KeepSize : TQSplitter::Stretch;
|
||
15 years ago
|
if( d->mSplitter )
|
||
|
d->mSplitter->setResizeMode( d->mListFrame, mTreeListResizeMode );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void KJanusWidget::setIconListAllVisible( bool state )
|
||
|
{
|
||
|
if( mFace == IconList )
|
||
|
{
|
||
|
mIconList->setShowAll( state );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KJanusWidget::setShowIconsInTreeList( bool state )
|
||
|
{
|
||
|
mShowIconsInTreeList = state;
|
||
|
}
|
||
|
|
||
|
void KJanusWidget::setRootIsDecorated( bool state )
|
||
|
{
|
||
|
if( mFace == TreeList ) {
|
||
|
mTreeList->setRootIsDecorated(state);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KJanusWidget::unfoldTreeList( bool persist )
|
||
|
{
|
||
|
if( mFace == TreeList )
|
||
|
{
|
||
|
if( persist )
|
||
15 years ago
|
connect( mTreeList, TQT_SIGNAL( collapsed( TQListViewItem * ) ), this, TQT_SLOT( slotReopen( TQListViewItem * ) ) );
|
||
15 years ago
|
else
|
||
15 years ago
|
disconnect( mTreeList, TQT_SIGNAL( collapsed( TQListViewItem * ) ), this, TQT_SLOT( slotReopen( TQListViewItem * ) ) );
|
||
15 years ago
|
|
||
15 years ago
|
for( TQListViewItem * item = mTreeList->firstChild(); item; item = item->itemBelow() )
|
||
15 years ago
|
item->setOpen( true );
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KJanusWidget::addWidgetBelowList( TQWidget * widget )
|
||
15 years ago
|
{
|
||
|
if( ( mFace == TreeList || mFace == IconList ) && d->mListFrame )
|
||
|
{
|
||
15 years ago
|
widget->reparent( d->mListFrame, TQPoint() );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KJanusWidget::addButtonBelowList( const TQString & text, TQObject * recv, const char * slot )
|
||
15 years ago
|
{
|
||
|
if( ( mFace == TreeList || mFace == IconList ) && d->mListFrame )
|
||
|
{
|
||
15 years ago
|
TQPushButton * button = new TQPushButton( text, d->mListFrame, "KJanusWidget::buttonBelowList" );
|
||
|
connect( button, TQT_SIGNAL( clicked() ), recv, slot );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KJanusWidget::addButtonBelowList( const KGuiItem & item, TQObject * recv, const char * slot )
|
||
15 years ago
|
{
|
||
|
if( ( mFace == TreeList || mFace == IconList ) && d->mListFrame )
|
||
|
{
|
||
|
KPushButton * button = new KPushButton( item, d->mListFrame, "KJanusWidget::buttonBelowList" );
|
||
15 years ago
|
connect( button, TQT_SIGNAL( clicked() ), recv, slot );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KJanusWidget::showEvent( TQShowEvent * )
|
||
15 years ago
|
{
|
||
|
if( mFace == TreeList )
|
||
|
{
|
||
|
if( d->mSplitter )
|
||
|
d->mSplitter->setResizeMode( d->mListFrame, 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.
|
||
|
//
|
||
15 years ago
|
bool KJanusWidget::eventFilter( TQObject *o, TQEvent *e )
|
||
15 years ago
|
{
|
||
15 years ago
|
if( e->type() == TQEvent::Show )
|
||
15 years ago
|
{
|
||
|
IconListItem *item = (IconListItem*)mIconList->item(0);
|
||
|
if( item )
|
||
|
{
|
||
|
int lw = item->width( mIconList );
|
||
14 years ago
|
int sw = mIconList->verticalScrollBar()->tqsizeHint().width();
|
||
15 years ago
|
mIconList->setFixedWidth( lw+sw+mIconList->frameWidth()*2 );
|
||
|
}
|
||
|
}
|
||
15 years ago
|
else if( e->type() == TQEvent::Hide )
|
||
15 years ago
|
{
|
||
|
IconListItem *item = (IconListItem*)mIconList->item(0);
|
||
|
if( item )
|
||
|
{
|
||
|
int lw = item->width( mIconList );
|
||
|
mIconList->setFixedWidth( lw+mIconList->frameWidth()*2 );
|
||
|
}
|
||
|
}
|
||
15 years ago
|
return TQWidget::eventFilter( o, e );
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
|
||
|
//
|
||
|
// Code for the icon list box
|
||
|
//
|
||
|
|
||
|
|
||
15 years ago
|
KJanusWidget::IconListBox::IconListBox( TQWidget *parent, const char *name,
|
||
15 years ago
|
WFlags f )
|
||
|
:KListBox( parent, name, f ), mShowAll(false), mHeightValid(false),
|
||
14 years ago
|
mWidthValid(false),
|
||
|
mOldItem(0)
|
||
15 years ago
|
{
|
||
|
}
|
||
|
|
||
|
void KJanusWidget::IconListBox::updateMinimumHeight()
|
||
|
{
|
||
|
if( mShowAll && !mHeightValid )
|
||
|
{
|
||
|
int h = frameWidth()*2;
|
||
15 years ago
|
for( TQListBoxItem *i = item(0); i; i = i->next() )
|
||
15 years ago
|
{
|
||
|
h += i->height( this );
|
||
|
}
|
||
|
setMinimumHeight( h );
|
||
|
mHeightValid = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void KJanusWidget::IconListBox::updateWidth()
|
||
|
{
|
||
|
if( !mWidthValid )
|
||
|
{
|
||
|
int maxWidth = 10;
|
||
15 years ago
|
for( TQListBoxItem *i = item(0); i; i = i->next() )
|
||
15 years ago
|
{
|
||
|
int w = ((IconListItem *)i)->width(this);
|
||
|
maxWidth = QMAX( w, maxWidth );
|
||
|
}
|
||
|
|
||
15 years ago
|
for( TQListBoxItem *i = item(0); i; i = i->next() )
|
||
15 years ago
|
{
|
||
|
((IconListItem *)i)->expandMinimumWidth( maxWidth );
|
||
|
}
|
||
|
|
||
|
if( verticalScrollBar()->isVisible() )
|
||
|
{
|
||
14 years ago
|
maxWidth += verticalScrollBar()->tqsizeHint().width();
|
||
15 years ago
|
}
|
||
|
|
||
|
setFixedWidth( maxWidth + frameWidth()*2 );
|
||
|
mWidthValid = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void KJanusWidget::IconListBox::invalidateHeight()
|
||
15 years ago
|
{
|
||
|
mHeightValid = false;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void KJanusWidget::IconListBox::invalidateWidth()
|
||
15 years ago
|
{
|
||
|
mWidthValid = false;
|
||
|
}
|
||
|
|
||
|
|
||
|
void KJanusWidget::IconListBox::setShowAll( bool showAll )
|
||
|
{
|
||
|
mShowAll = showAll;
|
||
|
mHeightValid = false;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void KJanusWidget::IconListBox::leaveEvent( TQEvent *ev )
|
||
|
{
|
||
|
KListBox::leaveEvent( ev );
|
||
|
|
||
|
if ( mOldItem && !mOldItem->isSelected() )
|
||
|
{
|
||
|
((KJanusWidget::IconListItem *) mOldItem)->highlight( true );
|
||
|
mOldItem = 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// hack because qt does not support Q_OBJECT in nested classes
|
||
|
void KJanusWidget::IconListBox::slotOnItem(TQListBoxItem *qitem)
|
||
|
{
|
||
|
KListBox::slotOnItem( qitem );
|
||
|
|
||
|
if ( qitem == mOldItem )
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if ( mOldItem && !mOldItem->isSelected() )
|
||
|
{
|
||
|
((KJanusWidget::IconListItem *) mOldItem)->highlight( true );
|
||
|
}
|
||
|
|
||
|
KJanusWidget::IconListItem *item = dynamic_cast< KJanusWidget::IconListItem * >( qitem );
|
||
|
if ( item && !item->isSelected() )
|
||
|
{
|
||
|
item->highlight( false );
|
||
|
mOldItem = item;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
mOldItem = 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
|
||
15 years ago
|
KJanusWidget::IconListItem::IconListItem( TQListBox *listbox, const TQPixmap &pixmap,
|
||
|
const TQString &text )
|
||
|
: TQListBoxItem( listbox )
|
||
15 years ago
|
{
|
||
|
mPixmap = pixmap;
|
||
|
if( mPixmap.isNull() )
|
||
|
{
|
||
|
mPixmap = defaultPixmap();
|
||
|
}
|
||
|
setText( text );
|
||
14 years ago
|
setCustomHighlighting( true );
|
||
15 years ago
|
mMinimumWidth = 0;
|
||
|
}
|
||
|
|
||
|
|
||
|
int KJanusWidget::IconListItem::expandMinimumWidth( int width )
|
||
|
{
|
||
|
mMinimumWidth = QMAX( mMinimumWidth, width );
|
||
|
return mMinimumWidth;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void KJanusWidget::IconListItem::highlight( bool erase )
|
||
14 years ago
|
{
|
||
|
// FIXME: Add configuration option to disable highlighting
|
||
|
// For now, always disable highlighting
|
||
|
erase = true;
|
||
|
|
||
14 years ago
|
TQRect r = listBox()->tqitemRect( this );
|
||
14 years ago
|
r.addCoords( 1, 1, -1, -1 );
|
||
|
|
||
14 years ago
|
TQPainter p( listBox()->viewport() );
|
||
|
p.setClipRegion( r );
|
||
14 years ago
|
|
||
14 years ago
|
const TQColorGroup &cg = listBox()->tqcolorGroup();
|
||
14 years ago
|
if ( erase )
|
||
|
{
|
||
|
p.setPen( cg.base() );
|
||
|
p.setBrush( cg.base() );
|
||
|
p.drawRect( r );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
p.setBrush( cg.highlight().light( 120 ) );
|
||
|
p.drawRect( r );
|
||
|
|
||
|
p.setPen( cg.highlight().dark( 140 ) );
|
||
14 years ago
|
p.drawRect( r );
|
||
14 years ago
|
}
|
||
14 years ago
|
|
||
14 years ago
|
p.setPen( cg.foreground() );
|
||
|
p.translate( r.x() - 1, r.y() - 1 );
|
||
|
paintContents( &p );
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
const TQPixmap &KJanusWidget::IconListItem::defaultPixmap()
|
||
15 years ago
|
{
|
||
15 years ago
|
static TQPixmap *pix=0;
|
||
15 years ago
|
if( !pix )
|
||
|
{
|
||
15 years ago
|
pix = new TQPixmap( 32, 32 );
|
||
|
TQPainter p( pix );
|
||
15 years ago
|
p.eraseRect( 0, 0, pix->width(), pix->height() );
|
||
|
p.setPen( Qt::red );
|
||
|
p.drawRect ( 0, 0, pix->width(), pix->height() );
|
||
|
p.end();
|
||
|
|
||
14 years ago
|
TQBitmap mask( pix->width(), pix->height(), true );
|
||
|
mask.fill( Qt::black );
|
||
|
p.begin( &mask );
|
||
15 years ago
|
p.setPen( Qt::white );
|
||
|
p.drawRect ( 0, 0, pix->width(), pix->height() );
|
||
|
p.end();
|
||
|
|
||
14 years ago
|
pix->setMask( mask );
|
||
15 years ago
|
}
|
||
|
return *pix;
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void KJanusWidget::IconListItem::paint( TQPainter *painter )
|
||
14 years ago
|
{
|
||
14 years ago
|
TQRect itemPaintRegion( listBox()->tqitemRect( this ) );
|
||
14 years ago
|
TQRect r( 1, 1, itemPaintRegion.width() - 2, itemPaintRegion.height() - 2);
|
||
|
|
||
|
if ( isSelected() )
|
||
|
{
|
||
|
painter->eraseRect( r );
|
||
|
|
||
|
painter->save();
|
||
14 years ago
|
painter->setPen( listBox()->tqcolorGroup().highlight().dark( 160 ) );
|
||
14 years ago
|
painter->drawRect( r );
|
||
|
painter->restore();
|
||
|
}
|
||
|
|
||
|
paintContents( painter );
|
||
|
}
|
||
|
|
||
|
|
||
|
void KJanusWidget::IconListItem::paintContents( TQPainter *painter )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQFontMetrics fm = painter->fontMetrics();
|
||
15 years ago
|
int ht = fm.boundingRect( 0, 0, 0, 0, Qt::AlignCenter, text() ).height();
|
||
|
int wp = mPixmap.width();
|
||
|
int hp = mPixmap.height();
|
||
14 years ago
|
painter->drawPixmap( (mMinimumWidth - wp) / 2, 5, mPixmap );
|
||
15 years ago
|
|
||
|
if( !text().isEmpty() )
|
||
|
{
|
||
14 years ago
|
painter->drawText( 1, hp + 7, mMinimumWidth - 2, ht, Qt::AlignCenter, text() );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
int KJanusWidget::IconListItem::height( const TQListBox *lb ) const
|
||
15 years ago
|
{
|
||
|
if( text().isEmpty() )
|
||
|
{
|
||
|
return mPixmap.height();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
int ht = lb->fontMetrics().boundingRect( 0, 0, 0, 0, Qt::AlignCenter, text() ).height();
|
||
|
return (mPixmap.height() + ht + 10);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
int KJanusWidget::IconListItem::width( const TQListBox *lb ) const
|
||
15 years ago
|
{
|
||
|
int wt = lb->fontMetrics().boundingRect( 0, 0, 0, 0, Qt::AlignCenter, text() ).width() + 10;
|
||
|
int wp = mPixmap.width() + 10;
|
||
|
int w = QMAX( wt, wp );
|
||
|
return QMAX( w, mMinimumWidth );
|
||
|
}
|
||
|
|
||
|
|
||
|
void KJanusWidget::virtual_hook( int, void* )
|
||
|
{ /*BASE::virtual_hook( id, data );*/ }
|
||
|
|
||
14 years ago
|
|
||
15 years ago
|
// 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
|
||
|
// delete the node.
|
||
15 years ago
|
void KJanusWidget::removePage( TQWidget *page )
|
||
15 years ago
|
{
|
||
13 years ago
|
if (!d || !d->mPageToInt.contains(page))
|
||
15 years ago
|
return;
|
||
|
|
||
|
int index = d->mPageToInt[page];
|
||
|
|
||
|
if ( mFace == TreeList )
|
||
|
{
|
||
15 years ago
|
TQMap<TQListViewItem*, TQWidget *>::Iterator i;
|
||
15 years ago
|
for( i = mTreeListToPageStack.begin(); i != mTreeListToPageStack.end(); ++i )
|
||
|
if (i.data()==page)
|
||
|
{
|
||
|
delete i.key();
|
||
|
mPageStack->removeWidget(page);
|
||
|
mTreeListToPageStack.remove(i);
|
||
|
d->mIntToTitle.remove(index);
|
||
|
d->mPageToInt.remove(page);
|
||
|
d->mIntToPage.remove(index);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
else if ( mFace == IconList )
|
||
|
{
|
||
15 years ago
|
TQMap<TQListBoxItem*, TQWidget *>::Iterator i;
|
||
15 years ago
|
for( i = mIconListToPageStack.begin(); i != mIconListToPageStack.end(); ++i )
|
||
|
if (i.data()==page)
|
||
|
{
|
||
|
delete i.key();
|
||
|
mPageStack->removeWidget(page);
|
||
|
mIconListToPageStack.remove(i);
|
||
|
d->mIntToTitle.remove(index);
|
||
|
d->mPageToInt.remove(page);
|
||
|
d->mIntToPage.remove(index);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
else // Tabbed
|
||
|
{
|
||
|
mTabControl->removePage(page);
|
||
|
d->mPageToInt.remove(page);
|
||
|
d->mIntToPage.remove(index);
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
|
||
15 years ago
|
TQString KJanusWidget::pageTitle(int index) const
|
||
15 years ago
|
{
|
||
13 years ago
|
if (!d || !d->mIntToTitle.contains(index))
|
||
15 years ago
|
return TQString::null;
|
||
15 years ago
|
else
|
||
|
return d->mIntToTitle[index];
|
||
|
}
|
||
|
|
||
14 years ago
|
|
||
15 years ago
|
TQWidget *KJanusWidget::pageWidget(int index) const
|
||
15 years ago
|
{
|
||
13 years ago
|
if (!d || !d->mIntToPage.contains(index))
|
||
15 years ago
|
return 0;
|
||
|
else
|
||
|
return d->mIntToPage[index];
|
||
|
}
|
||
|
|
||
|
#include "kjanuswidget.moc"
|