VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpViewer.h@ 93115

Last change on this file since 93115 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1/* $Id: UIHelpViewer.h 93115 2022-01-01 11:31:46Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIHelpBrowserWidget class declaration.
4 */
5
6/*
7 * Copyright (C) 2010-2022 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef FEQT_INCLUDED_SRC_helpbrowser_UIHelpViewer_h
19#define FEQT_INCLUDED_SRC_helpbrowser_UIHelpViewer_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24/* Qt includes: */
25#include <QTextBrowser>
26
27/* GUI includes: */
28#include "QIWithRetranslateUI.h"
29
30/* Forward declarations: */
31class QHelpEngine;
32class QGraphicsBlurEffect;
33class QLabel;
34class UIFindInPageWidget;
35
36#ifdef VBOX_WITH_QHELP_VIEWER
37
38/** A QTextBrowser extension used as poor man's html viewer. Since we were not happy with the quality of QTextBrowser's image
39 * rendering and didn't want to use WebKit module, this extension redraws the document images as overlays with improved QPainter
40 * parameters. There is also a small hack to render clicked image 1:1 (and the rest of the document blurred)
41 * for a zoom-in-image functionality. This extension can also scale the images while scaling the document. In contrast
42 * QTextBrowser scales only fonts. */
43class UIHelpViewer : public QIWithRetranslateUI<QTextBrowser>
44{
45
46 Q_OBJECT;
47
48signals:
49
50 void sigOpenLinkInNewTab(const QUrl &url, bool fBackground);
51 void sigFindInPageWidgetToogle(bool fVisible);
52 void sigFontPointSizeChanged(int iFontPointSize);
53 void sigGoBackward();
54 void sigGoForward();
55 void sigGoHome();
56 void sigAddBookmark();
57 void sigZoomPercentageChanged(int iPercentage);
58 void sigMouseOverImage(const QString &strImageName);
59
60public:
61
62 enum ZoomOperation
63 {
64 ZoomOperation_In = 0,
65 ZoomOperation_Out,
66 ZoomOperation_Reset,
67 ZoomOperation_Max
68 };
69
70 UIHelpViewer(const QHelpEngine *pHelpEngine, QWidget *pParent = 0);
71 virtual QVariant loadResource(int type, const QUrl &name) /* override */;
72 void emitHistoryChangedSignal();
73 virtual void setSource(const QUrl &url) /* override */;
74 void setFont(const QFont &);
75 bool isFindInPageWidgetVisible() const;
76 void zoom(ZoomOperation enmZoomOperation);
77 int zoomPercentage() const;
78 void setZoomPercentage(int iZoomPercentage);
79 void setHelpFileList(const QList<QUrl> &helpFileList);
80 bool hasSelectedText() const;
81 static const QPair<int, int> zoomPercentageMinMax;
82 void toggleFindInPageWidget(bool fVisible);
83
84public slots:
85
86 void sltSelectPreviousMatch();
87 void sltSelectNextMatch();
88 virtual void reload() /* overload */;
89
90protected:
91
92 virtual void contextMenuEvent(QContextMenuEvent *event) /* override */;
93 virtual void resizeEvent(QResizeEvent *pEvent) /* override */;
94 virtual void wheelEvent(QWheelEvent *pEvent) /* override */;
95 virtual void mouseReleaseEvent(QMouseEvent *pEvent) /* override */;
96 virtual void mousePressEvent(QMouseEvent *pEvent) /* override */;
97 virtual void mouseMoveEvent(QMouseEvent *pEvent) /* override */;
98 virtual void mouseDoubleClickEvent(QMouseEvent *pEvent) /* override */;
99 virtual void paintEvent(QPaintEvent *pEvent) /* override */;
100 virtual bool eventFilter(QObject *pObject, QEvent *pEvent) /* override */;
101 virtual void keyPressEvent(QKeyEvent *pEvent) /* override */;
102
103private slots:
104
105 void sltOpenLinkInNewTab();
106 void sltOpenLink();
107 void sltCopyLink();
108 void sltFindWidgetDrag(const QPoint &delta);
109 void sltFindInPageSearchTextChange(const QString &strSearchText);
110 void sltToggleFindInPageWidget(bool fVisible);
111 void sltCloseFindInPageWidget();
112
113private:
114
115 struct DocumentImage
116 {
117 qreal m_fInitialWidth;
118 qreal m_fScaledWidth;
119 QTextCursor m_textCursor;
120 QPixmap m_pixmap;
121 QString m_strName;
122 };
123
124 void retranslateUi();
125 bool isRectInside(const QRect &rect, int iMargin) const;
126 void moveFindWidgetIn(int iMargin);
127 void findAllMatches(const QString &searchString);
128 void highlightFinds(int iSearchTermLength);
129 void selectMatch(int iMatchIndex, int iSearchStringLength);
130 /** Scans the document and finds all the images, whose pixmap data is retrieved from QHelp system to be used in overlay draw. */
131 void iterateDocumentImages();
132 void scaleFont();
133 void scaleImages();
134 /** If there is image at @p globalPosition then its data is loaded to m_overlayPixmap. */
135 void loadImageAtPosition(const QPoint &globalPosition);
136 void clearOverlay();
137 void enableOverlay();
138 void setImageOverCursor(QPoint globalPosition);
139
140 const QHelpEngine* m_pHelpEngine;
141 UIFindInPageWidget *m_pFindInPageWidget;
142 /** Initilized as false and set to true once the user drag moves the find widget. */
143 bool m_fFindWidgetDragged;
144 int m_iMarginForFindWidget;
145 /** Document positions of the cursors within the document for all matches. */
146 QVector<int> m_matchedCursorPosition;
147 int m_iSelectedMatchIndex;
148 int m_iSearchTermLength;
149 int m_iInitialFontPointSize;
150 /** A container to store the original image sizes/positions in the document. key is image name value is DocumentImage. */
151 QHash<QString, DocumentImage> m_imageMap;
152 /** As percentage. */
153 int m_iZoomPercentage;
154 /** Used to change th document cursor back from m_handCursor. */
155 QCursor m_defaultCursor;
156 QCursor m_handCursor;
157 /** We need this list from th QHelp system to obtain information of images. */
158 QList<QUrl> m_helpFileList;
159 QPixmap m_overlayPixmap;
160 bool m_fOverlayMode;
161 bool m_fCursorChanged;
162 QLabel *m_pOverlayLabel;
163 QGraphicsBlurEffect *m_pOverlayBlurEffect;
164};
165
166#endif /* #ifdef VBOX_WITH_QHELP_VIEWER */
167#endif /* !FEQT_INCLUDED_SRC_helpbrowser_UIHelpViewer_h */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette