author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 01:19:32 +0300 | |
changeset 37 | 758a864f9613 |
parent 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the examples of the Qt Toolkit. |
|
8 |
** |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
9 |
** $QT_BEGIN_LICENSE:BSD$ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
10 |
** You may use this file under the terms of the BSD license as follows: |
0 | 11 |
** |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
12 |
** "Redistribution and use in source and binary forms, with or without |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
13 |
** modification, are permitted provided that the following conditions are |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
14 |
** met: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
15 |
** * Redistributions of source code must retain the above copyright |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
16 |
** notice, this list of conditions and the following disclaimer. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
17 |
** * Redistributions in binary form must reproduce the above copyright |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
18 |
** notice, this list of conditions and the following disclaimer in |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
19 |
** the documentation and/or other materials provided with the |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
20 |
** distribution. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
21 |
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
22 |
** the names of its contributors may be used to endorse or promote |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
23 |
** products derived from this software without specific prior written |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
24 |
** permission. |
0 | 25 |
** |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
26 |
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
27 |
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
28 |
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
29 |
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
30 |
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
31 |
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
32 |
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
33 |
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
34 |
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
35 |
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
36 |
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
0 | 37 |
** $QT_END_LICENSE$ |
38 |
** |
|
39 |
****************************************************************************/ |
|
40 |
||
41 |
#include <QApplication> |
|
42 |
#include <QMessageBox> |
|
43 |
#include <QProgressBar> |
|
44 |
#include <QStatusBar> |
|
45 |
#include <QMainWindow> |
|
46 |
#include <QAbstractEventDispatcher> |
|
47 |
||
48 |
#if defined(Q_WS_WINCE_WM) |
|
49 |
#include "ui_mainwindow_windowsmobile.h" |
|
50 |
#include <windows.h> |
|
51 |
#else |
|
52 |
#include "ui_mainwindow.h" |
|
53 |
#endif |
|
54 |
||
55 |
//! [0] |
|
56 |
class MainWindow : public QMainWindow, public Ui::MainWindow |
|
57 |
{ |
|
58 |
Q_OBJECT |
|
59 |
public: |
|
60 |
MainWindow(); |
|
61 |
||
62 |
public slots: |
|
63 |
void on_WebBrowser_TitleChange(const QString &title); |
|
64 |
void on_WebBrowser_ProgressChange(int a, int b); |
|
65 |
void on_WebBrowser_CommandStateChange(int cmd, bool on); |
|
66 |
void on_WebBrowser_BeforeNavigate(); |
|
67 |
void on_WebBrowser_NavigateComplete(QString); |
|
68 |
||
69 |
void on_actionGo_triggered(); |
|
70 |
void on_actionNewWindow_triggered(); |
|
71 |
void on_actionAbout_triggered(); |
|
72 |
void on_actionAboutQt_triggered(); |
|
73 |
void on_actionFileClose_triggered(); |
|
74 |
||
75 |
private: |
|
76 |
QProgressBar *pb; |
|
77 |
}; |
|
78 |
//! [0] //! [1] |
|
79 |
||
80 |
MainWindow::MainWindow() |
|
81 |
{ |
|
82 |
setupUi(this); |
|
83 |
||
84 |
connect(addressEdit, SIGNAL(returnPressed()), actionGo, SLOT(trigger())); |
|
85 |
connect(actionBack, SIGNAL(triggered()), WebBrowser, SLOT(GoBack())); |
|
86 |
connect(actionForward, SIGNAL(triggered()), WebBrowser, SLOT(GoForward())); |
|
87 |
connect(actionStop, SIGNAL(triggered()), WebBrowser, SLOT(Stop())); |
|
88 |
connect(actionRefresh, SIGNAL(triggered()), WebBrowser, SLOT(Refresh())); |
|
89 |
connect(actionHome, SIGNAL(triggered()), WebBrowser, SLOT(GoHome())); |
|
90 |
connect(actionSearch, SIGNAL(triggered()), WebBrowser, SLOT(GoSearch())); |
|
91 |
||
92 |
pb = new QProgressBar(statusBar()); |
|
93 |
pb->setTextVisible(false); |
|
94 |
pb->hide(); |
|
95 |
statusBar()->addPermanentWidget(pb); |
|
96 |
||
97 |
WebBrowser->dynamicCall("GoHome()"); |
|
98 |
} |
|
99 |
||
100 |
//! [1] //! [2] |
|
101 |
void MainWindow::on_WebBrowser_TitleChange(const QString &title) |
|
102 |
{ |
|
103 |
setWindowTitle("Qt WebBrowser - " + title); |
|
104 |
} |
|
105 |
||
106 |
void MainWindow::on_WebBrowser_ProgressChange(int a, int b) |
|
107 |
{ |
|
108 |
if (a <= 0 || b <= 0) { |
|
109 |
pb->hide(); |
|
110 |
return; |
|
111 |
} |
|
112 |
pb->show(); |
|
113 |
pb->setRange(0, b); |
|
114 |
pb->setValue(a); |
|
115 |
} |
|
116 |
||
117 |
void MainWindow::on_WebBrowser_CommandStateChange(int cmd, bool on) |
|
118 |
{ |
|
119 |
switch (cmd) { |
|
120 |
case 1: |
|
121 |
actionForward->setEnabled(on); |
|
122 |
break; |
|
123 |
case 2: |
|
124 |
actionBack->setEnabled(on); |
|
125 |
break; |
|
126 |
} |
|
127 |
} |
|
128 |
||
129 |
void MainWindow::on_WebBrowser_BeforeNavigate() |
|
130 |
{ |
|
131 |
actionStop->setEnabled(true); |
|
132 |
} |
|
133 |
||
134 |
void MainWindow::on_WebBrowser_NavigateComplete(QString) |
|
135 |
{ |
|
136 |
actionStop->setEnabled(false); |
|
137 |
} |
|
138 |
||
139 |
//! [2] //! [3] |
|
140 |
void MainWindow::on_actionGo_triggered() |
|
141 |
{ |
|
142 |
WebBrowser->dynamicCall("Navigate(const QString&)", addressEdit->text()); |
|
143 |
} |
|
144 |
||
145 |
void MainWindow::on_actionNewWindow_triggered() |
|
146 |
{ |
|
147 |
MainWindow *window = new MainWindow; |
|
148 |
window->show(); |
|
149 |
if (addressEdit->text().isEmpty()) |
|
150 |
return; |
|
151 |
window->addressEdit->setText(addressEdit->text()); |
|
152 |
window->actionStop->setEnabled(true); |
|
153 |
window->on_actionGo_triggered(); |
|
154 |
} |
|
155 |
||
156 |
void MainWindow::on_actionAbout_triggered() |
|
157 |
{ |
|
158 |
QMessageBox::about(this, tr("About WebBrowser"), |
|
159 |
tr("This Example has been created using the ActiveQt integration into Qt Designer.\n" |
|
160 |
"It demonstrates the use of QAxWidget to embed the Internet Explorer ActiveX\n" |
|
161 |
"control into a Qt application.")); |
|
162 |
} |
|
163 |
||
164 |
void MainWindow::on_actionAboutQt_triggered() |
|
165 |
{ |
|
166 |
QMessageBox::aboutQt(this, tr("About Qt")); |
|
167 |
} |
|
168 |
||
169 |
void MainWindow::on_actionFileClose_triggered() |
|
170 |
{ |
|
171 |
close(); |
|
172 |
} |
|
173 |
||
174 |
#include "main.moc" |
|
175 |
||
176 |
//! [3] //! [4] |
|
177 |
int main(int argc, char ** argv) |
|
178 |
{ |
|
179 |
QApplication a(argc, argv); |
|
180 |
MainWindow w; |
|
181 |
#if defined(Q_OS_WINCE) |
|
182 |
w.showMaximized(); |
|
183 |
#else |
|
184 |
w.show(); |
|
185 |
#endif |
|
186 |
return a.exec(); |
|
187 |
} |
|
188 |
//! [4] |