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

mailcommon

  • sources
  • kde-4.14
  • kdepim
  • mailcommon
  • widgets
favoritecollectionwidget.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-file-style: "gnu" -*-
2 
3  Copyright (c) 2012-2015 Montel Laurent <montel@kde.org>
4 
5  This program is free software; you can redistribute it and/or modify it
6  under the terms of the GNU General Public License, version 2, as
7  published by the Free Software Foundation.
8 
9  This program is distributed in the hope that it will be useful, but
10  WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include "favoritecollectionwidget.h"
20 #include "kernel/mailkernel.h"
21 #include "mailcommonsettings_base.h"
22 
23 #include <messagecore/settings/globalsettings.h>
24 
25 #include <KDE/KGlobalSettings>
26 #include <KDE/KLocale>
27 #include <KDE/KXMLGUIClient>
28 #include <KActionMenu>
29 #include <KActionCollection>
30 #include <akonadi/collectionstatisticsdelegate.h>
31 
32 #include <QPainter>
33 
34 using namespace MailCommon;
35 
36 class FavoriteCollectionWidget::Private
37 {
38 public:
39  Private()
40  : listMode(0),
41  iconMode(0)
42  {
43  }
44  QColor textColor;
45  QAction *listMode;
46  QAction *iconMode;
47 };
48 
49 FavoriteCollectionWidget::FavoriteCollectionWidget( KXMLGUIClient *xmlGuiClient, QWidget *parent )
50  : Akonadi::EntityListView( xmlGuiClient, parent ), d( new Private )
51 {
52  setFocusPolicy( Qt::NoFocus );
53 
54  connect( KGlobalSettings::self(), SIGNAL(kdisplayFontChanged()),
55  this, SLOT(slotGeneralFontChanged()));
56  connect( KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()),
57  this, SLOT(slotGeneralPaletteChanged()));
58 
59  Akonadi::CollectionStatisticsDelegate *delegate = new Akonadi::CollectionStatisticsDelegate( this );
60  delegate->setProgressAnimationEnabled( true );
61 
62  setItemDelegate(delegate);
63 
64  delegate->setUnreadCountShown( true );
65 
66  readConfig();
67 
68  createMenu(xmlGuiClient->actionCollection());
69 }
70 
71 FavoriteCollectionWidget::~FavoriteCollectionWidget()
72 {
73  delete d;
74 }
75 
76 void FavoriteCollectionWidget::updateMode()
77 {
78  switch(viewMode()) {
79  case ListMode:
80  d->listMode->setChecked( true );
81  d->iconMode->setChecked( false );
82  break;
83  case IconMode:
84  d->listMode->setChecked( false );
85  d->iconMode->setChecked( true );
86  break;
87  }
88 }
89 
90 void FavoriteCollectionWidget::createMenu(KActionCollection *ac)
91 {
92  KActionMenu *iconSizeMenu = new KActionMenu(i18n("Icon size"), this);
93  ac->addAction(QLatin1String("favorite_icon_size"), iconSizeMenu);
94 
95  static int icon_sizes[] = { 16, 22, 32 /*, 48, 64, 128 */ };
96 
97  QActionGroup *grp = new QActionGroup( iconSizeMenu );
98  const int nbElement( (int)( sizeof( icon_sizes ) / sizeof( int ) ) );
99  QAction *act = 0;
100  for ( int i = 0; i < nbElement; ++i ) {
101  act = new QAction(QString::fromLatin1( "%1x%2" ).arg( icon_sizes[ i ] ).arg( icon_sizes[ i ] ), iconSizeMenu);
102  iconSizeMenu->addAction( act );
103  act->setCheckable( true );
104  grp->addAction( act );
105  if ( iconSize().width() == icon_sizes[ i ] ) {
106  act->setChecked( true );
107  }
108  act->setData( QVariant( icon_sizes[ i ] ) );
109  connect( act, SIGNAL(triggered(bool)),
110  SLOT(slotChangeIconSize(bool)) );
111  }
112 
113  KActionMenu *modeFavoriteMenu = new KActionMenu(i18n("Mode"), this);
114  ac->addAction(QLatin1String("favorite_mode"), modeFavoriteMenu);
115 
116  grp = new QActionGroup( modeFavoriteMenu );
117  d->listMode = new QAction(i18n("List Mode"), modeFavoriteMenu);
118  modeFavoriteMenu->addAction( d->listMode );
119  d->listMode->setCheckable( true );
120  grp->addAction( d->listMode );
121  if ( viewMode() == ListMode) {
122  d->listMode->setChecked( true );
123  }
124  d->listMode->setData( QVariant( MailCommon::MailCommonSettings::EnumFavoriteCollectionViewMode::ListMode ) );
125  connect( d->listMode, SIGNAL(triggered(bool)),
126  SLOT(slotChangeMode(bool)) );
127 
128  d->iconMode = new QAction(i18n("Icon Mode"), modeFavoriteMenu);
129  modeFavoriteMenu->addAction( d->iconMode );
130  grp->addAction( d->iconMode );
131  d->iconMode->setCheckable( true );
132  if ( viewMode() == IconMode ) {
133  d->iconMode->setChecked( true );
134  }
135  d->iconMode->setData( QVariant( MailCommon::MailCommonSettings::EnumFavoriteCollectionViewMode::IconMode ) );
136  connect( d->iconMode, SIGNAL(triggered(bool)),
137  SLOT(slotChangeMode(bool)) );
138 }
139 
140 void FavoriteCollectionWidget::slotChangeMode(bool)
141 {
142  QAction *act = dynamic_cast< QAction * >( sender() );
143  if ( !act ) {
144  return;
145  }
146 
147  QVariant data = act->data();
148 
149  bool ok;
150  const int mode = data.toInt( &ok );
151  if ( !ok ) {
152  return;
153  }
154 
155  switch(mode) {
156  case MailCommon::MailCommonSettings::EnumFavoriteCollectionViewMode::IconMode:
157  changeViewMode(IconMode);
158  break;
159  case MailCommon::MailCommonSettings::EnumFavoriteCollectionViewMode::ListMode:
160  changeViewMode(ListMode);
161  break;
162  }
163 
164  MailCommon::MailCommonSettings::self()->setFavoriteCollectionViewMode(mode);
165  MailCommon::MailCommonSettings::self()->writeConfig();
166 }
167 
168 void FavoriteCollectionWidget::changeViewMode(QListView::ViewMode mode)
169 {
170  setViewMode(mode);
171  setDragEnabled(true);
172  setAcceptDrops(true);
173 }
174 
175 void FavoriteCollectionWidget::slotChangeIconSize(bool )
176 {
177  QAction *act = dynamic_cast< QAction * >( sender() );
178  if ( !act ) {
179  return;
180  }
181 
182  QVariant data = act->data();
183 
184  bool ok;
185  const int size = data.toInt( &ok );
186  if ( !ok ) {
187  return;
188  }
189 
190  const QSize newIconSize( QSize( size, size ) );
191  if ( newIconSize == iconSize() ) {
192  return;
193  }
194  setIconSize( newIconSize );
195  MailCommon::MailCommonSettings::self()->setIconSize(iconSize().width());
196  MailCommon::MailCommonSettings::self()->writeConfig();
197 }
198 
199 void FavoriteCollectionWidget::slotGeneralPaletteChanged()
200 {
201  const QPalette palette = viewport()->palette();
202  QColor color = palette.text().color();
203  color.setAlpha( 128 );
204  d->textColor = color;
205 }
206 
207 void FavoriteCollectionWidget::slotGeneralFontChanged()
208 {
209  // Custom/System font support
210  if ( MessageCore::GlobalSettings::self()->useDefaultFonts() ) {
211  setFont( KGlobalSettings::generalFont() );
212  }
213 }
214 
215 void FavoriteCollectionWidget::readConfig()
216 {
217  // Custom/System font support
218  if (!MessageCore::GlobalSettings::self()->useDefaultFonts() ) {
219  KConfigGroup fontConfig( KernelIf->config(), "Fonts" );
220  setFont( fontConfig.readEntry( "folder-font", KGlobalSettings::generalFont() ) );
221  } else {
222  setFont( KGlobalSettings::generalFont() );
223  }
224 
225  int iIconSize = MailCommon::MailCommonSettings::self()->iconSize();
226  if ( iIconSize < 16 || iIconSize > 32 ) {
227  iIconSize = 22;
228  }
229  setIconSize( QSize( iIconSize, iIconSize ) );
230 }
231 
232 void FavoriteCollectionWidget::paintEvent( QPaintEvent *event )
233 {
234  if ( !model() || model()->rowCount() == 0 ) {
235  QPainter p( viewport() );
236 
237  QFont font = p.font();
238  font.setItalic( true );
239  p.setFont( font );
240 
241  if (!d->textColor.isValid()) {
242  slotGeneralPaletteChanged();
243  }
244  p.setPen( d->textColor );
245 
246  p.drawText( QRect( 0, 0, width(), height() ), Qt::AlignCenter, i18n( "Drop your favorite folders here..." ) );
247  } else {
248  Akonadi::EntityListView::paintEvent( event );
249  }
250 }
251 
MailCommon::FavoriteCollectionWidget::slotGeneralPaletteChanged
void slotGeneralPaletteChanged()
Definition: favoritecollectionwidget.cpp:199
QWidget
KernelIf
#define KernelIf
Definition: mailkernel.h:191
QPalette::text
const QBrush & text() const
QActionGroup
QPainter::font
const QFont & font() const
QAction::setChecked
void setChecked(bool)
QAction::data
QVariant data() const
QFont
QColor::setAlpha
void setAlpha(int alpha)
MailCommon::FavoriteCollectionWidget::slotChangeIconSize
void slotChangeIconSize(bool)
Definition: favoritecollectionwidget.cpp:175
QActionGroup::addAction
QAction * addAction(QAction *action)
MailCommon::FavoriteCollectionWidget::readConfig
void readConfig()
Definition: favoritecollectionwidget.cpp:215
MailCommon::FavoriteCollectionWidget::~FavoriteCollectionWidget
~FavoriteCollectionWidget()
Definition: favoritecollectionwidget.cpp:71
QBrush::color
const QColor & color() const
QRect
QPainter::setFont
void setFont(const QFont &font)
MailCommon::FavoriteCollectionWidget::changeViewMode
void changeViewMode(QListView::ViewMode mode)
Definition: favoritecollectionwidget.cpp:168
QVariant::toInt
int toInt(bool *ok) const
favoritecollectionwidget.h
MailCommon::FavoriteCollectionWidget::FavoriteCollectionWidget
FavoriteCollectionWidget(KXMLGUIClient *xmlGuiClient, QWidget *parent=0)
Definition: favoritecollectionwidget.cpp:49
QPainter::setPen
void setPen(const QColor &color)
QPainter
MailCommon::FavoriteCollectionWidget::slotChangeMode
void slotChangeMode(bool)
Definition: favoritecollectionwidget.cpp:140
QPainter::drawText
void drawText(const QPointF &position, const QString &text)
QColor
MailCommon::FavoriteCollectionWidget::updateMode
void updateMode()
Definition: favoritecollectionwidget.cpp:76
QAction::setData
void setData(const QVariant &userData)
QSize
QAction::setCheckable
void setCheckable(bool)
QFont::setItalic
void setItalic(bool enable)
QLatin1String
mailkernel.h
MailCommon::FavoriteCollectionWidget::slotGeneralFontChanged
void slotGeneralFontChanged()
Definition: favoritecollectionwidget.cpp:207
QAction
QString::fromLatin1
QString fromLatin1(const char *str, int size)
MailCommon::FavoriteCollectionWidget::paintEvent
void paintEvent(QPaintEvent *)
Definition: favoritecollectionwidget.cpp:232
QPaintEvent
QPalette
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:31:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

mailcommon

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

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