2
Copyright 2010 Olivier Trichet <nive@nivalis.org>
4
Permission to use, copy, modify, and distribute this software
5
and its documentation for any purpose and without fee is hereby
6
granted, provided that the above copyright notice appear in all
7
copies and that both that the copyright notice and this
8
permission notice and warranty disclaimer appear in supporting
9
documentation, and that the name of the author not be used in
10
advertising or publicity pertaining to distribution of the
11
software without specific, written prior permission.
13
The author disclaim all warranties with regard to this
14
software, including all implied warranties of merchantability
15
and fitness. In no event shall the author be liable for any
16
special, indirect or consequential damages or any damages
17
whatsoever resulting from loss of use, data or profits, whether
18
in an action of contract, negligence or other tortious action,
19
arising out of or in connection with the use or performance of
23
#include "attachment_view.h"
25
#include "../kncomposer.h"
27
#include <QHeaderView>
34
// -- AttachmentView ---------------------------------------------------
36
AttachmentView::AttachmentView( QWidget *parent )
37
: QTreeWidget( parent )
39
QHeaderView *h = header();
40
h->setMovable( false );
41
h->setResizeMode( QHeaderView::Interactive );
42
h->setStretchLastSection( true );
45
AttachmentView::~AttachmentView()
51
void AttachmentView::removeCurrentAttachment()
53
QList<QTreeWidgetItem *> items = selectedItems();
54
foreach( QTreeWidgetItem *item, items ) {
55
takeTopLevelItem( indexOfTopLevelItem( item ) );
57
AttachmentViewItem *avi = static_cast< AttachmentViewItem * >( item );
58
bool lastItem = ( topLevelItemCount() == 0 );
59
emit attachmentRemoved( avi->mAttachment, lastItem );
64
void AttachmentView::editCurrentAttachment()
66
QList<QTreeWidgetItem *> items = selectedItems();
67
if ( items.isEmpty() ) {
70
// Update the view to reflect that we're only editing one item.
71
if ( items.size() > 1 ) {
72
setCurrentItem( items[ 0 ] );
75
AttachmentViewItem *item = static_cast< AttachmentViewItem * >( currentItem() );
76
QPointer<KNComposer::AttachmentPropertiesDlg> dlg = new KNComposer::AttachmentPropertiesDlg( item->mAttachment, this );
77
if ( dlg->exec() == QDialog::Accepted && dlg ) {
78
item->emitDataChanged(); // notify the changes
85
const QList<KNAttachment::Ptr> AttachmentView::attachments()
87
QList<KNAttachment::Ptr> al;
89
QTreeWidgetItemIterator it( this, QTreeWidgetItemIterator::All );
91
a = static_cast< AttachmentViewItem * >( *it )->mAttachment;
100
void AttachmentView::keyPressEvent( QKeyEvent *event )
102
if ( !selectedItems().isEmpty() ) {
103
switch ( event->key() ) {
105
emit deletePressed();
109
emit returnPressed();
114
QTreeView::keyPressEvent( event );
117
void AttachmentView::contextMenuEvent( QContextMenuEvent* event )
119
QTreeWidgetItem *item = itemAt( event->pos() );
121
setCurrentItem( item );
122
emit contextMenuRequested( event->globalPos() );
126
QAbstractScrollArea::contextMenuEvent( event );
131
// -- AttachmentViewItem -----------------------------------------------
133
AttachmentViewItem::AttachmentViewItem( AttachmentView *parent, KNAttachment::Ptr attachment )
134
: QTreeWidgetItem( parent ),
135
mAttachment( attachment )
137
Q_ASSERT( mAttachment );
140
AttachmentViewItem::~AttachmentViewItem()
144
QVariant AttachmentViewItem::data( int column, int role ) const
146
if ( role == Qt::DisplayRole ) {
148
case AttachmentView::File:
149
return mAttachment->name();
150
case AttachmentView::Type:
151
return mAttachment->mimeType();
152
case AttachmentView::Size:
153
return mAttachment->contentSize();
154
case AttachmentView::Description:
155
return mAttachment->description();
156
case AttachmentView::Encoding:
157
return mAttachment->encoding();
161
return QTreeWidgetItem::data( column, role );
167
} // namespace Composer
170
#include "attachment_view.moc"