/*! \internal */ bool QLineMarkPanel::event(QEvent *e) { if (e->type() == QEvent::ToolTip) { QHelpEvent *helpEvent = static_cast<QHelpEvent *>(e); int linen=editor()->document()->lineNumber(editor()->verticalOffset()+helpEvent->y()); markToolTip=""; if (linen>-1 && linen<editor()->document()->lines()) { QDocumentLine line = editor()->document()->line(linen); QList<int> lm = line.marks(); int count = 1; int bestMark = -1; QLineMarksInfoCenter *mic = QLineMarksInfoCenter::instance(); foreach ( int id, lm ) { if (mic->markType(id).icon.isNull()) continue; if (helpEvent->x()>count && helpEvent->x()<count+16) bestMark = id; //no break do to overdraw if (count < 16*(maxMarksPerLine-1)) { count += 16; if (bestMark!=-1) break; } } if (bestMark!=-1) emit toolTipRequested(linen,bestMark); }
bool MyTableView::viewportEvent(QEvent * event) { if ( event->type() == QEvent::ToolTip ) { qDebug() << "3"; QHelpEvent *hev = static_cast<QHelpEvent *>(event); int col = columnAt(hev->x()); int row = rowAt(hev->y()); qDebug() << "col = " << col << ", row = " << row; QModelIndex idx = model()->index(row, col, QModelIndex()); QString text = idx.data().toString(); QFont font = viewOptions().font; QFontMetrics fm(font); int requiredWidth = fm.width(text); qDebug() << "require width = " << requiredWidth; qDebug() << "col width = " << columnWidth(col); if ( columnWidth(col) > requiredWidth ) { // don't show the tooltip if all text is visible return true; } } return QTableView::viewportEvent(event); }
VisualNode* TreeCanvas::eventNode(QEvent* event) { int x = 0; int y = 0; switch (event->type()) { case QEvent::ToolTip: { QHelpEvent* he = static_cast<QHelpEvent*>(event); x = he->x(); y = he->y(); break; } case QEvent::MouseButtonDblClick: case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: case QEvent::MouseMove: { QMouseEvent* me = static_cast<QMouseEvent*>(event); x = me->x(); y = me->y(); break; } case QEvent::ContextMenu: { QContextMenuEvent* ce = static_cast<QContextMenuEvent*>(event); x = ce->x(); y = ce->y(); break; } default: return NULL; } QAbstractScrollArea* sa = static_cast<QAbstractScrollArea*>(parentWidget()->parentWidget()); int xoff = sa->horizontalScrollBar()->value()/scale; int yoff = sa->verticalScrollBar()->value()/scale; BoundingBox bb = root->getBoundingBox(); int w = static_cast<int>((bb.right-bb.left+Layout::extent)*scale); if (w < sa->viewport()->width()) xoff -= (sa->viewport()->width()-w)/2; VisualNode* n; n = root->findNode(*na, static_cast<int>(x/scale-xtrans+xoff), static_cast<int>((y-30)/scale+yoff)); return n; }
static PyObject *meth_QHelpEvent_x(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; { QHelpEvent *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QHelpEvent, &sipCpp)) { int sipRes; Py_BEGIN_ALLOW_THREADS sipRes = sipCpp->x(); Py_END_ALLOW_THREADS return SIPLong_FromLong(sipRes); } }
bool ViewToolTipAndUrlManager::eventFilter(QObject *, QEvent *event) { Graph *graph = _view->graph(); if (graph == nullptr) return false; // clear url if tooltip is no longer visible if (!_url.empty() && !QToolTip::isVisible()) _url.clear(); // get the property holding the urls associated to graph elements StringProperty *urlProp = _urlPropName.empty() ? nullptr : dynamic_cast<StringProperty *>(graph->getProperty(_urlPropName)); if (event->type() == QEvent::ToolTip && (_tooltips == true || urlProp != nullptr)) { QHelpEvent *he = static_cast<QHelpEvent *>(event); node tmpNode; edge tmpEdge; if (_view->getNodeOrEdgeAtViewportPos(he->x(), he->y(), tmpNode, tmpEdge)) { QString ttip; if (tmpNode.isValid()) { if (urlProp) _url = urlProp->getNodeValue(tmpNode); if (_tooltips) ttip = NodesGraphModel::getNodeTooltip(graph, tmpNode); } else if (tmpEdge.isValid()) { if (urlProp) _url = urlProp->getEdgeValue(tmpEdge); if (_tooltips) ttip = EdgesGraphModel::getEdgeTooltip(graph, tmpEdge); } // only http urls are valid if (!_url.empty() && _url.find("http://") != 0 && _url.find("https://")) _url.insert(0, "http://"); if (!_url.empty()) { // warn user that there is a web page associated to the current // graph element which can be opened with a space key press ttip.append(QString(ttip.isEmpty() ? "" : "\n\n")) .append(QString("hit <SPACE> bar to open <b>")) .append(tlpStringToQString(_url)) .append("</b>"); // give the focus to the parent widget // to ensure to catch the space key press _view->graphicsView()->viewport()->parentWidget()->setFocus(); } if (!ttip.isEmpty()) { // preserve current formatting ttip = QString("<p style='white-space:pre'><font size=\"-1\">") .append(ttip) .append(QString("</font></p>")); QToolTip::showText(he->globalPos(), ttip, _widget); return true; } } else { // be sure to hide the tooltip if the mouse cursor // is not under a node or an edge QToolTip::hideText(); event->ignore(); } } // if there is a current url to open, check for a space key press if (!_url.empty() && (event->type() == QEvent::KeyPress) && (static_cast<QKeyEvent *>(event)->key() == Qt::Key_Space)) { // open the current url QDesktopServices::openUrl(QUrl(tlpStringToQString(_url))); _url.clear(); return true; } return false; }