void KstViewWidget::dropEvent(QDropEvent *e) { if (e->source() != this && e->provides(PlotMimeSource::mimeType())) { // FIXME: support both copy and move KstViewObjectPtr vo = findChildFor(e->pos()); if (vo) { if (vo->paste(e)) { e->acceptAction(true); KstApp::inst()->updateViewManager(true); _view->paint(KstPainter::P_PAINT); } } else { if (viewObject()->paste(e)) { e->acceptAction(true); KstApp::inst()->updateViewManager(true); _view->paint(KstPainter::P_PAINT); } } } else if (_view->viewMode() != KstTopLevelView::LayoutMode) { KstViewObjectPtr vo = findChildFor(e->pos()); if (vo) { vo->dropEvent(this, e); return; } QWidget::dropEvent(e); } }
void KstViewWidget::mouseReleaseEvent(QMouseEvent *e) { //kstdDebug() << "Release event. button=" << e->button() << " state=" << e->state() << endl; if (_view->viewMode() == KstTopLevelView::DisplayMode) { KstViewObjectPtr vo; if (_view->mouseGrabbed()) { vo = _view->mouseGrabber(); } else { vo = findChildFor(e->pos()); } if (vo) { //kstdDebug() << "Found mouse handler " << vo->tagName() << endl; vo->mouseReleaseEvent(this, e); } return; } if ((e->state() & Qt::ShiftButton) && (e->button() & Qt::LeftButton) && !_view->tracking()) { _view->releasePress(e->pos(), true); } else if (e->button() & Qt::LeftButton) { //kstdDebug() << "doing releasePress" << endl; _view->releasePress(e->pos(), e->state() & Qt::ShiftButton); e->accept(); } else { if (e->state() & Qt::LeftButton && _view->tracking()) { e->accept(); // swallow return; } _view->updateFocus(e->pos()); QWidget::mouseReleaseEvent(e); } }
void KstViewWidget::mouseDoubleClickEvent(QMouseEvent *e) { //kstdDebug() << "DoubleClick event. button=" << e->button() << " state=" << e->state() << endl; if (_view->viewMode() == KstTopLevelView::DisplayMode) { KstViewObjectPtr vo; if (_view->mouseGrabbed()) { vo = _view->mouseGrabber(); } else { vo = findChildFor(e->pos()); } if (vo) { //kstdDebug() << "Found mouse handler " << vo->tagName() << endl; vo->mouseDoubleClickEvent(this, e); } return; } // layout/graphics mode if (e->button() & Qt::LeftButton) { // let the toplevel view handle it if (_view->handleDoubleClick(e->pos(), e->state() & Qt::ShiftButton)) { e->accept(); return; } } //kstdDebug() << " -> Passing up" << endl; QWidget::mouseDoubleClickEvent(e); }
KJS::Object KstBindLegend::construct(KJS::ExecState *exec, const KJS::List& args) { if (args.size() == 0 || args.size() > 2) { return createSyntaxError(exec); } KstViewObjectPtr view = extractViewObject(exec, args[0]); if (!view) { KstViewWindow *w = extractWindow(exec, args[0]); if (w) { view = w->view(); } else { return createTypeError(exec, 0); } } QString txt; if (args.size() == 2) { if (args[1].type() != KJS::StringType) { return createTypeError(exec, 1); } txt = args[1].toString(exec).qstring(); } KstViewLegendPtr b = new KstViewLegend; view->appendChild(b.data()); KstApp::inst()->paintAll(KstPainter::P_PAINT); return KJS::Object(new KstBindLegend(exec, b)); }
bool KstPlotGroup::popupMenu(KPopupMenu *menu, const QPoint& pos, KstViewObjectPtr topParent) { KstMetaPlot::popupMenu(menu, pos, topParent); KstViewObjectPtr c = findChild(pos + position()); if (c) { KPopupMenu *s = new KPopupMenu(menu); if (c->popupMenu(s, pos - c->position(), topParent)) { menu->insertItem(c->tagName(), s); } else { delete s; } } return true; }
void KstViewWidget::dragMoveEvent(QDragMoveEvent *e) { if (_dragEnabled && e->provides(PlotMimeSource::mimeType())) { e->accept(true); } else if (_view->viewMode() != KstTopLevelView::LayoutMode) { KstViewObjectPtr vo = findChildFor(e->pos()); if (vo) { vo->dragMoveEvent(this, e); } else { e->accept(false); } } QWidget::dragMoveEvent(e); }
void KstViewWidget::wheelEvent(QWheelEvent *e) { if (_view->viewMode() == KstTopLevelView::DisplayMode) { KstViewObjectPtr vo; if (_view->mouseGrabbed()) { vo = _view->mouseGrabber(); } else { vo = findChildFor(e->pos()); } if (vo) { //kstdDebug() << "Found mouse handler " << vo->tagName() << endl; vo->wheelEvent(this, e); } return; } }
void KstTopLevelView::releasePressLayoutModeMove(const QPoint& pos, bool shift) { Q_UNUSED(shift) QRect obj(_pressTarget->geometry()); const QRect old(obj); // the list of other selected objects if (!_selectionList.isEmpty()) { for (KstViewObjectList::ConstIterator i = _selectionList.begin(); i != _selectionList.end(); ++i) { obj = obj.unite((*i)->geometry()); } } const QPoint objOffset(old.topLeft() - obj.topLeft()); // do the move obj.moveTopLeft(pos - _moveOffset - _moveOffsetSticky - old.topLeft() + obj.topLeft()); if (!_geom.contains(obj, true)) { slideInto(_geom, obj); } // This is not entirely correct. findDeepestChild could actually return an // object inside the selection list or even presstarget. We should get // something that includes none of those. This is most likely the parent of // the returned object in that case. KstViewObjectPtr container = findDeepestChild(obj); bool updateViewManager = false; if (!container) { container = this; } if (container != _pressTarget && !container->children().contains(_pressTarget)) { _pressTarget->detach(); container->appendChild(_pressTarget); updateViewManager = true; } _pressTarget->move(obj.topLeft() + objOffset); for (KstViewObjectList::Iterator i = _selectionList.begin(); i != _selectionList.end(); ++i) { if (*i != _pressTarget) { KstViewObjectPtr thisObj = *i; // ref if (container != thisObj && !container->children().contains(thisObj)) { thisObj->detach(); container->appendChild(thisObj); updateViewManager = true; } thisObj->move(_pressTarget->position() + thisObj->geometry().topLeft() - old.topLeft()); } } if (updateViewManager) { KstApp::inst()->updateViewManager(true); } _onGrid = false; }
void KstTopLevelView::setCursorFor(const QPoint& pos, KstViewObjectPtr p) { // cursor directions are the same for centered resize signed direction = p->directionFor(pos) & ~CENTEREDRESIZE; if (direction & ENDPOINT) { _cursor.setShape(Qt::CrossCursor); } else { switch (direction) { case UP: case DOWN: _cursor.setShape(Qt::SizeVerCursor); break; case LEFT: case RIGHT: _cursor.setShape(Qt::SizeHorCursor); break; case UP|LEFT: case DOWN|RIGHT: _cursor.setShape(Qt::SizeFDiagCursor); break; case UP|RIGHT: case DOWN|LEFT: _cursor.setShape(Qt::SizeBDiagCursor); break; default: _cursor.setShape(Qt::SizeAllCursor); break; } } if (_cursor.shape() != _w->cursor().shape()) { _w->setCursor(_cursor); } }
void KstTopLevelView::updateFocus(const QPoint& pos) { if (_activeHandler) { _activeHandler->updateFocus(this, pos); return; } if (_mode == DisplayMode || _mode == Unknown || tracking()) { return; } //TODO: make this work better with click-select mode KstViewObjectPtr p = findDeepestChild(pos, false); if (p) { KstViewObjectPtr p2 = p; while (p2->_parent && p2->_parent->_container) { p2 = p2->_parent; } if (p2->_parent && !p2->_parent->_container) { p = p2->_parent; } } if (p) { if (p->focused()) { setCursorFor(pos, p); _focusOn = true; // just in case - seems to be false on occasion return; } p->setFocus(true); if (_focusOn) { // something else has the focus, clear it clearFocus(); } setCursorFor(pos, p); KstPainter painter; painter.begin(_w); painter.setRasterOp(Qt::NotROP); painter.setPen(QPen(Qt::black, 0, Qt::SolidLine)); painter.setBrush(Qt::NoBrush); p->drawFocusRect(painter); painter.end(); _focusOn = true; _hoverFocus = p; } else { clearFocus(); } }
// Optimize: cache previous child here to make it faster? How to invalidate? void KstViewWidget::mouseMoveEvent(QMouseEvent *e) { if (_view->viewMode() == KstTopLevelView::DisplayMode) { KstViewObjectPtr vo; if (_view->mouseGrabbed()) { vo = _view->mouseGrabber(); } else { vo = findChildFor(e->pos()); } if (KstApp::inst()->dataMode()) { if (vo.data() != _vo_datamode) { _vo_datamode = vo.data(); paint(); } } else { _vo_datamode = 0L; } if (vo) { //kstdDebug() << "Found mouse handler " << vo->tagName() << endl; vo->mouseMoveEvent(this, e); } else { setCursor(QCursor(Qt::ArrowCursor)); } } else { if ((e->state() & Qt::MouseButtonMask) == 0) { switch (_view->viewMode()) { case KstTopLevelView::LabelMode: setCursor(QCursor(Qt::IbeamCursor)); break; case KstTopLevelView::CreateMode: setCursor(QCursor(Qt::ArrowCursor)); break; default: break; } _view->updateFocus(e->pos()); e->accept(); } else if (e->state() & Qt::LeftButton) { //setCursor(QCursor(Qt::ArrowCursor)); _view->pressMove(e->pos(), e->state() & Qt::ShiftButton, e->state() & Qt::AltButton); e->accept(); } } }
bool KstIfaceImpl::deletePlot(const QString& window, const QString& name) { KstViewWindow *pView = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(window)); if (pView) { KstTopLevelViewPtr pTLV = pView->view(); KstViewObjectList objects = pTLV->findChildrenType<KstViewObject>(true); for (KstViewObjectList::Iterator it = objects.begin(); it != objects.end(); ++it) { KstViewObjectPtr object = *it; if (object->tagName() == name) { pTLV->removeChild(object, true); _doc->forceUpdate(); _doc->setModified(); return true; } } } return false; }
void KstViewWidget::dragEnterEvent(QDragEnterEvent *e) { if (e->provides(PlotMimeSource::mimeType())) { if (e->source() == this) { QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Escape, 0, 0); QApplication::sendEvent(this, &keyEvent); _view->restartMove(); } else { e->acceptAction(true); } } else if (_view->viewMode() != KstTopLevelView::LayoutMode) { KstViewObjectPtr vo = findChildFor(e->pos()); if (vo) { vo->dragEnterEvent(this, e); } else { e->accept(false); } } QWidget::dragEnterEvent(e); }
KJS::Object KstBindLine::construct(KJS::ExecState *exec, const KJS::List& args) { if (args.size() != 1) { return createSyntaxError(exec); } KstViewObjectPtr view = extractViewObject(exec, args[0]); if (!view) { KstViewWindow *w = extractWindow(exec, args[0]); if (w) { view = w->view(); } else { return createTypeError(exec, 0); } } KstViewLinePtr b = new KstViewLine; view->appendChild(b.data()); KstApp::inst()->paintAll(KstPainter::P_PAINT); return KJS::Object(new KstBindLine(exec, b)); }
void KstViewWidget::keyReleaseEvent(QKeyEvent *e) { if (_view->viewMode() == KstTopLevelView::DisplayMode) { KstViewObjectPtr vo; // Note: should mouse grabbers get keyboard input? if (_view->mouseGrabbed()) { vo = _view->mouseGrabber(); } else { vo = findChildFor(mapFromGlobal(QCursor::pos())); } if (vo) { vo->keyReleaseEvent(this, e); } return; } else if (e->key() == Qt::Key_Control && _view->viewMode() == KstTopLevelView::LayoutMode) { _view->setViewMode(_lastViewMode); _lastViewMode = KstTopLevelView::LayoutMode; } QWidget::keyReleaseEvent(e); }
void KstViewWidget::mousePressEvent(QMouseEvent *e) { //kstdDebug() << "Press event. button=" << e->button() << " state=" << e->state() << endl; if (_menu) { QWidget::mousePressEvent(e); return; } if (_view->viewMode() == KstTopLevelView::DisplayMode) { KstViewObjectPtr vo; if (_view->mouseGrabbed()) { vo = _view->mouseGrabber(); } else { vo = findChildFor(e->pos()); } if (vo) { //kstdDebug() << "Found mouse handler " << vo->tagName() << endl; vo->mousePressEvent(this, e); } return; } // Layout/graphics mode if (e->button() & Qt::LeftButton) { setCursor(QCursor(Qt::ArrowCursor)); //kstdDebug() << " -> left button" << endl; if (_view->handlePress(e->pos(), e->state() & Qt::ShiftButton)) { //kstdDebug() << " -> Accepting" << endl; e->accept(); return; } else if (_view->tracking()) { //kstdDebug() << " -> Swallowing" << endl; e->accept(); // swallow return; } } //kstdDebug() << " -> Passing up" << endl; QWidget::mousePressEvent(e); }
void KstViewWidget::keyPressEvent(QKeyEvent *e) { if (_view->viewMode() == KstTopLevelView::DisplayMode) { KstViewObjectPtr vo; // Note: should mouse grabbers get keyboard input? if (_view->mouseGrabbed()) { vo = _view->mouseGrabber(); } else { vo = findChildFor(mapFromGlobal(QCursor::pos())); } if (vo) { vo->keyPressEvent(this, e); } return; } else if (_view->viewMode() == KstTopLevelView::LayoutMode) { ButtonState s = e->stateAfter(); if (e->key() == Qt::Key_Escape) { _view->cancelMouseOperations(); return; } else if (e->key() == Qt::Key_A && (s & Qt::ControlButton) && _view->viewMode() == KstTopLevelView::LayoutMode) { if (s & Qt::ShiftButton) { _view->unselectAll(); } else { _view->selectAll(); } paint(); return; } else if (e->key() == Qt::Key_Delete) { _view->deleteSelectedObjects(); return; } else if (e->key() == Qt::Key_Control && (_view->viewMode() != KstTopLevelView::LayoutMode)) { _lastViewMode = _view->viewMode(); _view->setViewMode(KstTopLevelView::LayoutMode); return; } } QWidget::keyPressEvent(e); }
KJS::Object KstBindEllipse::construct(KJS::ExecState *exec, const KJS::List& args) { if (args.size() != 1) { KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError); exec->setException(eobj); return KJS::Object(); } KstViewObjectPtr view = extractViewObject(exec, args[0]); if (!view) { KstViewWindow *w = extractWindow(exec, args[0]); if (w) { view = w->view(); } else { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Object(); } } KstViewEllipsePtr b = new KstViewEllipse; view->appendChild(b.data()); KstApp::inst()->paintAll(KstPainter::P_PAINT); return KJS::Object(new KstBindEllipse(exec, b)); }
KstBindViewObject::KstBindViewObject(KJS::ExecState *exec, KstViewObjectPtr d, const char *name) : KstBindObject(exec, d.data(), name ? name : "ViewObject") { KJS::Object o(this); addBindings(exec, o); }