21#include "kivio_view.h"
22#include "kivio_page.h"
23#include "kivio_canvas.h"
24#include "kivio_factory.h"
27#include <kiconloader.h>
29#include <tdepopupmenu.h>
30#include <tdetoolbar.h>
31#include <KoMainWindow.h>
33#include <KoZoomHandler.h>
35#include <kstdaction.h>
36#include <KoZoomAction.h>
38#include <tqapplication.h>
41ZoomTool::ZoomTool(KivioView* parent) : Kivio::
MouseTool(parent,
"Zoom Mouse Tool")
43 m_zoomAction =
new TDERadioAction(i18n(
"&Zoom"),
"viewmag", CTRL + ALT + Key_Z, actionCollection(),
"zoom");
44 m_zoomAction->setWhatsThis(i18n(
"By pressing this button you can zoom in on a specific area."));
45 m_panAction =
new TDERadioAction(i18n(
"&Pan Document"),
"kivio_zoom_hand", CTRL + ALT + Key_H, actionCollection(),
"pan");
46 m_panAction->setWhatsThis(i18n(
"You can drag the document by using the mouse."));
47 m_zoomAction->setExclusiveGroup(
"zoomAction");
48 m_panAction->setExclusiveGroup(
"zoomAction");
49 connect(m_zoomAction,TQ_SIGNAL(activated()),TQ_SLOT(zoomActivated()));
50 connect(m_panAction,TQ_SIGNAL(activated()),TQ_SLOT(handActivated()));
51 connect(m_zoomAction, TQ_SIGNAL(toggled(
bool)),
this, TQ_SLOT(setActivated(
bool)));
52 connect(m_panAction, TQ_SIGNAL(toggled(
bool)),
this, TQ_SLOT(setActivated(
bool)));
54 KoZoomAction* viewZoom =
new KoZoomAction(i18n(
"Zoom &Level"),
"viewmag", 0, actionCollection(),
"viewZoom" );
55 viewZoom->setWhatsThis(i18n(
"This allows you to zoom in or out of a document. You can either choose one of the predefined zoomfactors or enter a new zoomfactor (in percent)."));
56 connect(viewZoom, TQ_SIGNAL(zoomChanged(
const TQString&)), parent, TQ_SLOT(viewZoom(
const TQString&)));
57 connect(parent, TQ_SIGNAL(zoomChanged(
int)), viewZoom, TQ_SLOT(setZoom(
int)));
59 m_pPlus = KStdAction::zoomIn(
this, TQ_SLOT(zoomPlus()), actionCollection(),
"zoomPlus");
60 m_pPlus->setWhatsThis(i18n(
"You can zoom in on the document by pressing this button."));
62 m_pMinus = KStdAction::zoomOut(
this, TQ_SLOT(zoomMinus()), actionCollection(),
"zoomMinus");
63 m_pMinus->setWhatsThis(i18n(
"By pressing this button you can zoom out of the document."));
65 m_pZoomWidth =
new TDEAction( i18n(
"Zoom Width"),
"kivio_zoom_width", SHIFT+Key_F4, actionCollection(),
"zoomWidth" );
66 m_pZoomWidth->setWhatsThis(i18n(
"You can zoom the document that it fits into the window width."));
67 connect(m_pZoomWidth,TQ_SIGNAL(activated()),TQ_SLOT(zoomWidth()));
69 m_pZoomHeight =
new TDEAction( i18n(
"Zoom Height"),
"kivio_zoom_height", SHIFT+Key_F5, actionCollection(),
"zoomHeight" );
70 m_pZoomHeight->setWhatsThis(i18n(
"You can zoom the document that it fits into the window height."));
71 connect(m_pZoomHeight,TQ_SIGNAL(activated()),TQ_SLOT(zoomHeight()));
73 m_pZoomPage =
new TDEAction( i18n(
"Zoom Page"),
"kivio_zoom_page", SHIFT+Key_F6, actionCollection(),
"zoomPage" );
74 m_pZoomPage->setWhatsThis(i18n(
"The Zoom Page button shows the entire page."));
75 connect(m_pZoomPage,TQ_SIGNAL(activated()),TQ_SLOT(zoomPage()));
77 m_pZoomSelected =
new TDEAction( i18n(
"Zoom Selected"),
"kivio_zoom_selected", CTRL+Key_Y, actionCollection(),
"zoomSelected" );
78 m_pZoomSelected->setWhatsThis(i18n(
"By pressing this button you zoom in on the document, so that all <b>selected</b> objects are visible."));
79 connect(m_pZoomSelected,TQ_SIGNAL(activated()),TQ_SLOT(zoomSelected()));
81 m_pZoomAllObjects =
new TDEAction( i18n(
"Zoom All Objects"),
"kivio_zoom_allobject", 0, actionCollection(),
"zoomAllObjects" );
82 m_pZoomAllObjects->setWhatsThis(i18n(
"You are able to zoom in on the document, so that all objects are visible by pressing this button."));
83 connect(m_pZoomAllObjects,TQ_SIGNAL(activated()),TQ_SLOT(zoomAllobjects()));
87 pix = BarIcon(
"kivio_zoom_plus",KivioFactory::global());
88 m_pPlusCursor =
new TQCursor(pix,pix.width()/2,pix.height()/2);
90 pix = BarIcon(
"kivio_zoom_minus",KivioFactory::global());
91 m_pMinusCursor =
new TQCursor(pix,pix.width()/2,pix.height()/2);
93 pix = BarIcon(
"kivio_zoom_hand",KivioFactory::global());
94 m_handCursor =
new TQCursor(pix,pix.width()/2,pix.height()/2);
101 delete m_pPlusCursor;
102 delete m_pMinusCursor;
106bool ZoomTool::processEvent(TQEvent* e)
108 KivioCanvas* canvas = view()->canvasWidget();
112 case TQEvent::KeyPress:
113 if (!m_bLockKeyboard && (
static_cast<TQKeyEvent*
>(e)->key() == Key_Shift)) {
114 m_pCurrent = m_pMinus;
115 canvas->setCursor(*m_pMinusCursor);
119 case TQEvent::KeyRelease:
120 if (!m_bLockKeyboard && (
static_cast<TQKeyEvent*
>(e)->key() == Key_Shift)) {
121 m_pCurrent = m_pPlus;
122 canvas->setCursor(*m_pPlusCursor);
126 case TQEvent::MouseButtonPress:
128 TQMouseEvent* me =
static_cast<TQMouseEvent*
>(e);
130 if(me->button() == TQt::LeftButton) {
131 if(m_pCurrent == m_pMinus) {
132 m_pCurrent->activate();
134 m_bLockKeyboard =
true;
135 m_bDrawRubber =
true;
136 canvas->startRectDraw(me->pos(), KivioCanvas::Rubber);
139 showPopupMenu(me->globalPos());
145 case TQEvent::MouseButtonRelease:
146 if(m_pCurrent == m_pPlus && m_bDrawRubber) {
147 canvas->endRectDraw();
148 m_bDrawRubber =
false;
149 m_bLockKeyboard =
false;
150 zoomRect(canvas->rect());
154 case TQEvent::MouseMove:
156 canvas->continueRectDraw(
static_cast<TQMouseEvent*
>(e)->pos(), KivioCanvas::Rubber);
165 case TQEvent::MouseButtonPress:
166 isHandMousePressed =
true;
167 mousePos =
static_cast<TQMouseEvent*
>(e)->pos();
170 case TQEvent::MouseButtonRelease:
171 isHandMousePressed =
false;
174 case TQEvent::MouseMove:
175 if (isHandMousePressed) {
176 canvas->setUpdatesEnabled(
false);
177 TQPoint newPos =
static_cast<TQMouseEvent*
>(e)->pos();
179 canvas->scrollDx(-mousePos.x());
180 canvas->scrollDy(-mousePos.y());
182 canvas->setUpdatesEnabled(
true);
194void ZoomTool::setActivated(
bool a)
197 m_pCurrent = m_pPlus;
198 emit activated(
this);
200 kdDebug(43000) <<
"ZoomTool DeActivate" << endl;
204 m_zoomAction->setChecked(
false);
205 m_panAction->setChecked(
false);
206 view()->setStatusBarInfo(
"");
208 if (!view()->canvasWidget()->isUpdatesEnabled()) {
209 view()->canvasWidget()->setUpdatesEnabled(
true);
214void ZoomTool::zoomActivated()
216 view()->canvasWidget()->setCursor(*m_pPlusCursor);
218 m_bDrawRubber =
false;
219 m_bLockKeyboard =
false;
220 m_zoomAction->setChecked(
true);
221 m_panAction->setChecked(
false);
222 view()->setStatusBarInfo(i18n(
"Hold Shift to zoom out."));
225void ZoomTool::handActivated()
227 view()->canvasWidget()->setCursor(*m_handCursor);
229 isHandMousePressed =
false;
230 m_zoomAction->setChecked(
false);
231 m_panAction->setChecked(
true);
234void ZoomTool::zoomPlus()
236 KivioCanvas* canvas = view()->canvasWidget();
237 canvas->zoomIn(TQPoint(canvas->width()/2, canvas->height()/2));
238 if(view()->zoomHandler()->zoom() >= 2000)
240 m_pPlus->setEnabled(
false);
241 m_pMinus->setEnabled(
true);
245 m_pPlus->setEnabled(
true);
246 m_pMinus->setEnabled(
true);
250void ZoomTool::zoomMinus()
252 KivioCanvas* canvas = view()->canvasWidget();
253 canvas->zoomOut(TQPoint(canvas->width()/2, canvas->height()/2));
254 if(view()->zoomHandler()->zoom() <= 25)
256 m_pMinus->setEnabled(
false);
257 m_pPlus->setEnabled(
true);
261 m_pMinus->setEnabled(
true);
262 m_pPlus->setEnabled(
true);
266void ZoomTool::zoomWidth()
268 KivioCanvas* canvas = view()->canvasWidget();
270 zoom.setZoomAndResolution(100, KoGlobal::dpiX(),
272 int cw = TQMAX(10,canvas->width()-20);
273 KoPageLayout pl = canvas->activePage()->paperLayout();
274 float w = zoom.zoomItX(pl.ptWidth);
277 canvas->setUpdatesEnabled(
false);
278 view()->viewZoom(tqRound(z * 100));
279 canvas->setUpdatesEnabled(
true);
282void ZoomTool::zoomHeight()
284 KivioCanvas* canvas = view()->canvasWidget();
286 zoom.setZoomAndResolution(100, KoGlobal::dpiX(),
288 int ch = TQMAX(10,canvas->height()-20);
289 KoPageLayout pl = canvas->activePage()->paperLayout();
290 float h = zoom.zoomItY(pl.ptHeight);
293 canvas->setUpdatesEnabled(
false);
294 view()->viewZoom(tqRound(zh * 100));
295 canvas->setUpdatesEnabled(
true);
298void ZoomTool::zoomPage()
300 KivioCanvas* canvas = view()->canvasWidget();
302 zoom.setZoomAndResolution(100, KoGlobal::dpiX(),
304 int cw = TQMAX(10,canvas->width()-20);
305 int ch = TQMAX(10,canvas->height()-20);
307 KoPageLayout pl = canvas->activePage()->paperLayout();
308 float w = zoom.zoomItX(pl.ptWidth);
309 float h = zoom.zoomItY(pl.ptHeight);
311 float z = TQMIN(cw/w,ch/h);
313 canvas->setUpdatesEnabled(
false);
314 view()->viewZoom(tqRound(z * 100));
315 canvas->setUpdatesEnabled(
true);
318void ZoomTool::showPopupMenu(
const TQPoint& p )
321 m_pMenu =
static_cast<TDEPopupMenu*
>(factory()->container(
"ZoomPopup",
this));
327 kdDebug(43000) <<
"What no popup! *ARGH*!" << endl;
331void ZoomTool::zoomSelected()
333 KivioCanvas* canvas = view()->canvasWidget();
334 KoRect r = canvas->activePage()->getRectForAllSelectedStencils();
336 if (!r.isNull() && r.isValid()) {
337 canvas->setVisibleArea(r);
341void ZoomTool::zoomAllobjects()
343 KivioCanvas* canvas = view()->canvasWidget();
344 KoRect r = canvas->activePage()->getRectForAllStencils();
346 if (!r.isNull() && r.isValid()) {
347 canvas->setVisibleArea(r);
351void ZoomTool::zoomRect(TQRect r)
353 KivioCanvas* canvas = view()->canvasWidget();
356 canvas->zoomIn(r.topLeft());
360 KoPoint p0 = canvas->mapFromScreen(r.topLeft());
361 canvas->setVisibleArea(KoRect(p0.x(), p0.y(), view()->zoomHandler()
362 ->unzoomItX(r.width()), view()->zoomHandler()->unzoomItY(r.height())));
364#include "tool_zoom.moc"