VirtualBox

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

Last change on this file since 100347 was 99910, checked in by vboxsync, 20 months ago

FE/Qt: bugref:10451. Removing endif guards and some more refactoring.

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

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