karbon
vtool.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <qevent.h>
00021 #include <qlabel.h>
00022
00023 #include <kdebug.h>
00024 #include <kiconloader.h>
00025
00026 #include "karbon_view.h"
00027 #include "karbon_part.h"
00028 #include "vtoolcontroller.h"
00029 #include "KoContextCelp.h"
00030 #include "vtool.h"
00031 #include "vtool.moc"
00032
00033
00034 VTool::VTool( KarbonView *view, const char *name ) : QObject( 0, name ), m_view( view )
00035 {
00036 m_mouseButtonIsDown = false;
00037 m_isDragging = false;
00038 m_shiftPressed = false;
00039 m_ctrlPressed = false;
00040 m_altPressed = false;
00041 m_action = 0;
00042 }
00043
00044 VTool::~VTool()
00045 {
00046 if (toolController())
00047 toolController()->unregisterTool( this );
00048
00049 delete m_action;
00050
00051 }
00052
00053 void
00054 VTool::registerTool( VTool *tool )
00055 {
00056 toolController()->registerTool( tool );
00057 }
00058
00059 VToolController *
00060 VTool::toolController() const
00061 {
00062 return m_view->toolController();
00063 }
00064
00065 KarbonView *
00066 VTool::view() const
00067 {
00068 return m_view;
00069 }
00070
00071 bool
00072 VTool::mouseEvent( QMouseEvent* mouseEvent, const KoPoint &canvasCoordinate )
00073 {
00074 if( !view() || !view()->part() || !view()->part()->isReadWrite() )
00075 return false;
00076
00077 m_lastPoint.setX( canvasCoordinate.x() );
00078 m_lastPoint.setY( canvasCoordinate.y() );
00079
00080 setCursor();
00081
00082 m_altPressed = mouseEvent->state() & Qt::AltButton;
00083 m_shiftPressed = mouseEvent->state() & Qt::ShiftButton;
00084 m_ctrlPressed = mouseEvent->state() & Qt::ControlButton;
00085
00086
00087 if( mouseEvent->type() == QEvent::MouseButtonDblClick )
00088 {
00089 mouseButtonDblClick();
00090
00091 return true;
00092 }
00093
00094 if( mouseEvent->type() == QEvent::MouseButtonPress )
00095 {
00096 m_firstPoint.setX( canvasCoordinate.x() );
00097 m_firstPoint.setY( canvasCoordinate.y() );
00098
00099 if( mouseEvent->button() == QEvent::RightButton )
00100 rightMouseButtonPress();
00101 else
00102 mouseButtonPress();
00103
00104 m_mouseButtonIsDown = true;
00105
00106 return true;
00107 }
00108
00109 if( mouseEvent->type() == QEvent::MouseMove )
00110 {
00111
00112
00113 if( m_mouseButtonIsDown )
00114 {
00115 mouseDrag();
00116
00117 m_isDragging = true;
00118 }
00119 else
00120 mouseMove();
00121
00122 return true;
00123 }
00124
00125 if( mouseEvent->type() == QEvent::MouseButtonRelease )
00126 {
00127 if( m_isDragging )
00128 {
00129 mouseDragRelease();
00130
00131 m_isDragging = false;
00132 }
00133 else if( m_mouseButtonIsDown )
00134 if( mouseEvent->button() == QEvent::RightButton )
00135 rightMouseButtonRelease();
00136 else
00137 mouseButtonRelease();
00138
00139 m_mouseButtonIsDown = false;
00140
00141 return true;
00142 }
00143
00144 return false;
00145 }
00146
00147 bool
00148 VTool::keyEvent( QEvent* event )
00149 {
00150
00151 if( event->type() == QEvent::KeyPress )
00152 {
00153 QKeyEvent* keyEvent = static_cast<QKeyEvent*>( event );
00154
00155
00156 if(
00157 ( keyEvent->key() == Qt::Key_Enter ||
00158 keyEvent->key() == Qt::Key_Return )
00159 && !m_isDragging )
00160 {
00161 accept();
00162
00163 return true;
00164 }
00165
00166
00167 if( keyEvent->key() == Qt::Key_Backspace && !m_isDragging )
00168 {
00169 cancelStep();
00170
00171 return true;
00172 }
00173
00174
00175 if( keyEvent->key() == Qt::Key_Escape )
00176 {
00177 cancel();
00178
00179 m_isDragging = false;
00180 m_mouseButtonIsDown = false;
00181
00182 return true;
00183 }
00184
00185
00186 if( keyEvent->key() == Qt::Key_Shift )
00187 {
00188 m_shiftPressed = true;
00189 if( m_isDragging )
00190 {
00191 mouseDragShiftPressed();
00192
00193 return true;
00194 }
00195 }
00196
00197
00198 if( keyEvent->key() == Qt::Key_Control )
00199 {
00200 m_ctrlPressed = true;
00201 if( m_isDragging )
00202 {
00203 mouseDragCtrlPressed();
00204
00205 return true;
00206 }
00207 }
00208
00209 }
00210
00211
00212 if( event->type() == QEvent::KeyRelease )
00213 {
00214 QKeyEvent* keyEvent = static_cast<QKeyEvent*>( event );
00215
00216 Qt::Key key = (Qt::Key)keyEvent->key();
00217 if( key == Qt::Key_Shift )
00218 {
00219 m_shiftPressed = false;
00220 if( m_isDragging )
00221 {
00222 mouseDragShiftReleased();
00223
00224 return true;
00225 }
00226 }
00227
00228 if( key == Qt::Key_Control )
00229 {
00230 m_ctrlPressed = false;
00231 if( m_isDragging )
00232 {
00233 mouseDragCtrlReleased();
00234
00235 return true;
00236 }
00237 }
00238
00239 if( key == Qt::Key_Left || key == Qt::Key_Right || key == Qt::Key_Up || key == Qt::Key_Down )
00240 {
00241 arrowKeyReleased( key );
00242 return true;
00243 }
00244
00245 return keyReleased( key );
00246 }
00247
00248 return false;
00249 }
00250
00251 void
00252 VTool::activate()
00253 {
00254 kdDebug() << k_funcinfo << endl;
00255 refreshUnit();
00256 QPixmap Icon = BarIcon( icon() );
00257 view()->contextHelpAction()->updateHelp( uiname(), contextHelp(), &Icon );
00258 view()->statusMessage()->setText( statusText() );
00259 toolController()->setCurrentTool( this );
00260 #if 0
00261 if( toolController()->activeTool() )
00262 {
00263 toolController()->activeTool()->action()->setChecked( false );
00264 toolController()->activeTool()->deactivate();
00265 }
00266
00267 if( toolController()->activeTool() == this )
00268 showDialog();
00269 else
00270 {
00271 refreshUnit();
00272 QPixmap Icon = BarIcon( icon() );
00273 view()->contextHelpAction()->updateHelp( uiname(), contextHelp(), &Icon );
00274 view()->statusMessage()->setText( statusText() );
00275 toolController()->activeTool()->action()->setChecked( true );
00276 }
00277 #endif
00278 }
00279
|