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

KDevelop Widgets Library

  • lib
  • widgets
fancylistviewitem.h
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#ifndef FANCYLISTVIEWITEM
21#define FANCYLISTVIEWITEM
22
23#include <tqvaluevector.h>
24#include <tqpainter.h>
25#include <tqfont.h>
26#include <tqlistview.h>
27#include <tdelistview.h>
28
29class TextPaintStyleStore {
30 public:
31 class Item {
32 public:
33 TQFont font;
34 TQColor color;
35 TQColor background;
36
37 Item(const TQFont& f = TQFont(), const TQColor& c = TQColor(), const TQColor b = TQColor() ) : font(f), color(c), background(b) {
38 }
39
40 bool bgValid() {
41 return background.isValid();
42 }
43
44 bool colValid() {
45 return color.isValid();
46 }
47 };
48
49 typedef TQMap<int, Item> Store ;
50
51 TextPaintStyleStore( TQFont defaultFont=TQFont() ) {
52 m_styles.insert( 0, Item( defaultFont ) );
53 }
54
55 Item& getStyle( int num ) {
56 Store::Iterator it = m_styles.find( num );
57 if( it != m_styles.end() ) return *it;
58 return m_styles[0];
59 }
60
61 void addStyle( int num, Item& style ) {
62 m_styles[num] = style;
63 }
64
65 void addStyle( int num, const TQFont& font ) {
66 m_styles[num] = Item( font );
67 }
68
69 bool hasStyle( int num ) {
70 Store::Iterator it = m_styles.find( num );
71 return ( it != m_styles.end() );
72 }
73
74 private:
75 Store m_styles;
76};
77
78class TextPaintItem {
79 public:
80 struct Item {
81 TQString text;
82 int style;
83
84 Item( const TQString& t = "", int st = 0 ) : text(t), style(st) {
85 }
86
87 };
88 typedef TQValueList<Item> Chain;
89
90 Chain& items() {
91 return m_chain;
92 }
93
94 TextPaintItem(const TQString& text="") {
95 addItem( text );
96 }
97
98 Item& addItem(const TQString& item, int style = 0) {
99 m_chain.append( Item(item, style) );
100 return m_chain.back();
101 }
102
103 void clear() {
104 m_chain.clear();
105 }
106
107 operator TQString () const {
108 TQString ret;
109 Chain::const_iterator it = m_chain.begin();
110 while(it != m_chain.end()) {
111 ret += (*it).text;
112 ++it;
113 }
114 return ret;
115 }
116
117 private:
118 Chain m_chain;
119};
120
123
124class FancyListViewItem : public TDEListViewItem
125{
126 public:
127 FancyListViewItem(TextPaintStyleStore& styles, TQListView *parent, const TQString &label1, const TQString &label2="") : TDEListViewItem(parent, label1, label2), m_styles(styles) {
128 init(label1, label2);
129 }
130
131 FancyListViewItem(TextPaintStyleStore& styles, TQListViewItem *parent, const TQString &label1, const TQString &label2="") : TDEListViewItem(parent, label1, label2), m_styles(styles) {
132 init(label1, label2);
133 }
134
135 virtual void paintCell(TQPainter *painter, const TQColorGroup &cg, int column, int width, int align);
136 virtual int width(const TQFontMetrics &fm, const TQListView *lv, int column);
137 virtual void setText ( int column, const TQString & text );
138 virtual TQString text(int column) const;
139
140 inline void clear() {
141 m_items.clear();
142 }
143
144 inline TextPaintItem& item(int column = 0) {
145 if(m_items.isEmpty()) {
146 m_items.append( TextPaintItem() );
147 }
148
149 return m_items[column];
150 }
151
152 void setItem(int column, TextPaintItem item);
153 private:
154 virtual TQColor backgroundColor(int col);
155 void init(const TQString& label1, const TQString& label2);
156 int textWidth(const TQFont& font, const TQString& text);
157 TQValueVector<TextPaintItem> m_items;
158 protected:
159 TextPaintStyleStore& m_styles;
160};
161
162#endif
FancyListViewItem
does not support multiple column, a "column" represents a part of the real first column TDEListViewIt...
Definition fancylistviewitem.h:125
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.9.8
This website is maintained by Timothy Pearson.