kword

KWMailMergeLabelAction.cpp
1/* This file is part of the KDE project
2
3 Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org>
4
5 Large parts are taken from tdebase/konqueror/konq_actions.*
6 Copyright (C) 2000 Simon Hausmann <hausmann@kde.org>
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
17
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#include "KWMailMergeLabelAction.h"
25#include "KWMailMergeLabelAction.moc"
26#include <KoMainWindow.h>
27#include <tdestyle.h>
28#include <tdepopupmenu.h>
29
30class MailMergeDraggableLabel : public TQToolButton
31{
32public:
33 MailMergeDraggableLabel( KoMainWindow * mw, const TQString & text, TQWidget * parent = 0, const char * name = 0 )
34 : TQToolButton( parent, name ), m_mw(mw)
35 {
36 setText(text);
37 setAcceptDrops(true);
38 validDrag = false;
39 }
40protected:
41 void mousePressEvent( TQMouseEvent * ev )
42 {
43 validDrag = true;
44 startDragPos = ev->pos();
45 }
46 void mouseMoveEvent( TQMouseEvent * ev )
47 {
48 if ((startDragPos - ev->pos()).manhattanLength() > TQApplication::startDragDistance())
49 {
50 validDrag = false;
51
52#if 0 // what was the goal here?
53 KWTextDrag *drag=new KWTextDrag(m_mw);
54// drag->setKWord(" <!DOCTYPE PARAGRAPHS> <PARAGRAPHS> <PARAGRAPH> <TEXT>fsfsd</TEXT> <LAYOUT> <NAME value=\"Standard\" /> <FLOW align=\"left\" /> <FORMAT id=\"1\" pos=\"0\" len=\"5\" > <WEIGHT value=\"50\" /> <FONT name=\"helvetica\" /> <SIZE value=\"12\" /> <ITALIC value=\"0\" /> <UNDERLINE value=\"0\" /> <STRIKEOUT value=\"0\" /> <VERTALIGN value=\"0\" /> </FORMAT> </LAYOUT> </PARAGRAPH></PARAGRAPHS>");
55 drag->setKWord(" <!DOCTYPE PARAGRAPHS> <PARAGRAPHS> <PARAGRAPH> <TEXT>fsfsd</TEXT> </PARAGRAPH> </PARAGRAPHS>");
56// drag->setKWord("<TEXT>fsfsd</TEXT>");
57
58 drag->dragCopy();
59#endif
60 }
61 }
62 void mouseReleaseEvent( TQMouseEvent * )
63 {
64 validDrag = false;
65 }
66 TQSize sizeHint() const
67 {
68 int w = fontMetrics().width( text() );
69 int h = fontMetrics().height();
70 return TQSize( w, h );
71 }
72 void drawButton( TQPainter * p )
73 {
74 // Draw the background
75 style().drawComplexControl( TQStyle::CC_ToolButton, p, this, rect(), colorGroup(),
76 TQStyle::Style_Enabled, TQStyle::SC_ToolButton );
77 // Draw the label
78 style().drawControl( TQStyle::CE_ToolButtonLabel, p, this, rect(), colorGroup(),
79 TQStyle::Style_Enabled );
80 }
81 void enterEvent( TQEvent* ) {};
82 void leaveEvent( TQEvent* ) {};
83#if 0
84 void dragEnterEvent( TQDragEnterEvent *ev ) {
85 if ( KURLDrag::canDecode( ev ) )
86 ev->acceptAction();
87 }
88 void dropEvent( TQDropEvent* ev ) {
89 KURL::List lst;
90 if ( KURLDrag::decode( ev, lst ) ) {
91 m_mw->openURL( 0L, lst.first() );
92 }
93 }
94#endif
95private:
96 TQPoint startDragPos;
97 bool validDrag;
98 KoMainWindow * m_mw;
99};
100
101
102
103
104
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 )
108{
109}
110
111int KWMailMergeLabelAction::plug( TQWidget *widget, int index )
112{
113 //do not call the previous implementation here
114
115 if ( widget->inherits( "TDEToolBar" ) )
116 {
117 TDEToolBar *tb = (TDEToolBar *)widget;
118
119 int id = TDEAction::getToolButtonID();
120
121 m_label = new MailMergeDraggableLabel( static_cast<KoMainWindow*>(tb->mainWindow()), text(), widget );
122 tb->insertWidget( id, m_label->width(), m_label, index );
123
124 addContainer( tb, id );
125
126 connect( tb, TQ_SIGNAL( destroyed() ), this, TQ_SLOT( slotDestroyed() ) );
127
128 return containerCount() - 1;
129 }
130
131 return -1;
132}
133
134void KWMailMergeLabelAction::unplug( TQWidget *widget )
135{
136 if ( widget->inherits( "TDEToolBar" ) )
137 {
138 TDEToolBar *bar = (TDEToolBar *)widget;
139
140 int idx = findContainer( bar );
141
142 if ( idx != -1 )
143 {
144 bar->removeItem( itemId( idx ) );
145 removeContainer( idx );
146 }
147
148 m_label = 0;
149 return;
150 }
151}
152