• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • KDevelop Widgets Library
 

KDevelop Widgets Library

  • lib
  • widgets
fancylistviewitem.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2006 David Nolden <david.nolden.kdevelop@art-master.de>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include <tqpixmap.h>
21#include <tqapplication.h>
22#include <tqnamespace.h>
23
24#include "fancylistviewitem.h"
25
26
27void FancyListViewItem::init(const TQString& label1, const TQString& /*label2*/) {
28 if( !label1.isEmpty() ) {
29 setText(0, label1);
30 }
31}
32
33
34void FancyListViewItem::setItem(int column, TextPaintItem item) {
35 if( column >= int(m_items.size()) ) {
36 m_items.append( item );
37 }else{
38 m_items[column] = item;
39 }
40}
41
42
43void FancyListViewItem::setText ( int column, const TQString & text ) {
44 if( column >= int(m_items.size()) ) {
45 m_items.append( TextPaintItem(text) );
46 }else{
47 m_items[column] = TextPaintItem(text);
48 }
49}
50
51
52TQString FancyListViewItem::text(int column) const {
53 if( m_items.isEmpty() ) return "";
54 return (TQString)m_items[column];
55}
56
57
58TQColor FancyListViewItem::backgroundColor(int col) {
59
60 return TDEListViewItem::backgroundColor(col);
61}
62
63
66
67void FancyListViewItem::paintCell( TQPainter *painter, const TQColorGroup &cg,
68 int column, int width, int align)
69{
70 if(column < 0 || column >= int(m_items.size()) || m_items[column].items().isEmpty()) {
71 TQListViewItem::paintCell(painter, cg, column, width, align);
72 return;
73 }
74
75 painter->save();
76 TQColorGroup grp(cg);
77
78 int styleNum = m_items[column].items()[0].style;
79 TextPaintStyleStore::Item& style = m_styles.getStyle( styleNum );
81 if( style.bgValid() ) {
82 grp.setColor( TQColorGroup::Base, style.background );
83 }else{
84 if(backgroundColor(column).isValid())
85 grp.setColor( TQColorGroup::Base, backgroundColor(column) );
86 }
87
88 TQListView *lv = listView();
89 if ( !lv )
90 return;
91 TQPainter* p = painter;
92 TQFontMetrics fm( p->fontMetrics() );
93
94 TQString t = text( column );
95
96 int marg = lv->itemMargin();
97 int r = marg;
98 const TQPixmap * icon = pixmap( column );
99
100 const BackgroundMode bgmode = lv->viewport()->backgroundMode();
101 const TQColorGroup::ColorRole crole = TQPalette::backgroundRoleFromMode( bgmode );
102 p->fillRect( 0, 0, width, height(), grp.brush( crole ) );
103
104 if ( isSelected() && (column == 0 || lv->allColumnsShowFocus()) ) {
105 p->fillRect( r - marg, 0, width - r + marg, height(), cg.brush( TQColorGroup::Highlight ) );
106
107 if ( isEnabled() || !lv )
108 p->setPen( cg.highlightedText() );
109 else if ( !isEnabled() && lv)
110 p->setPen( lv->palette().disabled().highlightedText() );
111 }
112 {
113 if ( isEnabled() || !lv )
114 p->setPen( cg.text() );
115 else if ( !isEnabled() && lv)
116 p->setPen( lv->palette().disabled().text() );
117
118
119 int iconWidth = 0;
120
121 if ( icon ) {
122 iconWidth = icon->width() + lv->itemMargin();
123 int xo = r;
124 int yo = ( height() - icon->height() ) / 2;
125
126 if ( align & AlignBottom )
127 yo = height() - icon->height();
128 else if ( align & AlignTop )
129 yo = 0;
130
131// respect horizontal alignment when there is no text for an item.
132 if ( t.isEmpty() ) {
133 if ( align & AlignRight )
134 xo = width - 2 * marg - iconWidth;
135 else if ( align & AlignHCenter )
136 xo = ( width - iconWidth ) / 2;
137 }
138 p->drawPixmap( xo, yo, *icon );
139 }
140
141
142 if ( !t.isEmpty() ) {
143 if ( !(align & AlignTop || align & AlignBottom) )
144 align |= AlignVCenter;
145
146 r += iconWidth;
147
148 TextPaintItem::Chain::iterator it = m_items[column].items().begin();
149 while(it != m_items[column].items().end())
150 {
151 int styleNum = (*it).style;
152 TextPaintStyleStore::Item& style = m_styles.getStyle( styleNum );
153
154 painter->setFont(style.font);
155 p->drawText( r, 0, width-marg-r, height(), align, (*it).text );
156 r += textWidth( style.font, (*it).text );
157 ++it;
158 }
159 }
160 }
161
162 painter->restore();
163}
164
165
166int FancyListViewItem::textWidth(const TQFont& font, const TQString& text)
167{
168 TQFontMetrics fm( font );
169 if ( multiLinesEnabled() )
170 return fm.size( AlignVCenter, text ).width();
171 else
172 return fm.width( text );
173
174}
175
176
177int FancyListViewItem::width(const TQFontMetrics &fm, const TQListView *lv, int column)
178{
179 int width = 0;
180 if (column >= 0 && column < (int)m_items.size() && !multiLinesEnabled()) {
181 TextPaintItem::Chain::iterator it = m_items[column].items().begin();
182 while(it != m_items[column].items().end()) {
183 int styleNum = (*it).style;
184 TextPaintStyleStore::Item& style = m_styles.getStyle( styleNum );
185
186 width += textWidth( style.font, (*it).text);
187 ++it;
188 }
189 width += lv->itemMargin() * 2;// - lv->d->minLeftBearing - lv->d->minRightBearing;
190
191 const TQPixmap * pm = pixmap( column );
192 if ( pm )
193 width += pm->width() + lv->itemMargin();
194
195 width = TQMAX( width, TQApplication::globalStrut().width() );
196 }
197 else
198 width = TQListViewItem::width(fm, lv, column);
199 return width;
200}
201
202
FancyListViewItem::paintCell
virtual void paintCell(TQPainter *painter, const TQColorGroup &cg, int column, int width, int align)
this is a modified version of the original TQListViewItem::paintCell from the qt source multiline is ...
Definition fancylistviewitem.cpp:67

KDevelop Widgets Library

Skip menu "KDevelop Widgets Library"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

KDevelop Widgets Library

Skip menu "KDevelop Widgets Library"
  • buildtools
  •   lib
  •     base
  •     parsers
  •       autotools
  •       qmake
  •     widgets
  •   api
  • languages
  •   lib
  •     debugger
  •     designer_integration
  •     interfaces
  • lib
  •   catalog
  •   interfaces
  •     extensions
  •     external
  •     extras
  •   util
  •   widgets
  •     propeditor
  • parts
  •   documentation
  •     interfaces
  • src
  •   profileengine
  •     lib
Generated for KDevelop Widgets Library by doxygen 1.15.0
This website is maintained by Timothy Pearson.