File: HTMLView.C

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 239,888 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; makefile: 95
file content (86 lines) | stat: -rw-r--r-- 1,986 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <BALL/VIEW/WIDGETS/HTMLView.h>

#include <BALL/VIEW/WIDGETS/HTMLPage.h>

#ifdef BALL_OS_LINUX
#	include <QOpenGLFunctions>
#endif

namespace BALL
{
	namespace VIEW
	{
		HTMLView::HTMLView(QWidget* parent)
			: QWebEngineView(parent)
		{
			setPage(new HTMLPage(this));
			setAttribute(Qt::WA_DontCreateNativeAncestors);
			hide();	// hiding WebEngine widgets seems to be sufficient to prevent nouveau-related crashes
		}

		HTMLViewDock::HTMLViewDock(HTMLView* view, QWidget* parent, const char* title)
			: DockWidget(parent, title),
			  skip_checks_(false),
			  show_error_(false),
			  html_view_(0)
		{
			checkForIncompatibleDrivers_();
			setHTMLView(view);
			registerWidget(this);
		}

		HTMLViewDock::HTMLViewDock(QWidget* parent, const char* title)
			: DockWidget(parent, title),
			  skip_checks_(false),
			  show_error_(false),
			  html_view_(0)
		{
			checkForIncompatibleDrivers_();
			setHTMLView(new HTMLView(this));
			registerWidget(this);
		}

		void HTMLViewDock::setHTMLView(HTMLView* html_view)
		{
			if (!html_view)
			{
				return;
			}

			if (html_view != html_view_)
			{
				delete html_view_;
				html_view_ = html_view;
			}

			if (!skip_checks_ && show_error_)
			{
				// In case of an error, replace the original widget with an error message
				// but still keep it as a member (hidden!) so that it can be restored if
				// the user decides to disable the driver checks.
				setWidget(new HTMLViewErrorWidget(this));
				return;
			}

			setWidget(html_view_);
		}

		void HTMLViewDock::resetHTMLView(bool skip_checks)
		{
			skip_checks_ = skip_checks;
			setHTMLView(html_view_);
		}

		void HTMLViewDock::checkForIncompatibleDrivers_()
		{
#ifdef BALL_OS_LINUX
			QOpenGLFunctions glFuncs(QOpenGLContext::currentContext());
			char* vendor = (char*) glFuncs.glGetString(GL_VENDOR);

			// https://bugreports.qt.io/browse/QTBUG-41242
			// Fixed in Qt 5.10.0
			show_error_ |= vendor && QString(vendor) == "nouveau";
#endif
		}
	}
}