kontact

summary.cpp

00001 /*
00002    This file is part of KDE Kontact.
00003 
00004    Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
00005    Copyright (c) 2003 Daniel Molkentin <molkentin@kde.org>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020    Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include "summary.h"
00024 
00025 #include <qimage.h>
00026 #include <qdragobject.h>
00027 #include <qhbox.h>
00028 #include <qfont.h>
00029 #include <qlabel.h>
00030 #include <qpainter.h>
00031 
00032 #include <kiconloader.h>
00033 #include <kdialog.h>
00034 
00035 using namespace Kontact;
00036 
00037 Summary::Summary( QWidget *parent, const char *name )
00038   : QWidget( parent, name )
00039 {
00040   setAcceptDrops( true );
00041 }
00042 
00043 Summary::~Summary()
00044 {
00045 }
00046 
00047 QWidget* Summary::createHeader(QWidget *parent, const QPixmap& icon, const QString& heading)
00048 {
00049   QHBox* hbox = new QHBox( parent );
00050   hbox->setMargin( 2 );
00051 
00052   QFont boldFont;
00053   boldFont.setBold( true );
00054   boldFont.setPointSize( boldFont.pointSize() + 2 );
00055 
00056   QLabel *label = new QLabel( hbox );
00057   label->setPixmap( icon );
00058   label->setFixedSize( label->sizeHint() );
00059   label->setPaletteBackgroundColor( colorGroup().mid() );
00060   label->setAcceptDrops( true );
00061 
00062   label = new QLabel( heading, hbox );
00063   label->setAlignment( AlignLeft|AlignVCenter );
00064   label->setIndent( KDialog::spacingHint() );
00065   label->setFont( boldFont );
00066   label->setPaletteForegroundColor( colorGroup().light() );
00067   label->setPaletteBackgroundColor( colorGroup().mid() );
00068 
00069   hbox->setPaletteBackgroundColor( colorGroup().mid() );
00070 
00071   hbox->setMaximumHeight( hbox->minimumSizeHint().height() );
00072 
00073   return hbox;
00074 }
00075 
00076 void Summary::mousePressEvent( QMouseEvent *event )
00077 {
00078   mDragStartPoint = event->pos();
00079 
00080   QWidget::mousePressEvent( event );
00081 }
00082 
00083 void Summary::mouseMoveEvent( QMouseEvent *event )
00084 {
00085   if ( (event->state() & LeftButton) &&
00086        (event->pos() - mDragStartPoint).manhattanLength() > 4 ) {
00087 
00088     QDragObject *drag = new QTextDrag( "", this, "SummaryWidgetDrag" );
00089 
00090     QPixmap pm = QPixmap::grabWidget( this );
00091     if ( pm.width() > 300 )
00092       pm = pm.convertToImage().smoothScale( 300, 300, QImage::ScaleMin );
00093 
00094     QPainter painter;
00095     painter.begin( &pm );
00096     painter.setPen( Qt::gray );
00097     painter.drawRect( 0, 0, pm.width(), pm.height() );
00098     painter.end();
00099     drag->setPixmap( pm );
00100     drag->dragMove();
00101   } else
00102     QWidget::mouseMoveEvent( event );
00103 }
00104 
00105 void Summary::dragEnterEvent( QDragEnterEvent *event )
00106 {
00107   event->accept( QTextDrag::canDecode( event ) );
00108 }
00109 
00110 void Summary::dropEvent( QDropEvent *event )
00111 {
00112   int alignment = (event->pos().y() < (height() / 2) ? Qt::AlignTop : Qt::AlignBottom);
00113   emit summaryWidgetDropped( this, event->source(), alignment );
00114 }
00115 
00116 #include "summary.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys