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

akregator

  • sources
  • kde-4.12
  • kdepim
  • akregator
  • src
subscriptionlistdelegate.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Akregator.
3 
4  Copyright (C) 2007 Frank Osterfeld <frank.osterfeld@kdemail.net>
5  Copyright (C) 2009 Jonathan Marten <jjm@keelhaul.me.uk>
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 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 
21  As a special exception, permission is given to link this program
22  with any edition of Qt, and distribute the resulting executable,
23  without including the source code for Qt in the source distribution.
24 */
25 
26 #include "subscriptionlistdelegate.h"
27 #include "subscriptionlistmodel.h"
28 
29 #include <KDebug>
30 #include <KGlobalSettings>
31 #include <KIconTheme>
32 
33 #include <QHeaderView>
34 #include <QTreeView>
35 
36 using namespace Akregator;
37 
38 
39 Akregator::SubscriptionListDelegate::SubscriptionListDelegate( QWidget *parent )
40  : QStyledItemDelegate( parent )
41 {
42  connect( KGlobalSettings::self(), SIGNAL(appearanceChanged()),
43  SLOT(recalculateRowHeight()) );
44  recalculateRowHeight();
45 }
46 
47 
48 Akregator::SubscriptionListDelegate::~SubscriptionListDelegate()
49 {
50 }
51 
52 
53 QSize Akregator::SubscriptionListDelegate::sizeHint( const QStyleOptionViewItem &option,
54  const QModelIndex &index ) const
55 {
56  QSize size = QStyledItemDelegate::sizeHint( option, index );
57  size.setHeight( qMax( size.height(), ( m_viewIconHeight + 2 ) ) );
58  // +2 for row top/bottom margin
59  return ( size );
60 }
61 
62 
63 void Akregator::SubscriptionListDelegate::paint( QPainter *painter,
64  const QStyleOptionViewItem &option,
65  const QModelIndex &index ) const
66 {
67  QStyleOptionViewItem newOption = option;
68  if ( index.data( SubscriptionListModel::HasUnreadRole ).toBool() )
69  { // feed has unread articles
70  newOption.font.setBold(true);
71  }
72 
73  //fix [Bug 190052] numeric columns aligned to the left
74  if ( index.column() == SubscriptionListModel::UnreadCountColumn ||
75  index.column() == SubscriptionListModel::TotalCountColumn )
76  {
77  newOption.displayAlignment = Qt::AlignRight;
78  }
79 
80  // No need to translate the painter here - the item is vertically centered
81  // within its sizeHint rectangle.
82  QStyledItemDelegate::paint( painter, newOption, index );
83 }
84 
85 
86 void Akregator::SubscriptionListDelegate::recalculateRowHeight()
87 {
88  KIconTheme *iconTheme = KIconLoader::global()->theme();
89  m_viewIconHeight = ( iconTheme != NULL ) ? iconTheme->defaultSize( KIconLoader::Small ) : 0;
90  kDebug() << "icon height" << m_viewIconHeight;
91 }
92 
93 
94 void Akregator::SubscriptionListDelegate::initStyleOption( QStyleOptionViewItem *option,
95  const QModelIndex &index ) const
96 {
97  QStyledItemDelegate::initStyleOption( option, index );
98 
99  if ( index.column() != 0 )
100  {
101  // Append unread count to the title column only (it is always the first
102  // one)
103  return;
104  }
105 
106  QTreeView *view = static_cast< QTreeView * >( parent() );
107  if ( !view->header()->isSectionHidden( SubscriptionListModel::UnreadCountColumn ) )
108  {
109  // Do not append unread count to the title if the unread count column
110  // is visible
111  return;
112  } else {
113  view->header()->resizeSection( SubscriptionListModel::UnreadCountColumn, QHeaderView::ResizeToContents );
114  }
115 
116  if ( !view->header()->isSectionHidden( SubscriptionListModel::TotalCountColumn ) ) {
117  view->header()->resizeSection( SubscriptionListModel::TotalCountColumn, QHeaderView::ResizeToContents );
118  }
119 
120  QStyleOptionViewItemV4 *optionV4 = qstyleoption_cast< QStyleOptionViewItemV4 * >( option );
121  if ( !optionV4 )
122  {
123  // Should never happen, but play it safe
124  return;
125  }
126 
127  QModelIndex unreadIndex = index.sibling( index.row(), SubscriptionListModel::UnreadCountColumn );
128  int unread = unreadIndex.data().toInt();
129  if ( unread > 0 )
130  {
131  optionV4->text += QString( " (%1)" ).arg( unread );
132  }
133 }
134 
135 
136 #include "subscriptionlistdelegate.moc"
Akregator::SubscriptionListModel::UnreadCountColumn
Definition: subscriptionlistmodel.h:58
Akregator::SubscriptionListDelegate::initStyleOption
void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const
Definition: subscriptionlistdelegate.cpp:94
subscriptionlistdelegate.h
QWidget
QStyledItemDelegate
Akregator::SubscriptionListDelegate::sizeHint
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: subscriptionlistdelegate.cpp:53
QTreeView
Akregator::SubscriptionListModel::HasUnreadRole
Definition: subscriptionlistmodel.h:53
Akregator::SubscriptionListDelegate::~SubscriptionListDelegate
~SubscriptionListDelegate()
Definition: subscriptionlistdelegate.cpp:48
Akregator::SubscriptionListDelegate::SubscriptionListDelegate
SubscriptionListDelegate(QWidget *parent=0)
Definition: subscriptionlistdelegate.cpp:39
Akregator::SubscriptionListDelegate::paint
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: subscriptionlistdelegate.cpp:63
subscriptionlistmodel.h
Akregator::SubscriptionListModel::TotalCountColumn
Definition: subscriptionlistmodel.h:59
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:14 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akregator

Skip menu "akregator"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

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