KDevelop API Documentation

doctreeitem.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 1999-2002 by Bernd Gehrmann                             *
00003  *   bernd@kdevelop.org                                                    *
00004  *   Copyright (C) 2002 by Sebastian Kratzert                              *
00005  *   skratzert@gmx.de                                                      *
00006  *   Copyright (C) 2003 by Alexander Dymo                                  *
00007  *   cloudtemple@mksat.net                                                 *
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  ***************************************************************************/
00015 
00016 #include "doctreeitem.h"
00017 
00018 #include <klistview.h>
00019 #include <kiconloader.h>
00020 #include <kdebug.h>
00021 #include <kcursor.h>
00022 #include <kapplication.h>
00023 
00024 #include "docindexwatcher.h"
00025 
00026 static DocIndexWatcher* m_watcher = 0L;
00027 
00028 static DocIndexWatcher* watcher()
00029 {
00030     if (!m_watcher)
00031         m_watcher = new DocIndexWatcher();
00032     
00033     return m_watcher;
00034 }
00035 
00036 DocTreeItem::DocTreeItem(KListView *parent, Type type, const QString &text, const QString &context, bool lazy)
00037   : QListViewItem(parent, text)
00038   , m_typ(type)
00039   , m_context(context)
00040   , m_current(false)
00041   , m_lazy(lazy)
00042 {
00043     init();
00044 }
00045 
00046 DocTreeItem::DocTreeItem(DocTreeItem *parent, Type type, const QString &text, const QString &context, bool lazy)
00047   : QListViewItem(parent, text)
00048   , m_typ(type)
00049   , m_context(context)
00050   , m_current(false)
00051   , m_lazy(lazy)
00052 {
00053     init();
00054 }
00055 
00056 DocTreeItem::~DocTreeItem()
00057 {
00058     if (!m_indexFileName.isEmpty())
00059         watcher()->removeItem(this);
00060 }
00061 
00062 void DocTreeItem::init()
00063 {
00064     QString icon;
00065     if (m_typ == Folder)
00066         icon = "folder";
00067     else if (m_typ == Book)
00068         icon = "contents";
00069     else
00070         icon = "document";
00071     setPixmap(0, SmallIcon(icon));
00072     
00073     if (m_lazy)
00074         setExpandable(true);
00075     /* gets called in setup()
00076     else
00077         refresh();*/
00078 }
00079 
00080 void DocTreeItem::setFileName(const QString &fn)
00081 { 
00082     m_fileName = fn;
00083 }
00084 
00085 QString DocTreeItem::fileName()
00086 { 
00087     return m_fileName;
00088 }
00089 
00090 QString DocTreeItem::context() const
00091 { 
00092     return m_context;
00093 }
00094 
00095 DocTreeItem::Type DocTreeItem::type() const
00096 {
00097     return m_typ;
00098 }
00099 
00100 bool DocTreeItem::isCurrent() const
00101 {
00102     return m_current;
00103 }
00104 
00105 void DocTreeItem::setDirty()
00106 {
00107     m_current = false;
00108 }
00109 
00110 void DocTreeItem::setOpen(bool open)
00111 {
00112     if (m_lazy && open && !isCurrent()) {
00113         kapp->setOverrideCursor(KCursor::waitCursor());
00114         refresh();
00115         kapp->restoreOverrideCursor();
00116     }
00117       
00118     QListViewItem::setOpen(open);
00119 }
00120 
00121 void DocTreeItem::refresh()
00122 {
00123     clear();
00124     m_current = true;
00125 }
00126 
00127 void DocTreeItem::clear()
00128 {
00129     QListViewItem *child = firstChild();
00130     while (child)
00131     {
00132         QListViewItem *old = child;
00133         child = child->nextSibling();
00134         delete old;
00135     }
00136 }
00137 
00138 const QString & DocTreeItem::indexFileName( ) const
00139 {
00140     return m_indexFileName;
00141 }
00142 
00143 void DocTreeItem::setIndexFileName( const QString & fileName )
00144 {
00145     if (!m_indexFileName.isEmpty())
00146         watcher()->removeItem(this);
00147     
00148     m_indexFileName = fileName;
00149     watcher()->addItem(this);
00150 }
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:22:39 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003