Merge pull request #506 from andrewcsmith/patch-2
[supercollider.git] / QtCollider / widgets / QcWebView.h
blob8a260c628c860196509bbc36011f84bd5f34d53c
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 ************************************************************************/
22 #ifndef QC_WEB_VIEW_H
23 #define QC_WEB_VIEW_H
25 #include <QWebView>
26 #include <QWebPage>
28 namespace QtCollider {
30 class WebPage;
32 class WebView : public QWebView
34 Q_OBJECT
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 );
44 public:
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 );
49 public Q_SLOTS:
50 void findText( const QString &searchText, bool reversed = false );
52 Q_SIGNALS:
53 void linkActivated( const QString & );
54 void reloadTriggered( const QString & );
55 void interpret( const QString & code );
56 void jsConsoleMsg( const QString &, int, const QString & );
58 public:
60 WebView( QWidget *parent = 0 );
62 QString url() const;
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 ) {
75 QUrl url( str );
76 if( url.scheme().isEmpty() ) url.setScheme( "file" );
77 return url;
80 protected:
81 virtual void keyPressEvent( QKeyEvent * );
83 private Q_SLOTS:
84 void onLinkClicked( const QUrl & );
85 void onPageReload();
87 private:
88 bool _interpretSelection;
91 class WebPage : public QWebPage
93 Q_OBJECT
95 public:
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; }
103 Q_SIGNALS:
104 void jsConsoleMsg( const QString &, int, const QString & );
106 private:
108 bool _delegateReload;
111 } // namespace QtCollider
113 #endif // QC_WEB_VIEW_H