akregator/src

treenodeitem.cpp
1/*
2 This file is part of Akregator.
3
4 Copyright (C) 2004 Frank Osterfeld <frank.osterfeld at kdemail.net>
5
6 This program 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 This program 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 this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 As a special exception, permission is given to link this program
21 with any edition of TQt, and distribute the resulting executable,
22 without including the source code for TQt in the source distribution.
23*/
24
25#include "akregatorconfig.h"
26
27#include "treenode.h"
28#include "treenodeitem.h"
29#include "folderitem.h"
30#include <tqfont.h>
31#include <tqheader.h>
32#include <tqpainter.h>
33#include <tqstring.h>
34
35#include <kstringhandler.h>
36
37#include <kdebug.h>
38
39namespace Akregator {
40
41TreeNodeItem::TreeNodeItem(FolderItem* parent, TreeNode* node)
42 : TDEListViewItem(parent), m_node(node)
43{
44 initialize(node);
45}
46
47TreeNodeItem::TreeNodeItem(TDEListView* parent, TreeNode* node)
48 : TDEListViewItem(parent), m_node(node)
49{
50 initialize(node);
51}
52
53TreeNodeItem::TreeNodeItem(TDEListView* parent, TreeNodeItem* after, TreeNode* node) : TDEListViewItem(parent, after), m_node(node)
54{
55 initialize(node);
56}
57
58TreeNodeItem::TreeNodeItem(FolderItem* parent, TreeNodeItem* after, TreeNode* node)
59 : TDEListViewItem(parent, after), m_node(node)
60{
61 initialize(node);
62}
63
64void TreeNodeItem::initialize(TreeNode* node)
65{
66 setRenameEnabled(0, true);
67 if (node)
68 setText(0, node->title() );
69}
70
71TreeNodeItem::~TreeNodeItem()
72{}
73
74TQString TreeNodeItem::toolTip() const
75{
76 return TQString();
77}
78
79TreeNode* TreeNodeItem::node()
80{
81 return m_node;
82}
83
84void TreeNodeItem::nodeChanged()
85{
86// kdDebug() << "enter TreeNodeItem::nodeChanged item" << text(0) << endl;
87 if (!node())
88 return;
89 if (text(0) != node()->title())
90 setText(0, node()->title());
91// kdDebug() << "leave TreeNodeItem::nodeChanged item" << text(0) << endl;
92}
93
94TreeNodeItem* TreeNodeItem::firstChild() const
95{
96 return static_cast<TreeNodeItem*>(TDEListViewItem::firstChild());
97}
98
99TreeNodeItem* TreeNodeItem::nextSibling() const
100{
101 return static_cast<TreeNodeItem*>(TDEListViewItem::nextSibling());
102}
103
104FolderItem* TreeNodeItem::parent() const
105{
106 return static_cast<FolderItem*>(TDEListViewItem::parent());
107}
108
109
110// TODO: reverse for reverse layout
111void TreeNodeItem::paintCell( TQPainter * p, const TQColorGroup & cg,
112 int column, int width, int align )
113
114{
115 int u = node() ? node()->unread() : 0;
116
117 if (u <= 0)
118 {
119 TDEListViewItem::paintCell(p,cg,column,width,align);
120 return;
121 }
122
123 // from kfoldertree
124 TQString oldText = text(column);
125 setText( column, " " );
126
127 // draw bg
128 TDEListViewItem::paintCell(p,cg,column,width,align);
129
130 setText( column, oldText);
131
132 // draw fg
133 TQFont f = p->font();
134 f.setWeight(TQFont::Bold);
135 p->setFont(f);
136
137 TQFontMetrics fm( p->fontMetrics() );
138 TQListView *lv = listView();
139 int x = lv ? lv->itemMargin() : 1;
140 int m=x;
141 const TQPixmap *icon = pixmap( column );
142 TQRect br;
143
144 if (icon)
145 x += icon->width() + m;
146
147 TQString txt = " (" + TQString::number(u) + ")";
148 int txtW=fm.width( txt );
149
150 if (fm.width( oldText ) + txtW + x > width)
151 oldText=KStringHandler::rPixelSqueeze(oldText,fm, width - txtW - x);
152
153 p->drawText( x, 0, width-m-x, height(), align | AlignVCenter, oldText, -1, &br );
154
155 if ( !isSelected() )
156 p->setPen( Settings::unreadTextColor() );
157
158 p->drawText( br.right(), 0, width-m-br.right(), height(),
159 align | AlignVCenter, txt );
160
161 /*if ( isSelected() )
162 p->setPen( cg.highlightedText() );
163 else
164 p->setPen( cg.text() );*/
165}
166
167} // namespace Akregator