VirtualBox

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

Last change on this file since 102493 was 101571, checked in by vboxsync, 12 months ago

FE/Qt: bugref:10450: Get rid of Qt5 stuff; This one is about replacing obsolete stuff.

  • 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 101571 2023-10-24 00:48:20Z 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 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() /* overload */;
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 void retranslateUi();
133 bool isRectInside(const QRect &rect, int iMargin) const;
134 void moveFindWidgetIn(int iMargin);
135 void findAllMatches(const QString &searchString);
136 void highlightFinds(int iSearchTermLength);
137 void selectMatch(int iMatchIndex, int iSearchStringLength);
138 /** Scans the document and finds all the images, whose pixmap data is retrieved from QHelp system to be used in overlay draw. */
139 void iterateDocumentImages();
140 void scaleFont();
141 void scaleImages();
142 void loadImage(const QUrl &imageFileUrl);
143 void clearOverlay();
144 void enableOverlay();
145
146 const QHelpEngine* m_pHelpEngine;
147 UIFindInPageWidget *m_pFindInPageWidget;
148 /** Initilized as false and set to true once the user drag moves the find widget. */
149 bool m_fFindWidgetDragged;
150 int m_iMarginForFindWidget;
151 /** Document positions of the cursors within the document for all matches. */
152 QVector<int> m_matchedCursorPosition;
153 int m_iSelectedMatchIndex;
154 int m_iSearchTermLength;
155 int m_iInitialFontPointSize;
156 /** A container to store the original image sizes/positions in the document. key is image name value is DocumentImage. */
157 QHash<QString, DocumentImage> m_imageMap;
158 /** We need this list from th QHelp system to obtain information of images. */
159 QList<QUrl> m_helpFileList;
160 QPixmap m_overlayPixmap;
161 bool m_fOverlayMode;
162 QLabel *m_pOverlayLabel;
163 QGraphicsBlurEffect *m_pOverlayBlurEffect;
164 int m_iZoomPercentage;
165};
166
167#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