summaryrefslogtreecommitdiffstats
path: root/klinkstatus/src/ui/treeview.h
blob: 05862bd4e728c1bba3494f49c2158b0718ca4853 (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
//
// C++ Interface: treeview
//
// Description:
//
//
// Author: Paulo Moura Guedes <moura@kdewebdev.org>, (C) 2004
//
// Copyright: See COPYING file that comes with this distribution
//
//
#ifndef TREEVIEW_H
#define TREEVIEW_H

#include <klistview.h>

#include "resultview.h"
class TreeViewItem;
class TreeColumnViewItem;
class LinkMatcher;

/**
@author Paulo Moura Guedes
TreeView and TreeViewItem and currently a little messes up in its API
because of ResultView. ResultView class was to be the base interface to
a TQTable and a TQListView, but the APIs are a little diferent... then I realize 
that a TQTable view isn't needed at all so some day I will clean this up.
*/
class TreeView : public KListView, public ResultView
{
    Q_OBJECT
  TQ_OBJECT
public:
    
    TreeView(TQWidget *parent = 0, const char *name = 0);
    ~TreeView();

    virtual void setColumns(TQStringList const& columns);
    virtual void clear();
    void removeColunas();
    virtual void show(ResultView::tqStatus const& status);
    void show(LinkMatcher link_matcher);
    virtual void showAll();
    
    void setTreeDisplay(bool tree_display);

    /**
    If tree_display is false the view scrolls to follow the last link inserted, 
    except if the user scrolls the view up (like Konsole).
    If tree_view, it follows always the last link inserted.
     */
    void ensureRowVisible(const TQListViewItem * i, bool tree_display);
    virtual bool isEmpty() const;

    TreeViewItem* myItem(TQListViewItem* item) const;
    
protected:
    virtual void resizeEvent(TQResizeEvent *e);

private slots:

    void slotPopupContextMenu(TQListViewItem *, const TQPoint &, int);    
    virtual void slotCopyUrlToClipboard() const;
    virtual void slotCopyParentUrlToClipboard() const;
    virtual void slotCopyCellTextToClipboard() const;
    virtual void slotEditReferrersWithQuanta();
    virtual void slotEditReferrerWithQuanta(int id);
    virtual void slotEditReferrerWithQuanta(KURL const& url);
    virtual void slotViewUrlInBrowser();
    virtual void slotViewParentUrlInBrowser();
    virtual void loadContextTableMenu(TQValueVector<KURL> const& referrers, bool is_root = false);

private:
    void resetColumns();
    double columnsWidth() const;

private:
    int current_column_; // apparently it's impossible to know what is the current column
    bool tree_display_;
};

inline void TreeView::setTreeDisplay(bool tree_display) { 
    tree_display_ = tree_display; 
    setRootIsDecorated(tree_display_);
}


/* ******************************* TreeViewItem ******************************* */

class TreeViewItem: public KListViewItem
{
public:

    TreeViewItem(TreeView* parent, TQListViewItem* after,
                 LinktqStatus const* linkstatus);
    TreeViewItem(TreeView* root, TQListViewItem* parent_item, TQListViewItem* after,
                 LinktqStatus const* linkstatus);
    virtual ~TreeViewItem();

    void setLastChild(TQListViewItem* last_child);
    TQListViewItem* lastChild() const;
    
    TQString key(int column, bool) const;
    LinktqStatus const* linktqStatus() const;

protected:
    virtual void paintCell(TQPainter * p, const TQColorGroup & cg, int column, int width, int align);

private:
    void init(LinktqStatus const* linkstatus);

private:
    TQValueVector<TreeColumnViewItem> column_items_;
    TQListViewItem* last_child_;
    TreeView* root_;
};


/* ******************************* TreeColumnViewItem ******************************* */

class TreeColumnViewItem
{
public:
    TreeColumnViewItem()
    {}
    ;
    TreeColumnViewItem(TreeView* root, LinktqStatus const* linkstatus, int column_index);
    ~TreeColumnViewItem();

    //void setColumnIndex(int i);
    int columnIndex() const;
    LinktqStatus const* linktqStatus() const;
    TQColor const& textStatusColor() const;
    TQString text(int column) const;
    TQPixmap pixmap(int column) const;

private:
    TreeView* root_;
    LinktqStatus const* ls_;
    int column_index_;
};

#endif