summaryrefslogtreecommitdiffstats
path: root/examples/helpsystem/helpsystem.doc
blob: e9e647e6cc007fd77972a49cfc95a14da5a7cacc (plain)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*!   
  \page helpsystem-example.html

  \ingroup examples
  \title Helpsystem

  This example demonstrates the different TQt classes
  that can be used to provide context sensitive help
  in an application.

  It uses QToolTip and QWhatsThis to provide both static and 
  dynamic balloon help for the widgets in the application, and 
  QToolTipGroup to display extended information for each tooltip
  in the statusbar. QAssistantClient is used to display help 
  pages using TQt Assistant. 

  The application has a user interface based on a 
  QMainWindow with a menubar, statusbar and a toolbar, and uses 
  a QTable as the central widget.
  \quotefile helpsystem/tooltip.h
  \skipto : public QToolTip
  \printuntil };

  Two QToolTip subclasses implement dynamic tooltips for
  QHeader and QTable by reimplementing maybeTip(). The 
  constructors differ from the QToolTip constructor in having a 
  QHeader and a QTable respectively as the first parameter for 
  the constructor instead of a TQWidget. This is because 
  we want to ensure that only headers and tables can be 
  passed as arguments. A QToolTipGroup can be provided as the
  second argument to show tooltips in, for example a statusbar.

  \printuntil };

  The TableToolTip class keeps a reference to the QTable
  as a member for easier access of the QTable object later on.

  \quotefile helpsystem/tooltip.cpp
  \skipto HeaderToolTip::HeaderToolTip
  \printuntil }

  The HeaderToolTip constructor propagates the parameters
  to the QToolTip constructor.
  \printuntil }

  The implementation of maybeTip() uses the QHeader API
  to get the section at the requested position and uses
  QToolTip::tip() to display the section's label in a
  tooltip. The second string is used by QToolTipGroup and will
  show up in the statusbar.

  \printuntil }

  Since QTable is a QScrollView all user interaction 
  happens on QTable's viewport() . The TableToolTip 
  constructor passes the viewport() and the tooltip
  group to the QToolTip constructor, and initializes the table
  member with the QTable pointer itself.
  \printto moveTopLeft

  The implementation of maybeTip() uses the QTable API
  to get information about the cell at the requested position. 
  The QTable API expects contents coordinates, and since the 
  requested point is relative to the viewport we need to translate
  the coordinates before we can use QTable's functions.  
  \printuntil }
  \quotefile helpsystem/whatsthis.h
  \skipto class WhatsThis

  We translate the cell's geometry back to viewport coordinates
  so that the tooltip disappears when the mouse cursor leaves 
  the cell, and use QToolTip::tip() to display the cell's label 
  in a tooltip and to provide text for the QToolTipGroup as before. 
  \printuntil };
  \quotefile helpsystem/whatsthis.cpp
  \skipto WhatsThis::WhatsThis


  The WhatsThis class is a subclass of both TQObject and 
  QWhatsThis and serves as a base class for the HeaderWhatsThis
  and TableWhatsThis classes. \footnote Note that moc requires that TQObject
  is the first base class. \endfootnote WhatsThis 
  reimplements clicked() which will be called when the user clicks
  inside the "What's this?" window. It also declares a signal 
  linkClicked() which will be emitted when a hyperlink is clicked.
  \printuntil }
  
  The WhatsThis constructor takes two parameters, the first is the
  widget we want to provide WhatsThis for, and the second is the
  one which receives the events. Normally this is the same widget,
  but some widgets, like QTable, are more complex and have a 
  viewport() widget which receives the events. If such a widget
  is passed to the constructor it will propagate the parameter to 
  the QWhatsThis constructor and store the TQWidget pointer itself 
  in it's member variable to allow easier use of the TQWidget API 
  later on.
  \skipto bool WhatsThis::clicked
  \printuntil }
  \quotefile helpsystem/whatsthis.h
  \skipto class HeaderWhatsThis

  The implementation of clicked() emits the linkClicked() signal 
  if a hyperlink has been clicked.
  \printuntil };

  \printuntil };

  \quotefile helpsystem/whatsthis.cpp
  \skipto HeaderWhatsThis::HeaderWhatsThis
  
  The HeaderWhatsThis and TableWhatsThis classes reimplement
  text() to make it possible to return texts depending on the 
  mouse click's position. All the other functionality is 
  already provided by the generic WhatsThis base class. We ensure
  type safety here in the same manner as in the tooltip classes.
  \printuntil }

  The HeaderWhatsThis constructor propagates the parameter to the 
  WhatsThis constructor.
  \printto TableWhatsThis::TableWhatsThis

  The implementation of text() uses the QHeader API to determine
  whether we have a horizontal or a vertical header and returns
  a string which states the header's orientation and section.
  \footnote
  Note that we have to explicitly scope the orientation
  (TQObject or QWhatsThis) since HeaderWhatsThis uses multiple 
  inheritance. \endfootnote 
  \printuntil }

  Since QTable is a scrollview and has a viewport() which receives
  the events, we propagate the table itself and the table's 
  viewport() to the WhatsThis constructor.
  \printuntil }
  \printuntil }
  \printuntil }
  \printuntil }

  The implementation of text() uses the QTable API to get 
  information about the cell at the requested position. 
  The QTable API expects contents coordinates, so we need to 
  translate the point as shown earlier for the tooltip classes. 
  We use the rtti() function to figure out the item's type 
  and return a string accordingly. 

  \quotefile helpsystem/mainwindow.h
  \skipto class MainWindow
  \printuntil };

  A QMainWindow is used to create a user interface that uses the 
  above classes in addition to TQt Assistant to provide context
  sensitive help in the application.

  The MainWindow class declares a slot called assistantSlot() 
  which creates an instance of TQt Assistant when it is called. 
  The class keeps references to the tooltip classes as members
  because they are not QObjects and need to be deleted explicitly.
  The class has a reference to QAssistantClient as a 
  member as well, to allow easier access to TQt Assistant later on.

  \quotefile helpsystem/mainwindow.cpp
  \skipto MainWindow::MainWindow
  \printuntil assistant
  
  The MainWindow constructor creates an instance of 
  QAssistantClient using TQString::null as the first argument
  so that the system path is used.
  \printto QWhatsThis::whatsThisButton
  
  A QTable is used as the central widget and the table, the menus 
  and the toolbar are populated.
  \printto // create
  
  The static function whatsThisButton() creates a QToolButton
  which will enter "What's this?" mode when clicked.
  \printto // set up
 
  A QToolTipGroup is created and will show and remove tooltips
  in the statusbar as the tooltips are displayed on the widgets.
  \printto // set up whats this
   
  The tooltips are set up. The static function add() sets up a 
  tooltip on the Assistant toolbutton. Tooltip objects are created
  using the QToolTip subclasses, the constructor's first parameter
  specifies the widget we want to add dynamic tooltips for and the
  second argument specifies the QToolTipGroup they should belong 
  to.
  \printto // connections
  
  The WhatsThis help is set up. The static function add() adds 
  What's This? help for the toolbutton which opens Assistant. 
  Instances of the two WhatsThis subclasses are created for the
  headers and the table. What's This? help is also added for the 
  menu items.
  \printto MainWindow::~MainWindow
   
  Signals and slots are connected, so that the relevant pages will
  be displayed in TQt Assistant when clicking on a hyperlink or on
  the assistant button.
  \printuntil }

  The destructor deletes the tooltips. We need to delete the 
  tooltips explicitly since QToolTip is, as mentioned above, not 
  a subclass of TQObject and the instances of QToolTip not will be
  deleted when the widget is deleted.
  \printuntil }  

  The assistantSlot() uses applicationDirPath() to find the 
  location of the documentation files and shows the specified page
  in TQt Assistant.
  \quotefile helpsystem/main.cpp
  \skipto #include
  \printuntil }

  The main function is a standard implementation opening
  the application main window.
  
  To build the example go to the helpsystem directory
  (TQTDIR/examples/helpsystem) run qmake to generate the makefile, 
  and use the make tool to build the library. 
*/