diff --git a/sheets/part/CanvasItem.cpp b/sheets/part/CanvasItem.cpp index f6f53583f48..f51290914ae 100644 --- a/sheets/part/CanvasItem.cpp +++ b/sheets/part/CanvasItem.cpp @@ -1,493 +1,491 @@ /* This file is part of the KDE project Copyright 2009 Thomas Zander Copyright 2006-2007 Stefan Nikolaus Copyright 2006 Robert Knight Copyright 2006 Inge Wallin Copyright 1999-2002,2004 Laurent Montel Copyright 2002-2005 Ariya Hidayat Copyright 1999-2004 David Faure Copyright 2004-2005 Meni Livne Copyright 2001-2003 Philipp Mueller Copyright 2002-2003 Norbert Andres Copyright 2003 Hamish Rodda Copyright 2003 Joseph Wenninger Copyright 2003 Lukas Tinkl Copyright 2000-2002 Werner Trobin Copyright 2002 Harri Porten Copyright 2002 John Dailey Copyright 2002 Daniel Naber Copyright 1999-2000 Torben Weis Copyright 1999-2000 Stephan Kulow Copyright 2000 Bernd Wuebben Copyright 2000 Wilco Greven Copyright 2000 Simon Hausmann Copyright 1999 Boris Wedl Copyright 1999 Reginald Stadlbauer This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ // Local #include "CanvasItem.h" // std #include #include #include // Qt #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // Calligra #include #include #include #include #include #include #include #include #include // Sheets #include "SheetsDebug.h" #include "CalculationSettings.h" #include "CellStorage.h" #include "Damages.h" #include "Doc.h" #include "Global.h" #include "HeaderItems.h" #include "Localization.h" #include "Map.h" #include "RowColumnFormat.h" #include "Sheet.h" #include "Util.h" #include "Validity.h" #include "View.h" // commands #include "commands/CopyCommand.h" #include "commands/DeleteCommand.h" #include "commands/PasteCommand.h" #include "commands/StyleCommand.h" // ui #include "ui/CellView.h" #include "ui/Selection.h" #include "ui/SheetView.h" #include "ui/RightToLeftPaintingStrategy.h" #define MIN_SIZE 10 using namespace Calligra::Sheets; class Q_DECL_HIDDEN CanvasItem::Private { public: Selection* selection; KoZoomHandler* zoomHandler; QHash sheetViews; Sheet* activeSheet; ColumnHeaderItem* columnHeader; RowHeaderItem* rowHeader; Doc *doc; }; CanvasItem::CanvasItem(Doc *doc, QGraphicsItem *parent) : QGraphicsWidget(parent) , CanvasBase(doc) , d(new Private) { setAttribute(Qt::WA_OpaquePaintEvent); - setAttribute(Qt::WA_StaticContents); //setBackgroundRole(QPalette::Base); QGraphicsWidget::setFocusPolicy(Qt::StrongFocus); //setMouseTracking(true); setAcceptHoverEvents(true); installEventFilter(this); // for TAB key processing, otherwise focus change setAcceptDrops(true); - setAttribute(Qt::WA_InputMethodEnabled, true); // ensure using the InputMethod d->doc = doc; d->rowHeader = 0; d->columnHeader = 0; d->selection = new Selection(this); d->zoomHandler = new KoZoomHandler(); d->activeSheet = 0; setActiveSheet(doc->map()->sheet(0)); d->selection->setActiveSheet(activeSheet()); connect(d->selection, SIGNAL(refreshSheetViews()), SLOT(refreshSheetViews())); connect(d->selection, SIGNAL(visibleSheetRequested(Sheet*)), this, SLOT(setActiveSheet(Sheet*))); connect(d->selection, SIGNAL(updateAccessedCellRange(Sheet*,QPoint)), this, SLOT(updateAccessedCellRange(Sheet*,QPoint))); connect(doc->map(), SIGNAL(damagesFlushed(QList)), SLOT(handleDamages(QList))); } CanvasItem::~CanvasItem() { if (d->doc->isReadWrite()) selection()->emitCloseEditor(true); d->selection->emitCloseEditor(false); d->selection->endReferenceSelection(false); d->activeSheet = 0; delete d->selection; delete d->zoomHandler; delete d; } void CanvasItem::mousePressEvent(QGraphicsSceneMouseEvent* event) { KoPointerEvent pev(event, QPointF()); mousePressed(&pev); } void CanvasItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) { KoPointerEvent pev(event, QPointF()); mouseReleased(&pev); } void CanvasItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) { KoPointerEvent pev(event, QPointF()); mouseMoved(&pev); } void CanvasItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) { KoPointerEvent pev(event, QPointF()); mouseDoubleClicked(&pev); } void CanvasItem::paint(QPainter* painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { Q_UNUSED(widget); CanvasBase::paint(painter, option->exposedRect); } void CanvasItem::dragEnterEvent(QGraphicsSceneDragDropEvent* event) { if (CanvasBase::dragEnter(event->mimeData())) { event->acceptProposedAction(); } } void CanvasItem::dragMoveEvent(QGraphicsSceneDragDropEvent* event) { if (CanvasBase::dragMove(event->mimeData(), event->pos(), event->source())) { event->acceptProposedAction(); } else { event->ignore(); } } void CanvasItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *) { CanvasBase::dragLeave(); } void CanvasItem::dropEvent(QGraphicsSceneDragDropEvent *event) { if (CanvasBase::drop(event->mimeData(), event->pos(), event->source())) { event->setAccepted(true); } else { event->ignore(); } } Selection* CanvasItem::selection() const { return d->selection; } Sheet* CanvasItem::activeSheet() const { return d->activeSheet; } KoZoomHandler* CanvasItem::zoomHandler() const { return d->zoomHandler; } SheetView* CanvasItem::sheetView(const Sheet* sheet) const { if (!d->sheetViews.contains(sheet)) { debugSheetsRender << "Creating SheetView for" << sheet->sheetName(); d->sheetViews.insert(sheet, new SheetView(sheet)); d->sheetViews[ sheet ]->setViewConverter(zoomHandler()); connect(d->sheetViews[ sheet ], SIGNAL(visibleSizeChanged(QSizeF)), this, SLOT(setDocumentSize(QSizeF))); connect(d->sheetViews[ sheet ], SIGNAL(obscuredRangeChanged(QSize)), this, SLOT(setObscuredRange(QSize))); //connect(d->sheetViews[ sheet ], SIGNAL(visibleSizeChanged(QSizeF)), //d->zoomController, SLOT(setDocumentSize(QSizeF))); connect(sheet, SIGNAL(visibleSizeChanged()), d->sheetViews[ sheet ], SLOT(updateAccessedCellRange())); } return d->sheetViews[ sheet ]; } void CanvasItem::refreshSheetViews() { const QList sheetViews = d->sheetViews.values(); for (int i = 0; i < sheetViews.count(); ++i) { disconnect(sheetViews[i], SIGNAL(visibleSizeChanged(QSizeF)), this, SLOT(setDocumentSize(QSizeF))); disconnect(sheetViews[i], SIGNAL(obscuredRangeChanged(QSize)), this, SLOT(setObscuredRange(QSize))); //disconnect(sheetViews[i], SIGNAL(visibleSizeChanged(QSizeF)), //d->zoomController, SLOT(setDocumentSize(QSizeF))); disconnect(sheetViews[i]->sheet(), SIGNAL(visibleSizeChanged()), sheetViews[i], SLOT(updateAccessedCellRange())); } qDeleteAll(d->sheetViews); d->sheetViews.clear(); const QList sheets = doc()->map()->sheetList(); for (int i = 0; i < sheets.count(); ++i) sheets[i]->cellStorage()->invalidateStyleCache(); } void CanvasItem::setActiveSheet(Sheet* sheet) { if (sheet == d->activeSheet) return; if (d->activeSheet != 0 && !d->selection->referenceSelectionMode()) { selection()->emitCloseEditor(true); //saveCurrentSheetSelection(); } const Sheet* oldSheet = d->activeSheet; d->activeSheet = sheet; if (d->activeSheet == 0) { return; } // flake // Change the active shape controller and its shapes. shapeController()->setShapeControllerBase(d->activeSheet); // and then update the toolmanager separately KoToolManager::instance()->updateShapeControllerBase(d->activeSheet, canvasController()); shapeManager()->setShapes(d->activeSheet->shapes()); // Tell the Canvas about the new visible sheet size. sheetView(d->activeSheet)->updateAccessedCellRange(); // If there was no sheet before or the layout directions differ. if (!oldSheet || oldSheet->layoutDirection() != d->activeSheet->layoutDirection()) { // Propagate the layout direction to the canvas and horz. scrollbar. const Qt::LayoutDirection direction = d->activeSheet->layoutDirection(); setLayoutDirection(direction); // XXX d->horzScrollBar->setLayoutDirection(direction); // Replace the painting strategy for painting shapes. KoShapeManager *const shapeManager = this->shapeManager(); KoShapeManagerPaintingStrategy *paintingStrategy = 0; if (direction == Qt::LeftToRight) { paintingStrategy = new KoShapeManagerPaintingStrategy(shapeManager); } else { paintingStrategy = new RightToLeftPaintingStrategy(shapeManager, this); } shapeManager->setPaintingStrategy(paintingStrategy); } /* // Restore the old scrolling offset. QMap::Iterator it3 = d->savedOffsets.find(d->activeSheet); if (it3 != d->savedOffsets.end()) { const QPoint offset = zoomHandler()->documentToView(*it3).toPoint(); d->canvas->setDocumentOffset(offset); d->horzScrollBar->setValue(offset.x()); d->vertScrollBar->setValue(offset.y()); }*/ // tell the resource manager of the newly active page resourceManager()->setResource(KoCanvasResourceManager::CurrentPage, QVariant(sheet->map()->indexOf(sheet) + 1)); // Always repaint the visible cells. update(); if (d->rowHeader) d->rowHeader->update(); if (d->columnHeader) d->columnHeader->update(); //d->selectAllButton->update(); if (d->selection->referenceSelectionMode()) { d->selection->setActiveSheet(d->activeSheet); return; } #if 0 /* see if there was a previous selection on this other sheet */ QMap::Iterator it = d->savedAnchors.find(d->activeSheet); QMap::Iterator it2 = d->savedMarkers.find(d->activeSheet); // restore the old anchor and marker const QPoint newAnchor = (it == d->savedAnchors.end()) ? QPoint(1, 1) : *it; const QPoint newMarker = (it2 == d->savedMarkers.end()) ? QPoint(1, 1) : *it2; #endif d->selection->clear(); d->selection->setActiveSheet(d->activeSheet); d->selection->setOriginSheet(d->activeSheet); //d->selection->initialize(QRect(newMarker, newAnchor)); // Auto calculation state for the INFO function. const bool autoCalc = d->activeSheet->isAutoCalculationEnabled(); doc()->map()->calculationSettings()->setAutoCalculationEnabled(autoCalc); } ColumnHeader* CanvasItem::columnHeader() const { if (!d->columnHeader) d->columnHeader = new ColumnHeaderItem(0, const_cast(this)); return d->columnHeader; } RowHeader* CanvasItem::rowHeader() const { if (!d->rowHeader) d->rowHeader = new RowHeaderItem(0, const_cast(this)); return d->rowHeader; } void CanvasItem::setCursor(const QCursor &cursor) { QGraphicsWidget::setCursor(cursor); } void CanvasItem::handleDamages(const QList& damages) { QRegion paintRegion; enum { Nothing, Everything, Clipped } paintMode = Nothing; QList::ConstIterator end(damages.end()); for (QList::ConstIterator it = damages.begin(); it != end; ++it) { Damage* damage = *it; if (!damage) continue; if (damage->type() == Damage::Cell) { CellDamage* cellDamage = static_cast(damage); debugSheetsDamage << "Processing\t" << *cellDamage; Sheet* const damagedSheet = cellDamage->sheet(); if (cellDamage->changes() & CellDamage::Appearance) { const Region& region = cellDamage->region(); sheetView(damagedSheet)->invalidateRegion(region); paintMode = Everything; } continue; } if (damage->type() == Damage::Sheet) { SheetDamage* sheetDamage = static_cast(damage); debugSheetsDamage << *sheetDamage; const SheetDamage::Changes changes = sheetDamage->changes(); if (changes & (SheetDamage::Name | SheetDamage::Shown)) { // d->tabBar->setTabs(doc()->map()->visibleSheets()); paintMode = Everything; } if (changes & (SheetDamage::Shown | SheetDamage::Hidden)) { // updateShowSheetMenu(); paintMode = Everything; } // The following changes only affect the active sheet. if (sheetDamage->sheet() != d->activeSheet) { continue; } if (changes.testFlag(SheetDamage::ContentChanged)) { update(); paintMode = Everything; } if (changes.testFlag(SheetDamage::PropertiesChanged)) { sheetView(d->activeSheet)->invalidate(); paintMode = Everything; } if (sheetDamage->changes() & SheetDamage::ColumnsChanged) columnHeader()->update(); if (sheetDamage->changes() & SheetDamage::RowsChanged) rowHeader()->update(); continue; } if (damage->type() == Damage::Selection) { SelectionDamage* selectionDamage = static_cast(damage); debugSheetsDamage << "Processing\t" << *selectionDamage; const Region region = selectionDamage->region(); if (paintMode == Clipped) { const QRectF rect = cellCoordinatesToView(region.boundingRect()); paintRegion += rect.toRect().adjusted(-3, -3, 4, 4); } else { paintMode = Everything; } continue; } debugSheetsDamage << "Unhandled\t" << *damage; } // At last repaint the dirty cells. if (paintMode == Clipped) { update(paintRegion.boundingRect()); } else if (paintMode == Everything) { update(); } } void CanvasItem::setObscuredRange(const QSize &size) { SheetView* sheetView = qobject_cast(sender()); if (!sheetView) return; emit obscuredRangeChanged(sheetView->sheet(), size); } void CanvasItem::updateAccessedCellRange(Sheet* sheet, const QPoint &location) { sheetView(sheet)->updateAccessedCellRange(location); } diff --git a/sheets/part/HeaderItems.cpp b/sheets/part/HeaderItems.cpp index e59df3135d8..6b0bc3865b5 100644 --- a/sheets/part/HeaderItems.cpp +++ b/sheets/part/HeaderItems.cpp @@ -1,476 +1,472 @@ /* This file is part of the KDE project Copyright 2006 Robert Knight Copyright 2006 Inge Wallin Copyright 2006 Stefan Nikolaus Copyright 1999-2002,2004 Laurent Montel Copyright 2002-2005 Ariya Hidayat Copyright 1999-2004 David Faure Copyright 2004-2005 Meni Livne Copyright 2001-2003 Philipp Mueller Copyright 2002-2003 Norbert Andres Copyright 2003 Hamish Rodda Copyright 2003 Joseph Wenninger Copyright 2003 Lukas Tinkl Copyright 2000-2002 Werner Trobin Copyright 2002 Harri Porten Copyright 2002 John Dailey Copyright 2002 Daniel Naber Copyright 1999-2000 Torben Weis Copyright 1999-2000 Stephan Kulow Copyright 2000 Bernd Wuebben Copyright 2000 Wilco Greven Copyright 2000 Simon Hausmann Copyright 1999 Boris Wedl Copyright 1999 Reginald Stadlbauer This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ // Local #include "HeaderItems.h" // Qt #include #include #include #include #include #include #include #include #include #include #include // KF5 #include // Calligra #include #include #include #include #include // Sheets #include "CanvasItem.h" #include "Cell.h" #include "Doc.h" #include "calligra_sheets_limits.h" #include "RowColumnFormat.h" #include "Sheet.h" // commands #include "commands/RowColumnManipulators.h" // ui #include "ui/Selection.h" using namespace Calligra::Sheets; /**************************************************************** * * RowHeaderItem * ****************************************************************/ RowHeaderItem::RowHeaderItem(QGraphicsItem *_parent, CanvasItem *_canvas) : QGraphicsWidget(_parent), RowHeader(_canvas) { - setAttribute(Qt::WA_StaticContents); - //setMouseTracking(true); setAcceptHoverEvents(true); //connect(m_pView, SIGNAL(autoScroll(QPoint)), //this, SLOT(slotAutoScroll(QPoint))); connect(m_pCanvas->toolProxy(), SIGNAL(toolChanged(QString)), this, SLOT(toolChanged(QString))); setFlag(ItemClipsToShape, true); } RowHeaderItem::~RowHeaderItem() { } void RowHeaderItem::mousePressEvent(QGraphicsSceneMouseEvent * _ev) { KoPointerEvent pev(_ev, QPointF()); mousePress(&pev); } void RowHeaderItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * _ev) { KoPointerEvent pev(_ev, QPointF()); mouseRelease(&pev); } void RowHeaderItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* _ev) { KoPointerEvent pev(_ev, QPointF()); mouseDoubleClick(&pev); } void RowHeaderItem::mouseMoveEvent(QGraphicsSceneMouseEvent * _ev) { KoPointerEvent pev(_ev, QPointF()); mouseMove(&pev); } /* void RowHeaderItem::slotAutoScroll(const QPoint& scrollDistance) { // NOTE Stefan: This slot is triggered by the same signal as // Canvas::slotAutoScroll and ColumnHeaderItem::slotAutoScroll. // Therefore, nothing has to be done except the scrolling was // initiated in this header. if (!m_bMousePressed) return; if (scrollDistance.y() == 0) return; const QPoint offset = m_pCanvas->viewConverter()->documentToView(m_pCanvas->offset()).toPoint(); if (offset.y() + scrollDistance.y() < 0) return; m_pCanvas->setDocumentOffset(offset + QPoint(0, scrollDistance.y())); // XXX: Port! //QGraphicsSceneMouseEvent event(QEvent::MouseMove, mapFromGlobal(QCursor::pos()), // Qt::NoButton, Qt::NoButton, QApplication::keyboardModifiers()); //QApplication::sendEvent(this, &event); m_pCanvas->update(); } */ void RowHeaderItem::wheelEvent(QGraphicsSceneWheelEvent* _ev) { Q_UNUSED(_ev); // TODO XXX } void RowHeaderItem::paintSizeIndicator(int mouseY) { register Sheet * const sheet = m_pCanvas->activeSheet(); if (!sheet) return; m_iResizePos = mouseY; // Don't make the row have a height < 2 pixel. double y = m_pCanvas->zoomHandler()->zoomItY(sheet->rowPosition(m_iResizedRow) - m_pCanvas->yOffset()); if (m_iResizePos < y + 2) m_iResizePos = (int) y; // XXX: Port to QGraphicsView //if (!m_rubberband) { // m_rubberband = new QRubberBand(QRubberBand::Line, m_pCanvas); // m_rubberband->setGeometry(0, m_iResizePos, m_pCanvas->width(), 2); // m_rubberband->show(); //} //m_rubberband->move(0, m_iResizePos); QString tmpSize; double hh = m_pCanvas->zoomHandler()->unzoomItY(m_iResizePos - y); double hu = m_pCanvas->doc()->unit().toUserValue(hh); if (hu > 0.01) tmpSize = i18n("Height: %1 %2", hu, m_pCanvas->doc()->unit().symbol()); else tmpSize = i18n("Hide Row"); if (!m_lSize) { int screenNo = 0; //QApplication::desktop()->screenNumber(topLevelWidget()); m_lSize = new QLabel(QApplication::desktop()->screen(screenNo) , Qt::ToolTip); m_lSize->setAlignment(Qt::AlignVCenter); m_lSize->setAutoFillBackground(true); m_lSize->setPalette(QToolTip::palette()); m_lSize->setMargin(1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, 0, m_lSize)); m_lSize->setFrameShape(QFrame::Box); m_lSize->setIndent(1); } m_lSize->setText(tmpSize); m_lSize->adjustSize(); QRectF rcf = static_cast(m_pCanvas)->boundingRect(); QPoint pos = (sheet->layoutDirection() == Qt::RightToLeft) ? QPoint(rcf.width() - m_lSize->width() - 3, (int)y + 3) : QPoint(3, (int)y + 3); pos -= QPoint(0, m_lSize->height()); // XXX: Port //m_lSize->move(m_pCanvas->mapToGlobal(pos).x(), m_pCanvas->mapToGlobal(pos).y()); m_lSize->show(); } void RowHeaderItem::removeSizeIndicator() { // XXX TODO } void RowHeaderItem::updateRows(int from, int to) { register Sheet * const sheet = m_pCanvas->activeSheet(); if (!sheet) return; double y0 = m_pCanvas->zoomHandler()->zoomItY(sheet->rowPosition(from)); double y1 = m_pCanvas->zoomHandler()->zoomItY(sheet->rowPosition(to + 1)); QGraphicsItem::update(0, (int) y0, boundingRect().width(), (int)(y1 - y0)); } void RowHeaderItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { Q_UNUSED(widget); RowHeader::paint(painter, option->exposedRect); } void RowHeaderItem::focusOutEvent(QFocusEvent* _ev) { focusOut(_ev); } void RowHeaderItem::toolChanged(const QString& toolId) { doToolChanged(toolId); } /**************************************************************** * * ColumnHeaderItem * ****************************************************************/ ColumnHeaderItem::ColumnHeaderItem(QGraphicsItem *_parent, CanvasItem *_canvas) : QGraphicsWidget(_parent), ColumnHeader(_canvas) { - setAttribute(Qt::WA_StaticContents); - //setMouseTracking(true); setAcceptHoverEvents(true); //connect(_view, SIGNAL(autoScroll(QPoint)), //this, SLOT(slotAutoScroll(QPoint))); connect(_canvas->toolProxy(), SIGNAL(toolChanged(QString)), this, SLOT(toolChanged(QString))); setFlag(ItemClipsToShape, true); } ColumnHeaderItem::~ColumnHeaderItem() { } void ColumnHeaderItem::mousePressEvent(QGraphicsSceneMouseEvent * _ev) { KoPointerEvent pev(_ev, QPointF()); mousePress(&pev); } void ColumnHeaderItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * _ev) { KoPointerEvent pev(_ev, QPointF()); mouseRelease(&pev); } void ColumnHeaderItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* _ev) { KoPointerEvent pev(_ev, QPointF()); mouseDoubleClick(&pev); } void ColumnHeaderItem::mouseMoveEvent(QGraphicsSceneMouseEvent * _ev) { KoPointerEvent pev(_ev, QPointF()); mouseMove(&pev); } /* void ColumnHeaderItem::slotAutoScroll(const QPoint& scrollDistance) { // NOTE Stefan: This slot is triggered by the same signal as // Canvas::slotAutoScroll and RowHeaderItem::slotAutoScroll. // Therefore, nothing has to be done except the scrolling was // initiated in this header. if (!m_bMousePressed) return; if (scrollDistance.x() == 0) return; const QPoint offset = m_pCanvas->viewConverter()->documentToView(m_pCanvas->offset()).toPoint(); if (offset.x() + scrollDistance.x() < 0) return; m_pCanvas->setDocumentOffset(offset + QPoint(scrollDistance.x(), 0)); //QGraphicsSceneMouseEvent event(QEvent::MouseMove, mapFromGlobal(QCursor::pos()), // Qt::NoButton, Qt::NoButton, QApplication::keyboardModifiers()); //QApplication::sendEvent(this, &event); m_pCanvas->update(); } */ void ColumnHeaderItem::wheelEvent(QGraphicsSceneWheelEvent* _ev) { Q_UNUSED(_ev); // TODO XXX } void ColumnHeaderItem::resizeEvent(QGraphicsSceneResizeEvent* _ev) { ColumnHeader::resize(_ev->newSize(), _ev->oldSize()); } void ColumnHeaderItem::paintSizeIndicator(int mouseX) { register Sheet * const sheet = m_pCanvas->activeSheet(); if (!sheet) return; if (sheet->layoutDirection() == Qt::RightToLeft) m_iResizePos = mouseX + m_pCanvas->width() - boundingRect().width(); else m_iResizePos = mouseX; // Don't make the column have a width < 2 pixels. double x = m_pCanvas->zoomHandler()->zoomItX(sheet->columnPosition(m_iResizedColumn) - m_pCanvas->xOffset()); if (sheet->layoutDirection() == Qt::RightToLeft) { x = m_pCanvas->width() - x; if (m_iResizePos > x - 2) m_iResizePos = (int) x; } else { if (m_iResizePos < x + 2) m_iResizePos = (int) x; } // XXX: Port // if (!m_rubberband) { // m_rubberband = new QRubberBand(QRubberBand::Line, m_pCanvas); // m_rubberband->setGeometry(m_iResizePos, 0, 2, m_pCanvas->height()); // m_rubberband->show(); // } // m_rubberband->move(m_iResizePos, 0); QString tmpSize; double ww = m_pCanvas->zoomHandler()->unzoomItX((sheet->layoutDirection() == Qt::RightToLeft) ? x - m_iResizePos : m_iResizePos - x); double wu = m_pCanvas->doc()->unit().toUserValue(ww); if (wu > 0.01) tmpSize = i18n("Width: %1 %2", wu, m_pCanvas->doc()->unit().symbol()); else tmpSize = i18n("Hide Column"); // XXX: Port // if (!m_lSize) { // int screenNo = 0; // QApplication::desktop()->screenNumber(this); // m_lSize = new QLabel(QApplication::desktop()->screen(screenNo) , Qt::ToolTip); // m_lSize->setAlignment(Qt::AlignVCenter); // m_lSize->setAutoFillBackground(true); // m_lSize->setPalette(QToolTip::palette()); // m_lSize->setMargin(1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, 0, m_lSize)); // m_lSize->setFrameShape(QFrame::Box); // m_lSize->setIndent(1); // } // // m_lSize->setText(tmpSize); // m_lSize->adjustSize(); // QPoint pos = (sheet->layoutDirection() == Qt::RightToLeft) ? QPoint((int) x - 3 - m_lSize->width(), 3) : // QPoint((int) x + 3, 3); // pos -= QPoint(0, m_lSize->height()); // m_lSize->move(m_pCanvas->mapToGlobal(pos).x(), mapToGlobal(pos).y()); // m_lSize->show(); } void ColumnHeaderItem::removeSizeIndicator() { // XXX TODO } void ColumnHeaderItem::updateColumns(int from, int to) { register Sheet * const sheet = m_pCanvas->activeSheet(); if (!sheet) return; double x0 = m_pCanvas->zoomHandler()->zoomItX(sheet->columnPosition(from)); double x1 = m_pCanvas->zoomHandler()->zoomItX(sheet->columnPosition(to + 1)); QGraphicsItem::update((int) x0, 0, (int)(x1 - x0), boundingRect().height()); } void ColumnHeaderItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { Q_UNUSED(widget); ColumnHeader::paint(painter, option->exposedRect); } void ColumnHeaderItem::focusOutEvent(QFocusEvent* _ev) { focusOut(_ev); } void ColumnHeaderItem::toolChanged(const QString& toolId) { doToolChanged(toolId); } void ColumnHeaderItem::scroll(qreal x, qreal y) { if (m_pCanvas->layoutDirection() == Qt::RightToLeft) { QGraphicsWidget::scroll(-x, y); } else { QGraphicsWidget::scroll(x, y); } } /**************************************************************** * * SelectAllButtonItem * ****************************************************************/ SelectAllButtonItem::SelectAllButtonItem(QGraphicsItem *_parent, CanvasBase* canvasBase) : QGraphicsWidget(_parent) , SelectAllButton(canvasBase) { connect(canvasBase->toolProxy(), SIGNAL(toolChanged(QString)), this, SLOT(toolChanged(QString))); } SelectAllButtonItem::~SelectAllButtonItem() { } void SelectAllButtonItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { Q_UNUSED(widget); SelectAllButton::paint(painter, option->exposedRect); } void SelectAllButtonItem::mousePressEvent(QGraphicsSceneMouseEvent* _ev) { KoPointerEvent pev(_ev, QPointF()); mousePress(&pev); } void SelectAllButtonItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* _ev) { KoPointerEvent pev(_ev, QPointF()); mouseRelease(&pev); } void SelectAllButtonItem::wheelEvent(QGraphicsSceneWheelEvent* _ev) { Q_UNUSED(_ev); // TODO XXX } void SelectAllButtonItem::toolChanged(const QString& toolId) { doToolChanged(toolId); } diff --git a/words/part/KWCanvasItem.cpp b/words/part/KWCanvasItem.cpp index ce850e5e738..1edd07e1764 100644 --- a/words/part/KWCanvasItem.cpp +++ b/words/part/KWCanvasItem.cpp @@ -1,173 +1,172 @@ /* This file is part of the KDE project * * Copyright (C) 2010 Boudewijn Rempt * Copyright (C) 2002-2006 David Faure * Copyright (C) 2005-2006 Thomas Zander * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ // words includes #include "KWCanvasItem.h" #include "KWGui.h" #include "KWViewMode.h" #include "KWPage.h" // calligra libs includes #include #include #include #include #include #include // Qt includes #include #include #include #include #include #include KWCanvasItem::KWCanvasItem(const QString &viewMode, KWDocument *document) : QGraphicsWidget(0), KWCanvasBase(document, this) { setAttribute(Qt::WA_OpaquePaintEvent, true); - setAttribute(Qt::WA_InputMethodEnabled, true); setFocusPolicy(Qt::StrongFocus); connect(document, SIGNAL(pageSetupChanged()), this, SLOT(pageSetupChanged())); m_viewConverter = new KoZoomHandler(); m_viewMode = KWViewMode::create(viewMode, document); } KWCanvasItem::~KWCanvasItem() { delete m_viewConverter; } void KWCanvasItem::pageSetupChanged() { m_viewMode->pageSetupChanged(); updateSize(); } void KWCanvasItem::updateSize() { resourceManager()->setResource(Words::CurrentPageCount, m_document->pageCount()); emit documentSize(m_viewMode->contentsSize()); } void KWCanvasItem::setDocumentOffset(const QPoint &offset) { m_documentOffset = offset; } bool KWCanvasItem::snapToGrid() const { return false; } void KWCanvasItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { QMouseEvent me(e->type(), e->pos().toPoint(), e->button(), e->buttons(), e->modifiers()); m_toolProxy->mouseMoveEvent(&me, m_viewMode->viewToDocument(e->pos() + m_documentOffset, m_viewConverter)); e->setAccepted(me.isAccepted()); } void KWCanvasItem::mousePressEvent(QGraphicsSceneMouseEvent *e) { QMouseEvent me(e->type(), e->pos().toPoint(), e->button(), e->buttons(), e->modifiers()); m_toolProxy->mousePressEvent(&me, m_viewMode->viewToDocument(e->pos() + m_documentOffset, m_viewConverter)); if (!me.isAccepted() && me.button() == Qt::RightButton) { // XXX: Port to graphicsitem! //m_view->popupContextMenu(e->globalPos(), m_toolProxy->popupActionList()); me.setAccepted(true); } e->setAccepted(me.isAccepted()); } void KWCanvasItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { QMouseEvent me(e->type(), e->pos().toPoint(), e->button(), e->buttons(), e->modifiers()); m_toolProxy->mouseReleaseEvent(&me, m_viewMode->viewToDocument(e->pos() + m_documentOffset, m_viewConverter)); e->setAccepted(me.isAccepted()); } void KWCanvasItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e) { QMouseEvent me(e->type(), e->pos().toPoint(), e->button(), e->buttons(), e->modifiers()); m_toolProxy->mouseDoubleClickEvent(&me, m_viewMode->viewToDocument(e->pos() + m_documentOffset, m_viewConverter)); e->setAccepted(me.isAccepted()); } void KWCanvasItem::keyPressEvent(QKeyEvent *e) { m_toolProxy->keyPressEvent(e); if (! e->isAccepted()) { if (e->key() == Qt::Key_Backtab || (e->key() == Qt::Key_Tab && (e->modifiers() & Qt::ShiftModifier))) focusNextPrevChild(false); else if (e->key() == Qt::Key_Tab) focusNextPrevChild(true); } } QVariant KWCanvasItem::inputMethodQuery(Qt::InputMethodQuery query) const { return m_toolProxy->inputMethodQuery(query, *(viewConverter())); } void KWCanvasItem::keyReleaseEvent(QKeyEvent *e) { m_toolProxy->keyReleaseEvent(e); } void KWCanvasItem::wheelEvent(QGraphicsSceneWheelEvent *event) { QWheelEvent ev(event->pos().toPoint(), event->delta(), event->buttons(), event->modifiers(), event->orientation()); m_toolProxy->wheelEvent(&ev, m_viewMode->viewToDocument(event->pos() + m_documentOffset, m_viewConverter)); event->setAccepted(ev.isAccepted()); } void KWCanvasItem::inputMethodEvent(QInputMethodEvent *event) { m_toolProxy->inputMethodEvent(event); } void KWCanvasItem::updateInputMethodInfo() { updateMicroFocus(); } void KWCanvasItem::updateCanvas(const QRectF &rc) { Q_UNUSED(rc) emit canvasUpdated(); } void KWCanvasItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) { painter->fillRect(option->exposedRect, QColor::fromRgb(232, 233, 234)); KWCanvasBase::paint(*painter, option->exposedRect); } void KWCanvasItem::setCursor(const QCursor &cursor) { QGraphicsWidget::setCursor(cursor); }