Rev 455 | Rev 564 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3 | paul | 1 | /**************************************************************************** |
560 | cbradney | 2 | ** Form implementation generated from reading ui file 'HelpBrowser.ui' |
3 | paul | 3 | ** |
560 | cbradney | 4 | ** Created: Sat Nov 6 22:12:24 2004 |
5 | ** by: The User Interface Compiler ($Id: helpbrowser.cpp 560 2004-11-08 01:39:29Z cbradney $) |
||
3 | paul | 6 | ** |
7 | ** WARNING! All changes made in this file will be lost! |
||
8 | ****************************************************************************/ |
||
560 | cbradney | 9 | |
3 | paul | 10 | #include "helpbrowser.h" |
11 | #include "helpbrowser.moc" |
||
560 | cbradney | 12 | |
3 | paul | 13 | #include <qvariant.h> |
560 | cbradney | 14 | #include <qpushbutton.h> |
15 | #include <qtabwidget.h> |
||
16 | #include <qwidget.h> |
||
17 | #include <qheader.h> |
||
18 | #include <qlistview.h> |
||
19 | #include <qtextbrowser.h> |
||
20 | #include <qlayout.h> |
||
3 | paul | 21 | #include <qtooltip.h> |
560 | cbradney | 22 | #include <qtoolbutton.h> |
23 | #include <qwhatsthis.h> |
||
3 | paul | 24 | #include <qimage.h> |
25 | #include <qpixmap.h> |
||
560 | cbradney | 26 | #include <qpopupmenu.h> |
27 | #include <qfileinfo.h> |
||
3 | paul | 28 | #include <qtextcodec.h> |
560 | cbradney | 29 | #include <qdom.h> |
128 | Franz | 30 | |
31 | #if (_MSC_VER >= 1200) |
||
32 | #include "win-config.h" |
||
33 | #else |
||
34 | #include "config.h" |
||
35 | #endif |
||
36 | |||
3 | paul | 37 | extern QPixmap loadIcon(QString nam); |
38 | |||
560 | cbradney | 39 | |
205 | Franz | 40 | /* |
560 | cbradney | 41 | * Constructs a HelpBrowser as a child of 'parent', with the |
42 | * name 'name' and widget flags set to 'f'. |
||
3 | paul | 43 | * |
44 | * The dialog will by default be modeless, unless you set 'modal' to |
||
45 | * TRUE to construct a modal dialog. |
||
46 | */ |
||
560 | cbradney | 47 | HelpBrowser::HelpBrowser( QWidget* parent, QString caption, QString guiLanguage, QString jumpTo, QString jumpToFile) |
48 | : QWidget( parent, "Help", WType_TopLevel | WDestructiveClose ) |
||
3 | paul | 49 | { |
560 | cbradney | 50 | QString fileName; |
51 | mHistory.clear(); |
||
52 | struct histd his; |
||
53 | /* |
||
54 | if ( !name ) |
||
55 | setName( "helpBrowser" ); |
||
56 | */ |
||
57 | helpBrowsermainLayout = new QVBoxLayout( this); |
||
3 | paul | 58 | |
560 | cbradney | 59 | buttonLayout = new QHBoxLayout; |
60 | buttonLayout->setSpacing( 6 ); |
||
61 | buttonLayout->setMargin( 0 ); |
||
3 | paul | 62 | |
560 | cbradney | 63 | homeButton = new QToolButton( this, "homeButton" ); |
64 | homeButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, |
||
65 | homeButton->sizePolicy().hasHeightForWidth() ) ); |
||
66 | homeButton->setMinimumSize( QSize( 0, 0 ) ); |
||
67 | homeButton->setMaximumSize( QSize( 32767, 32767 ) ); |
||
68 | homeButton->setText( "" ); |
||
69 | homeButton->setPixmap(loadIcon("gohome.png")); |
||
70 | buttonLayout->addWidget( homeButton ); |
||
3 | paul | 71 | |
560 | cbradney | 72 | histMenu = new QPopupMenu( this ); |
73 | backButton = new QToolButton( this, "backButton" ); |
||
74 | backButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, |
||
75 | backButton->sizePolicy().hasHeightForWidth() ) ); |
||
76 | backButton->setMinimumSize( QSize( 0, 0 ) ); |
||
77 | backButton->setMaximumSize( QSize( 32767, 32767 ) ); |
||
78 | backButton->setPixmap(loadIcon("back.png")); |
||
79 | backButton->setPopup(histMenu); |
||
80 | backButton->setPopupDelay(0); |
||
81 | buttonLayout->addWidget( backButton ); |
||
3 | paul | 82 | |
560 | cbradney | 83 | forwButton = new QToolButton( this, "forwButton" ); |
84 | forwButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, |
||
85 | forwButton->sizePolicy().hasHeightForWidth() ) ); |
||
86 | forwButton->setMinimumSize( QSize( 0, 0 ) ); |
||
87 | forwButton->setMaximumSize( QSize( 32767, 32767 ) ); |
||
88 | forwButton->setPixmap(loadIcon("forward.png")); |
||
89 | buttonLayout->addWidget( forwButton ); |
||
90 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); |
||
91 | buttonLayout->addItem( spacer ); |
||
3 | paul | 92 | |
560 | cbradney | 93 | helpBrowsermainLayout->addLayout( buttonLayout ); |
94 | |||
95 | helpBrowserLayout = new QHBoxLayout; |
||
96 | |||
97 | tabWidget = new QTabWidget( this, "tabWidget" ); |
||
98 | tabWidget->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, 1, 0, tabWidget->sizePolicy().hasHeightForWidth() ) ); |
||
99 | |||
100 | tabContents = new QWidget( tabWidget, "tabContents" ); |
||
101 | tabLayout = new QHBoxLayout( tabContents, 11, 6, "tabLayout"); |
||
102 | |||
103 | listView = new QListView( tabContents, "listView" ); |
||
104 | listView->addColumn( tr( "Contents" ) ); |
||
105 | listView->addColumn( tr( "Link" ), 0 ); |
||
106 | listView->setSorting(-1,-1); |
||
107 | listView->setRootIsDecorated( true ); |
||
108 | listView->setSelectionMode(QListView::Single); |
||
109 | listView->setDefaultRenameAction(QListView::Reject); |
||
110 | listView->clear(); |
||
111 | |||
112 | tabLayout->addWidget( listView ); |
||
113 | tabWidget->insertTab( tabContents, QString("Contents") ); |
||
114 | /* |
||
115 | tab_2 = new QWidget( tabWidget, "tab_2" ); |
||
116 | tabWidget->insertTab( tab_2, QString("") ); |
||
117 | */ |
||
118 | helpBrowserLayout->addWidget( tabWidget ); |
||
119 | |||
120 | textBrowser = new QTextBrowser( this, "textBrowser" ); |
||
121 | textBrowser->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, 2, 0, textBrowser->sizePolicy().hasHeightForWidth() ) ); |
||
122 | textBrowser->setFrameShape( QTextBrowser::StyledPanel ); |
||
123 | |||
124 | helpBrowserLayout->addWidget( textBrowser ); |
||
125 | helpBrowsermainLayout->addLayout( helpBrowserLayout ); |
||
126 | |||
127 | languageChange(); |
||
128 | resize( QSize(602, 491).expandedTo(minimumSizeHint()) ); |
||
129 | clearWState( WState_Polished ); |
||
130 | loadMenu(); |
||
131 | listView->header()->hide(); |
||
132 | jumpToHelpSection( guiLanguage, jumpTo, jumpToFile ); |
||
133 | |||
134 | connect( homeButton, SIGNAL( clicked() ), textBrowser, SLOT( home() ) ); |
||
135 | connect( forwButton, SIGNAL( clicked() ), textBrowser, SLOT( forward() ) ); |
||
136 | connect( backButton, SIGNAL( clicked() ), textBrowser, SLOT( backward() ) ); |
||
137 | connect(histMenu, SIGNAL(activated(int)), this, SLOT(histChosen(int))); |
||
138 | connect(listView, SIGNAL(clicked( QListViewItem *)), this, SLOT(itemSelected( QListViewItem *))); |
||
139 | } |
||
140 | |||
141 | /* |
||
142 | * Destroys the object and frees any allocated resources |
||
143 | */ |
||
144 | HelpBrowser::~HelpBrowser() |
||
145 | { |
||
146 | // no need to delete child widgets, Qt does it all for us |
||
147 | } |
||
148 | |||
149 | /* |
||
150 | * Sets the strings of the subwidgets using the current |
||
151 | * language. |
||
152 | */ |
||
153 | void HelpBrowser::languageChange() |
||
154 | { |
||
155 | setCaption( tr( "Scribus Online Help" ) ); |
||
156 | listView->header()->setLabel( 0, tr( "Contents" ) ); |
||
157 | listView->clear(); |
||
158 | |||
159 | tabWidget->changeTab( tabContents, tr( "Contents" ) ); |
||
160 | // tabWidget->changeTab( tab_2, tr( "Tab 2" ) ); |
||
161 | } |
||
162 | |||
163 | |||
164 | void HelpBrowser::sourceChanged(const QString& url) |
||
165 | { |
||
166 | bool inList = false; |
||
167 | struct histd his; |
||
168 | QString title = ""; |
||
169 | title = textBrowser->documentTitle(); |
||
170 | if (title == "") |
||
171 | title = url; |
||
172 | QMap<int, histd>::Iterator it; |
||
173 | for (it = mHistory.begin(); it != mHistory.end(); ++it) |
||
174 | { |
||
175 | if (it.data().Title == title) |
||
176 | inList = true; |
||
177 | } |
||
178 | if (!inList) |
||
179 | { |
||
180 | his.Title = title; |
||
181 | his.Url = url; |
||
182 | mHistory[histMenu->insertItem(title)] = his; |
||
183 | } |
||
184 | if (mHistory.count() > 15) |
||
185 | { |
||
186 | int itk = histMenu->idAt(0); |
||
187 | mHistory.remove(itk); |
||
188 | histMenu->removeItem(itk); |
||
189 | } |
||
190 | } |
||
191 | |||
192 | void HelpBrowser::histChosen(int i) |
||
193 | { |
||
194 | if (mHistory.contains(i)) |
||
195 | textBrowser->setSource(mHistory[i].Url); |
||
196 | } |
||
197 | |||
198 | void HelpBrowser::jumpToHelpSection(QString guiLanguage, QString jumpTo, QString jumpToFile) |
||
199 | { |
||
200 | QString toLoad; |
||
201 | |||
202 | if (guiLanguage=="") { |
||
203 | qDebug("Error: No help language found."); |
||
204 | guiLanguage="en"; |
||
205 | } |
||
206 | if (jumpToFile=="") { |
||
207 | QString pfad = PREL; |
||
208 | toLoad = pfad + "/share/scribus/doc/"; |
||
209 | toLoad += guiLanguage.left(2); //clean this later |
||
210 | toLoad+="/"; |
||
211 | if (jumpTo=="") { |
||
212 | toLoad+="index.html"; |
||
213 | listView->setSelected( listView->firstChild(), true ); |
||
205 | Franz | 214 | } |
560 | cbradney | 215 | else if (jumpTo=="scripter") { |
216 | toLoad+="scripter1.html"; |
||
217 | QListViewItemIterator it(listView); |
||
218 | while (it.current()) { |
||
219 | if (it.current()->text(1)=="scripter1.html") |
||
220 | listView->setSelected( it.current(), true ); |
||
221 | if (it.current()->text(1)=="developers.html") |
||
222 | it.current()->setOpen( true ); |
||
223 | ++it; |
||
224 | } |
||
225 | } |
||
205 | Franz | 226 | } |
560 | cbradney | 227 | else |
228 | toLoad+=jumpToFile; |
||
3 | paul | 229 | |
560 | cbradney | 230 | loadHelp(toLoad); |
3 | paul | 231 | } |
232 | |||
560 | cbradney | 233 | void HelpBrowser::loadHelp(QString filename) |
68 | Franz | 234 | { |
560 | cbradney | 235 | QString pfad = PREL; |
75 | Franz | 236 | struct histd his; |
560 | cbradney | 237 | bool Avail = true; |
238 | QString toLoad; |
||
239 | QFileInfo fi; |
||
240 | fi = QFileInfo(filename); |
||
241 | if (!fi.exists()) |
||
242 | { |
||
243 | toLoad = pfad + "/share/scribus/doc/en/index.html"; |
||
244 | fi = QFileInfo(toLoad); |
||
245 | if (!fi.exists()) |
||
246 | { |
||
247 | textBrowser->setText("<h2>"+ tr("Sorry, no manual available! Please see: http://docs.scribus.net for updated docs\nand www.scribus.net for downloads.")+"</h2>"); |
||
248 | Avail = false; |
||
249 | } |
||
250 | } |
||
251 | else |
||
252 | toLoad=filename; |
||
253 | if (Avail) |
||
254 | { |
||
255 | textBrowser->setSource(toLoad); |
||
256 | his.Title = textBrowser->documentTitle(); |
||
257 | if (his.Title == "") |
||
258 | his.Title = toLoad; |
||
259 | his.Url = toLoad; |
||
260 | mHistory[histMenu->insertItem(his.Title)] = his; |
||
261 | } |
||
262 | } |
||
263 | |||
264 | void HelpBrowser::loadMenu() |
||
265 | { |
||
266 | QString pfad = PREL; |
||
267 | QString pfad2; |
||
268 | bool Avail = true; |
||
269 | pfad2 = pfad + "/share/scribus/doc/"+QString(QTextCodec::locale()).left(2)+"/menu.xml"; |
||
270 | pfad2 = pfad + "/share/scribus/doc/en/menu.xml"; |
||
271 | |||
272 | QFileInfo fi = QFileInfo(pfad2); |
||
273 | if (fi.exists()) |
||
274 | { |
||
275 | textBrowser->setText("menu found"); |
||
276 | QDomDocument doc( "menuentries" ); |
||
277 | QFile file( pfad2 ); |
||
278 | if ( !file.open( IO_ReadOnly ) ) |
||
279 | return; |
||
280 | if ( !doc.setContent( &file ) ) { |
||
281 | file.close(); |
||
282 | return; |
||
283 | } |
||
284 | file.close(); |
||
285 | |||
286 | //use the doc |
||
287 | QDomElement docElem = doc.documentElement(); |
||
288 | QDomNode n = docElem.firstChild(); |
||
289 | QListViewItem *qlvi=NULL, *qlvi2=NULL, *qlvi3=NULL, *qlvi4=NULL, *qlvi5=NULL, *qlvi6=NULL; |
||
290 | |||
291 | while( !n.isNull() ) { |
||
292 | QDomElement e = n.toElement(); // try to convert the node to an element. |
||
293 | if( !e.isNull() ) { |
||
294 | if (e.hasAttribute( "text" ) && e.hasAttribute( "file" )) { |
||
295 | QDomAttr textAttr = e.attributeNode( "text" ); |
||
296 | QDomAttr fileAttr = e.attributeNode( "file" ); |
||
297 | if (qlvi2==NULL) |
||
298 | qlvi=new QListViewItem(listView, textAttr.value(), fileAttr.value()); |
||
299 | else { |
||
300 | qlvi=new QListViewItem(listView, qlvi2); |
||
301 | if (qlvi!=NULL) { |
||
302 | qlvi->setText(0, textAttr.value()); |
||
303 | qlvi->setText(1, fileAttr.value()); |
||
304 | } |
||
305 | } |
||
306 | if (qlvi!=NULL) |
||
307 | qlvi2=qlvi; |
||
308 | } |
||
309 | |||
310 | QDomNodeList nl=n.childNodes(); |
||
311 | for(uint i=0 ; i<= nl.count() ; i++) { |
||
312 | QDomNode child=nl.item(i); |
||
313 | if (child.isElement()) { |
||
314 | QDomElement ec = child.toElement(); |
||
315 | if (!ec.isNull()) { |
||
316 | if (ec.hasAttribute( "text" ) && ec.hasAttribute( "file" )) { |
||
317 | QDomAttr textAttr = ec.attributeNode( "text" ); |
||
318 | QDomAttr fileAttr = ec.attributeNode( "file" ); |
||
319 | if (qlvi4==NULL) |
||
320 | qlvi3=new QListViewItem(qlvi, textAttr.value(), fileAttr.value()); |
||
321 | else { |
||
322 | qlvi3=new QListViewItem(qlvi, qlvi4); |
||
323 | if (qlvi3!=NULL) { |
||
324 | qlvi3->setText(0, textAttr.value()); |
||
325 | qlvi3->setText(1, fileAttr.value()); |
||
326 | } |
||
327 | } |
||
328 | if (qlvi3!=NULL) |
||
329 | qlvi4=qlvi3; |
||
330 | } |
||
331 | //3rd level |
||
332 | QDomNodeList nl2=child.childNodes(); |
||
333 | for(uint i=0 ; i<= nl2.count() ; i++) { |
||
334 | QDomNode childchild=nl2.item(i); |
||
335 | if (childchild.isElement()) { |
||
336 | QDomElement ecc = childchild.toElement(); |
||
337 | if (!ecc.isNull()) { |
||
338 | if (ecc.hasAttribute( "text" ) && ecc.hasAttribute( "file" )) { |
||
339 | QDomAttr textAttr = ecc.attributeNode( "text" ); |
||
340 | QDomAttr fileAttr = ecc.attributeNode( "file" ); |
||
341 | if (qlvi6==NULL) |
||
342 | qlvi5=new QListViewItem(qlvi3, textAttr.value(), fileAttr.value()); |
||
343 | else { |
||
344 | qlvi5=new QListViewItem(qlvi3, qlvi6); |
||
345 | if (qlvi5!=NULL) { |
||
346 | qlvi5->setText(0, textAttr.value()); |
||
347 | qlvi5->setText(1, fileAttr.value()); |
||
348 | } |
||
349 | } |
||
350 | } |
||
351 | if (qlvi5!=NULL) |
||
352 | qlvi6=qlvi5; |
||
353 | } |
||
354 | } |
||
355 | } |
||
356 | } |
||
357 | } |
||
358 | } |
||
359 | } |
||
360 | n = n.nextSibling(); |
||
361 | } |
||
205 | Franz | 362 | } |
68 | Franz | 363 | } |
364 | |||
560 | cbradney | 365 | void HelpBrowser::itemSelected(QListViewItem *item) |
68 | Franz | 366 | { |
560 | cbradney | 367 | QString pfad = PREL; |
368 | if ( !item ) |
||
369 | return; |
||
370 | else if (item->text(1)!=QString::null) |
||
371 | loadHelp(pfad + "/share/scribus/doc/en/"+item->text(1)); |
||
68 | Franz | 372 | } |
373 |