VirtualBox

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

Last change on this file was 104358, checked in by vboxsync, 5 weeks ago

FE/Qt. bugref:10622. More refactoring around the retranslation functionality.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1/* $Id: UIHelpViewer.h 104358 2024-04-18 05:33:40Z 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 "UILibraryDefs.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 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 void setFont(const QFont &);
84 bool isFindInPageWidgetVisible() const;
85 void setZoomPercentage(int iZoomPercentage);
86 void setHelpFileList(const QList<QUrl> &helpFileList);
87 bool hasSelectedText() const;
88 static const QPair<int, int> zoomPercentageMinMax;
89 void toggleFindInPageWidget(bool fVisible);
90
91public slots:
92
93 void sltSelectPreviousMatch();
94 void sltSelectNextMatch();
95 virtual void reload() RT_OVERRIDE;
96
97protected:
98
99 virtual void contextMenuEvent(QContextMenuEvent *event) RT_OVERRIDE;
100 virtual void resizeEvent(QResizeEvent *pEvent) RT_OVERRIDE;
101 virtual void wheelEvent(QWheelEvent *pEvent) RT_OVERRIDE;
102 virtual void mouseReleaseEvent(QMouseEvent *pEvent) RT_OVERRIDE;
103 virtual void mousePressEvent(QMouseEvent *pEvent) RT_OVERRIDE;
104 virtual void mouseMoveEvent(QMouseEvent *pEvent) RT_OVERRIDE;
105 virtual void mouseDoubleClickEvent(QMouseEvent *pEvent) RT_OVERRIDE;
106 virtual void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE;
107 virtual bool eventFilter(QObject *pObject, QEvent *pEvent) RT_OVERRIDE;
108 virtual void keyPressEvent(QKeyEvent *pEvent) RT_OVERRIDE;
109 virtual void doSetSource(const QUrl &url, QTextDocument::ResourceType type = QTextDocument::UnknownResource) RT_OVERRIDE;
110
111private slots:
112
113 void sltOpenLinkInNewTab();
114 void sltOpenLink();
115 void sltCopyLink();
116 void sltFindWidgetDrag(const QPoint &delta);
117 void sltFindInPageSearchTextChange(const QString &strSearchText);
118 void sltToggleFindInPageWidget(bool fVisible);
119 void sltCloseFindInPageWidget();
120
121private:
122
123 struct DocumentImage
124 {
125 qreal m_fInitialWidth;
126 qreal m_fScaledWidth;
127 QTextCursor m_textCursor;
128 QPixmap m_pixmap;
129 QString m_strName;
130 };
131
132 bool isRectInside(const QRect &rect, int iMargin) const;
133 void moveFindWidgetIn(int iMargin);
134 void findAllMatches(const QString &searchString);
135 void highlightFinds(int iSearchTermLength);
136 void selectMatch(int iMatchIndex, int iSearchStringLength);
137 /** Scans the document and finds all the images, whose pixmap data is retrieved from QHelp system to be used in overlay draw. */
138 void iterateDocumentImages();
139 void scaleFont();
140 void scaleImages();
141 void loadImage(const QUrl &imageFileUrl);
142 void clearOverlay();
143 void enableOverlay();
144
145 const QHelpEngine* m_pHelpEngine;
146 UIFindInPageWidget *m_pFindInPageWidget;
147 /** Initilized as false and set to true once the user drag moves the find widget. */
148 bool m_fFindWidgetDragged;
149 int m_iMarginForFindWidget;
150 /** Document positions of the cursors within the document for all matches. */
151 QVector<int> m_matchedCursorPosition;
152 int m_iSelectedMatchIndex;
153 int m_iSearchTermLength;
154 int m_iInitialFontPointSize;
155 /** A container to store the original image sizes/positions in the document. key is image name value is DocumentImage. */
156 QHash<QString, DocumentImage> m_imageMap;
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 QLabel *m_pOverlayLabel;
162 QGraphicsBlurEffect *m_pOverlayBlurEffect;
163 int m_iZoomPercentage;
164};
165
166#endif /* !FEQT_INCLUDED_SRC_helpbrowser_UIHelpViewer_h */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use