1 /************************************************************************
3 * Copyright 2011 Jakob Leben (jakob.leben@gmail.com)
5 * This file is part of SuperCollider Qt GUI.
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 3 of the License, or
10 * (at your option) any later version.
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.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ************************************************************************/
28 namespace QtCollider
{
32 class WebView
: public QWebView
35 Q_PROPERTY( QString url READ url WRITE setUrl
);
36 Q_PROPERTY( QString html READ html
)
37 Q_PROPERTY( QString plainText READ plainText
)
38 Q_PROPERTY( QWebPage::LinkDelegationPolicy linkDelegationPolicy
39 READ linkDelegationPolicy WRITE setLinkDelegationPolicy
)
40 Q_PROPERTY( bool delegateReload READ delegateReload WRITE setDelegateReload
);
41 Q_PROPERTY( bool enterInterpretsSelection
42 READ interpretSelection WRITE setInterpretSelection
);
45 Q_INVOKABLE
void setHtml ( const QString
&html
, const QString
&baseUrl
= QString() );
46 Q_INVOKABLE
void evaluateJavaScript ( const QString
&script
);
47 Q_INVOKABLE
void setFontFamily( int genericFontFamily
, const QString
& fontFamily
);
50 void findText( const QString
&searchText
, bool reversed
= false );
53 void linkActivated( const QString
& );
54 void reloadTriggered( const QString
& );
55 void interpret( const QString
& code
);
56 void jsConsoleMsg( const QString
&, int, const QString
& );
60 WebView( QWidget
*parent
= 0 );
63 void setUrl( const QString
& );
64 QString
html () const;
65 QString
plainText () const;
67 QWebPage::LinkDelegationPolicy
linkDelegationPolicy () const;
68 void setLinkDelegationPolicy ( QWebPage::LinkDelegationPolicy
);
69 bool delegateReload() const;
70 void setDelegateReload( bool );
71 bool interpretSelection() const { return _interpretSelection
; }
72 void setInterpretSelection( bool b
) { _interpretSelection
= b
; }
74 inline static QUrl
urlFromString( const QString
& str
) {
76 if( url
.scheme().isEmpty() ) url
.setScheme( "file" );
81 virtual void keyPressEvent( QKeyEvent
* );
84 void onLinkClicked( const QUrl
& );
88 bool _interpretSelection
;
91 class WebPage
: public QWebPage
97 WebPage( QObject
*parent
) : QWebPage( parent
), _delegateReload(false) {}
98 virtual void triggerAction ( WebAction action
, bool checked
= false );
99 virtual void javaScriptConsoleMessage ( const QString
&, int, const QString
& );
100 bool delegateReload() const { return _delegateReload
; }
101 void setDelegateReload( bool flag
) { _delegateReload
= flag
; }
104 void jsConsoleMsg( const QString
&, int, const QString
& );
108 bool _delegateReload
;
111 } // namespace QtCollider
113 #endif // QC_WEB_VIEW_H