• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

knode

  • sources
  • kde-4.12
  • kdepim
  • knode
knhdrviewitem.cpp
Go to the documentation of this file.
1 /*
2  KNode, the KDE newsreader
3  Copyright (c) 1999-2006 the KNode authors.
4  See file AUTHORS for details
5  Copyright (c) 2005 Rafal Rzepecki <divide@users.sourceforge.net>
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11  You should have received a copy of the GNU General Public License
12  along with this program; if not, write to the Free Software Foundation,
13  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
14 */
15 
16 #include <QDrag>
17 #include <QPainter>
18 #include <QPixmap>
19 
20 #include <kdebug.h>
21 
22 #include "knglobals.h"
23 #include "knconfigmanager.h"
24 #include "knhdrviewitem.h"
25 #include "knarticle.h"
26 #include "headerview.h"
27 #include "settings.h"
28 
29 
30 KNHdrViewItem::KNHdrViewItem( KNHeaderView *ref, KNArticle::Ptr a ) :
31  K3ListViewItem( ref )
32 {
33  init( a );
34 }
35 
36 
37 KNHdrViewItem::KNHdrViewItem( KNHdrViewItem *ref, KNArticle::Ptr a ) :
38  K3ListViewItem( ref )
39 {
40  init( a );
41 }
42 
43 
44 void KNHdrViewItem::init( KNArticle::Ptr a )
45 {
46  art = a;
47  mActive = false;
48  for ( int i = 0; i < 5; ++i) // FIXME hardcoded column count
49  mShowToolTip[i] = false;
50 }
51 
52 
53 KNHdrViewItem::~KNHdrViewItem()
54 {
55  if (mActive) {
56  Q3ListView *lv = listView();
57  if (lv)
58  static_cast<KNHeaderView*>( lv )->activeRemoved();
59  }
60 
61  if (art) {
62  art->setListItem( 0, art );
63  }
64 }
65 
66 
67 void KNHdrViewItem::expandChildren()
68 {
69  Q3ListViewItemIterator it( firstChild() );
70  for ( ; it.current(); ++it) {
71  if (it.current()->depth() <= depth())
72  break;
73  it.current()->setOpen( true );
74  }
75 }
76 
77 
78 int KNHdrViewItem::compare( Q3ListViewItem *i, int col, bool ) const
79 {
80  KNArticle::Ptr otherArticle = static_cast<KNHdrViewItem*>( i )->art;
81  int diff = 0;
82  time_t date1 = 0, date2 = 0;
83 
84  switch (col) {
85  case 0:
86  case 1:
87  return text( col ).localeAwareCompare( i->text(col) );
88 
89  case 2:
90  if (art->type() == KNArticle::ATremote) {
91  diff = boost::static_pointer_cast<KNRemoteArticle>( art )->score() - boost::static_pointer_cast<KNRemoteArticle>( otherArticle )->score();
92  return (diff < 0 ? -1 : diff > 0 ? 1 : 0);
93  } else
94  return 0;
95 
96  case 3:
97  diff = art->lines()->numberOfLines() - otherArticle->lines()->numberOfLines();
98  return (diff < 0 ? -1 : diff > 0 ? 1 : 0);
99 
100  case 4:
101  date1 = art->date()->dateTime().toTime_t();
102  date2 = otherArticle->date()->dateTime().toTime_t();
103  if (art->type() == KNArticle::ATremote && static_cast<KNHeaderView*>( listView() )->sortByThreadChangeDate()) {
104  if ( boost::static_pointer_cast<KNRemoteArticle>( art )->subThreadChangeDate() > date1 )
105  date1 = boost::static_pointer_cast<KNRemoteArticle>( art )->subThreadChangeDate();
106  if ( boost::static_pointer_cast<KNRemoteArticle>( otherArticle )->subThreadChangeDate() > date2 ) {
107  date2 = boost::static_pointer_cast<KNRemoteArticle>( otherArticle )->subThreadChangeDate();
108  }
109  }
110  diff = date1 - date2;
111  return (diff < 0 ? -1 : diff > 0 ? 1 : 0);
112 
113  default:
114  return 0;
115  }
116 }
117 
118 
119 void KNHdrViewItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment )
120 {
121  int xText = 0, xPM = 3, yPM = 0;
122  QColor base;
123  const KPaintInfo *paintInfo = static_cast<KNHeaderView*>( listView() )->paintInfo();
124 
125  QPen pen = p->pen();
126  if (isSelected() || mActive) {
127  pen.setColor( cg.color( QPalette::HighlightedText ) );
128  base = cg.color( QPalette::Highlight );
129  } else {
130  if (greyOut())
131  pen.setColor( greyColor() );
132  else
133  pen.setColor( normalColor() );
134  base = backgroundColor( column );
135  }
136 
137  p->setPen( pen );
138 
139  p->fillRect( 0, 0, width, height(), QBrush(base) );
140 
141  if ( column == paintInfo->subCol ) {
142  QFont font = p->font();
143  font.setBold( firstColBold() );
144  p->setFont( font );
145  const QPixmap *pm;
146 
147  for (int i = 0; i < 4; ++i) {
148  pm = pixmap( i );
149  if (pm && !pm->isNull()) {
150  yPM = (height() - pm->height()) / 2;
151  p->drawPixmap( xPM, yPM, *pm );
152  xPM += pm->width() + 3;
153  }
154  }
155 
156  xText = xPM;
157  }
158 
159  if (width - xText - 5 > 0) {
160  int cntWidth = 0;
161  QString t2;
162  QFont f2;
163  if (countUnreadInThread() > 0 && column == paintInfo->subCol && !isOpen()) {
164  t2 = QString( " (%1)" ).arg( countUnreadInThread() );
165  f2 = p->font();
166  f2.setBold( true );
167  cntWidth = QFontMetrics( f2 ).width( t2, -1 );
168  }
169  QString t = p->fontMetrics().elidedText( text( column ), Qt::ElideRight, width - xText - cntWidth - 5 );
170 
171  // show tooltip if we have to squeeze the text
172  if ( t != text( column ) )
173  mShowToolTip[column] = true;
174  else
175  mShowToolTip[column] = false;
176 
177  p->drawText( xText, 0, width - xText - 5, height(), alignment | Qt::AlignVCenter, t );
178  if (cntWidth) {
179  QFont orig = p->font();
180  p->setFont( f2 );
181  QPen pen = p->pen();
182  if (isSelected() || mActive) {
183  pen.setColor( cg.color( QPalette::HighlightedText ) );
184  } else {
185  pen.setColor( cg.color( QPalette::Link ) );
186  }
187  p->setPen( pen );
188  p->drawText( xText + QFontMetrics( orig ).width( t, -1 ), 0, width - xText - 5, height(), alignment | Qt::AlignVCenter, t2 );
189  }
190  }
191 }
192 
193 
194 int KNHdrViewItem::width( const QFontMetrics &fm, const Q3ListView *, int column ) const
195 {
196  int ret = fm.boundingRect( text(column) ).width();
197  const KPaintInfo *paintInfo = static_cast<KNHeaderView*>( listView() )->paintInfo();
198 
199  // all pixmaps are drawn in the first column
200  if ( column == paintInfo->subCol ) {
201  const QPixmap *pm;
202  for (int i = 0; i < 4; ++i) {
203  pm = pixmap( i );
204  if (pm && !pm->isNull())
205  ret += pm->width() + 3;
206  }
207  }
208 
209  return ret;
210 }
211 
212 
213 QString KNHdrViewItem::text( int col ) const
214 {
215  if ( !art )
216  return QString();
217  KNHeaderView *hv = static_cast<KNHeaderView*>( listView() );
218 
219  if ( col == hv->paintInfo()->subCol ) {
220  return art->subject()->asUnicodeString();
221  }
222 
223  if ( col == hv->paintInfo()->sizeCol ) {
224  if ( art->lines()->numberOfLines() != 0 ) { // invalid values are read as '0' in KNGroup::insortHeaders()
225  return QString::number( art->lines()->numberOfLines() );
226  } else {
227  return QString();
228  }
229  }
230 
231  if ( col == hv->paintInfo()->scoreCol ) {
232  if ( art->type() == KNArticle::ATremote )
233  return QString::number( boost::static_pointer_cast<KNRemoteArticle>( art )->score() );
234  else
235  return QString();
236  }
237 
238  if ( col == hv->paintInfo()->dateCol ) {
239  return hv->mDateFormatter.dateString( art->date()->dateTime().toTime_t() );
240  } else
241  return K3ListViewItem::text( col );
242 }
243 
244 
245 Q3DragObject* KNHdrViewItem::dragObject()
246 {
247 #ifdef __GNUC__
248 #warning Enable this section again, once KNHdrView does not derive from K3ListView any more and can process QDrag (not Q3DragObject)
249 #endif
250 return 0;
251 #if 0
252  QDrag *drag = new QDrag( listView()->viewport() );
253  QMimeData *md = new QMimeData;
254  drag->setMimeData( md );
255 
256  KUrl::List list;
257  QString mid = art->messageID()->asUnicodeString();
258  // for some obscure reason it returns messageid in <>s
259  mid = mid.mid( 1, mid.length() - 2 );
260  list.append( QLatin1String( "news:" ) + mid );
261  QMap<QString,QString> metadata;
262  metadata["labels"] = KUrl::toPercentEncoding( art->subject()->asUnicodeString() );
263  list.populateMimeData( md, metadata );
264  md->setData( "x-knode-drag/article" , QByteArray() );
265 
266  drag->setPixmap( knGlobals.configManager()->appearance()->icon( KNode::Appearance::posting ) );
267  return drag;
268 #endif
269 }
270 
271 
272 int KNHdrViewItem::countUnreadInThread()
273 {
274  int count = 0;
275  if ( knGlobals.settings()->showUnread() ) {
276  if (art->type() == KNArticle::ATremote) {
277  count = boost::static_pointer_cast<KNRemoteArticle>( art )->unreadFollowUps();
278  }
279  }
280  return count;
281 }
282 
283 
284 bool KNHdrViewItem::greyOut()
285 {
286  if (art->type() == KNArticle::ATremote) {
287  return !boost::static_pointer_cast<KNRemoteArticle>( art )->hasUnreadFollowUps()
288  && boost::static_pointer_cast<KNRemoteArticle>( art )->isRead();
289  } else
290  return false;
291 }
292 
293 
294 bool KNHdrViewItem::firstColBold()
295 {
296  if(art->type() == KNArticle::ATremote)
297  return boost::static_pointer_cast<KNRemoteArticle>( art )->isNew();
298  else
299  return false;
300 }
301 
302 
303 QColor KNHdrViewItem::normalColor()
304 {
305  if (art->type()==KNArticle::ATremote)
306  return boost::static_pointer_cast<KNRemoteArticle>( art )->color();
307  else
308  return knGlobals.settings()->unreadThreadColor();
309 }
310 
311 
312 QColor KNHdrViewItem::greyColor()
313 {
314  return knGlobals.settings()->readThreadColor();
315 }
316 
KNHeaderView
Header view, displays the article listing of the currently selected news group or folder...
Definition: headerview.h:130
KNArticle::ATremote
Definition: knarticle.h:45
text
virtual QByteArray text(quint32 serialNumber) const =0
KNHdrViewItem::text
virtual QString text(int col) const
Definition: knhdrviewitem.cpp:213
KPaintInfo::sizeCol
int sizeCol
Definition: headerview.h:111
KPaintInfo::subCol
int subCol
Definition: headerview.h:109
KNHdrViewItem::expandChildren
void expandChildren()
Definition: knhdrviewitem.cpp:67
K3ListViewItem
KNHdrViewItem::compare
virtual int compare(Q3ListViewItem *i, int col, bool ascending) const
Definition: knhdrviewitem.cpp:78
KNHdrViewItem::KNHdrViewItem
KNHdrViewItem(KNHeaderView *ref, KNArticle::Ptr a=KNArticle::Ptr())
Definition: knhdrviewitem.cpp:30
KPaintInfo
Information shared by all items in a list view.
Definition: headerview.h:29
KNHdrViewItem
Header view item.
Definition: knhdrviewitem.h:26
QMimeData
Q3ListViewItem
KPaintInfo::dateCol
int dateCol
Definition: headerview.h:110
KNHdrViewItem::width
int width(const QFontMetrics &fm, const Q3ListView *lv, int column) const
Definition: knhdrviewitem.cpp:194
headerview.h
knglobals.h
KNHdrViewItem::~KNHdrViewItem
~KNHdrViewItem()
Definition: knhdrviewitem.cpp:53
KNHdrViewItem::art
KNArticle::Ptr art
Definition: knhdrviewitem.h:48
KNHdrViewItem::countUnreadInThread
int countUnreadInThread()
Definition: knhdrviewitem.cpp:272
settings.h
KNArticle::Ptr
boost::shared_ptr< KNArticle > Ptr
Shared pointer to a KNArticle. To be used instead of raw KNArticle*.
Definition: knarticle.h:39
KNHeaderView::paintInfo
const KPaintInfo * paintInfo() const
Definition: headerview.h:155
knarticle.h
knconfigmanager.h
KNRemoteArticle
KNRemoteArticle represents an article, whos body has to be retrieved from a remote host or from the l...
Definition: knarticle.h:103
KPaintInfo::scoreCol
int scoreCol
Definition: headerview.h:105
KNHdrViewItem::dragObject
Q3DragObject * dragObject()
Definition: knhdrviewitem.cpp:245
knhdrviewitem.h
KNHdrViewItem::paintCell
void paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
Definition: knhdrviewitem.cpp:119
knGlobals
#define knGlobals
Keep compatibility with the old way.
Definition: knglobals.h:28
KNode::Appearance::posting
Definition: knconfig.h:64
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:36 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

knode

Skip menu "knode"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal