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

Kontact Plugin Interface Library

  • sources
  • kde-4.14
  • kdepimlibs
  • 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 <QDrag>
29 #include <QPainter>
30 #include <QPixmap>
31 #include <QMouseEvent>
32 #include <QDragEnterEvent>
33 #include <QMimeData>
34 #include <QDropEvent>
35 
36 #include <KGlobalSettings>
37 #include <KHBox>
38 #include <KIconLoader>
39 #include <KDialog>
40 
41 using namespace KontactInterface;
42 
43 //@cond PRIVATE
44 namespace KontactInterface {
45 class SummaryMimeData : public QMimeData
46 {
47  public:
48  virtual bool hasFormat( const QString &format ) const
49  {
50  if ( format == QLatin1String("application/x-kontact-summary") ) {
51  return true;
52  }
53  return false;
54  }
55 };
56 }
57 //@endcond
58 
59 //@cond PRIVATE
60 class Summary::Private
61 {
62  public:
63  KStatusBar *mStatusBar;
64  QPoint mDragStartPoint;
65 };
66 //@endcond
67 
68 Summary::Summary( QWidget *parent )
69  : QWidget( parent ), d( new Private )
70 {
71  setFont( KGlobalSettings::generalFont() );
72  setAcceptDrops( true );
73 }
74 
75 Summary::~Summary()
76 {
77  delete d;
78 }
79 
80 int Summary::summaryHeight() const
81 {
82  return 1;
83 }
84 
85 QWidget *Summary::createHeader( QWidget *parent, const QString &iconname, const QString &heading )
86 {
87  setStyleSheet( QLatin1String("KHBox {"
88  "border: 0px;"
89  "font: bold large;"
90  "padding: 2px;"
91  "background: palette(window);"
92  "color: palette(windowtext);"
93  "}"
94  "KHBox > QLabel { font: bold larger; } ") );
95 
96  KHBox *hbox = new KHBox( parent );
97 
98  QLabel *label = new QLabel( hbox );
99  label->setPixmap( KIconLoader::global()->loadIcon( iconname, KIconLoader::Toolbar ) );
100 
101  label->setFixedSize( label->sizeHint() );
102  label->setAcceptDrops( true );
103 
104  label = new QLabel( heading, hbox );
105  label->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
106  label->setIndent( KDialog::spacingHint() );
107 
108  hbox->setMaximumHeight( hbox->minimumSizeHint().height() );
109 
110  return hbox;
111 }
112 
113 QStringList Summary::configModules() const
114 {
115  return QStringList();
116 }
117 
118 void Summary::configChanged()
119 {
120 }
121 
122 void Summary::updateSummary( bool force )
123 {
124  Q_UNUSED( force );
125 }
126 
127 void Summary::mousePressEvent( QMouseEvent *event )
128 {
129  d->mDragStartPoint = event->pos();
130 
131  QWidget::mousePressEvent( event );
132 }
133 
134 void Summary::mouseMoveEvent( QMouseEvent *event )
135 {
136  if ( ( event->buttons() & Qt::LeftButton ) &&
137  ( event->pos() - d->mDragStartPoint ).manhattanLength() > 4 ) {
138 
139  QDrag *drag = new QDrag( this );
140  drag->setMimeData( new SummaryMimeData() );
141  drag->setObjectName( QLatin1String("SummaryWidgetDrag") );
142 
143  QPixmap pm = QPixmap::grabWidget( this );
144  if ( pm.width() > 300 ) {
145  pm = QPixmap::fromImage(
146  pm.toImage().scaled( 300, 300, Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
147  }
148 
149  QPainter painter;
150  painter.begin( &pm );
151  painter.setPen( QPalette::AlternateBase );
152  painter.drawRect( 0, 0, pm.width(), pm.height() );
153  painter.end();
154  drag->setPixmap( pm );
155  drag->start( Qt::MoveAction );
156  } else {
157  QWidget::mouseMoveEvent( event );
158  }
159 }
160 
161 void Summary::dragEnterEvent( QDragEnterEvent *event )
162 {
163  if ( event->mimeData()->hasFormat( QLatin1String("application/x-kontact-summary") ) ) {
164  event->acceptProposedAction();
165  }
166 }
167 
168 void Summary::dropEvent( QDropEvent *event )
169 {
170  int alignment = ( event->pos().y() < ( height() / 2 ) ? Qt::AlignTop : Qt::AlignBottom );
171  emit summaryWidgetDropped( this, event->source(), alignment );
172 }
173 
KontactInterface::Summary::createHeader
QWidget * createHeader(QWidget *parent, const QString &icon, const QString &heading)
Creates a heading for a typical summary view with an icon and a heading.
Definition: summary.cpp:85
QWidget::setStyleSheet
void setStyleSheet(const QString &styleSheet)
QDropEvent::source
QWidget * source() const
QWidget
QPixmap::width
int width() const
KontactInterface::Summary::summaryHeight
virtual int summaryHeight() const
Returns the logical height of summary widget.
Definition: summary.cpp:80
QPainter::end
bool end()
QDropEvent::mimeData
const QMimeData * mimeData() const
QDrag::setMimeData
void setMimeData(QMimeData *data)
QDrag::start
Qt::DropAction start(QFlags< Qt::DropAction > request)
QMimeData::hasFormat
virtual bool hasFormat(const QString &mimeType) const
QDrag::setPixmap
void setPixmap(const QPixmap &pixmap)
KontactInterface::Summary::updateSummary
virtual void updateSummary(bool force=false)
This method is called if the displayed information should be updated.
Definition: summary.cpp:122
QLabel::setPixmap
void setPixmap(const QPixmap &)
QLabel::setAlignment
void setAlignment(QFlags< Qt::AlignmentFlag >)
QPixmap::fromImage
QPixmap fromImage(const QImage &image, QFlags< Qt::ImageConversionFlag > flags)
QPoint
QMouseEvent
QMouseEvent::buttons
Qt::MouseButtons buttons() const
QMimeData
QPainter::drawRect
void drawRect(const QRectF &rectangle)
KontactInterface::Summary::configModules
virtual QStringList configModules() const
Returns a list of names identifying configuration modules for this summary widget.
Definition: summary.cpp:113
QWidget::mousePressEvent
virtual void mousePressEvent(QMouseEvent *event)
KontactInterface::Summary::configChanged
virtual void configChanged()
This method is called whenever the configuration has been changed.
Definition: summary.cpp:118
QPainter::setPen
void setPen(const QColor &color)
QDropEvent
QPainter
QObject::setObjectName
void setObjectName(const QString &name)
QDrag
QWidget::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *event)
QString
KontactInterface::Summary::~Summary
virtual ~Summary()
Destroys the summary widget.
Definition: summary.cpp:75
QStringList
QPixmap
QWidget::setAcceptDrops
void setAcceptDrops(bool on)
QWidget::setFixedSize
void setFixedSize(const QSize &s)
KontactInterface::Summary::summaryWidgetDropped
void summaryWidgetDropped(QWidget *target, QWidget *widget, int alignment)
QPixmap::height
int height() const
QWidget::setFont
void setFont(const QFont &)
QDragEnterEvent
QLatin1String
QLabel::sizeHint
virtual QSize sizeHint() const
QPixmap::grabWidget
QPixmap grabWidget(QWidget *widget, const QRect &rectangle)
KontactInterface::Summary::Summary
Summary(QWidget *parent)
Creates a new summary widget.
Definition: summary.cpp:68
QMouseEvent::pos
const QPoint & pos() const
QPixmap::toImage
QImage toImage() const
QLabel::setIndent
void setIndent(int)
QLabel
QPainter::begin
bool begin(QPaintDevice *device)
QWidget::height
int height() const
QImage::scaled
QImage scaled(int width, int height, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformMode) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:37:55 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs 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

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