Changeset 88488 in vbox
- Timestamp:
- Apr 13, 2021 10:10:31 AM (4 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpViewer.cpp
r88475 r88488 397 397 QTextBrowser::setSource(url); 398 398 QTextDocument *pDocument = document(); 399 iterateDocumentImages();400 399 if (!pDocument || pDocument->isEmpty()) 401 400 setText(tr("<div><p><h3>404. Not found.</h3>The page <b>%1</b> could not be found.</p></div>").arg(url.toString())); … … 405 404 m_pFindInPageWidget->clearSearchField(); 406 405 } 406 iterateDocumentImages(); 407 407 scaleImages(); 408 408 } … … 582 582 void UIHelpViewer::mouseReleaseEvent(QMouseEvent *pEvent) 583 583 { 584 bool fOverlayMode = m_fOverlayMode;584 // bool fOverlayMode = m_fOverlayMode; 585 585 clearOverlay(); 586 586 … … 598 598 QIWithRetranslateUI<QTextBrowser>::mouseReleaseEvent(pEvent); 599 599 600 if (!fOverlayMode)601 loadImageAtPosition(pEvent->globalPos());600 // if (!fOverlayMode) 601 // loadImageAtPosition(pEvent->globalPos()); 602 602 } 603 603 … … 638 638 QIWithRetranslateUI<QTextBrowser>::paintEvent(pEvent); 639 639 640 if (m_pOverlayLabel) 641 { 642 if (m_fOverlayMode) 643 { 644 /* Scale the image to 1005 as long as it fits into avaible space (minus some margins and scrollbar sizes): */ 645 int vWidth = 0; 646 if (verticalScrollBar() && verticalScrollBar()->isVisible()) 647 vWidth = verticalScrollBar()->width(); 648 int hMargin = qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin) + 649 qApp->style()->pixelMetric(QStyle::PM_LayoutRightMargin) + vWidth; 650 651 int hHeight = 0; 652 if (horizontalScrollBar() && horizontalScrollBar()->isVisible()) 653 hHeight = horizontalScrollBar()->height(); 654 int vMargin = qApp->style()->pixelMetric(QStyle::PM_LayoutTopMargin) + 655 qApp->style()->pixelMetric(QStyle::PM_LayoutBottomMargin) + hHeight; 656 657 QSize size(qMin(width() - hMargin, m_overlayPixmap.width()), 658 qMin(height() - vMargin, m_overlayPixmap.height())); 659 m_pOverlayLabel->setPixmap(m_overlayPixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation)); 660 /* Center the label: */ 661 int x = 0.5 * (width() - vWidth - m_pOverlayLabel->width()); 662 int y = 0.5 * (height() - hHeight - m_pOverlayLabel->height()); 663 m_pOverlayLabel->move(x, y); 664 m_pOverlayLabel->show(); 665 } 666 else 667 m_pOverlayLabel->hide(); 668 } 640 641 // if (m_pOverlayLabel) 642 // { 643 // if (m_fOverlayMode) 644 // { 645 // /* Scale the image to 1:1 as long as it fits into avaible space (minus some margins and scrollbar sizes): */ 646 // int vWidth = 0; 647 // if (verticalScrollBar() && verticalScrollBar()->isVisible()) 648 // vWidth = verticalScrollBar()->width(); 649 // int hMargin = qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin) + 650 // qApp->style()->pixelMetric(QStyle::PM_LayoutRightMargin) + vWidth; 651 652 // int hHeight = 0; 653 // if (horizontalScrollBar() && horizontalScrollBar()->isVisible()) 654 // hHeight = horizontalScrollBar()->height(); 655 // int vMargin = qApp->style()->pixelMetric(QStyle::PM_LayoutTopMargin) + 656 // qApp->style()->pixelMetric(QStyle::PM_LayoutBottomMargin) + hHeight; 657 658 // QSize size(qMin(width() - hMargin, m_overlayPixmap.width()), 659 // qMin(height() - vMargin, m_overlayPixmap.height())); 660 // m_pOverlayLabel->setPixmap(m_overlayPixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation)); 661 // /* Center the label: */ 662 // int x = 0.5 * (width() - vWidth - m_pOverlayLabel->width()); 663 // int y = 0.5 * (height() - hHeight - m_pOverlayLabel->height()); 664 // m_pOverlayLabel->move(x, y); 665 // m_pOverlayLabel->show(); 666 // } 667 // else 668 // m_pOverlayLabel->hide(); 669 // } 669 670 } 670 671 … … 860 861 if (cursor.charFormat().isImageFormat()) 861 862 { 862 DocumentImage image;863 863 QTextImageFormat imageFormat = cursor.charFormat().toImageFormat(); 864 /* There seems to be two cursors per image. Use the first one: */ 865 if (m_imageMap.contains(imageFormat.name())) 866 continue; 867 QHash<QString, DocumentImage>::iterator iterator = m_imageMap.insert(imageFormat.name(), DocumentImage()); 868 DocumentImage &image = iterator.value(); 864 869 image.m_fInitialWidth = imageFormat.width(); 865 image.m_iPosition = cursor.position(); 866 m_imageMap[imageFormat.name()] = image; 870 //image.m_iPosition = cursor.position(); 871 image.m_textCursor = cursor; 872 QUrl imageFileUrl; 873 foreach (const QUrl &fileUrl, m_helpFileList) 874 { 875 if (fileUrl.toString().contains(imageFormat.name(), Qt::CaseInsensitive)) 876 { 877 imageFileUrl = fileUrl; 878 break; 879 } 880 } 881 if (imageFileUrl.isValid()) 882 { 883 QByteArray fileData = m_pHelpEngine->fileData(imageFileUrl); 884 if (!fileData.isEmpty()) 885 image.m_pixmap.loadFromData(fileData,"PNG"); 886 } 867 887 } 868 888 } … … 878 898 void UIHelpViewer::scaleImages() 879 899 { 880 for (QMap<QString, DocumentImage>::iterator iterator = m_imageMap.begin(); 881 iterator != m_imageMap.end(); ++iterator) 882 { 883 QTextCursor cursor = textCursor(); 884 cursor.movePosition(QTextCursor::Start); 885 cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, (*iterator).m_iPosition); 886 if (cursor.isNull()) 887 continue; 900 // for (QHash<QString, DocumentImage>::iterator iterator = m_imageMap.begin(); 901 // iterator != m_imageMap.end(); ++iterator) 902 foreach(const DocumentImage &image, m_imageMap) 903 { 904 905 // QTextCursor cursor = textCursor(); 906 // cursor.movePosition(QTextCursor::Start); 907 // cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, image.m_iPosition); 908 // if (cursor.isNull()) 909 // continue; 910 QTextCursor cursor = image.m_textCursor; 888 911 QTextCharFormat format = cursor.charFormat(); 889 912 if (!format.isImageFormat()) 890 913 continue; 891 914 QTextImageFormat imageFormat = format.toImageFormat(); 892 imageFormat.setWidth( (*iterator).m_fInitialWidth * m_iZoomPercentage / 100.);915 imageFormat.setWidth(image.m_fInitialWidth * m_iZoomPercentage / 100.); 893 916 cursor.deletePreviousChar(); 917 cursor.deleteChar(); 894 918 cursor.insertImage(imageFormat); 895 919 } -
trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpViewer.h
r88438 r88488 109 109 { 110 110 qreal m_fInitialWidth; 111 int m_iPosition; 111 //int m_iPosition; 112 QTextCursor m_textCursor; 113 QPixmap m_pixmap; 112 114 }; 113 115 … … 136 138 int m_iInitialFontPointSize; 137 139 /** A container to store the original image sizes/positions in the document. key is image name value is DocumentImage. */ 138 Q Map<QString, DocumentImage> m_imageMap;140 QHash<QString, DocumentImage> m_imageMap; 139 141 /** As percentage. */ 140 142 int m_iZoomPercentage;
Note:
See TracChangeset
for help on using the changeset viewer.