Kontact Plugin Interface Library
summary.cpp
00001
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>
00026 #include <QFont>
00027 #include <QLabel>
00028 #include <QPainter>
00029 #include <QPixmap>
00030 #include <QMouseEvent>
00031 #include <QDragEnterEvent>
00032 #include <QDropEvent>
00033
00034 #include <KGlobalSettings>
00035 #include <KHBox>
00036 #include <KIconLoader>
00037 #include <KDialog>
00038
00039 using namespace KontactInterface;
00040
00041
00042 namespace KontactInterface {
00043 class SummaryMimeData : public QMimeData
00044 {
00045 public:
00046 virtual bool hasFormat( const QString &format ) const
00047 {
00048 if ( format == "application/x-kontact-summary" ) {
00049 return true;
00050 }
00051 return false;
00052 }
00053 };
00054 }
00055
00056
00057
00058 class Summary::Private
00059 {
00060 public:
00061 KStatusBar *mStatusBar;
00062 QPoint mDragStartPoint;
00063 };
00064
00065
00066 Summary::Summary( QWidget *parent )
00067 : QWidget( parent ), d( new Private )
00068 {
00069 setFont( KGlobalSettings::generalFont() );
00070 setAcceptDrops( true );
00071 }
00072
00073 Summary::~Summary()
00074 {
00075 delete d;
00076 }
00077
00078 int Summary::summaryHeight() const
00079 {
00080 return 1;
00081 }
00082
00083 QWidget *Summary::createHeader( QWidget *parent, const QString &iconname, const QString &heading )
00084 {
00085 setStyleSheet( "KHBox {"
00086 "border: 0px;"
00087 "font: bold large;"
00088 "padding: 2px;"
00089 "background: palette(window);"
00090 "color: palette(windowtext);"
00091 "}"
00092 "KHBox > QLabel { font: bold larger; } " );
00093
00094 KHBox *hbox = new KHBox( parent );
00095
00096 QLabel *label = new QLabel( hbox );
00097 label->setPixmap( KIconLoader::global()->loadIcon( iconname, KIconLoader::Toolbar ) );
00098
00099 label->setFixedSize( label->sizeHint() );
00100 label->setAcceptDrops( true );
00101
00102 label = new QLabel( heading, hbox );
00103 label->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
00104 label->setIndent( KDialog::spacingHint() );
00105
00106 hbox->setMaximumHeight( hbox->minimumSizeHint().height() );
00107
00108 return hbox;
00109 }
00110
00111 QStringList Summary::configModules() const
00112 {
00113 return QStringList();
00114 }
00115
00116 void Summary::configChanged()
00117 {
00118 }
00119
00120 void Summary::updateSummary( bool force )
00121 {
00122 Q_UNUSED( force );
00123 }
00124
00125 void Summary::mousePressEvent( QMouseEvent *event )
00126 {
00127 d->mDragStartPoint = event->pos();
00128
00129 QWidget::mousePressEvent( event );
00130 }
00131
00132 void Summary::mouseMoveEvent( QMouseEvent *event )
00133 {
00134 if ( ( event->buttons() & Qt::LeftButton ) &&
00135 ( event->pos() - d->mDragStartPoint ).manhattanLength() > 4 ) {
00136
00137 QDrag *drag = new QDrag( this );
00138 drag->setMimeData( new SummaryMimeData() );
00139 drag->setObjectName( "SummaryWidgetDrag" );
00140
00141 QPixmap pm = QPixmap::grabWidget( this );
00142 if ( pm.width() > 300 ) {
00143 pm = QPixmap::fromImage(
00144 pm.toImage().scaled( 300, 300, Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
00145 }
00146
00147 QPainter painter;
00148 painter.begin( &pm );
00149 painter.setPen( QPalette::AlternateBase );
00150 painter.drawRect( 0, 0, pm.width(), pm.height() );
00151 painter.end();
00152 drag->setPixmap( pm );
00153 drag->start( Qt::MoveAction );
00154 } else {
00155 QWidget::mouseMoveEvent( event );
00156 }
00157 }
00158
00159 void Summary::dragEnterEvent( QDragEnterEvent *event )
00160 {
00161 if ( event->mimeData()->hasFormat( "application/x-kontact-summary" ) ) {
00162 event->acceptProposedAction();
00163 }
00164 }
00165
00166 void Summary::dropEvent( QDropEvent *event )
00167 {
00168 int alignment = ( event->pos().y() < ( height() / 2 ) ? Qt::AlignTop : Qt::AlignBottom );
00169 emit summaryWidgetDropped( this, event->source(), alignment );
00170 }
00171
00172 #include "summary.moc"