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
);
59 WebView( QWidget
*parent
= 0 );
62 void setUrl( const QString
& );
63 QString
html () const;
64 QString
plainText () const;
66 QWebPage::LinkDelegationPolicy
linkDelegationPolicy () const;
67 void setLinkDelegationPolicy ( QWebPage::LinkDelegationPolicy
);
68 bool delegateReload() const;
69 void setDelegateReload( bool );
70 bool interpretSelection() const { return _interpretSelection
; }
71 void setInterpretSelection( bool b
) { _interpretSelection
= b
; }
73 inline static QUrl
urlFromString( const QString
& str
) {
75 if( url
.scheme().isEmpty() ) url
.setScheme( "file" );
80 virtual void keyPressEvent( QKeyEvent
* );
83 void onLinkClicked( const QUrl
& );
87 bool _interpretSelection
;
90 class WebPage
: public QWebPage
96 WebPage( QObject
*parent
) : QWebPage( parent
), _delegateReload(false) {}
97 virtual void triggerAction ( WebAction action
, bool checked
= false );
98 bool delegateReload() const { return _delegateReload
; }
99 void setDelegateReload( bool flag
) { _delegateReload
= flag
; }
103 bool _delegateReload
;
106 } // namespace QtCollider
108 #endif // QC_WEB_VIEW_H