~ubuntu-branches/ubuntu/quantal/kdepim/quantal

« back to all changes in this revision

Viewing changes to mailcommon/foldertreeview.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-15 14:17:51 UTC
  • mto: This revision was merged to the branch mainline in revision 193.
  • Revision ID: package-import@ubuntu.com-20111215141751-bmhdpiwl23wd9w26
Tags: upstream-4.7.90
ImportĀ upstreamĀ versionĀ 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
 
44
44
 
45
45
FolderTreeView::FolderTreeView( KXMLGUIClient* xmlGuiClient, QWidget* parent, bool showUnreadCount )
46
 
  :Akonadi::EntityTreeView( xmlGuiClient, parent ), mbDisableContextMenuAndExtraColumn( false )    
 
46
  :Akonadi::EntityTreeView( xmlGuiClient, parent ), mbDisableContextMenuAndExtraColumn( false )
47
47
{
48
48
  init(showUnreadCount);
49
49
}
56
56
 
57
57
void FolderTreeView::setTooltipsPolicy( FolderTreeWidget::ToolTipDisplayPolicy policy )
58
58
{
 
59
  if ( mToolTipDisplayPolicy == policy )
 
60
    return;
 
61
  
59
62
  mToolTipDisplayPolicy = policy;
60
63
  writeConfig();
61
64
}
78
81
  mToolTipDisplayPolicy = FolderTreeWidget::DisplayAlways;
79
82
 
80
83
  header()->setContextMenuPolicy( Qt::CustomContextMenu );
81
 
  connect( header(), SIGNAL( customContextMenuRequested( const QPoint& ) ),
82
 
           SLOT( slotHeaderContextMenuRequested( const QPoint& ) ) );
 
84
  connect( header(), SIGNAL(customContextMenuRequested(QPoint)),
 
85
           SLOT(slotHeaderContextMenuRequested(QPoint)) );
83
86
  readConfig();
84
87
 
85
88
  mCollectionStatisticsDelegate = new Akonadi::CollectionStatisticsDelegate( this );
86
89
  mCollectionStatisticsDelegate->setProgressAnimationEnabled( true );
87
90
  setItemDelegate(mCollectionStatisticsDelegate);
88
91
  mCollectionStatisticsDelegate->setUnreadCountShown( showUnreadCount && !header()->isSectionHidden( 1 ) );
89
 
 
90
92
}
91
93
 
92
94
void FolderTreeView::showStatisticAnimation( bool anim )
95
97
}
96
98
 
97
99
void FolderTreeView::writeConfig()
98
 
{
 
100
{  
99
101
  KConfigGroup myGroup( KernelIf->config(), "MainFolderView");
100
102
  myGroup.writeEntry( "IconSize", iconSize().width() );
101
103
  myGroup.writeEntry( "ToolTipDisplayPolicy", ( int ) mToolTipDisplayPolicy );
109
111
  if ( iIconSize < 16 || iIconSize > 32 )
110
112
    iIconSize = 22;
111
113
  setIconSize( QSize( iIconSize, iIconSize ) );
112
 
  setTooltipsPolicy( static_cast<FolderTreeWidget::ToolTipDisplayPolicy>( myGroup.readEntry( "ToolTipDisplayPolicy", static_cast<int>( FolderTreeWidget::DisplayAlways ) ) ) );
113
 
  setSortingPolicy( ( FolderTreeWidget::SortingPolicy )myGroup.readEntry( "SortingPolicy", ( int ) mSortingPolicy ) );
 
114
  mToolTipDisplayPolicy = static_cast<FolderTreeWidget::ToolTipDisplayPolicy>( myGroup.readEntry( "ToolTipDisplayPolicy", static_cast<int>( FolderTreeWidget::DisplayAlways ) ) );
 
115
  
 
116
  setSortingPolicy( ( FolderTreeWidget::SortingPolicy )myGroup.readEntry( "SortingPolicy", ( int ) FolderTreeWidget::SortByCurrentColumn ),false );
114
117
}
115
118
 
116
119
void FolderTreeView::slotHeaderContextMenuRequested( const QPoint&pnt )
133
136
    act->setData( QVariant( i ) );
134
137
    if ( i == 0)
135
138
       act->setEnabled( false );
136
 
    connect( act,  SIGNAL( triggered( bool ) ),
137
 
             SLOT( slotHeaderContextMenuChangeHeader( bool ) ) );
 
139
    connect( act,  SIGNAL(triggered(bool)),
 
140
             SLOT(slotHeaderContextMenuChangeHeader(bool)) );
138
141
  }
