5 |
5 |
6 """ |
6 """ |
7 Module implementing an embedded viewer for QtHelp and local HTML files. |
7 Module implementing an embedded viewer for QtHelp and local HTML files. |
8 """ |
8 """ |
9 |
9 |
|
10 from PyQt6.QtCore import pyqtSlot, QUrl |
|
11 from PyQt6.QtGui import QTextDocument |
10 from PyQt6.QtWidgets import ( |
12 from PyQt6.QtWidgets import ( |
11 QWidget, QVBoxLayout, QComboBox, QSizePolicy, QStackedWidget |
13 QWidget, QHBoxLayout, QVBoxLayout, QComboBox, QSizePolicy, QStackedWidget, |
|
14 QToolButton, QButtonGroup, QAbstractButton |
12 ) |
15 ) |
|
16 |
|
17 import UI.PixmapCache |
|
18 |
|
19 from .OpenPagesWidget import OpenPagesWidget |
13 |
20 |
14 |
21 |
15 class HelpViewerWidget(QWidget): |
22 class HelpViewerWidget(QWidget): |
16 """ |
23 """ |
17 Class implementing an embedded viewer for QtHelp and local HTML files. |
24 Class implementing an embedded viewer for QtHelp and local HTML files. |
28 |
35 |
29 self.__layout = QVBoxLayout() |
36 self.__layout = QVBoxLayout() |
30 self.__layout.setObjectName("MainLayout") |
37 self.__layout.setObjectName("MainLayout") |
31 self.__layout.setContentsMargins(0, 3, 0, 0) |
38 self.__layout.setContentsMargins(0, 3, 0, 0) |
32 |
39 |
|
40 ################################################################### |
|
41 |
|
42 self.__selectorLayout = QHBoxLayout() |
|
43 |
33 self.__helpSelector = QComboBox(self) |
44 self.__helpSelector = QComboBox(self) |
34 self.__helpSelector.setSizePolicy( |
45 self.__helpSelector.setSizePolicy( |
35 QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred) |
46 QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred) |
36 self.__layout.addWidget(self.__helpSelector) |
47 self.__selectorLayout.addWidget(self.__helpSelector) |
37 self.__populateHelpSelector() |
48 self.__populateHelpSelector() |
|
49 |
|
50 self.__openButton = QToolButton(self) |
|
51 self.__openButton.setIcon(UI.PixmapCache.getIcon("open")) |
|
52 self.__openButton.setToolTip(self.tr("Open a local file")) |
|
53 self.__openButton.clicked.connect(self.__openFile) |
|
54 self.__selectorLayout.addWidget(self.__openButton) |
|
55 |
|
56 self.__layout.addLayout(self.__selectorLayout) |
|
57 |
|
58 ################################################################### |
38 |
59 |
39 self.__helpStack = QStackedWidget(self) |
60 self.__helpStack = QStackedWidget(self) |
40 self.__helpStack.setSizePolicy( |
61 self.__helpStack.setSizePolicy( |
41 QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding) |
62 QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding) |
42 self.__layout.addWidget(self.__helpStack) |
63 self.__layout.addWidget(self.__helpStack) |
43 |
64 |
|
65 ################################################################### |
|
66 |
44 self.__helpNavigationStack = QStackedWidget(self) |
67 self.__helpNavigationStack = QStackedWidget(self) |
45 self.__helpNavigationStack.setSizePolicy( |
68 self.__helpNavigationStack.setSizePolicy( |
46 QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred) |
69 QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred) |
|
70 self.__helpNavigationStack.setMaximumHeight(200) |
47 self.__layout.addWidget(self.__helpNavigationStack) |
71 self.__layout.addWidget(self.__helpNavigationStack) |
48 self.__populateNavigationStack() |
72 self.__populateNavigationStack() |
49 |
73 |
|
74 ################################################################### |
|
75 |
|
76 self.__buttonLayout = QHBoxLayout() |
|
77 |
|
78 self.__buttonGroup = QButtonGroup(self) |
|
79 self.__buttonGroup.setExclusive(True) |
|
80 self.__buttonGroup.buttonClicked.connect( |
|
81 self.__selectNavigationWidget) |
|
82 |
|
83 self.__buttonLayout.addStretch() |
|
84 |
|
85 self.__openPagesButton = QToolButton(self) |
|
86 self.__openPagesButton.setIcon(UI.PixmapCache.getIcon("fileMisc")) |
|
87 self.__openPagesButton.setToolTip(self.tr("Show list of open pages")) |
|
88 self.__openPagesButton.setCheckable(True) |
|
89 self.__buttonGroup.addButton(self.__openPagesButton) |
|
90 self.__buttonLayout.addWidget(self.__openPagesButton) |
|
91 |
|
92 self.__buttonLayout.addStretch() |
|
93 |
|
94 self.__layout.addLayout(self.__buttonLayout) |
|
95 |
|
96 ################################################################### |
|
97 |
50 self.setLayout(self.__layout) |
98 self.setLayout(self.__layout) |
|
99 |
|
100 self.__openPagesButton.setChecked(True) |
|
101 |
|
102 self.addPage() |
51 |
103 |
52 def __populateNavigationStack(self): |
104 def __populateNavigationStack(self): |
53 """ |
105 """ |
54 Private method to populate the stack of navigation widgets. |
106 Private method to populate the stack of navigation widgets. |
55 """ |
107 """ |
|
108 self.__openPagesList = OpenPagesWidget(self.__helpStack, self) |
|
109 self.__helpNavigationStack.addWidget(self.__openPagesList) |
|
110 |
|
111 # TODO: not yet implemented |
|
112 |
|
113 @pyqtSlot(QAbstractButton) |
|
114 def __selectNavigationWidget(self, button): |
|
115 """ |
|
116 Private slot to select the navigation widget. |
|
117 |
|
118 @param button reference to the clicked button |
|
119 @type QAbstractButton |
|
120 """ |
|
121 if button == self.__openPagesButton: |
|
122 self.__helpNavigationStack.setCurrentWidget(self.__openPagesList) |
|
123 |
56 # TODO: not yet implemented |
124 # TODO: not yet implemented |
57 |
125 |
58 def __populateHelpSelector(self): |
126 def __populateHelpSelector(self): |
59 """ |
127 """ |
60 Private method to populate the help selection combo box. |
128 Private method to populate the help selection combo box. |