1
1
//=========================================================
3
3
// Linux Music Editor
4
// $Id: help.cpp,v 1.1 2002/01/30 14:10:07 muse Exp $
4
// $Id: help.cpp,v 1.1.1.1 2003/10/29 10:05:18 wschweer Exp $
6
6
// (C) Copyright 1999/2000 Werner Schweer (ws@seh.de)
7
7
//=========================================================
11
10
#include "globals.h"
15
#include <qstatusbar.h>
17
#include <qpopupmenu.h>
20
#include <qtoolbutton.h>
23
#include <qtextstream.h>
24
#include <qstylesheet.h>
25
12
#include <qmessagebox.h>
26
#include <qfiledialog.h>
27
#include <qapplication.h>
28
#include <qcombobox.h>
30
#include <qlineedit.h>
31
#include <qobjectlist.h>
32
#include <qfileinfo.h>
34
#include <qdatastream.h>
36
#include <qsimplerichtext.h>
37
#include <qpaintdevicemetrics.h>
38
#include <qsplitter.h>
40
#include <qtabwidget.h>
42
#include <qlistview.h>
44
14
#include <unistd.h>
53
static const Contents contents[] = {
54
{ "Arranger", "arranger.html" },
55
{ "Pianoroll Editor", "pianoroll.html" },
56
{ "Drum Editor", "drumedit.html" },
57
{ "List Editor", "listedit.html" },
58
{ "ScoreEditor", "scoreedit.html" },
59
{ "Transport Panel", "transport.html" },
60
{ "Create New Song", "newsong.html" },
61
{ "Record Events", "record.html" },
62
{ "Step Recording", "steprecord.html" },
66
//---------------------------------------------------------
68
//---------------------------------------------------------
70
void MusE::helpBrowser()
16
//---------------------------------------------------------
18
//---------------------------------------------------------
20
void MusE::startHelpBrowser()
72
if (helpViewer == 0) {
73
QString lang = getenv("LANG");
74
QString museHelp = museGlobalShare + "/html/toc_" + lang + ".txt";
22
QString lang(getenv("LANG"));
23
QString museHelp = museGlobalShare + QString("/html/index_") + lang + QString(".html");
24
if (access(museHelp.latin1(), R_OK) != 0) {
25
museHelp = museGlobalShare + QString("/html/index.html");
75
26
if (access(museHelp.latin1(), R_OK) != 0) {
76
27
QString info(tr("no help found at: "));
78
29
QMessageBox::critical(this, tr("MusE: Open Help"), info);
81
helpViewer = new HelpWindow(museHelp, museGlobalShare + "/html");
86
//---------------------------------------------------------
88
//---------------------------------------------------------
90
HelpWindow::HelpWindow(const QString& home_, const QString& _path, QWidget* parent, const char *name)
91
: MainWindow(parent, name, WType_TopLevel)
95
fileList = path.entryList();
97
QSplitter* split = new QSplitter(this);
98
setCentralWidget(split);
100
tab = new QTabWidget(split);
101
tab->setMinimumWidth(10);
102
split->setResizeMode(tab, QSplitter::Stretch);
104
contentsList = new QListView(tab, "toc");
105
contentsList->setRootIsDecorated(true);
106
contentsList->setSelectionMode(QListView::Single);
107
contentsList->setSorting(-1, false);
108
contentsList->addColumn(tr("Table of Contents"));
109
connect(contentsList, SIGNAL(clicked(QListViewItem*)),
110
this, SLOT(contentsSelected(QListViewItem*)));
112
indexList = new QListBox(tab, "indexlist");
113
bookmarkList = new QListBox(tab, "bookmarks");
114
connect(bookmarkList, SIGNAL(clicked(QListBoxItem*)),
115
this, SLOT(bookmarkSelected(QListBoxItem*)));
120
FILE* f = fopen(home_.latin1(), "r");
122
QString info(tr("no help found at: "));
124
QMessageBox::critical(this, tr("MusE: Open index"), info);
127
std::stack<QListViewItem*> istack;
130
bool expandable = false;
133
char* p1 = fgets(buffer, 1024, f);
136
if (*p1 == 0 || *p1 == '\n' || *p1 == '#')
138
while (isspace(*p1)) {
155
if (nlevel < level) {
156
while (!istack.empty() && nlevel < level) {
182
qp2 = qp2.stripWhiteSpace();
184
qp2 = qp2.mid(1, qp2.length()-2);
186
item = new QListViewItem(istack.top(), qp1, qp2);
188
item = new QListViewItem(contentsList, qp1, qp2);
190
item->setExpandable(true);
196
tab->addTab(contentsList, tr("TOC"));
198
tab->addTab(indexList, tr("IDX"));
199
tab->addTab(bookmarkList, tr("BM"));
200
browser = new QTextBrowser(split);
201
QValueList<int> sizes;
204
split->setSizes(sizes);
206
browser->mimeSourceFactory()->setFilePath(_path);
207
browser->setFrameStyle(QFrame::Panel | QFrame::Sunken);
208
connect(browser, SIGNAL(textChanged()), SLOT(textChanged()));
209
connect(browser, SIGNAL(highlighted(const QString&)),
210
statusBar(), SLOT(message(const QString&)));
213
setToolBarsMovable(false);
215
QPopupMenu* file = new QPopupMenu(this);
216
file->insertItem(tr("&New Window"), this, SLOT(newWindow()), ALT | Key_N);
217
file->insertItem(tr("&Open File"), this, SLOT(openFile()), ALT | Key_O);
218
file->insertItem(tr("&Print"), this, SLOT(print()), ALT | Key_P);
219
file->insertSeparator();
220
file->insertItem(tr("&Close"), this, SLOT(close()), ALT | Key_Q);
221
file->insertItem(tr("E&xit"), qApp, SLOT(closeAllWindows()), ALT | Key_X);
223
//---------Actions----------------------------
224
QAction* backward = new QAction("backward",
225
QIconSet(*backIcon), "&Backward",
226
0, this, "backward");
227
connect(backward, SIGNAL(activated()), browser, SLOT(backward()));
229
QAction* forward = new QAction("forward",
230
QIconSet(*forwardIcon), "&Forward",
232
connect(forward, SIGNAL(activated()), browser, SLOT(forward()));
234
QPopupMenu* go = new QPopupMenu(this);
237
go->insertItem(*homeIcon, tr("&Home"), browser, SLOT(home()));
239
bookm = new QPopupMenu(this);
240
bookm->insertItem(tr("Add Bookmark"), this, SLOT(addBookmark()));
241
bookm->insertSeparator();
243
QStringList::Iterator it2 = bookmarks.begin();
244
for ( ; it2 != bookmarks.end(); ++it2 ) {
245
mBookmarks[ bookm->insertItem( *it2 ) ] = *it2;
246
bookmarkList->insertItem(*it2);
249
connect(bookm, SIGNAL(activated(int)), SLOT(bookmChosen(int)));
251
menuBar()->insertItem(tr("&File"), file);
252
menuBar()->insertItem(tr("&Go"), go);
253
menuBar()->insertItem(tr( "Bookmarks"), bookm);
254
menuBar()->insertSeparator();
256
connect(browser, SIGNAL(backwardAvailable(bool)),
257
backward, SLOT(setEnabled(bool)));
258
connect(browser, SIGNAL(forwardAvailable(bool)),
259
forward, SLOT(setEnabled(bool)));
261
QToolBar* toolbar = new QToolBar(this);
262
addToolBar(toolbar, "Toolbar");
265
backward->addTo(toolbar);
266
forward->addTo(toolbar);
268
button = new QToolButton(*homeIcon, tr("Home"), "", browser, SLOT(home()), toolbar);
270
toolbar->addSeparator();
271
button = new QToolButton(toolbar);
272
button->setToggleButton(true);
273
button->setPixmap(*tocIcon);
275
connect(button, SIGNAL(toggled(bool)), SLOT(toggleToc(bool)));
276
toolbar->addSeparator();
278
pathCombo = new QComboBox(true, toolbar );
279
connect( pathCombo, SIGNAL( activated( const QString & ) ),
280
this, SLOT( pathSelected( const QString & ) ) );
281
toolbar->setStretchableWidget( pathCombo );
282
setRightJustification(true);
283
setDockEnabled( Left, false);
284
setDockEnabled( Right, false);
286
pathCombo->insertItem( home_ );
287
pathCombo->installEventFilter( this );
288
QObjectList *l = queryList( "QLineEdit" );
289
if ( l && l->first() )
290
( (QLineEdit*)l->first() )->installEventFilter( this );
293
contentsSelected(contentsList->firstChild());
294
// if (!home_.isEmpty())
295
// browser->setSource(home_);
298
//---------------------------------------------------------
300
//---------------------------------------------------------
302
void HelpWindow::bookmarkSelected(QListBoxItem* item)
304
browser->setSource(item->text());
307
//---------------------------------------------------------
309
//---------------------------------------------------------
311
void HelpWindow::contentsSelected(QListViewItem* item)
314
// printf("<%s> - <%s>\n", item->text(0).latin1(), item->text(1).latin1());
315
browser->setSource(item->text(1));
319
//---------------------------------------------------------
321
//---------------------------------------------------------
323
HelpWindow::~HelpWindow()
326
QMap<int, QString>::Iterator it2 = mBookmarks.begin();
327
for ( ; it2 != mBookmarks.end(); ++it2 )
328
bookmarks.append( *it2 );
330
QFile f2( QDir::currentDirPath() + "/.bookmarks" );
331
f2.open( IO_WriteOnly );
332
QDataStream s2( &f2 );
337
//---------------------------------------------------------
339
//---------------------------------------------------------
341
void HelpWindow::textChanged()
343
if (browser->documentTitle().isNull())
344
setCaption(browser->context());
346
setCaption(browser->documentTitle());
347
selectedURL = caption();
348
if (!selectedURL.isEmpty() && pathCombo) {
349
path = QDir(QFileInfo(selectedURL).dirPath(true), "*.html *.htm");
350
fileList = path.entryList();
353
for (i = 0; i < pathCombo->count(); ++i) {
354
if (pathCombo->text(i) == selectedURL) {
360
pathCombo->insertItem(selectedURL, 0);
361
pathCombo->setCurrentItem(0);
364
pathCombo->setCurrentItem(i);
365
selectedURL = QString::null;
369
//---------------------------------------------------------
371
//---------------------------------------------------------
373
void HelpWindow::openFile()
375
QString fn = QFileDialog::getOpenFileName( QString::null, QString::null, this );
377
browser->setSource(fn);
380
//---------------------------------------------------------
382
//---------------------------------------------------------
384
void HelpWindow::newWindow()
386
(new HelpWindow(browser->source(), "qbrowser"))->show();
389
//---------------------------------------------------------
391
//---------------------------------------------------------
393
void HelpWindow::print()
396
printer.setFullPage(true);
397
if ( printer.setup() ) {
398
QPainter p( &printer );
399
QPaintDeviceMetrics metrics(p.device());
400
int dpix = metrics.logicalDpiX();
401
int dpiy = metrics.logicalDpiY();
402
const int margin = 72; // pt
403
QRect body(margin*dpix/72, margin*dpiy/72,
404
metrics.width()-margin*dpix/72*2,
405
metrics.height()-margin*dpiy/72*2 );
407
p.scale(scale, scale );
408
body = QRect( int(body.x()/scale), int(body.y()/scale),
409
int(body.width()/scale), int(body.height()/scale) );
411
QSimpleRichText richText( browser->text(), font, browser->context(), browser->styleSheet(),
412
browser->mimeSourceFactory(), body.height() );
413
richText.setWidth( &p, body.width() );
417
richText.draw( &p, body.left(), body.top(), view, colorGroup() );
418
view.moveBy( 0, body.height() );
419
p.translate( 0 , -body.height() );
421
p.drawText( view.right() - p.fontMetrics().width( QString::number(page) ),
422
view.bottom() + p.fontMetrics().ascent() + 5, QString::number(page) );
423
if ( view.top() >= richText.height() )
431
//---------------------------------------------------------
433
//---------------------------------------------------------
435
void HelpWindow::pathSelected(const QString &_path)
437
browser->setSource( _path );
438
path = QDir(QFileInfo(_path).dirPath(true), "*.html *.htm");
439
fileList = path.entryList();
440
QMap<int, QString>::Iterator it = mHistory.begin();
442
for ( ; it != mHistory.end(); ++it) {
443
if ( *it == _path ) {
450
//---------------------------------------------------------
452
//---------------------------------------------------------
454
bool HelpWindow::eventFilter( QObject * o, QEvent * e )
456
if ( QMainWindow::eventFilter( o, e ) )
459
QObjectList *l = queryList( "QLineEdit" );
460
if ( !l || !l->first() )
463
QLineEdit *lined = (QLineEdit*)l->first();
465
if (( o == pathCombo || o == lined) &&
466
e->type() == QEvent::KeyPress) {
468
//TODO if ( isprint(((QKeyEvent *)e)) ) {
470
if ( lined->hasMarkedText() )
472
QString nt( lined->text() );
473
nt.remove( 0, nt.findRev( '/' ) + 1 );
474
nt.truncate( lined->cursorPosition() );
475
nt += (char)(((QKeyEvent *)e));
477
QStringList::Iterator it = fileList.begin();
478
while ( it != fileList.end() && (*it).left( nt.length() ) != nt )
481
if (!(*it).isEmpty()) {
483
int cp = lined->cursorPosition() + 1;
484
int l = path.canonicalPath().length() + 1;
485
lined->validateAndSet( path.canonicalPath() + "/" + nt, cp, cp, l + nt.length() );
493
//---------------------------------------------------------
495
//---------------------------------------------------------
497
void HelpWindow::readBookmarks()
499
if (QFile::exists( QDir::currentDirPath() + "/.bookmarks")) {
500
QFile f( QDir::currentDirPath() + "/.bookmarks" );
501
f.open( IO_ReadOnly );
508
//---------------------------------------------------------
510
//---------------------------------------------------------
512
void HelpWindow::bookmChosen(int i)
514
if (mBookmarks.contains(i))
515
browser->setSource(mBookmarks[ i ]);
518
//---------------------------------------------------------
520
//---------------------------------------------------------
522
void HelpWindow::addBookmark()
524
mBookmarks[bookm->insertItem(caption())] = caption();
527
//---------------------------------------------------------
529
//---------------------------------------------------------
531
void HelpWindow::toggleToc(bool flag)
34
execlp(helpBrowser.latin1(), helpBrowser.latin1(), museHelp.latin1(), 0);