1 /*
2  * Hydrogen
3  * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4  *
5  * http://www.hydrogen-music.org
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY, without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22 
23 
24 #include "HelpBrowser.h"
25 #include "Skin.h"
26 
27 #include <QtGui>
28 #if QT_VERSION >= 0x050000
29 #  include <QtWidgets>
30 #endif
31 #include <hydrogen/globals.h>
32 
33 const char* SimpleHTMLBrowser::__class_name = "SimpleHTMLBrowser";
34 
SimpleHTMLBrowser(QWidget * pParent,const QString & sDataPath,const QString & sFilename,SimpleHTMLBrowserType type)35 SimpleHTMLBrowser::SimpleHTMLBrowser( QWidget *pParent, const QString& sDataPath, const QString& sFilename, SimpleHTMLBrowserType type )
36  : QDialog( pParent )
37  , Object( __class_name )
38  , m_type( type )
39  , m_sDataPath( sDataPath )
40  , m_sFilename( sFilename )
41 {
42 	if (m_type == MANUAL ) {
43 		setWindowTitle( tr( "Manual" ) );
44 		resize( 800, 600 );
45 		setMinimumSize( 300, 200 );
46 		setStyleSheet("color:#000000;");
47 	}
48 	else {
49 		setWindowTitle( tr( "Welcome to Hydrogen" ) );
50 		resize( 800, 650 );
51 		setMinimumSize( width(), height() );
52 		setMaximumSize( width(), height() );
53 	}
54 
55 	m_pDontShowAnymoreBtn = new QPushButton( tr( "Don't show this message anymore"), this );
56 	connect( m_pDontShowAnymoreBtn, SIGNAL( clicked() ), this, SLOT( dontShowAnymoreBtnClicked() ) );
57 	m_pDontShowAnymoreBtn->resize( 300, 25 );
58 	m_pDontShowAnymoreBtn->hide();
59 
60 	m_pCloseWindowBtn = new QPushButton( tr( "Ok" ), this );
61 	connect( m_pCloseWindowBtn, SIGNAL( clicked() ), this, SLOT( closeWindow() ) );
62 	m_pCloseWindowBtn->resize( 100, 25 );
63 	m_pCloseWindowBtn->hide();
64 
65 	m_pDocHomeBtn = new QPushButton( tr( "Documentation index" ), this );
66 	connect( m_pDocHomeBtn, SIGNAL( clicked() ), this, SLOT( docIndex() ) );
67 	m_pDocHomeBtn->resize( 300, 25 );
68 	m_pDocHomeBtn->hide();
69 
70 	m_pBrowser = new QTextBrowser( this );
71 	m_pBrowser->setReadOnly( true );
72 	m_pBrowser->setSearchPaths( QStringList( m_sDataPath ) );
73 	//m_pBrowser->setStyleSheet("background-color:#000000;");
74 
75 	QFile file( m_sFilename.toLocal8Bit() ); // Read the text from a file
76 	if ( file.open( QIODevice::ReadOnly ) ) {
77 		QTextStream stream( &file );
78 		m_pBrowser->setHtml( stream.readAll() );
79 	}
80 
81 	QRect rect( QGuiApplication::screens().first()->geometry() );
82 	move( rect.center() - this->rect().center() );
83 }
84 
85 
86 
~SimpleHTMLBrowser()87 SimpleHTMLBrowser::~SimpleHTMLBrowser()
88 {
89 //	INFOLOG( "DESTROY" );
90 }
91 
92 
93 
showEvent(QShowEvent * ev)94 void SimpleHTMLBrowser::showEvent ( QShowEvent *ev )
95 {
96 	UNUSED( ev );
97 //	INFOLOG( "[showEvent]" );
98 }
99 
100 
101 
resizeEvent(QResizeEvent * ev)102 void SimpleHTMLBrowser::resizeEvent( QResizeEvent *ev )
103 {
104 	UNUSED( ev );
105 
106 	if ( m_type == MANUAL ) {
107 		m_pBrowser->move( 0, 29 );
108 		m_pBrowser->resize( width(), height() - 29 );
109 
110 		m_pDocHomeBtn->move( 5, 3 );
111 		m_pDocHomeBtn->show();
112 
113 		m_pDontShowAnymoreBtn->hide();
114 		m_pCloseWindowBtn->hide();
115 	}
116 	else if ( m_type == WELCOME ) {
117 		m_pBrowser->move( 0, 0 );
118 		m_pBrowser->resize( width(), height() - 29 );
119 
120 		m_pDontShowAnymoreBtn->move( width() - m_pDontShowAnymoreBtn->width() - m_pCloseWindowBtn->width() - 5 - 5, height() - 27 );
121 		m_pDontShowAnymoreBtn->show();
122 
123 		m_pCloseWindowBtn->move( width() - m_pCloseWindowBtn->width() - 5, height() - 27 );
124 		m_pCloseWindowBtn->show();
125 		m_pCloseWindowBtn->setDefault(true);
126 
127 		m_pDocHomeBtn->hide();
128 	}
129 }
130 
131 
dontShowAnymoreBtnClicked()132 void SimpleHTMLBrowser::dontShowAnymoreBtnClicked()
133 {
134 	accept();
135 }
136 
closeWindow()137 void SimpleHTMLBrowser::closeWindow()
138 {
139 	reject();
140 }
141 
docIndex()142 void SimpleHTMLBrowser::docIndex()
143 {
144 	INFOLOG( "[docIndex]" );
145 
146 	QFile file( m_sFilename ); // Read the text from a file
147 	if ( file.open( QIODevice::ReadOnly ) ) {
148 		QTextStream stream( &file );
149 		m_pBrowser->setHtml( stream.readAll() );
150 	}
151 
152 }
153