- Timestamp:
- Mar 22, 2023 1:11:49 PM (19 months ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser
- Files:
-
- 2 edited
-
UIHelpViewer.cpp (modified) (9 diffs)
-
UIHelpViewer.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpViewer.cpp
r98103 r99115 42 42 #include <QGraphicsBlurEffect> 43 43 #include <QLabel> 44 #include <QMimeDatabase> 44 45 #include <QPainter> 45 46 #include <QScrollBar> … … 410 411 , m_iSearchTermLength(0) 411 412 , m_fOverlayMode(false) 412 , m_fCursorChanged(false)413 413 , m_pOverlayLabel(0) 414 414 , m_iZoomPercentage(100) … … 427 427 connect(m_pFindInPageWidget, &UIFindInPageWidget::sigClose, 428 428 this, &UIHelpViewer::sltCloseFindInPageWidget); 429 430 m_defaultCursor = cursor();431 m_handCursor = QCursor(Qt::PointingHandCursor);432 429 433 430 m_pFindInPageWidget->setVisible(false); … … 675 672 void UIHelpViewer::mouseReleaseEvent(QMouseEvent *pEvent) 676 673 { 674 /* If overlay mode is active just clear it and return: */ 677 675 bool fOverlayMode = m_fOverlayMode; 678 676 clearOverlay(); 679 677 if (fOverlayMode) 678 return; 680 679 QString strAnchor = anchorAt(pEvent->pos()); 681 680 682 681 if (!strAnchor.isEmpty()) 683 682 { 684 685 683 QString strLink = source().resolved(strAnchor).toString(); 686 684 QFileInfo fInfo(strLink); 685 QMimeDatabase base; 686 QMimeType type = base.mimeTypeForFile(fInfo); 687 if (type.isValid() && type.inherits("image/png")) 688 { 689 if (!fOverlayMode) 690 loadImage(source().resolved(strAnchor)); 691 return; 692 } 687 693 if (source().resolved(strAnchor).scheme() != "qthelp" && pEvent->button() == Qt::LeftButton) 688 694 { … … 700 706 } 701 707 QIWithRetranslateUI<QTextBrowser>::mousePressEvent(pEvent); 702 703 if (!fOverlayMode)704 loadImageAtPosition(pEvent->globalPos());705 708 } 706 709 … … 710 713 } 711 714 712 void UIHelpViewer::setImageOverCursor(QPoint globalPosition)713 {714 QPoint viewportCoordinates = viewport()->mapFromGlobal(globalPosition);715 QTextCursor cursor = cursorForPosition(viewportCoordinates);716 if (!m_fCursorChanged && cursor.charFormat().isImageFormat())717 {718 m_fCursorChanged = true;719 UICursor::setCursor(viewport(), m_handCursor);720 emit sigMouseOverImage(cursor.charFormat().toImageFormat().name());721 }722 if (m_fCursorChanged && !cursor.charFormat().isImageFormat())723 {724 UICursor::setCursor(viewport(), m_defaultCursor);725 m_fCursorChanged = false;726 }727 728 }729 730 715 void UIHelpViewer::mouseMoveEvent(QMouseEvent *pEvent) 731 716 { 732 if (m_fOverlayMode) 733 return; 734 setImageOverCursor(pEvent->globalPos()); 717 /*if (m_fOverlayMode) 718 return;*/ 735 719 QIWithRetranslateUI<QTextBrowser>::mouseMoveEvent(pEvent); 736 720 } … … 1021 1005 { 1022 1006 AssertReturnVoid(m_pOverlayLabel); 1023 setImageOverCursor(cursor().pos());1024 1007 1025 1008 if (!m_fOverlayMode) … … 1038 1021 if (m_pOverlayBlurEffect) 1039 1022 m_pOverlayBlurEffect->setEnabled(true); 1040 UICursor::setCursor(viewport(), m_defaultCursor);1041 m_fCursorChanged = false;1042 1023 toggleFindInPageWidget(false); 1043 1024 … … 1066 1047 } 1067 1048 1068 void UIHelpViewer::loadImage AtPosition(const QPoint &globalPosition)1049 void UIHelpViewer::loadImage(const QUrl &imageFileUrl) 1069 1050 { 1070 1051 clearOverlay(); 1071 QPoint viewportCoordinates = viewport()->mapFromGlobal(globalPosition);1072 QTextCursor cursor = cursorForPosition(viewportCoordinates);1073 if (!cursor.charFormat().isImageFormat())1074 return;1075 1052 /* Dont zoom into image if mouse button released after a mouse drag: */ 1076 1053 if (textCursor().hasSelection()) 1077 1054 return; 1078 1079 QTextImageFormat imageFormat = cursor.charFormat().toImageFormat();1080 QUrl imageFileUrl;1081 foreach (const QUrl &fileUrl, m_helpFileList)1082 {1083 if (fileUrl.toString().contains(imageFormat.name(), Qt::CaseInsensitive))1084 {1085 imageFileUrl = fileUrl;1086 break;1087 }1088 }1089 1090 1055 if (!imageFileUrl.isValid()) 1091 1056 return; -
trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpViewer.h
r98103 r99115 49 49 * rendering and didn't want to use WebKit module, this extension redraws the document images as overlays with improved QPainter 50 50 * parameters. There is also a small hack to render clicked image 1:1 (and the rest of the document blurred) 51 * for a zoom-in-image functionality. This extension can also scale the images while scaling the document. In contrast 51 * for a zoom-in-image functionality. This extension can also scale the images while scaling the document. In contrast, 52 52 * QTextBrowser scales only fonts. */ 53 53 class UIHelpViewer : public QIWithRetranslateUI<QTextBrowser> … … 147 147 void scaleFont(); 148 148 void scaleImages(); 149 /** If there is image at @p globalPosition then its data is loaded to m_overlayPixmap. */ 150 void loadImageAtPosition(const QPoint &globalPosition); 149 void loadImage(const QUrl &imageFileUrl); 151 150 void clearOverlay(); 152 151 void enableOverlay(); 153 void setImageOverCursor(QPoint globalPosition);154 152 155 153 const QHelpEngine* m_pHelpEngine; … … 165 163 /** A container to store the original image sizes/positions in the document. key is image name value is DocumentImage. */ 166 164 QHash<QString, DocumentImage> m_imageMap; 167 /** Used to change th document cursor back from m_handCursor. */168 QCursor m_defaultCursor;169 QCursor m_handCursor;170 165 /** We need this list from th QHelp system to obtain information of images. */ 171 166 QList<QUrl> m_helpFileList; 172 167 QPixmap m_overlayPixmap; 173 168 bool m_fOverlayMode; 174 bool m_fCursorChanged;175 169 QLabel *m_pOverlayLabel; 176 170 QGraphicsBlurEffect *m_pOverlayBlurEffect;
Note:
See TracChangeset
for help on using the changeset viewer.

