doctreeitem.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
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
00076
00077
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 }
This file is part of the documentation for KDevelop Version 3.1.2.