• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • superkaramba
 

superkaramba

  • superkaramba
  • src
kwidgetlistbox.cpp
1/*
2 * Copyright (C) 2005 Petri Damstén <petri.damsten@iki.fi>
3 *
4 * This file is part of SuperKaramba.
5 *
6 * SuperKaramba is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * SuperKaramba is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with SuperKaramba; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 ****************************************************************************/
20#include "kwidgetlistbox.h"
21#include <kdebug.h>
22#include <tdeglobalsettings.h>
23
24KWidgetListbox::KWidgetListbox(TQWidget *parent, const char *name)
25 : TQTable(parent, name)
26{
27 setNumRows(0);
28 setNumCols(1);
29 setColumnStretchable(0, true);
30 setLeftMargin(0);
31 setTopMargin(0);
32 horizontalHeader()->hide();
33 verticalHeader()->hide();
34 setSelectionMode(TQTable::NoSelection);
35 setFocusStyle(TQTable::FollowStyle);
36 connect(this, TQ_SIGNAL(currentChanged(int, int)),
37 this, TQ_SLOT(selectionChanged(int, int)));
38 setHScrollBarMode(TQScrollView::AlwaysOff);
39 setVScrollBarMode(TQScrollView::Auto);
40}
41
42KWidgetListbox::~KWidgetListbox()
43{
44 clear();
45}
46
47void KWidgetListbox::clear()
48{
49 for(int i = 0; i < numRows(); ++i)
50 clearCellWidget(i, 0);
51 setNumRows(0);
52}
53
54int KWidgetListbox::insertItem(TQWidget* item, int index)
55{
56 int row;
57
58 if(index == -1)
59 {
60 row = numRows();
61 setNumRows(row + 1);
62 }
63 else
64 return -1;
65
66 setRowHeight(row, item->height());
67 setCellWidget(row, 0, item);
68 setItemColors(row, even(row));
69 return row;
70}
71
72void KWidgetListbox::setSelected(TQWidget* item)
73{
74 setSelected(index(item));
75}
76
77void KWidgetListbox::selectionChanged(int row, int col)
78{
79 ensureCellVisible(row, col);
80 updateColors();
81 emit selected(row);
82}
83
84void KWidgetListbox::removeItem(TQWidget* item)
85{
86 removeItem(index(item));
87}
88
89void KWidgetListbox::removeItem(int index)
90{
91 removeRow(index);
92 updateColors();
93}
94
95void KWidgetListbox::setSelected(int index)
96{
97 setCurrentCell(index, 0);
98}
99
100int KWidgetListbox::selected() const
101{
102 return currentRow();
103}
104
105TQWidget* KWidgetListbox::selectedItem() const
106{
107 return item(selected());
108}
109
110TQWidget* KWidgetListbox::item(int index) const
111{
112 return cellWidget(index, 0);
113}
114
115int KWidgetListbox::index(TQWidget* itm) const
116{
117 for(int i = 0; i < numRows(); ++i)
118 if(item(i) == itm)
119 return i;
120 return -1;
121}
122
123bool KWidgetListbox::even(int index)
124{
125 int v = 0;
126 for(int i = 0; i < numRows(); ++i)
127 {
128 if(index == i)
129 break;
130 if(!isRowHidden(i))
131 ++v;
132 }
133 return (v%2 == 0);
134}
135
136void KWidgetListbox::updateColors()
137{
138 int v = 0;
139 for(int i = 0; i < numRows(); ++i)
140 {
141 if(!isRowHidden(i))
142 {
143 setItemColors(i, (v%2 == 0));
144 ++v;
145 }
146 }
147}
148
149void KWidgetListbox::setItemColors(int index, bool even)
150{
151 TQWidget* itm = item(index);
152
153 if(index == selected())
154 {
155 itm->setPaletteBackgroundColor(TDEGlobalSettings::highlightColor());
156 itm->setPaletteForegroundColor(TDEGlobalSettings::highlightedTextColor());
157 }
158 else if(even)
159 {
160 itm->setPaletteBackgroundColor(TDEGlobalSettings::baseColor());
161 itm->setPaletteForegroundColor(TDEGlobalSettings::textColor());
162 }
163 else
164 {
165 itm->setPaletteBackgroundColor(
166 TDEGlobalSettings::alternateBackgroundColor());
167 itm->setPaletteForegroundColor(TDEGlobalSettings::textColor());
168 }
169}
170
171void KWidgetListbox::showItems(show_callback func, void* data)
172{
173 for(int i = 0; i < numRows(); ++i)
174 {
175 if(func == 0)
176 showRow(i);
177 else
178 {
179 if(func(i, item(i), data))
180 showRow(i);
181 else
182 hideRow(i);
183 }
184 }
185 updateColors();
186}
187
188void KWidgetListbox::showEvent(TQShowEvent*)
189{
190 //kdDebug() << k_funcinfo << endl;
191 repaintContents(false);
192}
193
194void KWidgetListbox::paintCell(TQPainter*, int, int, const TQRect&,
195 bool, const TQColorGroup&)
196{
197 //kdDebug() << k_funcinfo << endl;
198}
199
200#include "kwidgetlistbox.moc"

superkaramba

Skip menu "superkaramba"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

superkaramba

Skip menu "superkaramba"
  • kcalc
  •   knumber
  • superkaramba
Generated for superkaramba by doxygen 1.9.4
This website is maintained by Timothy Pearson.