139
142
 
140
143
 
143
146
  static int icon_sizes[] = { 16, 22, 32 /*, 48, 64, 128 */ };
144
147
 
145
148
  QActionGroup *grp = new QActionGroup( &menu );
146
 
 
147
 
  for ( int i = 0; i < (int)( sizeof( icon_sizes ) / sizeof( int ) ); i++ )
 
149
  const int nbElement( (int)( sizeof( icon_sizes ) / sizeof( int ) ) );
 
150
  for ( int i = 0; i < nbElement; i++ )
148
151
  {
149
152
    act = menu.addAction( QString("%1x%2").arg( icon_sizes[ i ] ).arg( icon_sizes[ i ] ) );
150
153
    act->setCheckable( true );
153
156
      act->setChecked( true );
154
157
    act->setData( QVariant( icon_sizes[ i ] ) );
155
158
 
156
 
    connect( act, SIGNAL( triggered( bool ) ),
157
 
             SLOT( slotHeaderContextMenuChangeIconSize( bool ) ) );
 
159
    connect( act, SIGNAL(triggered(bool)),
 
160
             SLOT(slotHeaderContextMenuChangeIconSize(bool)) );
158
161
  }
159
162
  menu.addTitle( i18n( "Display Tooltips" ) );
160
163
 
165
168
  grp->addAction( act );
166
169
  act->setChecked( mToolTipDisplayPolicy == FolderTreeWidget::DisplayAlways );
167
170
  act->setData( QVariant( (int)FolderTreeWidget::DisplayAlways ) );
168
 
  connect( act, SIGNAL( triggered( bool ) ),
169
 
           SLOT( slotHeaderContextMenuChangeToolTipDisplayPolicy( bool ) ) );
 
171
  connect( act, SIGNAL(triggered(bool)),
 
172
           SLOT(slotHeaderContextMenuChangeToolTipDisplayPolicy(bool)) );
170
173
  act = menu.addAction( i18nc("@action:inmenu", "When Text Obscured") );
171
174
  act->setCheckable( true );
172
175
 
175
178
  grp->addAction( act );
176
179
  act->setChecked( mToolTipDisplayPolicy == FolderTreeWidget::DisplayWhenTextElided );
177
180
  act->setData( QVariant( (int)FolderTreeWidget::DisplayWhenTextElided ) );
178
 
  connect( act, SIGNAL( triggered( bool ) ),
179
 
           SLOT( slotHeaderContextMenuChangeToolTipDisplayPolicy( bool ) ) );
 
181
  connect( act, SIGNAL(triggered(bool)),
 
182
           SLOT(slotHeaderContextMenuChangeToolTipDisplayPolicy(bool)) );
180
183
 
181
184
  act = menu.addAction( i18nc("@action:inmenu Never display tooltips.", "Never") );
182
185
  act->setCheckable( true );
183
186
  grp->addAction( act );
184
187
  act->setChecked( mToolTipDisplayPolicy == FolderTreeWidget::DisplayNever );
185
188
  act->setData( QVariant( (int)FolderTreeWidget::DisplayNever ) );
186
 
  connect( act, SIGNAL( triggered( bool ) ),
187
 
           SLOT( slotHeaderContextMenuChangeToolTipDisplayPolicy( bool ) ) );
 
