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

akonadi_next

  • sources
  • kde-4.12
  • kdepim
  • akonadi_next
quotacolorproxymodel.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2009 Kevin Ottens <ervin@kde.org>
3 
4 
5  This library is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Library General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or (at your
8  option) any later version.
9 
10  This library is distributed in the hope that it will be useful, but WITHOUT
11  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13  License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to the
17  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  02110-1301, USA.
19 */
20 
21 #include "quotacolorproxymodel.h"
22 
23 #include <akonadi/entitytreemodel.h>
24 #include <akonadi/collectionquotaattribute.h>
25 
26 #include <QColor>
27 
28 using namespace Akonadi;
29 
30 static const int qmlForegroundRole = 1984;
31 
35 class QuotaColorProxyModel::Private
36 {
37  public:
38  Private( QuotaColorProxyModel *parent )
39  : mParent( parent ), mThreshold( 100.0 ), mColor( Qt::red )
40  {
41  }
42 
43  QuotaColorProxyModel *mParent;
44 
45  qreal mThreshold;
46  QColor mColor;
47 };
48 
49 QuotaColorProxyModel::QuotaColorProxyModel( QObject *parent )
50  : KIdentityProxyModel( parent ),
51  d( new Private( this ) )
52 {
53 }
54 
55 QuotaColorProxyModel::~QuotaColorProxyModel()
56 {
57  delete d;
58 }
59 
60 void QuotaColorProxyModel::setWarningThreshold( qreal threshold )
61 {
62  d->mThreshold = threshold;
63 }
64 
65 qreal QuotaColorProxyModel::warningThreshold() const
66 {
67  return d->mThreshold;
68 }
69 
70 void QuotaColorProxyModel::setWarningColor( const QColor &color )
71 {
72  d->mColor = color;
73 }
74 
75 QColor QuotaColorProxyModel::warningColor() const
76 {
77  return d->mColor;
78 }
79 
80 QVariant QuotaColorProxyModel::data( const QModelIndex & index, int role) const
81 {
82  if ( role == Qt::ForegroundRole || role == qmlForegroundRole ) {
83  const QModelIndex sourceIndex = mapToSource( index );
84  const QModelIndex rowIndex = sourceIndex.sibling( sourceIndex.row(), 0 );
85  const Collection collection = sourceModel()->data( rowIndex, EntityTreeModel::CollectionRole ).value<Collection>();
86 
87  if ( collection.isValid() && collection.hasAttribute<CollectionQuotaAttribute>() ) {
88  const CollectionQuotaAttribute *quota = collection.attribute<CollectionQuotaAttribute>();
89 
90  if ( quota->currentValue() > -1 && quota->maximumValue() > 0 ) {
91  const qreal percentage = ( 100.0 * quota->currentValue() ) / quota->maximumValue();
92 
93  if ( percentage >= d->mThreshold ) {
94  return (role == Qt::ForegroundRole ? d->mColor : d->mColor.name());
95  }
96  }
97  }
98  }
99 
100  return KIdentityProxyModel::data( index, role );
101 }
102 
103 void QuotaColorProxyModel::setSourceModel( QAbstractItemModel *sourceModel )
104 {
105  KIdentityProxyModel::setSourceModel( sourceModel );
106 
107  if ( sourceModel ) {
108  QHash<int, QByteArray> names = sourceModel->roleNames();
109  names.insert( qmlForegroundRole, "foreground" );
110  setRoleNames( names );
111  }
112 }
113 
114 #include "quotacolorproxymodel.moc"
115 
KIdentityProxyModel
Akonadi::QuotaColorProxyModel::QuotaColorProxyModel
QuotaColorProxyModel(QObject *parent=0)
Creates a new quota color proxy model.
Definition: quotacolorproxymodel.cpp:49
Akonadi::QuotaColorProxyModel
A proxy model that colors collection text if they're above a given quota threshold.
Definition: quotacolorproxymodel.h:48
Akonadi::QuotaColorProxyModel::warningThreshold
qreal warningThreshold() const
Definition: quotacolorproxymodel.cpp:65
QObject
Akonadi::QuotaColorProxyModel::setWarningThreshold
void setWarningThreshold(qreal threshold)
Definition: quotacolorproxymodel.cpp:60
Akonadi::QuotaColorProxyModel::warningColor
QColor warningColor() const
Definition: quotacolorproxymodel.cpp:75
Akonadi::QuotaColorProxyModel::setSourceModel
virtual void setSourceModel(QAbstractItemModel *sourceModel)
Definition: quotacolorproxymodel.cpp:103
Akonadi::QuotaColorProxyModel::data
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition: quotacolorproxymodel.cpp:80
qmlForegroundRole
static const int qmlForegroundRole
Definition: quotacolorproxymodel.cpp:30
Akonadi::QuotaColorProxyModel::~QuotaColorProxyModel
virtual ~QuotaColorProxyModel()
Destroys the statistics tooltip proxy model.
Definition: quotacolorproxymodel.cpp:55
Akonadi::QuotaColorProxyModel::setWarningColor
void setWarningColor(const QColor &color)
Definition: quotacolorproxymodel.cpp:70
quotacolorproxymodel.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:54:56 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi_next

Skip menu "akonadi_next"
  • Main Page
  • Namespace List
  • 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