bool MapWidget::eventFilter(QObject *object, QEvent *ev) { if (ev->type() == QEvent::ToolTip) { QHelpEvent *event = static_cast<QHelpEvent *>(ev); QPoint mousePosition = event->pos(); //check if mouse is intercepting some marker and show country name as tooltip for (const MapMarker &marker : markers) { QPointF markerPosition = getMarkerScreenCoordinate(marker); QRectF markerRect(markerPosition.x() - 2.5, markerPosition.y() - 2.5, 5, 5); if (markerRect.contains(QPointF(mousePosition))) { QToolTip::showText(event->globalPos(), marker.getCountryName()); return true; }else { QToolTip::hideText(); event->ignore(); } } } return QWidget::eventFilter(object, ev); }
// Trap for help/tool-tip events. bool qtractorFileListView::eventFilter ( QObject *pObject, QEvent *pEvent ) { QWidget *pViewport = QTreeWidget::viewport(); if (static_cast<QWidget *> (pObject) == pViewport && pEvent->type() == QEvent::ToolTip) { QHelpEvent *pHelpEvent = static_cast<QHelpEvent *> (pEvent); if (pHelpEvent) { QTreeWidgetItem *pItem = QTreeWidget::itemAt(pHelpEvent->pos()); qtractorFileGroupItem *pFileItem = static_cast<qtractorFileGroupItem *> (pItem); if (pFileItem) { QToolTip::showText(pHelpEvent->globalPos(), pFileItem->toolTip(), pViewport); return true; } } } // Not handled here. return QTreeWidget::eventFilter(pObject, pEvent); }
bool TextBrowserHelpWidget::eventFilter(QObject *obj, QEvent *event) { if (obj == this) { if (event->type() == QEvent::FontChange) { if (!forceFont) return true; } else if (event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); if (keyEvent->key() == Qt::Key_Slash) { keyEvent->accept(); Core::FindPlugin::instance()->openFindToolBar(Core::FindPlugin::FindForwardDirection); return true; } } else if (event->type() == QEvent::ToolTip) { QHelpEvent *e = static_cast<QHelpEvent *>(event); QToolTip::showText(e->globalPos(), linkAt(e->pos())); return true; } } return QTextBrowser::eventFilter(obj, event); }
bool QFCompleterTextEditNumberBar::event(QEvent *event) { if (event->type() == QEvent::ToolTip) { QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event); // now we have to check whether any marker is at this position int item=-1; bool found=false; QMapIterator<int, itemData> i(markers); while (i.hasNext() && !found) { i.next(); itemData d=i.value(); if (d.rect.contains(helpEvent->pos())) { item=d.line; } } if (item>-1) QToolTip::showText(helpEvent->globalPos(), markers[item].message); else QToolTip::hideText(); } return QWidget::event(event); }
bool BookTreeView::viewportEvent(QEvent* event) { if (event->type() == QEvent::ToolTip) { QHelpEvent *helpEvent = (QHelpEvent *) event; QModelIndex book = indexAt(helpEvent->pos()); // if it's not a book don't show anything if (book.data(CollectionTreeModel::UrlRole).isNull()) { return QTreeView::viewportEvent(event); } QString location = book.data(CollectionTreeModel::UrlRole).toString(); QString summary = book.data(CollectionTreeModel::SummaryRole).toString(); QString cacheKey = book.data(CollectionTreeModel::LargePreviewRole).toString(); emit dataRequested(location, summary, cacheKey); return true; } else { return QTreeView::viewportEvent(event); } }
bool CView::event(QEvent *event) { if (event->type() == QEvent::ToolTip) { QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event); QGraphicsItem* pItem = itemAt(helpEvent->pos()); if (pItem != NULL) { QString strToolTip ;//= m_PluginLoader->getToolTip(pItem,m_appID); if (!strToolTip.isEmpty()) { QToolTip::showText(helpEvent->globalPos(), strToolTip); } } else { QToolTip::hideText(); event->ignore(); } } return QGraphicsView::event(event); }
bool SearchList::event(QEvent *e) { if (e->type() == QEvent::ToolTip) { QHelpEvent *hEvent = static_cast<QHelpEvent *>(e); QPoint pt = m_pList->mapFromParent(hEvent->pos()); pt.setY(pt.y() - m_pList->header()->height()); QTreeWidgetItem* pItem = m_pList->itemAt(pt); if (pItem) { QString sTip; getTip(pItem, sTip); QToolTip::showText(hEvent->globalPos(), sTip); } else { QToolTip::hideText(); e->ignore(); } return true; } return QWidget::event(e); }
bool TableViewTooltip::eventFilter(QObject * obj, QEvent * event) { if (event->type() != QEvent::ToolTip) { return false; } QAbstractItemView* view = qobject_cast<QAbstractItemView*>(obj->parent()); if (!view) { return false; } QHelpEvent * helpEvent = static_cast<QHelpEvent*>(event); QPoint pos = helpEvent->pos(); QModelIndex index = view->indexAt(pos); if (!index.isValid()) { return false; } QString itemTooltip = view->model()->data(index, Qt::ToolTipRole).toString(); if (itemTooltip.isEmpty()) { QToolTip::hideText(); return true; } QString itemText = view->model()->data(index).toString(); QFontMetrics fm(view->font()); int textIdentWidth =6;// fm.width('r'); // don't know how to calculate an ident for text in an item :-( int itemTextWidth = fm.width(itemText) + textIdentWidth; QRect rect = view->visualRect(index); int rectWidth = rect.width(); if (itemTextWidth > rectWidth) { QToolTip::showText(helpEvent->globalPos(), itemTooltip, view, rect); } else { QToolTip::hideText(); } return true; }
bool QFoldPanel::event(QEvent *e) { if (e->type() == QEvent::ToolTip) { QDocument *doc = editor()->document(); QLanguageDefinition *def = doc->languageDefinition(); QHelpEvent* helpEvent = static_cast<QHelpEvent*>(e); int line = mapRectPosToLine(helpEvent->pos()); if ( def && doc && line != -1 && doc->line(line).hasFlag(QDocumentLine::CollapsedBlockStart) ){ QFoldedLineIterator it = def->foldedLineIterator(doc, line); it.incrementUntilBlockEnd(); QString tooltip; int lineWidth = 80; int maxShownLines = 9; int wrapCount = 2; if (editor()->flag(QEditor::HardLineWrap)) { lineWidth = -1; // rely on wrapping of editor maxShownLines = 15; wrapCount = 0; } if (it.lineNr - line < maxShownLines) tooltip = doc->exportAsHtml(doc->cursor(line,0,it.lineNr),true,true,lineWidth,wrapCount); else { tooltip = doc->exportAsHtml(doc->cursor(line,0,line+maxShownLines/2),true,true,lineWidth,wrapCount); tooltip.replace("</body></html>",""); tooltip += "<br>...<br>"; tooltip += doc->exportAsHtml(doc->cursor(it.lineNr-maxShownLines/2,0,it.lineNr),false,true,lineWidth,wrapCount); tooltip += "</body></html>"; } if (tooltip.isEmpty()) QToolTip::hideText(); else QToolTip::showText(helpEvent->globalPos(), tooltip); e->setAccepted(true); } } return QWidget::event(e); }
bool UIMenu::event(QEvent *pEvent) { /* Handle particular event-types: */ switch (pEvent->type()) { /* Tool-tip request handler: */ case QEvent::ToolTip: { /* Get current help-event: */ QHelpEvent *pHelpEvent = static_cast<QHelpEvent*>(pEvent); /* Get action which caused help-event: */ QAction *pAction = actionAt(pHelpEvent->pos()); /* If action present => show action's tool-tip if needed: */ if (pAction && m_fShowToolTips) QToolTip::showText(pHelpEvent->globalPos(), pAction->toolTip()); break; } default: break; } /* Base-class event-handler: */ return QMenu::event(pEvent); }
bool ColumnToolTip::eventFilter(QObject* obj, QEvent* event) { if (event->type() == QEvent::ToolTip) { QAbstractItemView* view = qobject_cast<QAbstractItemView*>(obj->parent()); if (!view) { return false; } QHelpEvent* helpEvent = static_cast<QHelpEvent*>(event); QPoint pos = helpEvent->pos(); QModelIndex index = view->indexAt(pos); if (!index.isValid()) return false; QString itemText = view->model()->data(index).toString(); QString itemTooltip = view->model()->data(index, Qt::ToolTipRole).toString(); QFontMetrics fm(view->font()); int itemTextWidth = fm.width(itemText); QRect rect = view->visualRect(index); int rectWidth = rect.width(); if ((itemTextWidth > rectWidth) && !itemTooltip.isEmpty()) { QToolTip::showText(helpEvent->globalPos(), itemTooltip, view, rect); } else { QToolTip::hideText(); } return true; } return false; }
bool KoDocumentSectionDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) { if ((event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick) && (index.flags() & Qt::ItemIsEnabled)) { QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event); const QRect iconsRect_ = iconsRect(option, index).translated(option.rect.topLeft()); if (iconsRect_.isValid() && iconsRect_.contains(mouseEvent->pos())) { const int iconWidth = option.decorationSize.width(); int xPos = mouseEvent->pos().x() - iconsRect_.left(); if (xPos % (iconWidth + d->margin) < iconWidth) { //it's on an icon, not a margin Model::PropertyList propertyList = index.data(Model::PropertiesRole).value<Model::PropertyList>(); int clickedProperty = -1; // Discover which of all properties was clicked for (int i = 0; i < propertyList.count(); ++i) { if (propertyList[i].isMutable) { xPos -= iconWidth + d->margin; } ++clickedProperty; if (xPos < 0) break; } // Using Ctrl+click to enter stasis if (mouseEvent->modifiers() == Qt::ControlModifier && propertyList[clickedProperty].canHaveStasis) { // STEP 0: Prepare to Enter or Leave control key stasis quint16 numberOfLeaves = model->rowCount(index.parent()); QModelIndex eachItem; // STEP 1: Go. if (propertyList[clickedProperty].isInStasis == false) { // Enter /* Make every leaf of this node go State = False, saving the old property value to stateInStasis */ for (quint16 i = 0; i < numberOfLeaves; ++i) { // Foreach leaf in the node (index.parent()) eachItem = model->index(i, 0, index.parent()); // The entire property list has to be altered because model->setData cannot set individual properties Model::PropertyList eachPropertyList = eachItem.data(Model::PropertiesRole).value<Model::PropertyList>(); eachPropertyList[clickedProperty].stateInStasis = eachPropertyList[clickedProperty].state.toBool(); eachPropertyList[clickedProperty].state = false; eachPropertyList[clickedProperty].isInStasis = true; model->setData(eachItem, QVariant::fromValue(eachPropertyList), Model::PropertiesRole); } /* Now set the current node's clickedProperty back to True, to save the user time (obviously, if the user is clicking one item with ctrl+click, he's interested in that item to have a True property value while the others are in stasis and set to False) */ // First refresh propertyList, otherwise old data will be saved back causing bugs propertyList = index.data(Model::PropertiesRole).value<Model::PropertyList>(); propertyList[clickedProperty].state = true; model->setData(index, QVariant::fromValue(propertyList), Model::PropertiesRole); } else { // Leave /* Make every leaf of this node go State = stateInStasis */ for (quint16 i = 0; i < numberOfLeaves; ++i) { eachItem = model->index(i, 0, index.parent()); // The entire property list has to be altered because model->setData cannot set individual properties Model::PropertyList eachPropertyList = eachItem.data(Model::PropertiesRole).value<Model::PropertyList>(); eachPropertyList[clickedProperty].state = eachPropertyList[clickedProperty].stateInStasis; eachPropertyList[clickedProperty].isInStasis = false; model->setData(eachItem, QVariant::fromValue(eachPropertyList), Model::PropertiesRole); } } } else { propertyList[clickedProperty].state = !propertyList[clickedProperty].state.toBool(); model->setData(index, QVariant::fromValue(propertyList), Model::PropertiesRole); } } return true; } if (mouseEvent->button() != Qt::LeftButton) { d->view->setCurrentIndex(index); return false; } } else if (event->type() == QEvent::ToolTip) { QHelpEvent *helpEvent = static_cast<QHelpEvent*>(event); d->tip.showTip(d->view, helpEvent->pos(), option, index); return true; } else if (event->type() == QEvent::Leave) { d->tip.hide(); } return false; }
bool ContactListView::event( QEvent *e ) { if( e->type() != QEvent::ToolTip ) return K3ListView::event( e ); if ( !tooltips() ) return true; QHelpEvent * he = static_cast< QHelpEvent * >( e ); QPoint pnt = viewport()->mapFromGlobal( mapToGlobal( he->pos() ) ); Q3ListViewItem * item = itemAt ( pnt ); if ( item ) { ContactListViewItem *plvi = static_cast<ContactListViewItem *>( item ); QString s; //kDebug(5720) <<"Tip rec:" << r.x() <<"," << r.y() <<"," << r.width() // << "," << r.height(); KABC::Addressee a = plvi->addressee(); if (a.isEmpty()) return true; s += i18nc("label: value", "%1: %2", a.formattedNameLabel(), a.formattedName()); s += '\n'; s += i18nc("label: value", "%1: %2", a.organizationLabel(), a.organization()); QString notes = a.note().trimmed(); if ( !notes.isEmpty() ) { notes += '\n'; s += '\n' + i18nc("label: value", "%1: \n", a.noteLabel()); QFontMetrics fm( font() ); // Begin word wrap code based on QMultiLineEdit code int i = 0; bool doBreak = false; int linew = 0; int lastSpace = -1; int a = 0; int lastw = 0; while ( i < int(notes.length()) ) { doBreak = false; if ( notes[i] != '\n' ) linew += fm.width( notes[i] ); if ( lastSpace >= a && notes[i] != '\n' ) if (linew >= parentWidget()->width()) { doBreak = true; if ( lastSpace > a ) { i = lastSpace; linew = lastw; } else i = qMax( a, i-1 ); } if ( notes[i] == '\n' || doBreak ) { s += notes.mid( a, i - a + (doBreak?1:0) ) +'\n'; a = i + 1; lastSpace = a; linew = 0; } if ( notes[i].isSpace() ) { lastSpace = i; lastw = linew; } if ( lastSpace <= a ) { lastw = linew; } ++i; } } if ( s.isEmpty() ) QToolTip::hideText(); else QToolTip::showText( he->globalPos(), s ); } return true; }
bool TabTreeView::viewportEvent(QEvent *event) { switch (event->type()) { case QEvent::MouseButtonPress: { QMouseEvent *me = static_cast<QMouseEvent*>(event); const QModelIndex index = indexAt(me->pos()); updateIndex(index); WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>(); if (me->buttons() == Qt::MiddleButton && tab) { tab->closeTab(); } if (me->buttons() != Qt::LeftButton) { m_pressedIndex = QModelIndex(); m_pressedButton = NoButton; break; } m_pressedIndex = index; m_pressedButton = buttonAt(me->pos(), m_pressedIndex); if (m_pressedIndex.isValid()) { if (m_pressedButton == ExpandButton) { if (isExpanded(m_pressedIndex)) { collapse(m_pressedIndex); } else { expand(m_pressedIndex); } } else if (m_pressedButton == NoButton && tab) { tab->makeCurrentTab(); } } if (m_pressedButton == CloseButton) { me->accept(); return true; } break; } case QEvent::MouseMove: { QMouseEvent *me = static_cast<QMouseEvent*>(event); if (m_pressedButton == CloseButton) { me->accept(); return true; } break; } case QEvent::MouseButtonRelease: { QMouseEvent *me = static_cast<QMouseEvent*>(event); if (me->buttons() != Qt::NoButton) { break; } const QModelIndex index = indexAt(me->pos()); updateIndex(index); if (m_pressedIndex != index) { break; } DelegateButton button = buttonAt(me->pos(), index); if (m_pressedButton == button) { if (m_pressedButton == ExpandButton) { me->accept(); return true; } WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>(); if (tab) { if (m_pressedButton == CloseButton) { tab->closeTab(); } else if (m_pressedButton == AudioButton) { tab->toggleMuted(); } } } if (m_pressedButton == CloseButton) { me->accept(); return true; } break; } case QEvent::HoverEnter: case QEvent::HoverLeave: case QEvent::HoverMove: { QHoverEvent *he = static_cast<QHoverEvent*>(event); updateIndex(m_hoveredIndex); m_hoveredIndex = indexAt(he->pos()); updateIndex(m_hoveredIndex); break; } case QEvent::ToolTip: { QHelpEvent *he = static_cast<QHelpEvent*>(event); const QModelIndex index = indexAt(he->pos()); DelegateButton button = buttonAt(he->pos(), index); if (button == AudioButton) { const bool muted = index.data(TabModel::AudioMutedRole).toBool(); QToolTip::showText(he->globalPos(), muted ? tr("Unmute Tab") : tr("Mute Tab"), this, visualRect(index)); he->accept(); return true; } else if (button == CloseButton) { QToolTip::showText(he->globalPos(), tr("Close Tab"), this, visualRect(index)); he->accept(); return true; } else if (button == NoButton) { QToolTip::showText(he->globalPos(), index.data().toString(), this, visualRect(index)); he->accept(); return true; } break; } case QEvent::ContextMenu: { QContextMenuEvent *ce = static_cast<QContextMenuEvent*>(event); const QModelIndex index = indexAt(ce->pos()); WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>(); const int tabIndex = tab ? tab->tabIndex() : -1; TabContextMenu::Options options = TabContextMenu::VerticalTabs | TabContextMenu::ShowDetachTabAction; if (m_tabsInOrder) { options |= TabContextMenu::ShowCloseOtherTabsActions; } TabContextMenu menu(tabIndex, m_window, options); addMenuActions(&menu, index); menu.exec(ce->globalPos()); break; } default: break; } return QTreeView::viewportEvent(event); }
bool MainWindow::eventFilter(QObject *obj, QEvent *event) { switch(event->type()) { case QEvent::ToolTip: { if (obj != viewer) break; QHelpEvent* e = static_cast<QHelpEvent*>(event); if (attributeRect.contains(e->pos())){ QString attribute = viewer->attribute(); if(!attribute.isEmpty()) ToolTip::showText(e->globalPos(), attribute.prepend("<b>").append("</b>"), false, 0.8); } return true; } case QEvent::MouseButtonDblClick: { if (obj != viewer && obj != bottomFrame) break; QMouseEvent *e = static_cast<QMouseEvent*>(event); if(e->button() & Qt::LeftButton) changeFullScreen(); return true; } case QEvent::ContextMenu: { QContextMenuEvent *e = static_cast<QContextMenuEvent*>(event); showContextMenu(e->globalPos()); return true; } case QEvent::Wheel: { QWheelEvent *e = static_cast<QWheelEvent *>(event); // if (e->delta() < 0) // viewer->nextPic(); // else // viewer->prePic(); qreal factor = 0.1; switch(e->modifiers()){ case Qt::ShiftModifier: factor = e->delta() / qreal(2400); // e->delta() is +120 or -120 break; case Qt::ControlModifier: factor = e->delta() / qreal(600); break; default: factor = e->delta() / qreal(1200); break; } viewer->zoomIn(factor, viewer->mapFromGlobal(e->globalPos())); break; } default: break; } return false; }
bool OutlineWidget::viewportEvent(QEvent *event) { if (event->type() == QEvent::ToolTip) { QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event); QTreeWidgetItem* it = itemAt(helpEvent->pos()); if (it != 0) { OutlineTreeItem *item = (OutlineTreeItem*)it; if (item != NULL) { QString tipText(""); if ((item->type == 1) || (item->type == 3) || (item->type == 4)) { PageItem *pgItem = item->PageItemObject; switch (pgItem->itemType()) { case PageItem::ImageFrame: if (pgItem->asLatexFrame()) tipText = CommonStrings::itemType_LatexFrame; #ifdef HAVE_OSG else if (pgItem->asOSGFrame()) tipText = CommonStrings::itemType_OSGFrame; #endif else tipText = CommonStrings::itemType_ImageFrame; break; case PageItem::TextFrame: switch (pgItem->annotation().Type()) { case 2: tipText = CommonStrings::itemSubType_PDF_PushButton; break; case 3: tipText = CommonStrings::itemSubType_PDF_TextField; break; case 4: tipText = CommonStrings::itemSubType_PDF_CheckBox; break; case 5: tipText = CommonStrings::itemSubType_PDF_ComboBox; break; case 6: tipText = CommonStrings::itemSubType_PDF_ListBox; break; case 10: tipText = CommonStrings::itemSubType_PDF_TextAnnotation; break; case 11: tipText = CommonStrings::itemSubType_PDF_LinkAnnotation; break; default: tipText = CommonStrings::itemType_TextFrame; break; } break; case PageItem::Line: tipText = CommonStrings::itemType_Line; break; case PageItem::Polygon: tipText = CommonStrings::itemType_Polygon; break; case PageItem::PolyLine: tipText = CommonStrings::itemType_Polyline; break; case PageItem::PathText: tipText = CommonStrings::itemType_PathText; break; default: break; } QToolTip::showText(helpEvent->globalPos(), tipText, this); return true; } } } } return QTreeWidget::viewportEvent(event); }