kivio
kiviotargettool.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "kiviotargettool.h"
00020
00021 #include <qcursor.h>
00022
00023 #include <klocale.h>
00024
00025 #include "kivio_stencil.h"
00026 #include "kivio_view.h"
00027 #include "kivio_canvas.h"
00028 #include "kivio_page.h"
00029 #include "kivio_doc.h"
00030 #include "mousetoolaction.h"
00031 #include "kivio_pluginmanager.h"
00032 #include "kivio_command.h"
00033
00034 namespace Kivio {
00035 TargetTool::TargetTool(KivioView* parent) : MouseTool(parent, "Add Target Mouse Tool")
00036 {
00037 m_targetAction = new Kivio::MouseToolAction(i18n("Add Connector Target"),
00038 "add_target", 0, actionCollection(), "addTargetTool");
00039 connect(m_targetAction, SIGNAL(toggled(bool)), this, SLOT(setActivated(bool)));
00040 connect(m_targetAction, SIGNAL(doubleClicked()), this, SLOT(makePermanent()));
00041
00042 m_permanent = false;
00043 }
00044
00045 TargetTool::~TargetTool()
00046 {
00047 }
00048
00049 bool TargetTool::processEvent(QEvent* e)
00050 {
00051 if(e->type() == QEvent::MouseButtonPress) {
00052 mousePress(static_cast<QMouseEvent*>(e));
00053 return true;
00054 } else if(e->type() == QEvent::MouseMove) {
00055 mouseMove(static_cast<QMouseEvent*>(e));
00056 return true;
00057 }
00058
00059 return false;
00060 }
00061
00062 void TargetTool::setActivated(bool a)
00063 {
00064 if(a) {
00065 m_targetAction->setChecked(true);
00066 emit activated(this);
00067 } else if(m_targetAction->isChecked()) {
00068 m_targetAction->setChecked(false);
00069 m_permanent = false;
00070 }
00071 }
00072
00073 void TargetTool::applyToolAction(KivioStencil* stencil, const KoPoint& pos)
00074 {
00075 KivioAddConnectorTargetCommand* command = new KivioAddConnectorTargetCommand(i18n("Add Connector Target"), view()->activePage(), stencil, pos);
00076 command->execute();
00077 view()->doc()->addCommand(command);
00078 }
00079
00080 void TargetTool::mousePress(QMouseEvent* e)
00081 {
00082 KoPoint p = view()->canvasWidget()->mapFromScreen(e->pos());
00083 int colType;
00084 KivioStencil* stencil = view()->canvasWidget()->activePage()->checkForStencil(&p, &colType, 0, false);
00085
00086 if(stencil) {
00087 applyToolAction(stencil, p);
00088
00089 if(!m_permanent) {
00090 view()->pluginManager()->activateDefaultTool();
00091 }
00092 }
00093 }
00094
00095 void TargetTool::mouseMove(QMouseEvent* e)
00096 {
00097 KoPoint p = view()->canvasWidget()->mapFromScreen(e->pos());
00098 int colType;
00099
00100 if(view()->canvasWidget()->activePage()->checkForStencil(&p, &colType, 0, false)) {
00101 view()->canvasWidget()->setCursor(Qt::CrossCursor);
00102 } else {
00103 view()->canvasWidget()->setCursor(Qt::ForbiddenCursor);
00104 }
00105 }
00106
00107 void TargetTool::makePermanent()
00108 {
00109 m_permanent = true;
00110 }
00111 }
00112
00113 #include "kiviotargettool.moc"
|