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
|
/*
* resultlistviewtext.cpp - part of abakus
* Copyright (C) 2004, 2005 Michael Pyne <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <kdebug.h>
#include <tqregexp.h>
#include <tqpainter.h>
#include <tqfontmetrics.h>
#include <tqfont.h>
#include <tqpalette.h>
#include "resultlistviewtext.h"
using namespace ResultList;
ResultListViewText::ResultListViewText(KListView *listView,
const TQString &text,
const TQString &result,
ResultListViewText *after,
bool isError)
: KListViewItem(listView, after, text, result), m_text(text),
m_result(result), m_wasError(isError), m_stackPosition(0)
{
// This is some kind of non-result answer, don't bother worrying about the
// stack status, it hasn't changed.
}
ResultListViewText::ResultListViewText(KListView *listView,
const TQString &text,
const Abakus::number_t &result,
ResultListViewText *after,
bool isError)
: KListViewItem(listView, after, text), m_text(text),
m_result(result.toString()), m_wasError(isError), m_stackPosition(0),
m_value(result)
{
if(after) {
ResultListViewText *item = static_cast<ResultListViewText *>(listView->firstChild());
for (; item && item != this; item = static_cast<ResultListViewText *>(item->itemBelow())) {
if(!item->wasError()) {
item->setStackPosition(item->stackPosition() + 1);
item->tqrepaint();
}
}
}
setStackPosition(0);
// Call this manually to be rid of trailing zeroes.
setText(ResultColumn, m_value.toString());
}
void ResultListViewText::setStackPosition(unsigned pos)
{
setText(ShortcutColumn, TQString("$%1").tqarg(pos));
m_stackPosition = pos;
}
void ResultListViewText::precisionChanged()
{
if(m_wasError)
return;
m_result = m_value.toString();
setText(ResultColumn, m_result);
}
void ResultListViewText::paintCell(TQPainter *p, const TQColorGroup &cg, int column, int width, int align)
{
TQColorGroup group(cg);
// XXX: The TQt::red may not provide good contrast with weird color schemes.
// If so I apologize.
if(m_wasError && column == ResultColumn)
group.setColor(TQColorGroup::Text, m_result == "OK" ? cg.link() : TQt::red);
if(column == ResultColumn) {
TQFont f = p->font();
f.setBold(true);
p->setFont(f);
}
if(column == ShortcutColumn) {
TQFont f = p->font();
f.setItalic(true);
f.setPointSize(TQMIN(f.pointSize() * 9 / 11, 10));
p->setFont(f);
}
KListViewItem::paintCell(p, group, column, width, align);
}
int ResultListViewText::width(const TQFontMetrics &fm, const TQListView *lv, int c) const
{
// Simulate painting the text to get accurate results.
if(c == ResultColumn) {
TQFont f = lv->font();
f.setBold(true);
return KListViewItem::width(TQFontMetrics(f), lv, c);
}
if(c == ShortcutColumn) {
TQFont f = lv->font();
f.setItalic(true);
f.setPointSize(TQMIN(f.pointSize() * 9 / 11, 10));
return KListViewItem::width(TQFontMetrics(f), lv, c);
}
return KListViewItem::width(fm, lv, c);
}
void ResultListViewText::setText(int column, const TQString &text)
{
if(!m_wasError && column == ResultColumn) {
KListViewItem::setText(column, m_value.toString());
return;
}
KListViewItem::setText(column, text);
}
|