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

knode

  • sources
  • kde-4.12
  • kdepim
  • knode
  • composer
attachment_view.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2010 Olivier Trichet <nive@nivalis.org>
3 
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.
12 
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
20  this software.
21 */
22 
23 #include "attachment_view.h"
24 
25 #include "../kncomposer.h"
26 
27 #include <QHeaderView>
28 #include <QKeyEvent>
29 
30 
31 namespace KNode {
32 namespace Composer {
33 
34 // -- AttachmentView ---------------------------------------------------
35 
36 AttachmentView::AttachmentView( QWidget *parent )
37  : QTreeWidget( parent )
38 {
39  QHeaderView *h = header();
40  h->setMovable( false );
41  h->setResizeMode( QHeaderView::Interactive );
42  h->setStretchLastSection( true );
43 }
44 
45 AttachmentView::~AttachmentView()
46 {
47 }
48 
49 
50 
51 void AttachmentView::removeCurrentAttachment()
52 {
53  QList<QTreeWidgetItem *> items = selectedItems();
54  foreach( QTreeWidgetItem *item, items ) {
55  takeTopLevelItem( indexOfTopLevelItem( item ) );
56 
57  AttachmentViewItem *avi = static_cast< AttachmentViewItem * >( item );
58  bool lastItem = ( topLevelItemCount() == 0 );
59  emit attachmentRemoved( avi->mAttachment, lastItem );
60  }
61  qDeleteAll( items );
62 }
63 
64 void AttachmentView::editCurrentAttachment()
65 {
66  QList<QTreeWidgetItem *> items = selectedItems();
67  if ( items.isEmpty() ) {
68  return;
69  }
70  // Update the view to reflect that we're only editing one item.
71  if ( items.size() > 1 ) {
72  setCurrentItem( items[ 0 ] );
73  }
74 
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
79  }
80  delete dlg;
81 }
82 
83 
84 
85 const QList<KNAttachment::Ptr> AttachmentView::attachments()
86 {
87  QList<KNAttachment::Ptr> al;
88  KNAttachment::Ptr a;
89  QTreeWidgetItemIterator it( this, QTreeWidgetItemIterator::All );
90  while ( *it ) {
91  a = static_cast< AttachmentViewItem * >( *it )->mAttachment;
92  al.append( a );
93  ++it;
94  }
95  return al;
96 }
97 
98 
99 
100 void AttachmentView::keyPressEvent( QKeyEvent *event )
101 {
102  if ( !selectedItems().isEmpty() ) {
103  switch ( event->key() ) {
104  case Qt::Key_Delete:
105  emit deletePressed();
106  break;
107  case Qt::Key_Return:
108  case Qt::Key_Enter:
109  emit returnPressed();
110  break;
111  }
112  }
113 
114  QTreeView::keyPressEvent( event );
115 }
116 
117 void AttachmentView::contextMenuEvent( QContextMenuEvent* event )
118 {
119  QTreeWidgetItem *item = itemAt( event->pos() );
120  if ( item ) {
121  setCurrentItem( item );
122  emit contextMenuRequested( event->globalPos() );
123  return;
124  }
125 
126  QAbstractScrollArea::contextMenuEvent( event );
127 }
128 
129 
130 
131 // -- AttachmentViewItem -----------------------------------------------
132 
133 AttachmentViewItem::AttachmentViewItem( AttachmentView *parent, KNAttachment::Ptr attachment )
134  : QTreeWidgetItem( parent ),
135  mAttachment( attachment )
136 {
137  Q_ASSERT( mAttachment );
138 }
139 
140 AttachmentViewItem::~AttachmentViewItem()
141 {
142 }
143 
144 QVariant AttachmentViewItem::data( int column, int role ) const
145 {
146  if ( role == Qt::DisplayRole ) {
147  switch ( column ) {
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();
158  }
159  }
160 
161  return QTreeWidgetItem::data( column, role );
162 }
163 
164 
165 
166 
167 } // namespace Composer
168 } // namespace KNode
169 
170 #include "attachment_view.moc"
KNode::Composer::AttachmentView::removeCurrentAttachment
void removeCurrentAttachment()
Remove the currently selected attachment if there is a selection.
Definition: attachment_view.cpp:51
KNode::Composer::AttachmentView::File
file name.
Definition: attachment_view.h:46
KNode::Composer::AttachmentViewItem::data
QVariant data(int column, int role) const
Reimplemented to return data from the underlying KNAttachment.
Definition: attachment_view.cpp:144
KNode::Composer::AttachmentViewItem
Item of the AttachmentView.
Definition: attachment_view.h:120
KNode::Composer::AttachmentView::AttachmentView
AttachmentView(QWidget *parent=0)
Constructor for the selection widget of identity.
Definition: attachment_view.cpp:36
QTreeWidget
KNode::Composer::AttachmentView
Attachment view in the composer.
Definition: attachment_view.h:37
KNode::Composer::AttachmentView::returnPressed
void returnPressed()
This signal is emitted when the Return or Enter key is pressed on this widget.
KNode::Composer::AttachmentViewItem::~AttachmentViewItem
virtual ~AttachmentViewItem()
Destructor.
Definition: attachment_view.cpp:140
QWidget
KNode::Composer::AttachmentView::editCurrentAttachment
void editCurrentAttachment()
Edit the currently selected attachment.
Definition: attachment_view.cpp:64
KNode::Composer::AttachmentViewItem::AttachmentViewItem
AttachmentViewItem(AttachmentView *parent, KNAttachment::Ptr attachment)
Constructor.
Definition: attachment_view.cpp:133
KNode::Composer::AttachmentView::Description
description of the attachment.
Definition: attachment_view.h:49
KNode::Composer::AttachmentView::attachments
const QList< KNAttachment::Ptr > attachments()
Returns the list of attachments contained by this view .
Definition: attachment_view.cpp:85
KNode::Composer::AttachmentView::Size
size.
Definition: attachment_view.h:48
setCurrentItem
static int setCurrentItem(K3ListBox *box, const QString &s)
Definition: kscoringeditor.cpp:51
KNode::Composer::AttachmentView::deletePressed
void deletePressed()
This signal is emitted when the Delete key is pressed on this widget.
KNode::Composer::AttachmentView::~AttachmentView
virtual ~AttachmentView()
Destructor.
Definition: attachment_view.cpp:45
KNode::Composer::AttachmentView::contextMenuEvent
virtual void contextMenuEvent(QContextMenuEvent *event)
Reimplemented to emit the contextMenuRequested() signal.
Definition: attachment_view.cpp:117
attachment_view.h
QTreeWidgetItem
KNode::Composer::AttachmentView::keyPressEvent
virtual void keyPressEvent(QKeyEvent *event)
Reimplemented to emit the deletePressed() and returnPressed() signals.
Definition: attachment_view.cpp:100
KNode::Composer::AttachmentView::contextMenuRequested
void contextMenuRequested(const QPoint &point)
Request a context menu on an attachment item at point.
KNode::Composer::AttachmentView::Type
mime-type.
Definition: attachment_view.h:47
KNode::Composer::AttachmentView::Encoding
MIME encoding (7bit, base64, etc.).
Definition: attachment_view.h:50
KNode::Composer::AttachmentView::attachmentRemoved
void attachmentRemoved(KNAttachment::Ptr attachment, bool last)
This signal is emitted when an attachment was actually removed.
KNAttachment::Ptr
boost::shared_ptr< KNAttachment > Ptr
Shared pointer to a KNAttachment.
Definition: knarticle.h:281
KNComposer::AttachmentPropertiesDlg
Attachment properties dialog.
Definition: kncomposer.h:234
QList
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:36 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

knode

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

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