• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 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 <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
41using namespace KontactInterface;
42
43//@cond PRIVATE
44namespace KontactInterface {
45class 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
60class Summary::Private
61{
62 public:
63 KStatusBar *mStatusBar;
64 QPoint mDragStartPoint;
65};
66//@endcond
67
68Summary::Summary( QWidget *parent )
69 : QWidget( parent ), d( new Private )
70{
71 setFont( KGlobalSettings::generalFont() );
72 setAcceptDrops( true );
73}
74
75Summary::~Summary()
76{
77 delete d;
78}
79
80int Summary::summaryHeight() const
81{
82 return 1;
83}
84
85QWidget *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
113QStringList Summary::configModules() const
114{
115 return QStringList();
116}
117
118void Summary::configChanged()
119{
120}
121
122void Summary::updateSummary( bool force )
123{
124 Q_UNUSED( force );
125}
126
127void Summary::mousePressEvent( QMouseEvent *event )
128{
129 d->mDragStartPoint = event->pos();
130
131 QWidget::mousePressEvent( event );
132}
133
134void 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
161void Summary::dragEnterEvent( QDragEnterEvent *event )
162{
163 if ( event->mimeData()->hasFormat( QLatin1String("application/x-kontact-summary") ) ) {
164 event->acceptProposedAction();
165 }
166}
167
168void 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::summaryWidgetDropped
void summaryWidgetDropped(QWidget *target, QWidget *widget, int alignment)
KontactInterface::Summary::configModules
virtual QStringList configModules() const
Returns a list of names identifying configuration modules for this summary widget.
Definition: summary.cpp:113
KontactInterface::Summary::summaryHeight
virtual int summaryHeight() const
Returns the logical height of summary widget.
Definition: summary.cpp:80
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
KontactInterface::Summary::Summary
Summary(QWidget *parent)
Creates a new summary widget.
Definition: summary.cpp:68
KontactInterface::Summary::updateSummary
virtual void updateSummary(bool force=false)
This method is called if the displayed information should be updated.
Definition: summary.cpp:122
KontactInterface::Summary::~Summary
virtual ~Summary()
Destroys the summary widget.
Definition: summary.cpp:75
KontactInterface::Summary::configChanged
virtual void configChanged()
This method is called whenever the configuration has been changed.
Definition: summary.cpp:118
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 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.14.10 API Reference

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