26#include <tqtoolbutton.h>
31#include <tdeglobalsettings.h>
33#include <tdetoolbar.h>
37#include <KoDocument.h>
39#include "wdgbirdeye.h"
40#include "kobirdeyepanel.h"
41#include "kis_int_spinbox.h"
43KoCanvasAdapter::KoCanvasAdapter() {}
44KoCanvasAdapter::~KoCanvasAdapter() {}
46KoZoomAdapter::KoZoomAdapter() {}
47KoZoomAdapter::~KoZoomAdapter() {}
49KoThumbnailAdapter::KoThumbnailAdapter() {}
50KoThumbnailAdapter::~KoThumbnailAdapter() {}
53 KoThumbnailAdapter * thumbnailProvider,
54 KoCanvasAdapter * canvas,
58 : TQWidget(parent, name, f)
59 , m_zoomListener(zoomListener)
60 , m_thumbnailProvider(thumbnailProvider)
64 TQHBoxLayout * l =
new TQHBoxLayout(
this);
65 m_page =
new WdgBirdEye(
this);
66 m_page->zoom->setRange((
int) (TQMAX(1, 100 * zoomListener->
getMinZoom())), (
int) (100 * zoomListener->
getMaxZoom()));
67 m_page->zoom->setValue(100);
68 m_page->zoom->setSuffix(
"%");
70 m_page->toolbar->setIconSize(16);
71 m_page->view->installEventFilter(
this);
72 m_page->view->setBackgroundMode(TQt::NoBackground);
74 m_zoomIn =
new TDEAction( i18n(
"Zoom In"),
"birdeye_zoom_plus", 0,
this, TQ_SLOT(zoomPlus()),
this,
"zoomIn" );
75 m_zoomOut =
new TDEAction( i18n(
"Zoom Out"),
"birdeye_zoom_minus", 0,
this, TQ_SLOT(zoomMinus()),
this,
"zoomOut" );
79 connect(m_page->zoom, TQ_SIGNAL(valueChanged(
int)), TQ_SLOT(zoomValueChanged(
int)));
80 connect(m_page->bn100, TQ_SIGNAL(clicked()), TQ_SLOT(zoom100()));
81 connect(m_page->slZoom, TQ_SIGNAL(valueChanged(
int)), TQ_SLOT(sliderChanged(
int )));
84KoBirdEyePanel::~KoBirdEyePanel()
87 delete m_thumbnailProvider;
88 delete m_zoomListener;
91void KoBirdEyePanel::setZoom(
int zoom)
93 m_page->zoom->blockSignals(
true);
94 m_page->slZoom->blockSignals(
true);
96 m_page->zoom->setValue(zoom);
99 m_page->slZoom->setValue(0);
101 else if (zoom > 10 && zoom < 100) {
102 m_page->slZoom->setValue(zoom / 10);
104 else if (zoom >= 100 && zoom < 150) {
105 m_page->slZoom->setValue(10);
107 else if (zoom >= 150 && zoom < 250) {
108 m_page->slZoom->setValue(11);
110 else if (zoom >= 250 && zoom < 350) {
111 m_page->slZoom->setValue(12);
113 else if (zoom >= 350 && zoom < 450) {
114 m_page->slZoom->setValue(13);
116 else if (zoom >= 450 && zoom < 550) {
117 m_page->slZoom->setValue(14);
119 else if (zoom >= 550 && zoom < 650) {
120 m_page->slZoom->setValue(15);
122 else if (zoom >= 650 && zoom < 875) {
123 m_page->slZoom->setValue(16);
125 else if (zoom >= 875 && zoom < 1150) {
126 m_page->slZoom->setValue(17);
128 else if (zoom >= 1150 && zoom < 1450) {
129 m_page->slZoom->setValue(18);
131 else if (zoom >= 1450) {
132 m_page->slZoom->setValue(19);
136 m_page->zoom->blockSignals(
false);
137 m_page->slZoom->blockSignals(
false);
142void KoBirdEyePanel::zoomValueChanged(
int zoom)
145 center = m_canvas->visibleArea().center();
146 m_zoomListener->zoomTo(center.x(), center.y(), zoom / 100.0);
150void KoBirdEyePanel::zoom100()
152 zoomValueChanged( 100 );
155void KoBirdEyePanel::sliderChanged(
int v )
158 zoomValueChanged((v + 1) * 10);
163 zoomValueChanged(100);
166 zoomValueChanged(200);
169 zoomValueChanged(300);
171 zoomValueChanged(400);
174 zoomValueChanged(500);
177 zoomValueChanged(600);
180 zoomValueChanged(750);
183 zoomValueChanged(1000);
186 zoomValueChanged(1300);
189 zoomValueChanged(1600);
195void KoBirdEyePanel::cursorPosChanged(TQ_INT32 xpos, TQ_INT32 ypos)
197 m_page->txtX->setText(TQString(
"%L1").arg(xpos, 5));
198 m_page->txtY->setText(TQString(
"%L1").arg(ypos, 5));
203 delete m_thumbnailProvider;
204 m_thumbnailProvider = thumbnailProvider;
211 m_page->view->update();
212 setZoom(tqRound(m_canvas->zoomFactor() * 100));
217 TQRect updateRect = r;
219 if (m_thumbnailProvider->pixelSize() != m_documentSize) {
220 m_documentSize = m_thumbnailProvider->pixelSize();
221 fitThumbnailToView();
222 updateRect = TQRect(0, 0, m_documentSize.width(), m_documentSize.height());
225 updateRect &= TQRect(0, 0, m_documentSize.width(), m_documentSize.height());
227 if (!updateRect.isEmpty() && !m_documentSize.isEmpty()) {
231 if (!thumbnailRect.isEmpty()) {
233 TQImage thumbnailImage = m_thumbnailProvider->image(thumbnailRect, m_thumbnail.size());
235 if (!thumbnailImage.isNull()) {
237 Q_ASSERT(thumbnailImage.size() == thumbnailRect.size());
239 TQPainter painter(&m_thumbnail);
241 painter.fillRect(thumbnailRect, colorGroup().mid());
242 painter.drawImage(thumbnailRect.x(), thumbnailRect.y(), thumbnailImage);
248 m_page->view->update();
253 if (docRect.isEmpty() || m_documentSize.isEmpty() || m_thumbnail.isNull()) {
257 TQ_INT32 thumbnailLeft =
static_cast<TQ_INT32
>((docRect.left() * m_thumbnail.width()) / m_documentSize.width());
258 TQ_INT32 thumbnailRight =
static_cast<TQ_INT32
>(((docRect.right() + 1) * m_thumbnail.width()) / m_documentSize.width());
259 TQ_INT32 thumbnailTop =
static_cast<TQ_INT32
>((docRect.top() * m_thumbnail.height()) / m_documentSize.height());
260 TQ_INT32 thumbnailBottom =
static_cast<TQ_INT32
>(((docRect.bottom() + 1) * m_thumbnail.height()) / m_documentSize.height());
262 TQRect thumbnailRect(thumbnailLeft, thumbnailTop, thumbnailRight - thumbnailLeft + 1, thumbnailBottom - thumbnailTop + 1);
263 thumbnailRect &= m_thumbnail.rect();
265 return thumbnailRect;
270 if (thumbnailRect.isEmpty() || m_documentSize.isEmpty() || m_thumbnail.isNull()) {
274 double docLeft = (
static_cast<double>(thumbnailRect.left()) * m_documentSize.width()) / m_thumbnail.width();
275 double docRight = (
static_cast<double>(thumbnailRect.right() + 1) * m_documentSize.width()) / m_thumbnail.width();
276 double docTop = (
static_cast<double>(thumbnailRect.top()) * m_documentSize.height()) / m_thumbnail.height();
277 double docBottom = (
static_cast<double>(thumbnailRect.bottom() + 1) * m_documentSize.height()) / m_thumbnail.height();
279 KoRect docRect(docLeft, docTop, docRight - docLeft + 1, docBottom - docTop + 1);
280 docRect &= KoRect(0, 0, m_documentSize.width(), m_documentSize.height());
287 int thumbnailX = (m_viewBuffer.width() - m_thumbnail.width()) / 2;
288 int thumbnailY = (m_viewBuffer.height() - m_thumbnail.height()) / 2;
290 return TQPoint(viewPoint.x() - thumbnailX, viewPoint.y() - thumbnailY);
294void KoBirdEyePanel::zoomMinus()
298void KoBirdEyePanel::zoomPlus()
302void KoBirdEyePanel::updateVisibleArea()
308bool KoBirdEyePanel::eventFilter(TQObject* o, TQEvent* ev)
310 if (o == m_page->view && ev->type() == TQEvent::Resize) {
311 resizeViewEvent(
static_cast<TQResizeEvent*
>(ev)->size());
314 if (o == m_page->view && ev->type() == TQEvent::Paint) {
315 paintViewEvent(
static_cast<TQPaintEvent*
>(ev));
318 if (o == m_page->view && ev->type() == TQEvent::MouseMove) {
320 TQMouseEvent* me = (TQMouseEvent*)ev;
324 handleMouseMoveAction(thumbnailPos);
326 handleMouseMove(thumbnailPos);
332 if (o == m_page->view && ev->type() == TQEvent::MouseButtonPress) {
334 TQMouseEvent* me = (TQMouseEvent*)ev;
337 if (me->button() == TQt::LeftButton) {
338 handleMousePress(thumbnailPos);
344 if (o == m_page->view && ev->type() == TQEvent::MouseButtonRelease) {
346 TQMouseEvent* me = (TQMouseEvent*)ev;
348 if (me->button() == TQt::LeftButton) {
355 return m_page->eventFilter(o, ev);
358KoBirdEyePanel::enumDragHandle KoBirdEyePanel::dragHandleAt(TQPoint p)
360 TQRect left = TQRect(m_visibleAreaInThumbnail.left()-1, m_visibleAreaInThumbnail.top()-1, 3, m_visibleAreaInThumbnail.height()+2);
361 TQRect right = TQRect(m_visibleAreaInThumbnail.right()-1, m_visibleAreaInThumbnail.top()-1, 3, m_visibleAreaInThumbnail.height()+2);
362 TQRect top = TQRect(m_visibleAreaInThumbnail.left()-1, m_visibleAreaInThumbnail.top()-1, m_visibleAreaInThumbnail.width()+2, 3);
363 TQRect bottom = TQRect(m_visibleAreaInThumbnail.left()-1, m_visibleAreaInThumbnail.bottom()-1, m_visibleAreaInThumbnail.width()+2, 3);
365 if (left.contains(p)) {
366 return DragHandleLeft;
369 if (right.contains(p)) {
370 return DragHandleRight;
373 if (top.contains(p)) {
374 return DragHandleTop;
377 if (bottom.contains(p)) {
378 return DragHandleBottom;
381 if (m_visibleAreaInThumbnail.contains(p)) {
382 return DragHandleCentre;
385 return DragHandleNone;
388void KoBirdEyePanel::handleMouseMove(TQPoint p)
392 switch (dragHandleAt(p)) {
394 case DragHandleRight:
395 cursor = TQt::sizeHorCursor;
398 case DragHandleBottom:
399 cursor = TQt::sizeVerCursor;
401 case DragHandleCentre:
402 cursor = TQt::sizeAllCursor;
406 if (m_thumbnail.rect().contains(p)) {
407 cursor = TQt::PointingHandCursor;
409 cursor = TQt::arrowCursor;
414 m_page->view->setCursor(cursor);
417void KoBirdEyePanel::handleMouseMoveAction(TQPoint p)
421 TQ_INT32 dx = p.x() - m_lastDragPos.x();
422 TQ_INT32 dy = p.y() - m_lastDragPos.y();
426 TQRect thumbnailRect = m_visibleAreaInThumbnail;
428 switch (m_dragHandle) {
429 case DragHandleLeft: {
430 thumbnailRect.setLeft(thumbnailRect.left()+dx);
433 case DragHandleRight: {
434 thumbnailRect.setRight(thumbnailRect.right()+dx);
437 case DragHandleTop: {
438 thumbnailRect.setTop(thumbnailRect.top()+dy);
441 case DragHandleBottom: {
442 thumbnailRect.setBottom(thumbnailRect.bottom()+dy);
445 case DragHandleCentre: {
446 thumbnailRect.moveBy(dx, dy);
454 makeThumbnailRectVisible(thumbnailRect);
458void KoBirdEyePanel::handleMousePress(TQPoint p)
462 enumDragHandle dragHandle = dragHandleAt(p);
464 if (dragHandle == DragHandleNone) {
465 if (m_thumbnail.rect().contains(p)) {
469 TQRect thumbnailRect = m_visibleAreaInThumbnail;
470 thumbnailRect.moveCenter(p);
471 makeThumbnailRectVisible(thumbnailRect);
473 m_dragHandle = DragHandleCentre;
474 m_page->view->setCursor(TQt::sizeAllCursor);
478 m_dragHandle = dragHandle;
485void KoBirdEyePanel::makeThumbnailRectVisible(
const TQRect& r)
491 TQRect thumbnailRect = r;
493 if (thumbnailRect.left() < m_thumbnail.rect().left()) {
494 thumbnailRect.moveLeft(m_thumbnail.rect().left());
496 if (thumbnailRect.right() > m_thumbnail.rect().right()) {
497 thumbnailRect.moveRight(m_thumbnail.rect().right());
499 if (thumbnailRect.top() < m_thumbnail.rect().top()) {
500 thumbnailRect.moveTop(m_thumbnail.rect().top());
502 if (thumbnailRect.bottom() > m_thumbnail.rect().bottom()) {
503 thumbnailRect.moveBottom(m_thumbnail.rect().bottom());
506 if (thumbnailRect.width() > m_thumbnail.rect().width()) {
507 thumbnailRect.setLeft(m_thumbnail.rect().left());
508 thumbnailRect.setRight(m_thumbnail.rect().right());
510 if (thumbnailRect.height() > m_thumbnail.rect().height()) {
511 thumbnailRect.setTop(m_thumbnail.rect().top());
512 thumbnailRect.setBottom(m_thumbnail.rect().bottom());
515 double zoomFactor = m_canvas->zoomFactor();
517 if (thumbnailRect.size() == m_visibleAreaInThumbnail.size()) {
519 }
else if (thumbnailRect.width() != m_visibleAreaInThumbnail.width()) {
521 Q_ASSERT(thumbnailRect.height() == m_visibleAreaInThumbnail.height());
523 zoomFactor *=
static_cast<double>(m_visibleAreaInThumbnail.width()) / thumbnailRect.width();
526 Q_ASSERT(thumbnailRect.width() == m_visibleAreaInThumbnail.width());
528 zoomFactor *=
static_cast<double>(m_visibleAreaInThumbnail.height()) / thumbnailRect.height();
531 if (zoomFactor < m_zoomListener->getMinZoom()) {
532 zoomFactor = m_zoomListener->getMinZoom();
533 }
else if (zoomFactor > m_zoomListener->getMaxZoom()) {
534 zoomFactor = m_zoomListener->getMaxZoom();
538 m_zoomListener->zoomTo(docRect.center().x(), docRect.center().y(), zoomFactor);
541void KoBirdEyePanel::resizeViewEvent(TQSize size)
543 m_viewBuffer.resize(size);
544 fitThumbnailToView();
545 slotUpdate(TQRect(0, 0, m_documentSize.width(), m_documentSize.height()));
548void KoBirdEyePanel::fitThumbnailToView()
550 TQRect docRect = TQRect(0, 0, m_thumbnailProvider->pixelSize().width(), m_thumbnailProvider->pixelSize().height());
551 TQ_INT32 thumbnailWidth;
552 TQ_INT32 thumbnailHeight;
554 if (docRect.isEmpty()) {
558 const int thumbnailBorderPixels = 4;
560 double xScale = double(m_page->view->contentsRect().width() - thumbnailBorderPixels) / docRect.width();
561 double yScale = double(m_page->view->contentsRect().height() - thumbnailBorderPixels) / docRect.height();
563 if (xScale < yScale) {
564 thumbnailWidth = m_page->view->contentsRect().width() - thumbnailBorderPixels;
565 thumbnailHeight = TQ_INT32(ceil(docRect.height() * xScale));
567 thumbnailWidth = TQ_INT32(ceil(docRect.width() * yScale));
568 thumbnailHeight = m_page->view->contentsRect().height() - thumbnailBorderPixels;
572 m_thumbnail.resize(thumbnailWidth, thumbnailHeight);
576void KoBirdEyePanel::renderView()
578 Q_ASSERT(!m_viewBuffer.isNull());
580 if (!m_viewBuffer.isNull()) {
584 TQPainter painter(&m_viewBuffer);
586 painter.fillRect(0, 0, m_viewBuffer.width(), m_viewBuffer.height(), colorGroup().mid());
588 if (!m_thumbnail.isNull()) {
590 int thumbnailX = (m_viewBuffer.width() - m_thumbnail.width()) / 2;
591 int thumbnailY = (m_viewBuffer.height() - m_thumbnail.height()) / 2;
593 painter.drawPixmap(thumbnailX, thumbnailY, m_thumbnail);
595 painter.setPen(TQt::red);
596 painter.drawRect(thumbnailX + m_visibleAreaInThumbnail.x() - 1,
597 thumbnailY + m_visibleAreaInThumbnail.y() - 1,
598 m_visibleAreaInThumbnail.width() + 2,
599 m_visibleAreaInThumbnail.height() + 2);
600 painter.setPen(TQt::red.light());
601 painter.drawRect(thumbnailX + m_visibleAreaInThumbnail.x() - 2,
602 thumbnailY + m_visibleAreaInThumbnail.y() - 2,
603 m_visibleAreaInThumbnail.width() + 4,
604 m_visibleAreaInThumbnail.height() + 4);
609void KoBirdEyePanel::paintViewEvent(TQPaintEvent *e)
611 Q_ASSERT(!m_viewBuffer.isNull());
613 if (!m_viewBuffer.isNull()) {
614 bitBlt(m_page->view, e->rect().x(), e->rect().y(), &m_viewBuffer,
615 e->rect().x(), e->rect().y(), e->rect().width(), e->rect().height());
619#include "kobirdeyepanel.moc"
void slotViewTransformationChanged()
Connect to this slot to inform the bird's eye view of changes in the view transformation,...
KoBirdEyePanel(KoZoomAdapter *zoomListener, KoThumbnailAdapter *thumbnailProvider, KoCanvasAdapter *canvas, TQWidget *parent, const char *name=0, WFlags f=0)
Create a new bird eye panel.
KoRect thumbnailToDocument(const TQRect &thumbnailRect)
Returns the rectangle in the document covered by the given thumbnail rectangle.
void setThumbnailProvider(KoThumbnailAdapter *thumbnailProvider)
Set a new thumbnail provider.
void slotUpdate(const TQRect &r)
Connect to this slot if a (rectangular) area of your document is changed.
TQRect documentToThumbnail(const KoRect &docRect)
Returns the rectangle in the thumbnail covered by the given document rectangle.
TQPoint viewToThumbnail(const TQPoint &viewPoint)
Converts a point in the view to a point in the thumbnail.
The zoom listener interface defines methods that the bird eye panel will call whenever the zoomlevel ...
virtual double getMaxZoom()=0
Get the maximum zoom factor that this listener supports.
virtual double getMinZoom()=0
Get the minimum zoom factor that this listener supports.