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 <tqimage.h> 00026 #include <tqdragobject.h> 00027 #include <tqhbox.h> 00028 #include <tqfont.h> 00029 #include <tqlabel.h> 00030 #include <tqpainter.h> 00031 00032 #include <kiconloader.h> 00033 #include <kdialog.h> 00034 00035 using namespace Kontact; 00036 00037 Summary::Summary( TQWidget *parent, const char *name ) 00038 : TQWidget( parent, name ) 00039 { 00040 setAcceptDrops( true ); 00041 } 00042 00043 Summary::~Summary() 00044 { 00045 } 00046 00047 TQWidget* Summary::createHeader(TQWidget *parent, const TQPixmap& icon, const TQString& heading) 00048 { 00049 TQHBox* hbox = new TQHBox( parent ); 00050 hbox->setMargin( 2 ); 00051 00052 TQFont boldFont; 00053 boldFont.setBold( true ); 00054 boldFont.setPointSize( boldFont.pointSize() + 2 ); 00055 00056 TQLabel *label = new TQLabel( hbox ); 00057 label->setPixmap( icon ); 00058 label->setFixedSize( label->sizeHint() ); 00059 label->setPaletteBackgroundColor( colorGroup().mid() ); 00060 label->setAcceptDrops( true ); 00061 00062 label = new TQLabel( 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( TQMouseEvent *event ) 00077 { 00078 mDragStartPoint = event->pos(); 00079 00080 TQWidget::mousePressEvent( event ); 00081 } 00082 00083 void Summary::mouseMoveEvent( TQMouseEvent *event ) 00084 { 00085 if ( (event->state() & Qt::LeftButton) && 00086 (event->pos() - mDragStartPoint).manhattanLength() > 4 ) { 00087 00088 TQDragObject *drag = new TQTextDrag( "", this, "SummaryWidgetDrag" ); 00089 00090 TQPixmap pm = TQPixmap::grabWidget( this ); 00091 if ( pm.width() > 300 ) 00092 pm = pm.convertToImage().smoothScale( 300, 300, TQ_ScaleMin ); 00093 00094 TQPainter painter; 00095 painter.begin( &pm ); 00096 painter.setPen( TQt::gray ); 00097 painter.drawRect( 0, 0, pm.width(), pm.height() ); 00098 painter.end(); 00099 drag->setPixmap( pm ); 00100 drag->dragMove(); 00101 } else 00102 TQWidget::mouseMoveEvent( event ); 00103 } 00104 00105 void Summary::dragEnterEvent( TQDragEnterEvent *event ) 00106 { 00107 event->accept( TQTextDrag::canDecode( event ) ); 00108 } 00109 00110 void Summary::dropEvent( TQDropEvent *event ) 00111 { 00112 int alignment = (event->pos().y() < (height() / 2) ? TQt::AlignTop : TQt::AlignBottom); 00113 emit summaryWidgetDropped( this, event->source(), alignment ); 00114 } 00115 00116 #include "summary.moc"