• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.10.5 API Reference
  • KDE Home
  • Contact Us
 

Kontact Plugin Interface Library

  • kontactinterface
summary.cpp
1 /*
2  This file is part of the KDE Kontact Plugin Interface Library.
3 
4  Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
5  Copyright (c) 2003 Daniel Molkentin <molkentin@kde.org>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include "summary.h"
24 
25 #include <QImage>
26 #include <QFont>
27 #include <QLabel>
28 #include <QPainter>
29 #include <QPixmap>
30 #include <QMouseEvent>
31 #include <QDragEnterEvent>
32 #include <QDropEvent>
33 
34 #include <KGlobalSettings>
35 #include <KHBox>
36 #include <KIconLoader>
37 #include <KDialog>
38 
39 using namespace KontactInterface;
40 
41 //@cond PRIVATE
42 namespace KontactInterface {
43 class SummaryMimeData : public QMimeData
44 {
45  public:
46  virtual bool hasFormat( const QString &format ) const
47  {
48  if ( format == "application/x-kontact-summary" ) {
49  return true;
50  }
51  return false;
52  }
53 };
54 }
55 //@endcond
56 
57 //@cond PRIVATE
58 class Summary::Private
59 {
60  public:
61  KStatusBar *mStatusBar;
62  QPoint mDragStartPoint;
63 };
64 //@endcond
65 
66 Summary::Summary( QWidget *parent )
67  : QWidget( parent ), d( new Private )
68 {
69  setFont( KGlobalSettings::generalFont() );
70  setAcceptDrops( true );
71 }
72 
73 Summary::~Summary()
74 {
75  delete d;
76 }
77 
78 int Summary::summaryHeight() const
79 {
80  return 1;
81 }
82 
83 QWidget *Summary::createHeader( QWidget *parent, const QString &iconname, const QString &heading )
84 {
85  setStyleSheet( "KHBox {"
86  "border: 0px;"
87  "font: bold large;"
88  "padding: 2px;"
89  "background: palette(window);"
90  "color: palette(windowtext);"
91  "}"
92  "KHBox > QLabel { font: bold larger; } " );
93 
94  KHBox *hbox = new KHBox( parent );
95 
96  QLabel *label = new QLabel( hbox );
97  label->setPixmap( KIconLoader::global()->loadIcon( iconname, KIconLoader::Toolbar ) );
98 
99  label->setFixedSize( label->sizeHint() );
100  label->setAcceptDrops( true );
101 
102  label = new QLabel( heading, hbox );
103  label->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
104  label->setIndent( KDialog::spacingHint() );
105 
106  hbox->setMaximumHeight( hbox->minimumSizeHint().height() );
107 
108  return hbox;
109 }
110 
111 QStringList Summary::configModules() const
112 {
113  return QStringList();
114 }
115 
116 void Summary::configChanged()
117 {
118 }
119 
120 void Summary::updateSummary( bool force )
121 {
122  Q_UNUSED( force );
123 }
124 
125 void Summary::mousePressEvent( QMouseEvent *event )
126 {
127  d->mDragStartPoint = event->pos();
128 
129  QWidget::mousePressEvent( event );
130 }
131 
132 void Summary::mouseMoveEvent( QMouseEvent *event )
133 {
134  if ( ( event->buttons() & Qt::LeftButton ) &&
135  ( event->pos() - d->mDragStartPoint ).manhattanLength() > 4 ) {
136 
137  QDrag *drag = new QDrag( this );
138  drag->setMimeData( new SummaryMimeData() );
139  drag->setObjectName( "SummaryWidgetDrag" );
140 
141  QPixmap pm = QPixmap::grabWidget( this );
142  if ( pm.width() > 300 ) {
143  pm = QPixmap::fromImage(
144  pm.toImage().scaled( 300, 300, Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
145  }
146 
147  QPainter painter;
148  painter.begin( &pm );
149  painter.setPen( QPalette::AlternateBase );
150  painter.drawRect( 0, 0, pm.width(), pm.height() );
151  painter.end();
152  drag->setPixmap( pm );
153  drag->start( Qt::MoveAction );
154  } else {
155  QWidget::mouseMoveEvent( event );
156  }
157 }
158 
159 void Summary::dragEnterEvent( QDragEnterEvent *event )
160 {
161  if ( event->mimeData()->hasFormat( "application/x-kontact-summary" ) ) {
162  event->acceptProposedAction();
163  }
164 }
165 
166 void Summary::dropEvent( QDropEvent *event )
167 {
168  int alignment = ( event->pos().y() < ( height() / 2 ) ? Qt::AlignTop : Qt::AlignBottom );
169  emit summaryWidgetDropped( this, event->source(), alignment );
170 }
171 
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:27:09 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kontact Plugin Interface Library

Skip menu "Kontact Plugin Interface Library"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
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