diff options
Diffstat (limited to 'examples/activeqt/webbrowser')
-rw-r--r-- | examples/activeqt/webbrowser/main.cpp | 105 | ||||
-rw-r--r-- | examples/activeqt/webbrowser/webaxwidget.h | 17 |
2 files changed, 70 insertions, 52 deletions
diff --git a/examples/activeqt/webbrowser/main.cpp b/examples/activeqt/webbrowser/main.cpp index 869ddfc..6d6d6d5 100644 --- a/examples/activeqt/webbrowser/main.cpp +++ b/examples/activeqt/webbrowser/main.cpp @@ -6,7 +6,17 @@ ** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are @@ -125,8 +135,8 @@ class MainWindow : public QMainWindow, public Ui::MainWindow { Q_OBJECT public: - MainWindow(); - ~MainWindow(); + explicit MainWindow(); + virtual ~MainWindow(); public slots: void navigate(const QString &address); @@ -145,17 +155,17 @@ public slots: private: inline const QString address() const - { return addressEdit->text().trimmed(); } + { return m_addressEdit->text().trimmed(); } QList<Location> bookmarks() const; QAction *addLocation(const Location &location, QMenu *menu); inline void addBookmark(const Location &location) - { bookmarkActions << addLocation(location, BookmarksMenu); } + { m_bookmarkActions << addLocation(location, BookmarksMenu); } - QProgressBar *pb; - QLineEdit *addressEdit; - QList<QAction *> bookmarkActions; - QList<QAction *> historyActions; - QSignalMapper locationActionMapper; + QProgressBar *m_progressBar; + QLineEdit *m_addressEdit; + QList<QAction *> m_bookmarkActions; + QList<QAction *> m_historyActions; + QSignalMapper m_locationActionMapper; }; //! [0] //! [1] @@ -163,11 +173,12 @@ MainWindow::MainWindow() { setupUi(this); - addressEdit = new QLineEdit; + m_addressEdit = new QLineEdit; tbAddress->insertWidget(actionGo, new QLabel(tr("Address"))); - tbAddress->insertWidget(actionGo, addressEdit); + tbAddress->insertWidget(actionGo, m_addressEdit); + + connect(m_addressEdit, SIGNAL(returnPressed()), actionGo, SLOT(trigger())); - connect(addressEdit, SIGNAL(returnPressed()), actionGo, SLOT(trigger())); connect(actionBack, SIGNAL(triggered()), WebBrowser, SLOT(GoBack())); connect(actionForward, SIGNAL(triggered()), WebBrowser, SLOT(GoForward())); connect(actionStop, SIGNAL(triggered()), WebBrowser, SLOT(Stop())); @@ -175,12 +186,12 @@ MainWindow::MainWindow() connect(actionHome, SIGNAL(triggered()), WebBrowser, SLOT(GoHome())); connect(actionSearch, SIGNAL(triggered()), WebBrowser, SLOT(GoSearch())); - pb = new QProgressBar(statusBar()); - pb->setTextVisible(false); - pb->hide(); - statusBar()->addPermanentWidget(pb); + m_progressBar = new QProgressBar(statusBar()); + m_progressBar->setTextVisible(false); + m_progressBar->hide(); + statusBar()->addPermanentWidget(m_progressBar); - connect(&locationActionMapper, SIGNAL(mapped(QString)), this, SLOT(navigate(QString))); + connect(&m_locationActionMapper, QOverload<const QString &>::of(&QSignalMapper::mapped), this, &MainWindow::navigate); QSettings settings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName()); @@ -214,23 +225,23 @@ QAction *MainWindow::addLocation(const Location &location, QMenu *menu) { QAction *action = menu->addAction(location.title); action->setData(QVariant::fromValue(location)); - locationActionMapper.setMapping(action, location.address); - connect(action, SIGNAL(triggered()), &locationActionMapper, SLOT(map())); + m_locationActionMapper.setMapping(action, location.address); + connect(action, &QAction::triggered, &m_locationActionMapper, QOverload<>::of(&QSignalMapper::map)); return action; } QList<Location> MainWindow::bookmarks() const { QList<Location> result; - for (const QAction *action : qAsConst(bookmarkActions)) + for (const QAction *action : qAsConst(m_bookmarkActions)) result.append(locationFromAction(action)); return result; } void MainWindow::on_actionAddBookmark_triggered() { - if (!historyActions.isEmpty()) { - const Location location = locationFromAction(historyActions.last()); + if (!m_historyActions.isEmpty()) { + const Location location = locationFromAction(m_historyActions.last()); if (!containsAddress(bookmarks(), location.address)) addBookmark(location); } @@ -241,26 +252,26 @@ void MainWindow::on_WebBrowser_TitleChange(const QString &title) { // This is called multiple times after NavigateComplete(). // Add new URLs to history here. - setWindowTitle("Qt WebBrowser - " + title); + setWindowTitle(tr("Qt WebBrowser - ") + title); const QString currentAddress = address(); - const QString historyAddress = historyActions.isEmpty() ? - QString() : locationFromAction(historyActions.last()).address; - if (currentAddress.isEmpty() || currentAddress == "about:blank" || currentAddress == historyAddress) + const QString historyAddress = m_historyActions.isEmpty() ? + QString() : locationFromAction(m_historyActions.last()).address; + if (currentAddress.isEmpty() || currentAddress == QStringLiteral("about:blank") || currentAddress == historyAddress) return; - historyActions << addLocation(Location(title, currentAddress), HistoryMenu); - if (historyActions.size() > 10) - delete historyActions.takeFirst(); + m_historyActions << addLocation(Location(title, currentAddress), HistoryMenu); + if (m_historyActions.size() > 10) + delete m_historyActions.takeFirst(); } void MainWindow::on_WebBrowser_ProgressChange(int a, int b) { if (a <= 0 || b <= 0) { - pb->hide(); + m_progressBar->hide(); return; } - pb->show(); - pb->setRange(0, b); - pb->setValue(a); + m_progressBar->setRange(0, b); + m_progressBar->setValue(a); + m_progressBar->show(); } void MainWindow::on_WebBrowser_CommandStateChange(int cmd, bool on) @@ -282,10 +293,9 @@ void MainWindow::on_WebBrowser_BeforeNavigate() void MainWindow::on_WebBrowser_NavigateComplete(const QString &url) { + QSignalBlocker blocker(m_addressEdit); actionStop->setEnabled(false); - const bool blocked = addressEdit->blockSignals(true); - addressEdit->setText(url); - addressEdit->blockSignals(blocked); + m_addressEdit->setText(url); } //! [3] @@ -305,9 +315,9 @@ void MainWindow::on_actionNewWindow_triggered() { MainWindow *window = new MainWindow; window->show(); - if (addressEdit->text().isEmpty()) + if (m_addressEdit->text().isEmpty()) return; - window->addressEdit->setText(addressEdit->text()); + window->m_addressEdit->setText(m_addressEdit->text()); window->actionStop->setEnabled(true); window->on_actionGo_triggered(); } @@ -315,9 +325,9 @@ void MainWindow::on_actionNewWindow_triggered() void MainWindow::on_actionAbout_triggered() { QMessageBox::about(this, tr("About WebBrowser"), - tr("This Example has been created using the ActiveQt integration into Qt Designer.\n" - "It demonstrates the use of QAxWidget to embed the Internet Explorer ActiveX\n" - "control into a Qt application.")); + tr("This Example has been created using the ActiveQt integration into Qt Designer.\n" + "It demonstrates the use of QAxWidget to embed the Internet Explorer ActiveX\n" + "control into a Qt application.")); } void MainWindow::on_actionAboutQt_triggered() @@ -333,16 +343,15 @@ void MainWindow::on_actionFileClose_triggered() #include "main.moc" //! [3] //! [4] -int main(int argc, char ** argv) +int main(int argc, char *argv[]) { QApplication a(argc, argv); QCoreApplication::setApplicationVersion(QT_VERSION_STR); - QCoreApplication::setApplicationName("Active Qt Web Browser"); - QCoreApplication::setOrganizationName("QtProject"); + QCoreApplication::setApplicationName(QStringLiteral("Active Qt Web Browser")); + QCoreApplication::setOrganizationName(QStringLiteral("QtProject")); MainWindow w; - const QStringList arguments = QCoreApplication::arguments(); - const QString url = arguments.size() > 1 ? - arguments.at(1) : QString::fromLatin1(qtUrl); + const auto &arguments = QCoreApplication::arguments(); + const QString url = arguments.value(1, QString::fromLatin1(qtUrl)); w.navigate(url); w.show(); return a.exec(); diff --git a/examples/activeqt/webbrowser/webaxwidget.h b/examples/activeqt/webbrowser/webaxwidget.h index acb936e..9a15a72 100644 --- a/examples/activeqt/webbrowser/webaxwidget.h +++ b/examples/activeqt/webbrowser/webaxwidget.h @@ -6,7 +6,17 @@ ** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are @@ -48,7 +58,7 @@ class WebAxWidget : public QAxWidget { public: - WebAxWidget(QWidget* parent = 0, Qt::WindowFlags f = 0) + WebAxWidget(QWidget *parent = nullptr, Qt::WindowFlags f = 0) : QAxWidget(parent, f) { } @@ -57,8 +67,7 @@ protected: { if (message >= WM_KEYFIRST && message <= WM_KEYLAST) return true; - else - return QAxWidget::translateKeyEvent(message, keycode); + return QAxWidget::translateKeyEvent(message, keycode); } }; |