00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "KWMailMergeLabelAction.h"
00025 #include "KWMailMergeLabelAction.moc"
00026 #include <KoMainWindow.h>
00027 #include <kstyle.h>
00028 #include <kpopupmenu.h>
00029
00030 class MailMergeDraggableLabel : public QToolButton
00031 {
00032 public:
00033 MailMergeDraggableLabel( KoMainWindow * mw, const QString & text, QWidget * parent = 0, const char * name = 0 )
00034 : QToolButton( parent, name ), m_mw(mw)
00035 {
00036 setText(text);
00037 setAcceptDrops(true);
00038 validDrag = false;
00039 }
00040 protected:
00041 void mousePressEvent( QMouseEvent * ev )
00042 {
00043 validDrag = true;
00044 startDragPos = ev->pos();
00045 }
00046 void mouseMoveEvent( QMouseEvent * ev )
00047 {
00048 if ((startDragPos - ev->pos()).manhattanLength() > QApplication::startDragDistance())
00049 {
00050 validDrag = false;
00051
00052 #if 0 // what was the goal here?
00053 KWTextDrag *drag=new KWTextDrag(m_mw);
00054
00055 drag->setKWord(" <!DOCTYPE PARAGRAPHS> <PARAGRAPHS> <PARAGRAPH> <TEXT>fsfsd</TEXT> </PARAGRAPH> </PARAGRAPHS>");
00056
00057
00058 drag->dragCopy();
00059 #endif
00060 }
00061 }
00062 void mouseReleaseEvent( QMouseEvent * )
00063 {
00064 validDrag = false;
00065 }
00066 QSize sizeHint() const
00067 {
00068 int w = fontMetrics().width( text() );
00069 int h = fontMetrics().height();
00070 return QSize( w, h );
00071 }
00072 void drawButton( QPainter * p )
00073 {
00074
00075 style().drawComplexControl( QStyle::CC_ToolButton, p, this, rect(), colorGroup(),
00076 QStyle::Style_Enabled, QStyle::SC_ToolButton );
00077
00078 style().drawControl( QStyle::CE_ToolButtonLabel, p, this, rect(), colorGroup(),
00079 QStyle::Style_Enabled );
00080 }
00081 void enterEvent( QEvent* ) {};
00082 void leaveEvent( QEvent* ) {};
00083 #if 0
00084 void dragEnterEvent( QDragEnterEvent *ev ) {
00085 if ( KURLDrag::canDecode( ev ) )
00086 ev->acceptAction();
00087 }
00088 void dropEvent( QDropEvent* ev ) {
00089 KURL::List lst;
00090 if ( KURLDrag::decode( ev, lst ) ) {
00091 m_mw->openURL( 0L, lst.first() );
00092 }
00093 }
00094 #endif
00095 private:
00096 QPoint startDragPos;
00097 bool validDrag;
00098 KoMainWindow * m_mw;
00099 };
00100
00101
00102
00103
00104
00105 KWMailMergeLabelAction::KWMailMergeLabelAction( const QString &text, int accel,
00106 QObject* receiver, const char* slot, QObject *parent, const char *name )
00107 : KAction( text, accel, receiver, slot, parent, name ), m_label( 0L )
00108 {
00109 }
00110
00111 int KWMailMergeLabelAction::plug( QWidget *widget, int index )
00112 {
00113
00114
00115 if ( widget->inherits( "KToolBar" ) )
00116 {
00117 KToolBar *tb = (KToolBar *)widget;
00118
00119 int id = KAction::getToolButtonID();
00120
00121 m_label = new MailMergeDraggableLabel( static_cast<KoMainWindow*>(tb->mainWindow()), text(), widget );
00122 tb->insertWidget( id, m_label->width(), m_label, index );
00123
00124 addContainer( tb, id );
00125
00126 connect( tb, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
00127
00128 return containerCount() - 1;
00129 }
00130
00131 return -1;
00132 }
00133
00134 void KWMailMergeLabelAction::unplug( QWidget *widget )
00135 {
00136 if ( widget->inherits( "KToolBar" ) )
00137 {
00138 KToolBar *bar = (KToolBar *)widget;
00139
00140 int idx = findContainer( bar );
00141
00142 if ( idx != -1 )
00143 {
00144 bar->removeItem( itemId( idx ) );
00145 removeContainer( idx );
00146 }
00147
00148 m_label = 0;
00149 return;
00150 }
00151 }
00152