189
  connect( act, SIGNAL(triggered(bool)),
 
190
           SLOT(slotHeaderContextMenuChangeToolTipDisplayPolicy(bool)) );
188
191
 
189
192
  menu.addTitle( i18nc("@action:inmenu", "Sort Items" ) );
190
193
 
195
198
  grp->addAction( act );
196
199
  act->setChecked( mSortingPolicy == FolderTreeWidget::SortByCurrentColumn );
197
200
  act->setData( QVariant( (int)FolderTreeWidget::SortByCurrentColumn ) );
198
 
  connect( act, SIGNAL( triggered( bool ) ),
199
 
           SLOT( slotHeaderContextMenuChangeSortingPolicy( bool ) ) );
 
201
  connect( act, SIGNAL(triggered(bool)),
 
202
           SLOT(slotHeaderContextMenuChangeSortingPolicy(bool)) );
200
203
 
201
204
  act = menu.addAction( i18nc("@action:inmenu", "Manually, by Drag And Drop") );
202
205
  act->setCheckable( true );
203
206
  grp->addAction( act );
204
207
  act->setChecked( mSortingPolicy == FolderTreeWidget::SortByDragAndDropKey );
205
208
  act->setData( QVariant( (int)FolderTreeWidget::SortByDragAndDropKey ) );
206
 
  connect( act, SIGNAL( triggered( bool ) ),
207
 
           SLOT( slotHeaderContextMenuChangeSortingPolicy( bool ) ) );
 
209
  connect( act, SIGNAL(triggered(bool)),
 
210
           SLOT(slotHeaderContextMenuChangeSortingPolicy(bool)) );
208
211
 
209
212
  menu.exec( header()->mapToGlobal( pnt ) );
210
213
}
222
225
  if ( !ok )
223
226
    return;
224
227
 
225
 
  setSortingPolicy( ( FolderTreeWidget::SortingPolicy )policy );
 
228
  setSortingPolicy( ( FolderTreeWidget::SortingPolicy )policy, true );
226
229
}
227
230
 
228
231
 
229
 
void FolderTreeView::setSortingPolicy( FolderTreeWidget::SortingPolicy policy )
 
232
void FolderTreeView::setSortingPolicy( FolderTreeWidget::SortingPolicy policy, bool writeInConfig )
230
233
{
 
234
  if ( mSortingPolicy == policy )
 
235
    return;
231
236
  mSortingPolicy = policy;
232
237
  switch ( mSortingPolicy )
233
238
  {
240
245
  case FolderTreeWidget::SortByDragAndDropKey:
241
246
      header()->setClickable( false );
242
247
      header()->setSortIndicatorShown( false );
 
248
      
243
249
#if 0
244
250
      //
245
251
      // Qt 4.5 introduced a nasty bug here:
250
256
      // performed by the view whenever it wants. We want to control sorting.
251
257
      //
252
258
      setSortingEnabled( true ); // hack for qutie bug: the param here should be false
253
 
      sortByColumn( 0, Qt::AscendingOrder );
 
259
      header()->setSortIndicator( 0, Qt::AscendingOrder );
254
260
#endif
255
261
      setSortingEnabled( false ); // hack for qutie bug: this call shouldn't be here at all
256
262
      emit manualSortingChanged( true );
260
266
      // should never happen
261
267
    break;
262
268
  }
263
 
  writeConfig();
 
269
  if ( writeInConfig )
 
270
    writeConfig();
264
271
}
265
272
 
266
273
void FolderTreeView::slotHeaderContextMenuChangeToolTipDisplayPolicy( bool )
313
320
  if ( !ok )
314
321
    return;
315
322
 
316
 
  setIconSize( QSize( size, size ) );
 
323
  const QSize newIconSize( QSize( size, size ) );
 
324
  if ( newIconSize == iconSize() )
 
325
    return;
 
326
  setIconSize( newIconSize );
 
327
  
317
328
  writeConfig();
318
329
}
319
330