1 /***************************************************************************
2 * Copyright (C) 2008 by Alexey Balakin *
3 * mathgl.abalakin@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 #include <QLayout>
21 #include <QLineEdit>
22 #include <QToolBar>
23 #include <QPushButton>
24 #include <QTextBrowser>
25 #include <QToolButton>
26 #include <stdio.h>
27 //-----------------------------------------------------------------------------
28 #include "mgl2/define.h"
29 #include "help_pnl.h"
30 extern QString pathHelp;
31 void raisePanel(QWidget *w);
32 //-----------------------------------------------------------------------------
createHlpPanel(QWidget * p)33 QWidget *createHlpPanel(QWidget *p) { return new HelpPanel(p); }
showHelpMGL(QWidget * p,QString s)34 void showHelpMGL(QWidget *p,QString s)
35 {
36 HelpPanel *hlp = dynamic_cast<HelpPanel *>(p);
37 if(hlp) hlp->showHelp(s);
38 }
39 //void showExMGL(QWidget *hlp) { ((HelpPanel *)hlp)->showExamples(); }
40 //-----------------------------------------------------------------------------
HelpPanel(QWidget * parent)41 HelpPanel::HelpPanel(QWidget *parent) : QWidget(parent)
42 {
43
44 QToolBar *t = new QToolBar(this); t->setMovable(false);
45 QVBoxLayout *v = new QVBoxLayout(this); v->addWidget(t);
46 help = new QTextBrowser(this); v->addWidget(help); help->setOpenExternalLinks(false);
47
48 t->addAction(QPixmap(":/png/go-previous.png"), _("Backward"), help, SLOT(backward()));
49 entry = new QLineEdit(this); t->addWidget(entry);
50 connect(entry, SIGNAL(textChanged(const QString &)), this, SLOT(showHelp(const QString &)));
51 connect(entry, SIGNAL(returnPressed()), this, SLOT(showHelp()));
52 t->addAction(QPixmap(":/png/go-next.png"), _("Forward"), help, SLOT(forward()));
53 t->addSeparator();
54 // t->addAction(QPixmap(":/png/help-faq.png"), _("Examples"), this, SLOT(showExamples()));
55 t->addAction(QPixmap(":/png/zoom-in.png"), _("Zoom in text"), this, SLOT(zoomIn()));
56 t->addAction(QPixmap(":/png/zoom-out.png"), _("Zoom out text"), this, SLOT(zoomOut()));
57 setWindowTitle(_("Help"));
58 }
59 //-----------------------------------------------------------------------------
60 // void HelpPanel::showExamples()
61 // {
62 // QStringList s; s<<(pathHelp);
63 // help->setSearchPaths(s);
64 // setWindowTitle("Examples"); raisePanel(this);
65 // help->setSource("mgl_en"+"_2.html");
66 // }
67 //-----------------------------------------------------------------------------
showHelp(const QString & txt)68 void HelpPanel::showHelp(const QString &txt)
69 {
70 QString cmd=txt;
71 raisePanel(this);
72 QStringList s; s<<(pathHelp);
73 help->setSearchPaths(s);
74 if(cmd.isEmpty()) cmd = entry->text().trimmed();
75 // NOTE disable other translations for help files due to Qt bug
76 if(cmd.isEmpty()) help->setSource("mgl_en"+QString(".html"));
77 else help->setSource("mgl_en"+QString(".html#")+cmd);
78 setWindowTitle("Help");
79 }
80 //-----------------------------------------------------------------------------
zoomIn()81 void HelpPanel::zoomIn()
82 { QFont f(help->font()); f.setPointSize(f.pointSize()+1); help->setFont(f); }
83 //-----------------------------------------------------------------------------
zoomOut()84 void HelpPanel::zoomOut()
85 { QFont f(help->font()); f.setPointSize(f.pointSize()-1); help->setFont(f); }
86 //-----------------------------------------------------------------------------
87