• 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 #include <tdeversion.h>
24 
25 #include "fancylistviewitem.h"
26 
27 
28 void FancyListViewItem::init(const TQString& label1, const TQString& /*label2*/) {
29  if( !label1.isEmpty() ) {
30  setText(0, label1);
31  }
32 }
33 
34 
35 void FancyListViewItem::setItem(int column, TextPaintItem item) {
36  if( column >= int(m_items.size()) ) {
37  m_items.append( item );
38  }else{
39  m_items[column] = item;
40  }
41 }
42 
43 
44 void FancyListViewItem::setText ( int column, const TQString & text ) {
45  if( column >= int(m_items.size()) ) {
46  m_items.append( TextPaintItem(text) );
47  }else{
48  m_items[column] = TextPaintItem(text);
49  }
50 }
51 
52 
53 TQString FancyListViewItem::text(int column) const {
54  if( m_items.isEmpty() ) return "";
55  return (TQString)m_items[column];
56 }
57 
58 
59 TQColor FancyListViewItem::backgroundColor(int col) {
60 
61  return TDEListViewItem::backgroundColor(col);
62 }
63 
64 
67 
68 void FancyListViewItem::paintCell( TQPainter *painter, const TQColorGroup &cg,
69  int column, int width, int align)
70 {
71  if(column < 0 || column >= int(m_items.size()) || m_items[column].items().isEmpty()) {
72  TQListViewItem::paintCell(painter, cg, column, width, align);
73  return;
74  }
75 
76  painter->save();
77  TQColorGroup grp(cg);
78 
79  int styleNum = m_items[column].items()[0].style;
80  TextPaintStyleStore::Item& style = m_styles.getStyle( styleNum );
82  if( style.bgValid() ) {
83  grp.setColor( TQColorGroup::Base, style.background );
84  }else{
85  if(backgroundColor(column).isValid())
86  grp.setColor( TQColorGroup::Base, backgroundColor(column) );
87  }
88 
89  TQListView *lv = listView();
90  if ( !lv )
91  return;
92  TQPainter* p = painter;
93  TQFontMetrics fm( p->fontMetrics() );
94 
95  TQString t = text( column );
96 
97  int marg = lv->itemMargin();
98  int r = marg;
99  const TQPixmap * icon = pixmap( column );
100 
101  const BackgroundMode bgmode = lv->viewport()->backgroundMode();
102  const TQColorGroup::ColorRole crole = TQPalette::backgroundRoleFromMode( bgmode );
103  p->fillRect( 0, 0, width, height(), grp.brush( crole ) );
104 
105  if ( isSelected() && (column == 0 || lv->allColumnsShowFocus()) ) {
106  p->fillRect( r - marg, 0, width - r + marg, height(), cg.brush( TQColorGroup::Highlight ) );
107 
108  if ( isEnabled() || !lv )
109  p->setPen( cg.highlightedText() );
110  else if ( !isEnabled() && lv)
111  p->setPen( lv->palette().disabled().highlightedText() );
112  }
113  {
114  if ( isEnabled() || !lv )
115  p->setPen( cg.text() );
116  else if ( !isEnabled() && lv)
117  p->setPen( lv->palette().disabled().text() );
118 
119 
120  int iconWidth = 0;
121 
122  if ( icon ) {
123  iconWidth = icon->width() + lv->itemMargin();
124  int xo = r;
125  int yo = ( height() - icon->height() ) / 2;
126 
127  if ( align & AlignBottom )
128  yo = height() - icon->height();
129  else if ( align & AlignTop )
130  yo = 0;
131 
132 // respect horizontal alignment when there is no text for an item.
133  if ( t.isEmpty() ) {
134  if ( align & AlignRight )
135  xo = width - 2 * marg - iconWidth;
136  else if ( align & AlignHCenter )
137  xo = ( width - iconWidth ) / 2;
138  }
139  p->drawPixmap( xo, yo, *icon );
140  }
141 
142 
143  if ( !t.isEmpty() ) {
144  if ( !(align & AlignTop || align & AlignBottom) )
145  align |= AlignVCenter;
146 
147  r += iconWidth;
148 
149  TextPaintItem::Chain::iterator it = m_items[column].items().begin();
150  while(it != m_items[column].items().end())
151  {
152  int styleNum = (*it).style;
153  TextPaintStyleStore::Item& style = m_styles.getStyle( styleNum );
154 
155  painter->setFont(style.font);
156  p->drawText( r, 0, width-marg-r, height(), align, (*it).text );
157  r += textWidth( style.font, (*it).text );
158  ++it;
159  }
160  }
161  }
162 
163  painter->restore();
164 }
165 
166 
167 int FancyListViewItem::textWidth(const TQFont& font, const TQString& text)
168 {
169  TQFontMetrics fm( font );
170  if ( multiLinesEnabled() )
171  return fm.size( AlignVCenter, text ).width();
172  else
173  return fm.width( text );
174 
175 }
176 
177 
178 int FancyListViewItem::width(const TQFontMetrics &fm, const TQListView *lv, int column)
179 {
180  int width = 0;
181  if (column >= 0 && column < (int)m_items.size() && !multiLinesEnabled()) {
182  TextPaintItem::Chain::iterator it = m_items[column].items().begin();
183  while(it != m_items[column].items().end()) {
184  int styleNum = (*it).style;
185  TextPaintStyleStore::Item& style = m_styles.getStyle( styleNum );
186 
187  width += textWidth( style.font, (*it).text);
188  ++it;
189  }
190  width += lv->itemMargin() * 2;// - lv->d->minLeftBearing - lv->d->minRightBearing;
191 
192  const TQPixmap * pm = pixmap( column );
193  if ( pm )
194  width += pm->width() + lv->itemMargin();
195 
196  width = TQMAX( width, TQApplication::globalStrut().width() );
197  }
198  else
199  width = TQListViewItem::width(fm, lv, column);
200  return width;
201 }
202 
203 
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:68

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.8.13
This website is maintained by Timothy Pearson.