bool TreeWidget::viewportEvent(QEvent* event) { if (event->type() == QEvent::ToolTip) { QHelpEvent* he = static_cast<QHelpEvent*>(event); TreeItem* item = static_cast<TreeItem*>(itemAt(he->pos())); if (item && !item->parentItem() && !item->toolTip(0).isEmpty()) { QStyleOptionViewItem opt = viewOptions(); opt.icon = item->icon(0); opt.rect = visualItemRect(item); opt.features |= QStyleOptionViewItem::HasDecoration; QRect rect = style()->subElementRect(QStyle::SE_ItemViewItemDecoration, &opt, this); if (rect.contains(he->pos())) { #if QT_VERSION >= 0x050200 QToolTip::showText(he->globalPos(), item->toolTip(0), this, rect, 1250); #else QToolTip::showText(he->globalPos(), item->toolTip(0), this, rect); #endif } } return true; } return QTreeWidget::viewportEvent(event); }
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 KateViewSpace::eventFilter(QObject *obj, QEvent *event) { QToolButton *button = qobject_cast<QToolButton *>(obj); // quick open button: show tool tip with shortcut if (button == m_quickOpen && event->type() == QEvent::ToolTip) { QHelpEvent *e = static_cast<QHelpEvent *>(event); QAction *quickOpen = m_viewManager->mainWindow()->actionCollection()->action(QStringLiteral("view_quick_open")); Q_ASSERT(quickOpen); QToolTip::showText(e->globalPos(), button->toolTip() + QStringLiteral(" (%1)").arg(quickOpen->shortcut().toString()), button); return true; } // quick open button: What's This if (button == m_quickOpen && event->type() == QEvent::WhatsThis) { QHelpEvent *e = static_cast<QHelpEvent *>(event); const int hiddenDocs = hiddenDocuments(); QString helpText = (hiddenDocs == 0) ? i18n("Click here to switch to the Quick Open view.") : i18np("Currently, there is one more document open. To see all open documents, switch to the Quick Open view by clicking here.", "Currently, there are %1 more documents open. To see all open documents, switch to the Quick Open view by clicking here.", hiddenDocs); QWhatsThis::showText(e->globalPos(), helpText, m_quickOpen); return true; } // on mouse press on view space bar tool buttons: activate this space if (button && ! isActiveSpace() && event->type() == QEvent::MouseButtonPress) { m_viewManager->setActiveSpace(this); if (currentView()) { m_viewManager->activateView(currentView()->document()); } } return false; }
bool KrugovyeChasy::event(QEvent *e) { switch (e->type()) { case QEvent::ToolTip: { QHelpEvent *he = static_cast<QHelpEvent *>(e); QString chas = QString::number(mChas); QString chast = QString::number(mChast); QString dolya = QString::number(mDolya); if (chas.length() < 2) chas.prepend("0"); if (chast.length() < 2) chast.prepend("00"); else if (chast.length() < 3) chast.prepend("0"); if (dolya.length() < 2) dolya.prepend("000"); else if (dolya.length() < 3) dolya.prepend("00"); else if (dolya.length() < 4) dolya.prepend("0"); QString toolTip(tr("<b>%1:%2:%3</b><p style='white-space:pre'><b style='color: %4'>%5</b> - %6") .arg(chas).arg(chast).arg(dolya).arg(KDChetvertySutok_Cveta[CHETVERT(mChas)].second) .arg(KDChasy_Opisaniya[mChas - 1].first).arg(KDChasy_Opisaniya[mChas - 1].second)); QToolTip::showText(he->globalPos(), toolTip, this); return true; } default: return QWidget::event(e); } }
bool RSButtonOnText::isEventForThis(QObject *obj, QEvent *event, QPoint &point) { switch (event->type()) { case QEvent::MouseButtonPress://2 case QEvent::MouseButtonRelease://3 case QEvent::MouseButtonDblClick://4 case QEvent::MouseMove://5 { QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event); point = mouseEvent->pos(); } break; case QEvent::ToolTip://110 { QHelpEvent* helpEvent = static_cast<QHelpEvent*>(event); point = helpEvent->globalPos(); } break; default: return false; } if (!event->isAccepted()) return false;//Already other take this event (true by default) if (obj ==_textEditViewPort) { if (_textEdit){ QTextCursor cursor = _textEdit->cursorForPosition(point); if ( (_textCursor->anchor() <= cursor.anchor()) && (cursor.position() <= _textCursor->anchor()+_lenght)){ return true; } } } return false; }
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 QgsLayerTreeViewItemDelegate::helpEvent( QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index ) { if ( event && event->type() == QEvent::ToolTip ) { QHelpEvent *he = static_cast<QHelpEvent *>( event ); QgsLayerTreeNode *node = mLayerTreeView->layerTreeModel()->index2node( index ); if ( node ) { const QList<QgsLayerTreeViewIndicator *> indicators = mLayerTreeView->indicators( node ); if ( !indicators.isEmpty() ) { QStyleOptionViewItem opt = option; initStyleOption( &opt, index ); _fixStyleOption( opt ); QRect indRect = mLayerTreeView->style()->subElementRect( static_cast<QStyle::SubElement>( QgsLayerTreeViewProxyStyle::SE_LayerTreeItemIndicator ), &opt, mLayerTreeView ); if ( indRect.contains( he->pos() ) ) { int indicatorIndex = ( he->pos().x() - indRect.left() ) / indRect.height(); if ( indicatorIndex >= 0 && indicatorIndex < indicators.count() ) { const QString tooltip = indicators[indicatorIndex]->toolTip(); if ( !tooltip.isEmpty() ) { QToolTip::showText( he->globalPos(), tooltip, view ); return true; } } } } } } return QStyledItemDelegate::helpEvent( event, view, option, index ); }
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; }
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 GoBackActionWidget::event(QEvent *event) { if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick || event->type() == QEvent::Wheel) { QList<GesturesManager::GesturesContext> contexts; contexts << GesturesManager::ToolBarGesturesContext << GesturesManager::GenericGesturesContext; if (GesturesManager::startGesture(this, event, contexts)) { return true; } } if (event->type() == QEvent::ContextMenu) { QContextMenuEvent *contextMenuEvent = static_cast<QContextMenuEvent*>(event); if (contextMenuEvent) { if (contextMenuEvent->reason() == QContextMenuEvent::Mouse) { contextMenuEvent->accept(); return true; } event->accept(); Window *window = getWindow(); QMenu menu(this); menu.addAction(window ? window->getContentsWidget()->getAction(ActionsManager::ClearTabHistoryAction) : ActionsManager::getAction(ActionsManager::ClearTabHistoryAction, this)); menu.addAction(window ? window->getContentsWidget()->getAction(ActionsManager::PurgeTabHistoryAction) : ActionsManager::getAction(ActionsManager::PurgeTabHistoryAction, this)); ToolBarWidget *toolBar = qobject_cast<ToolBarWidget*>(parentWidget()); if (toolBar) { menu.addSeparator(); menu.addActions(ToolBarWidget::createCustomizationMenu(toolBar->getIdentifier(), QList<QAction*>(), &menu)->actions()); } menu.exec(contextMenuEvent->globalPos()); return true; } return false; } if (event->type() == QEvent::ToolTip) { QHelpEvent *helpEvent = dynamic_cast<QHelpEvent*>(event); if (helpEvent) { const QVector<QKeySequence> shortcuts = ActionsManager::getActionDefinition(ActionsManager::GoBackAction).shortcuts; QString toolTip = text() + (shortcuts.isEmpty() ? QString() : QLatin1String(" (") + shortcuts.at(0).toString(QKeySequence::NativeText) + QLatin1Char(')')); if (getWindow()) { const WindowHistoryInformation history = getWindow()->getContentsWidget()->getHistory(); if (!history.entries.isEmpty() && history.index > 0) { QString title = history.entries.at(history.index - 1).title; title = (title.isEmpty() ? tr("(Untitled)") : title.replace(QLatin1Char('&'), QLatin1String("&&"))); toolTip = title + QLatin1String(" (") + text() + (shortcuts.isEmpty() ? QString() : QLatin1String(" - ") + shortcuts.at(0).toString(QKeySequence::NativeText)) + QLatin1Char(')'); } } QToolTip::showText(helpEvent->globalPos(), toolTip); } return true; } return ActionWidget::event(event); }
bool LMPSystemTrayIcon::event (QEvent *event) { if (event->type () == QEvent::Wheel) { QWheelEvent *wheel = static_cast<QWheelEvent*> (event); emit changedVolume (wheel->delta ()); return true; } else if (event->type () == QEvent::ToolTip) { QHelpEvent *help = static_cast<QHelpEvent*> (event); QString text; if (PlayerTab_ && !CurrentSong_.Title_.isEmpty ()) { const QString& trackText = tr ("%1 (%2)") .arg ("<b>" + CurrentSong_.Title_ + "</b>") .arg ("<b>" + QTime ().addSecs (CurrentSong_.Length_).toString ("mm:ss") + "</b>"); auto ao = PlayerTab_->GetPlayer ()->GetAudioOutput (); int vol = 0; if (ao) { qreal volume = ao->volume (); vol = volume * 100; } const QString& volumeText = tr ("Volume: %1%") .arg (vol); text = QString ("<table border='0'>" "<tr><td align='center' valign='top' rowspan='5'><img src='%1' width='%2' height='%3'></td></tr>" "<tr><td><p style='white-space:pre;'>%4</p></td></tr>" "<tr><td><p style='white-space:pre;'>%5</p></td></tr>" "<tr><td><p style='white-space:pre;'>%6</p></td></tr>" "<tr><td><p style='white-space:pre;'>%7</p></td></tr>" "</table>") .arg (CurrentAlbumArt_) .arg (130) .arg (130) .arg (trackText) .arg ("<b>" + CurrentSong_.Album_ + "</b>") .arg ("<b>" + CurrentSong_.Artist_ + "</b>") .arg ("<em>" + volumeText + "</em>"); } else if (CurrentSong_.Title_.isEmpty ()) text = QString ("<table border='0'><tr>" "<td align='center' valign='middle'><img src='%1' width='%2' height='%3'></td>" "<td align='center' valign='middle'><b>%4</b><br>%5</td>" "</tr></table>") .arg ("lcicons:/lmp/resources/images/lmp.svg") .arg (48) .arg (48) .arg ("LMP") .arg (tr ("No track playing")); QToolTip::showText (help->globalPos (), text); return true; } return QSystemTrayIcon::event (event); }
bool KrTreeWidget::event(QEvent * event) { switch (event->type()) { // HACK: QT 4 Context menu key isn't handled properly case QEvent::ContextMenu: { QContextMenuEvent* ce = (QContextMenuEvent*) event; if (ce->reason() == QContextMenuEvent::Mouse) { QPoint pos = viewport()->mapFromGlobal(ce->globalPos()); QTreeWidgetItem * item = itemAt(pos); int column = columnAt(pos.x()); emit itemRightClicked(item, ce->globalPos(), column); return true; } else { if (currentItem()) { QRect r = visualItemRect(currentItem()); QPoint p = viewport()->mapToGlobal(QPoint(r.x() + 5, r.y() + 5)); emit itemRightClicked(currentItem(), p, currentColumn()); return true; } } } break; case QEvent::KeyPress: { // HACK: QT 4 Ctrl+A bug fix: Ctrl+A doesn't work if QTreeWidget contains parent / child items // Insert doesn't change the selections for multi selection modes QKeyEvent* ke = (QKeyEvent*) event; switch (ke->key()) { case Qt::Key_Insert: { if (ke->modifiers() != 0) break; QAbstractItemView::SelectionMode mode = selectionMode(); if (mode != QAbstractItemView::ContiguousSelection && mode != QAbstractItemView::ExtendedSelection && mode != QAbstractItemView::MultiSelection) break; ke->accept(); if (currentItem() == 0) return true; currentItem()->setSelected(!currentItem()->isSelected()); return true; } case Qt::Key_A: if (ke->modifiers() == Qt::ControlModifier) { QAbstractItemView::SelectionMode mode = selectionMode(); if (mode == QAbstractItemView::ContiguousSelection || mode == QAbstractItemView::ExtendedSelection || mode == QAbstractItemView::MultiSelection) { selectAll(); ke->accept(); return true; } } break; default: break; } } break; case QEvent::Resize: { QResizeEvent * re = (QResizeEvent *)event; if (!_inResize && re->oldSize() != re->size()) { if (_stretchingColumn != -1 && columnCount()) { QList< int > columnsSizes; int oldSize = 0; for (int i = 0; i != header()->count(); i++) { columnsSizes.append(header()->sectionSize(i)); oldSize += header()->sectionSize(i); } bool res = QTreeWidget::event(event); int newSize = viewport()->width(); int delta = newSize - oldSize; if (delta) { _inResize = true; for (int i = 0; i != header()->count(); i++) { if (i == _stretchingColumn) { int newNs = columnsSizes[ i ] + delta; if (newNs < 8) newNs = 8; header()->resizeSection(i, newNs); } else if (header()->sectionSize(i) != columnsSizes[ i ]) { header()->resizeSection(i, columnsSizes[ i ]); } } _inResize = false; } return res; } } break; } case QEvent::ToolTip: { QHelpEvent *he = static_cast<QHelpEvent*>(event); if (viewport()) { QPoint pos = viewport()->mapFromGlobal(he->globalPos()); QTreeWidgetItem * item = itemAt(pos); int column = columnAt(pos.x()); if (item) { if (!item->toolTip(column).isEmpty()) break; QString tip = item->text(column); int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1; int requiredWidth = QFontMetrics(font()).width(tip) + 2 * textMargin; if (column == 0 && indentation()) { int level = 0; QTreeWidgetItem *parent = item; while ((parent = parent->parent())) level++; if (rootIsDecorated()) level++; requiredWidth += level * indentation(); } QIcon icon = item->icon(column); if (!icon.isNull()) { QStyleOptionViewItem opts = viewOptions(); QSize iconSize = icon.actualSize(opts.decorationSize); requiredWidth += iconSize.width(); int pixmapMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, this) + 1; requiredWidth += 2 * pixmapMargin; } if (!tip.isEmpty() && (columnWidth(column) < requiredWidth)) QToolTip::showText(he->globalPos(), tip, this); return true; } } } break; default: break; } return QTreeWidget::event(event); }
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); }