2 This file is part of Akonadi.
4 Copyright (c) 2008 Bruno Virlet <bvirlet@kdemail.net>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 #include "mainwidget.h"
23 #include "mainwindow.h"
25 #include <QtGui/QSortFilterProxyModel>
27 MainWidget::MainWidget( MainWindow
* parent
)
28 : QWidget( parent
), mMainWindow( parent
)
31 QHBoxLayout
*layout
= new QHBoxLayout( this );
32 QSplitter
*topSplitter
= new QSplitter( Qt::Vertical
, this );
33 layout
->addWidget( topSplitter
);
34 QSplitter
*splitter
= new QSplitter( Qt::Horizontal
, this );
35 topSplitter
->addWidget( splitter
);
41 mCollectionList
= new Akonadi::CollectionView();
42 splitter
->addWidget( mCollectionList
);
45 mIncidenceList
= new QTreeView( this );
46 mIncidenceList
->setDragEnabled( this );
47 mIncidenceList
->setRootIsDecorated( false );
48 splitter
->addWidget( mIncidenceList
);
51 mIncidenceViewer
= new Akonadi::KCalItemBrowser( this );
52 topSplitter
->addWidget( mIncidenceViewer
);
59 mCollectionModel
= new Akonadi::CollectionModel( this );
60 mCollectionProxyModel
= new Akonadi::CollectionFilterProxyModel( this );
61 mCollectionProxyModel
->setSourceModel( mCollectionModel
);
62 mCollectionProxyModel
->addMimeTypeFilter( QString::fromLatin1( "text/calendar" ) );
64 // display collections sorted
65 QSortFilterProxyModel
*sortModel
= new QSortFilterProxyModel( this );
66 sortModel
->setDynamicSortFilter( true );
67 sortModel
->setSortCaseSensitivity( Qt::CaseInsensitive
);
68 sortModel
->setSourceModel( mCollectionProxyModel
);
70 // Calendar view (list of incidences)
71 mIncidenceModel
= new Akonadi::KCalModel( this );
74 * Connexion between views and models
76 mIncidenceList
->setModel( mIncidenceModel
);
77 mCollectionList
->setModel( sortModel
);
80 * React to user orders
82 connect( mCollectionList
, SIGNAL(clicked(const Akonadi::Collection
&)),
83 SLOT(collectionClicked(const Akonadi::Collection
&)) );
84 connect( mIncidenceList
, SIGNAL(clicked(QModelIndex
)), SLOT(itemActivated(QModelIndex
)) );
87 void MainWidget::collectionClicked( const Akonadi::Collection
& collection
)
89 mIncidenceModel
->setCollection( collection
);
92 void MainWidget::itemActivated( const QModelIndex
& index
)
94 const Akonadi::Item item
= mIncidenceModel
->itemForIndex( index
);
95 mIncidenceViewer
->setItem( item
);