summaryrefslogtreecommitdiffstats
path: root/adept/adept/filterlist.h
blob: 57c5eaf749e7327c99d51c6fa3ea3c97559f7b1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/** -*- C++ -*-
    @file adept/filterlist.h
    @author Peter Rockai <me@mornfall.net>
*/

#include <tqtooltip.h>
#include <kdebug.h>

#include <apt-front/predicate/matchers.h>
#include <apt-front/predicate/combinators.h>
#include <apt-front/predicate/factory.h>
#include <apt-front/cache/entity/entity.h>
#include <apt-front/cache/component/packagetags.h>
//#include <apt-front/cache/component/tags.h>

#include <adept/listerpredicate.h>
#include <adept/extendablelist.h>

#ifndef EPT_FILTERLIST_H
#define EPT_FILTERLIST_H

class TQPopupMenu;

namespace adept {
using namespace aptFront;
using namespace aptFront::cache;
class Lister;

// MOC_SKIP_BEGIN
#ifdef Q_MOC_RUN
struct InterfacingPredicate;
#else
// MOC_SKIP_END
struct InterfacingPredicate
{
public:
    virtual std::string summary() const = 0;
    virtual void reset() {}
signals:
    void changed();
};
// MOC_SKIP_BEGIN
#endif
// MOC_SKIP_END

class PredicateInterface: public ItemExtender
{
    Q_OBJECT
    
public:
    typedef predicate::Predicate< entity::Entity > Predicate;
    PredicateInterface( TQWidget *w = 0, const char *n = 0 );
    virtual Predicate predicate() = 0;
signals:
    void predicateAdd( Predicate );
    void predicateDrop( Predicate );
public slots:
    virtual void setPredicate( const Predicate &p ) {
        m_pred = p;
        predicateChanged();
    }
    virtual void widgetsChanged();
    virtual void predicateChanged() = 0;
protected:
    predicate::Predicate< entity::Entity > m_pred;
};

class FilterItem;

class FilterList : public ExtendableList
{
    Q_OBJECT
    
public:
    friend class FilterItem;
    typedef predicate::Predicate< entity::Entity > Predicate;
    // typedef std::map< KListViewItem *, Predicate > Map;
    FilterList( TQWidget *parent = 0, const char *name = 0 );
    typedef predicate::And< entity::Entity > And;
    void appendPredicate( Predicate p );
    void plugLister( Lister *l );
    void emitPredicateChanged();
signals:
    void predicateChanged( ListerPredicate p );
public slots:
    void setPredicate( Predicate p );
    void setHiddenPredicate( Predicate p );
protected slots:
    void editorPredicateDrop( Predicate );
    void editorPredicateAdd( Predicate );
    void contextMenu( TQListViewItem *, const TQPoint &, int );
    // TQPopupMenu *tagMenu();
    void contextActivated( int );
    // void tagMenuActivated( int );
    void updateHeight();
protected:
    void drawContents( TQPainter *, int, int, int, int );
    Predicate m_pred;
    Predicate m_hidden;
    FilterItem *m_context;
    bool m_changed;
    Lister *m_lister;
    int m_itemsSeen;
    std::vector< ept::debtags::Tag > m_tagMenuMap;
};

class FilterItem : public ExtendableItem
{
public:
    ItemExtender *createExtender();
    FilterItem( FilterList *l ) 
        : ExtendableItem( l ), m_delayedDone( false )
        {
        }
    void setup() {
        ExtendableItem::setup();
        if (m_delayedDone)
            return;
        m_delayedDone = true;
        showExtender();
    }

    TQString text( int ) const;

    virtual bool less( const ExtendableItem *other ) const {
        const FilterItem *o = dynamic_cast< const FilterItem * >( other );
        return downcast< InterfacingPredicate >( m_pred ).summary() <
            downcast< InterfacingPredicate >( o->m_pred ).summary();
    }

    void setPredicate( predicate::Predicate< entity::Entity > p ) {
        m_pred = p;
    }

    FilterList::Predicate predicate() const {
        return m_pred;
    }

    FilterList *filterList() { return dynamic_cast< FilterList * >( list() ); }

    void reset() {
        filterList()->editorPredicateDrop( m_pred );
        downcast< InterfacingPredicate >( m_pred ).reset();
        if ( extender() ) {
            downcast< PredicateInterface >( extender() ).setPredicate( m_pred );
            extender()->setFocus();
        }
        filterList()->editorPredicateAdd( m_pred );
    }

protected:
    predicate::Predicate< entity::Entity > m_pred;
    bool m_delayedDone:1;
};

}

#endif