summary.cpp
1/*
2 This file is part of KDE Kontact.
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 <tqimage.h>
26#include <tqdragobject.h>
27#include <tqhbox.h>
28#include <tqfont.h>
29#include <tqlabel.h>
30#include <tqpainter.h>
31
32#include <kiconloader.h>
33#include <kdialog.h>
34
35using namespace Kontact;
36
37Summary::Summary( TQWidget *parent, const char *name )
38 : TQWidget( parent, name )
39{
40 setAcceptDrops( true );
41}
42
43Summary::~Summary()
44{
45}
46
47TQWidget* Summary::createHeader(TQWidget *parent, const TQPixmap& icon, const TQString& heading)
48{
49 TQHBox* hbox = new TQHBox( parent );
50 hbox->setMargin( 2 );
51
52 TQFont boldFont;
53 boldFont.setBold( true );
54 boldFont.setPointSize( boldFont.pointSize() + 2 );
55
56 TQLabel *label = new TQLabel( hbox );
57 label->setPixmap( icon );
58 label->setFixedSize( label->sizeHint() );
59 label->setPaletteBackgroundColor( colorGroup().mid() );
60 label->setAcceptDrops( true );
61
62 label = new TQLabel( heading, hbox );
63 label->setAlignment( AlignLeft|AlignVCenter );
64 label->setIndent( KDialog::spacingHint() );
65 label->setFont( boldFont );
66 label->setPaletteForegroundColor( colorGroup().light() );
67 label->setPaletteBackgroundColor( colorGroup().mid() );
68
69 hbox->setPaletteBackgroundColor( colorGroup().mid() );
70
71 hbox->setMaximumHeight( hbox->minimumSizeHint().height() );
72
73 return hbox;
74}
75
76void Summary::mousePressEvent( TQMouseEvent *event )
77{
78 mDragStartPoint = event->pos();
79
80 TQWidget::mousePressEvent( event );
81}
82
83void Summary::mouseMoveEvent( TQMouseEvent *event )
84{
85 if ( (event->state() & TQt::LeftButton) &&
86 (event->pos() - mDragStartPoint).manhattanLength() > 4 ) {
87
88 TQDragObject *drag = new TQTextDrag( "", this, "SummaryWidgetDrag" );
89
90 TQPixmap pm = TQPixmap::grabWidget( this );
91 if ( pm.width() > 300 )
92 pm = pm.convertToImage().smoothScale( 300, 300, TQImage::ScaleMin );
93
94 TQPainter painter;
95 painter.begin( &pm );
96 painter.setPen( TQt::gray );
97 painter.drawRect( 0, 0, pm.width(), pm.height() );
98 painter.end();
99 drag->setPixmap( pm );
100 drag->dragMove();
101 } else
102 TQWidget::mouseMoveEvent( event );
103}
104
105void Summary::dragEnterEvent( TQDragEnterEvent *event )
106{
107 event->accept( TQTextDrag::canDecode( event ) );
108}
109
110void Summary::dropEvent( TQDropEvent *event )
111{
112 int alignment = (event->pos().y() < (height() / 2) ? TQt::AlignTop : TQt::AlignBottom);
113 emit summaryWidgetDropped( this, event->source(), alignment );
114}
115
116#include "summary.moc"
TQWidget * createHeader(TQWidget *parent, const TQPixmap &icon, const TQString &heading)
Creates a heading for a typical summary view with an icon and a heading.
Definition: summary.cpp:47