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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
/***************************************************************************
copyright : (C) 2001-2006 by Robby Stephenson
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of version 2 of the GNU General Public License as *
* published by the Free Software Foundation; *
* *
***************************************************************************/
#ifndef TELLICO_LISTVIEW_H
#define TELLICO_LISTVIEW_H
#include "../datavectors.h"
#include "../listviewcomparison.h"
#include <tdelistview.h>
#include <tdeversion.h>
#include <tqdict.h>
namespace Tellico {
class ListViewComparison;
namespace GUI {
class ListViewItem;
typedef TQPtrList<ListViewItem> ListViewItemList;
typedef TQPtrListIterator<ListViewItem> ListViewItemListIt;
/**
* A ListView keeps track of the selected items and allows subclasses to determine
* whether child items may be selected or not. In addition, it provides alternating
* background colors and shaded sort columns.
*
* @see GroupView
* @see DetailedListView
*
* @author Robby Stephenson
*/
class ListView : public TDEListView {
Q_OBJECT
friend class ListViewItem; // needed so the ListViewItem d'tor can update selection list
public:
enum SortStyle {
SortByText = 0, // don't change these values, they're saved as ints in the config
SortByCount = 1
};
ListView(TQWidget* parent, const char* name = 0);
virtual ~ListView();
void clearSelection();
/**
* Returns a list of the currently selected items;
*
* @return The list of selected items
*/
const ListViewItemList& selectedItems() const { return m_selectedItems; }
/**
* Used to determine whether an item may be selected without having to setSelectable on
* every child item.
*
* @return Whether the item may be selected
*/
virtual bool isSelectable(ListViewItem*) const;
SortStyle sortStyle() const { return m_sortStyle; }
void setSortStyle(SortStyle style) { m_sortStyle = style; }
int firstVisibleColumn() const;
int lastVisibleColumn() const;
virtual void setColumnText(int column, const TQString& label);
void setComparison(int column, ListViewComparison* comp);
void removeComparison(int column);
void clearComparisons();
virtual int compare(int col, const GUI::ListViewItem* item1, GUI::ListViewItem* item2, bool asc);
#if !KDE_IS_VERSION(3,3,90)
// taken from KDE bug 59791
void setShadeSortColumn(bool shade_);
bool shadeSortColumn() const { return m_shadeSortColumn; }
const TQColor& background2() const { return m_backColor2; }
const TQColor& alternateBackground2() const { return m_altColor2; }
#endif
protected slots:
/**
* Handles everything when an item is selected. The proper signal is emitted, depending
* on whether the item refers to a collection, a group, or a entry.
*/
virtual void slotSelectionChanged();
protected:
virtual void drawContentsOffset(TQPainter* p, int ox, int oy, int cx, int cy, int cw, int ch);
private slots:
void slotUpdateColors();
void slotDoubleClicked(TQListViewItem* item);
private:
/**
* Updates the pointer list.
*
* @param item The item being selected or deselected
* @param s Selected or not
*/
void updateSelected(ListViewItem* item, bool s);
SortStyle m_sortStyle;
bool m_isClear;
ListViewItemList m_selectedItems;
TQDict<ListViewComparison> m_comparisons;
#if !KDE_IS_VERSION(3,3,90)
bool m_shadeSortColumn;
TQColor m_backColor2;
TQColor m_altColor2;
#endif
};
/**
* The ListViewItem keeps track of what kind of specialized listview item it is, as
* well as taking care of the selection tracking.
*
* @author Robby Stephenson
*/
class ListViewItem : public TDEListViewItem {
public:
ListViewItem(ListView* parent) : TDEListViewItem(parent), m_sortWeight(-1) {}
ListViewItem(ListView* parent, TQListViewItem* after) : TDEListViewItem(parent, after), m_sortWeight(-1) {}
ListViewItem(ListViewItem* parent) : TDEListViewItem(parent), m_sortWeight(-1) {}
ListViewItem(ListView* parent, const TQString& text) : TDEListViewItem(parent, text), m_sortWeight(-1) {}
ListViewItem(ListViewItem* parent, const TQString& text) : TDEListViewItem(parent, text), m_sortWeight(-1) {}
virtual ~ListViewItem();
virtual size_t realChildCount() const { return childCount(); }
virtual void clear();
virtual bool isEntryGroupItem() const { return false; }
virtual bool isEntryItem() const { return false; }
virtual bool isFilterItem() const { return false; }
virtual bool isBorrowerItem() const { return false; }
virtual bool isLoanItem() const { return false; }
int sortWeight() const { return m_sortWeight; }
void setSortWeight(int w) { m_sortWeight = w; }
virtual int compare(TQListViewItem* item, int col, bool ascending) const;
virtual void setSelected(bool selected);
/**
* Returns the background color for the column, which depends on whether the item
* is an alternate row and whether the column is selected.
*
* @param column The column number
* @param alternate The alternate row color can be forced
*/
virtual TQColor backgroundColor(int column); // not virtual in TDEListViewItem!!!
virtual void paintCell(TQPainter* painter, const TQColorGroup& colorGroup,
int column, int width, int alignment);
ListView* listView () const { return static_cast<ListView*>(TDEListViewItem::listView()); }
virtual void doubleClicked() {}
virtual Data::EntryVec entries() const;
private:
int compareWeight(TQListViewItem* item, int col, bool ascending) const;
int m_sortWeight;
};
} // end namespace
} // end namespace
#endif
|