kontact
summary.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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"
|