24#include "KWMailMergeLabelAction.h"
25#include "KWMailMergeLabelAction.moc"
26#include <KoMainWindow.h>
28#include <tdepopupmenu.h>
30class MailMergeDraggableLabel :
public TQToolButton
33 MailMergeDraggableLabel( KoMainWindow * mw,
const TQString & text, TQWidget * parent = 0,
const char * name = 0 )
34 : TQToolButton( parent, name ), m_mw(mw)
41 void mousePressEvent( TQMouseEvent * ev )
44 startDragPos = ev->pos();
46 void mouseMoveEvent( TQMouseEvent * ev )
48 if ((startDragPos - ev->pos()).manhattanLength() > TQApplication::startDragDistance())
53 KWTextDrag *drag=
new KWTextDrag(m_mw);
55 drag->setKWord(
" <!DOCTYPE PARAGRAPHS> <PARAGRAPHS> <PARAGRAPH> <TEXT>fsfsd</TEXT> </PARAGRAPH> </PARAGRAPHS>");
62 void mouseReleaseEvent( TQMouseEvent * )
66 TQSize sizeHint()
const
68 int w = fontMetrics().width( text() );
69 int h = fontMetrics().height();
70 return TQSize( w, h );
72 void drawButton( TQPainter * p )
75 style().drawComplexControl( TQStyle::CC_ToolButton, p,
this, rect(), colorGroup(),
76 TQStyle::Style_Enabled, TQStyle::SC_ToolButton );
78 style().drawControl( TQStyle::CE_ToolButtonLabel, p,
this, rect(), colorGroup(),
79 TQStyle::Style_Enabled );
81 void enterEvent( TQEvent* ) {};
82 void leaveEvent( TQEvent* ) {};
84 void dragEnterEvent( TQDragEnterEvent *ev ) {
85 if ( KURLDrag::canDecode( ev ) )
88 void dropEvent( TQDropEvent* ev ) {
90 if ( KURLDrag::decode( ev, lst ) ) {
91 m_mw->openURL( 0L, lst.first() );
105KWMailMergeLabelAction::KWMailMergeLabelAction(
const TQString &text,
int accel,
106 TQObject* receiver,
const char* slot, TQObject *parent,
const char *name )
107 : TDEAction( text, accel, receiver, slot, parent, name ), m_label( 0L )
111int KWMailMergeLabelAction::plug( TQWidget *widget,
int index )
115 if ( widget->inherits(
"TDEToolBar" ) )
117 TDEToolBar *tb = (TDEToolBar *)widget;
119 int id = TDEAction::getToolButtonID();
121 m_label =
new MailMergeDraggableLabel(
static_cast<KoMainWindow*
>(tb->mainWindow()), text(), widget );
122 tb->insertWidget(
id, m_label->width(), m_label, index );
124 addContainer( tb,
id );
126 connect( tb, TQ_SIGNAL( destroyed() ),
this, TQ_SLOT( slotDestroyed() ) );
128 return containerCount() - 1;
134void KWMailMergeLabelAction::unplug( TQWidget *widget )
136 if ( widget->inherits(
"TDEToolBar" ) )
138 TDEToolBar *bar = (TDEToolBar *)widget;
140 int idx = findContainer( bar );
144 bar->removeItem( itemId( idx ) );
145 removeContainer( idx );