31 #include <QMouseEvent>
32 #include <QDragEnterEvent>
36 #include <KGlobalSettings>
38 #include <KIconLoader>
41 using namespace KontactInterface;
44 namespace KontactInterface {
45 class SummaryMimeData :
public QMimeData
48 virtual bool hasFormat(
const QString &format )
const
50 if ( format ==
"application/x-kontact-summary" ) {
60 class Summary::Private
63 KStatusBar *mStatusBar;
64 QPoint mDragStartPoint;
69 : QWidget( parent ), d( new Private )
71 setFont( KGlobalSettings::generalFont() );
72 setAcceptDrops(
true );
87 setStyleSheet(
"KHBox {"
91 "background: palette(window);"
92 "color: palette(windowtext);"
94 "KHBox > QLabel { font: bold larger; } " );
96 KHBox *hbox =
new KHBox( parent );
98 QLabel *label =
new QLabel( hbox );
99 label->setPixmap( KIconLoader::global()->loadIcon( iconname, KIconLoader::Toolbar ) );
101 label->setFixedSize( label->sizeHint() );
102 label->setAcceptDrops(
true );
104 label =
new QLabel( heading, hbox );
105 label->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
106 label->setIndent( KDialog::spacingHint() );
108 hbox->setMaximumHeight( hbox->minimumSizeHint().height() );
115 return QStringList();
127 void Summary::mousePressEvent( QMouseEvent *event )
129 d->mDragStartPoint =
event->pos();
131 QWidget::mousePressEvent( event );
134 void Summary::mouseMoveEvent( QMouseEvent *event )
136 if ( ( event->buttons() & Qt::LeftButton ) &&
137 ( event->pos() - d->mDragStartPoint ).manhattanLength() > 4 ) {
139 QDrag *drag =
new QDrag(
this );
140 drag->setMimeData(
new SummaryMimeData() );
141 drag->setObjectName(
"SummaryWidgetDrag" );
143 QPixmap pm = QPixmap::grabWidget(
this );
144 if ( pm.width() > 300 ) {
145 pm = QPixmap::fromImage(
146 pm.toImage().scaled( 300, 300, Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
150 painter.begin( &pm );
151 painter.setPen( QPalette::AlternateBase );
152 painter.drawRect( 0, 0, pm.width(), pm.height() );
154 drag->setPixmap( pm );
155 drag->start( Qt::MoveAction );
157 QWidget::mouseMoveEvent( event );
161 void Summary::dragEnterEvent( QDragEnterEvent *event )
163 if ( event->mimeData()->hasFormat(
"application/x-kontact-summary" ) ) {
164 event->acceptProposedAction();
168 void Summary::dropEvent( QDropEvent *event )
170 int alignment = (
event->pos().y() < ( height() / 2 ) ? Qt::AlignTop : Qt::AlignBottom );
QWidget * createHeader(QWidget *parent, const QString &icon, const QString &heading)
Creates a heading for a typical summary view with an icon and a heading.
virtual int summaryHeight() const
Returns the logical height of summary widget.
virtual void updateSummary(bool force=false)
This method is called if the displayed information should be updated.
virtual QStringList configModules() const
Returns a list of names identifying configuration modules for this summary widget.
virtual void configChanged()
This method is called whenever the configuration has been changed.
virtual ~Summary()
Destroys the summary widget.
void summaryWidgetDropped(QWidget *target, QWidget *widget, int alignment)
Summary(QWidget *parent)
Creates a new summary widget.