1/* This file is part of the KDE project
2 Copyright 2002 Cornelius Schumacher <schumacher@kde.org>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public
6 License version 2 or at your option version 3 as published
7 by the Free Software Foundation.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#ifndef KHC_SCOPEITEM_H
21#define KHC_SCOPEITEM_H
22
23#include <QTreeWidgetItem>
24
25#include "docmetainfo.h"
26
27namespace KHC {
28
29class ScopeItem : public QTreeWidgetItem
30{
31 public:
32 ScopeItem( QTreeWidget *parent, DocEntry *entry )
33 : QTreeWidgetItem( parent, QStringList() << entry->name(), rttiId() ),
34 mEntry( entry ), mObserver( 0 ) { init(); }
35
36 ScopeItem( QTreeWidgetItem *parent, DocEntry *entry )
37 : QTreeWidgetItem( parent, QStringList() << entry->name(), rttiId() ),
38 mEntry( entry ), mObserver( 0 ) { init(); }
39
40 DocEntry *entry()const { return mEntry; }
41
42 static int rttiId() { return 734678; }
43
44 class Observer
45 {
46 public:
47 virtual ~Observer() {}
48 virtual void scopeItemChanged( ScopeItem * ) = 0;
49 };
50
51 void setObserver( Observer *o ) { mObserver = o; }
52
53 void setOn( bool on ) { setCheckState( 0, on ? Qt::Checked : Qt::Unchecked ); }
54 bool isOn() const { return checkState( 0 ) == Qt::Checked; }
55
56 protected:
57 void stateChange ( bool )
58 {
59 if ( mObserver ) mObserver->scopeItemChanged( this );
60 }
61
62 private:
63 void init() { setCheckState(0, Qt::Checked); }
64
65 DocEntry *mEntry;
66
67 Observer *mObserver;
68};
69
70}
71
72#endif //KHC_SCOPEITEM_H
73// vim:ts=2:sw=2:et
74