diff options
-rw-r--r-- | qt-ui/mainwindow.cpp | 2 | ||||
-rw-r--r-- | qt-ui/mainwindow.h | 3 | ||||
-rw-r--r-- | qt-ui/searchbar.ui | 121 | ||||
-rw-r--r-- | qt-ui/usermanual.cpp | 90 | ||||
-rw-r--r-- | qt-ui/usermanual.h | 33 | ||||
-rw-r--r-- | qt-ui/usermanual.ui | 163 | ||||
-rw-r--r-- | subsurface.pro | 6 |
7 files changed, 197 insertions, 221 deletions
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 28e4d7415..27f025402 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -706,7 +706,7 @@ void MainWindow::on_actionUserManual_triggered() { #ifndef NO_USERMANUAL if (!helpView) { - helpView = new UserManual(this); + helpView = new UserManual(); } helpView->show(); #endif diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index cfac072d2..8bdb47e99 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -29,6 +29,7 @@ class ProfileGraphicsView; class QWebView; class QSettings; class UpdateManager; +class UserManual; enum MainWindowTitleFormat { MWTF_DEFAULT, @@ -163,7 +164,7 @@ private: Ui::MainWindow ui; QAction *actionNextDive; QAction *actionPreviousDive; - QMainWindow *helpView; + UserManual *helpView; QTreeView *yearlyStats; QAbstractItemModel *yearlyStatsModel; CurrentState state; diff --git a/qt-ui/searchbar.ui b/qt-ui/searchbar.ui new file mode 100644 index 000000000..df956b230 --- /dev/null +++ b/qt-ui/searchbar.ui @@ -0,0 +1,121 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>SearchBar</class> + <widget class="QWidget" name="SearchBar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>34</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <property name="spacing"> + <number>2</number> + </property> + <property name="leftMargin"> + <number>2</number> + </property> + <property name="topMargin"> + <number>2</number> + </property> + <property name="rightMargin"> + <number>2</number> + </property> + <property name="bottomMargin"> + <number>2</number> + </property> + <item> + <widget class="QLineEdit" name="searchEdit"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>100</width> + <height>0</height> + </size> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="findPrev"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset theme="go-up"> + <normaloff/> + </iconset> + </property> + <property name="flat"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="findNext"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset theme="go-down"> + <normaloff/> + </iconset> + </property> + <property name="flat"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="findClose"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset theme="window-close"> + <normaloff/> + </iconset> + </property> + <property name="flat"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/qt-ui/usermanual.cpp b/qt-ui/usermanual.cpp index a57717a49..6d9c56432 100644 --- a/qt-ui/usermanual.cpp +++ b/qt-ui/usermanual.cpp @@ -4,19 +4,43 @@ #include <QDebug> #include "usermanual.h" -#include "ui_usermanual.h" #include "helpers.h" -UserManual::UserManual(QWidget *parent) : QMainWindow(parent), - ui(new Ui::UserManual) +SearchBar::SearchBar(QWidget *parent): QWidget(parent) { - ui->setupUi(this); + ui.setupUi(this); + #if defined(Q_OS_MAC) || defined(Q_OS_WIN) + ui.findNext->setIcon(QIcon(":icons/subsurface/32x32/actions/go-down.png")); + ui.findPrev->setIcon(QIcon(":icons/subsurface/32x32/actions/go-up.png")); + ui.findClose->setIcon(QIcon(":icons/subsurface/32x32/actions/window-close.png")); + #endif + + connect(ui.findNext, SIGNAL(pressed()), this, SIGNAL(searchNext())); + connect(ui.findPrev, SIGNAL(pressed()), this, SIGNAL(searchPrev())); + connect(ui.searchEdit, SIGNAL(textChanged(QString)), this, SIGNAL(searchTextChanged(QString))); + connect(ui.searchEdit, SIGNAL(textChanged(QString)), this, SLOT(enableButtons(QString))); + connect(ui.findClose, SIGNAL(pressed()), this, SLOT(hide())); +} + +void SearchBar::setVisible(bool visible) +{ + QWidget::setVisible(visible); + ui.searchEdit->setFocus(); +} +void SearchBar::enableButtons(const QString &s) +{ + ui.findPrev->setEnabled(s.length()); + ui.findNext->setEnabled(s.length()); +} + +UserManual::UserManual(QWidget *parent) : QWebView(parent) +{ QShortcut *closeKey = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this); connect(closeKey, SIGNAL(activated()), this, SLOT(close())); QShortcut *quitKey = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this); - connect(quitKey, SIGNAL(activated()), parent, SLOT(close())); + connect(quitKey, SIGNAL(activated()), qApp, SLOT(quit())); QAction *actionShowSearch = new QAction(this); actionShowSearch->setShortcut(Qt::CTRL + Qt::Key_F); @@ -30,7 +54,7 @@ UserManual::UserManual(QWidget *parent) : QMainWindow(parent), setWindowTitle(tr("User Manual")); - ui->webView->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks); + page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks); QString searchPath = getSubsurfaceDataPath("Documentation"); if (searchPath.size()) { // look for localized versions of the manual first @@ -42,65 +66,48 @@ UserManual::UserManual(QWidget *parent) : QMainWindow(parent), if (!manual.exists()) manual.setFileName(prefix + ".html"); if (!manual.exists()) { - ui->webView->setHtml(tr("Cannot find the Subsurface manual")); + setHtml(tr("Cannot find the Subsurface manual")); } else { QString urlString = QString("file:///") + manual.fileName(); - QUrl url(urlString, QUrl::TolerantMode); - ui->webView->setUrl(url); + setUrl(QUrl(urlString, QUrl::TolerantMode)); } } else { - ui->webView->setHtml(tr("Cannot find the Subsurface manual")); + setHtml(tr("Cannot find the Subsurface manual")); } - ui->searchPanel->setParent(this); - ui->searchPanel->hide(); - - connect(actionShowSearch, SIGNAL(triggered(bool)), this, SLOT(showSearchPanel())); - connect(actionHideSearch, SIGNAL(triggered(bool)), this, SLOT(hideSearchPanel())); - connect(ui->webView, SIGNAL(linkClicked(QUrl)), this, SLOT(linkClickedSlot(QUrl))); - connect(ui->searchEdit, SIGNAL(textChanged(QString)), this, SLOT(searchTextChanged(QString))); - connect(ui->findNext, SIGNAL(clicked()), this, SLOT(searchNext())); - connect(ui->findPrev, SIGNAL(clicked()), this, SLOT(searchPrev())); -} -void UserManual::showSearchPanel() -{ - ui->searchPanel->show(); - ui->searchEdit->setFocus(); - ui->searchEdit->selectAll(); -} - -void UserManual::hideSearchPanel() -{ - ui->searchPanel->hide(); + searchBar = new SearchBar(this); + searchBar->hide(); + connect(actionShowSearch, SIGNAL(triggered(bool)), searchBar, SLOT(show())); + connect(actionHideSearch, SIGNAL(triggered(bool)), searchBar, SLOT(hide())); + connect(this, SIGNAL(linkClicked(QUrl)), this, SLOT(linkClickedSlot(QUrl))); + connect(searchBar, SIGNAL(searchTextChanged(QString)), this, SLOT(searchTextChanged(QString))); + connect(searchBar, SIGNAL(searchNext()), this, SLOT(searchNext())); + connect(searchBar, SIGNAL(searchPrev()), this, SLOT(searchPrev())); } void UserManual::search(QString text, QWebPage::FindFlags flags = 0) { - if (ui->webView->findText(text, QWebPage::FindWrapsAroundDocument | flags) || text.length() == 0) { - ui->searchEdit->setStyleSheet(""); + if (findText(text, QWebPage::FindWrapsAroundDocument | flags) || text.length() == 0) { + searchBar->setStyleSheet(""); } else { - ui->searchEdit->setStyleSheet("QLineEdit{background: red;}"); + searchBar->setStyleSheet("QLineEdit{background: red;}"); } } -void UserManual::searchTextChanged(QString text) +void UserManual::searchTextChanged(const QString& text) { - bool hasText = text.length() > 0; - - ui->findPrev->setEnabled(hasText); - ui->findNext->setEnabled(hasText); - + mLastText = text; search(text); } void UserManual::searchNext() { - search(ui->searchEdit->text()); + search(mLastText); } void UserManual::searchPrev() { - search(ui->searchEdit->text(), QWebPage::FindBackward); + search(mLastText, QWebPage::FindBackward); } void UserManual::linkClickedSlot(QUrl url) @@ -110,5 +117,4 @@ void UserManual::linkClickedSlot(QUrl url) UserManual::~UserManual() { - delete ui; } diff --git a/qt-ui/usermanual.h b/qt-ui/usermanual.h index de8770eba..7cd10c185 100644 --- a/qt-ui/usermanual.h +++ b/qt-ui/usermanual.h @@ -1,31 +1,42 @@ #ifndef USERMANUAL_H #define USERMANUAL_H -#include <QMainWindow> -#include <QWebPage> +#include <QWebView> -namespace Ui { - class UserManual; -} +#include "ui_searchbar.h" -class UserManual : public QMainWindow { +class SearchBar : public QWidget{ + Q_OBJECT +public: + SearchBar(QWidget *parent = 0); +signals: + void searchTextChanged(const QString& s); + void searchNext(); + void searchPrev(); +protected: + void setVisible(bool visible); +private slots: + void enableButtons(const QString& s); +private: + Ui::SearchBar ui; +}; + +class UserManual : public QWebView { Q_OBJECT public: explicit UserManual(QWidget *parent = 0); ~UserManual(); - private slots: - void showSearchPanel(); - void hideSearchPanel(); - void searchTextChanged(QString); + void searchTextChanged(const QString& s); void searchNext(); void searchPrev(); void linkClickedSlot(QUrl url); private: - Ui::UserManual *ui; + SearchBar *searchBar; + QString mLastText; void search(QString, QWebPage::FindFlags); }; #endif // USERMANUAL_H diff --git a/qt-ui/usermanual.ui b/qt-ui/usermanual.ui deleted file mode 100644 index e8f0095f5..000000000 --- a/qt-ui/usermanual.ui +++ /dev/null @@ -1,163 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>UserManual</class> - <widget class="QMainWindow" name="UserManual"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>834</width> - <height>599</height> - </rect> - </property> - <property name="windowIcon"> - <iconset resource="../subsurface.qrc"> - <normaloff>:/subsurface-icon</normaloff>:/subsurface-icon</iconset> - </property> - <widget class="QWidget" name="centralWidget"> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="QWidget" name="searchPanel" native="true"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Maximum" vsizetype="Maximum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>230</width> - <height>40</height> - </size> - </property> - <property name="autoFillBackground"> - <bool>true</bool> - </property> - <layout class="QHBoxLayout" name="horizontalLayout"> - <property name="spacing"> - <number>0</number> - </property> - <property name="leftMargin"> - <number>9</number> - </property> - <property name="topMargin"> - <number>9</number> - </property> - <property name="rightMargin"> - <number>0</number> - </property> - <property name="bottomMargin"> - <number>0</number> - </property> - <item> - <widget class="QLineEdit" name="searchEdit"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>100</width> - <height>0</height> - </size> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="findPrev"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset theme="go-up"> - <normaloff/> - </iconset> - </property> - <property name="flat"> - <bool>true</bool> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="findNext"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset theme="go-down"> - <normaloff/> - </iconset> - </property> - <property name="flat"> - <bool>true</bool> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="findClose"> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset theme="window-close"> - <normaloff/> - </iconset> - </property> - <property name="flat"> - <bool>true</bool> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item> - <widget class="QWebView" name="webView" native="true"/> - </item> - </layout> - </widget> - </widget> - <layoutdefault spacing="6" margin="11"/> - <customwidgets> - <customwidget> - <class>QWebView</class> - <extends>QWidget</extends> - <header>qwebview.h</header> - </customwidget> - </customwidgets> - <resources> - <include location="../subsurface.qrc"/> - </resources> - <connections> - <connection> - <sender>findClose</sender> - <signal>clicked()</signal> - <receiver>searchPanel</receiver> - <slot>hide()</slot> - <hints> - <hint type="sourcelabel"> - <x>261</x> - <y>37</y> - </hint> - <hint type="destinationlabel"> - <x>220</x> - <y>11</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/subsurface.pro b/subsurface.pro index 3dec531c2..b9ff68a4f 100644 --- a/subsurface.pro +++ b/subsurface.pro @@ -4,7 +4,7 @@ QT = core gui network svg concurrent lessThan(QT_MAJOR_VERSION, 5) { QT += webkit } else { - !android: QT += webkitwidgets + !android: QT += webkitwidgets webkit android: QT += androidextras } INCLUDEPATH += qt-ui $$PWD @@ -191,13 +191,13 @@ FORMS = \ qt-ui/webservices.ui \ qt-ui/tableview.ui \ qt-ui/divelogimportdialog.ui \ - qt-ui/usermanual.ui \ + qt-ui/searchbar.ui \ qt-ui/divelogexportdialog.ui \ qt-ui/plannerSettings.ui \ qt-ui/usersurvey.ui # Nether usermanual or printing is supported on android right now -android: FORMS -= qt-ui/usermanual.ui qt-ui/printoptions.ui +android: FORMS -= qt-ui/printoptions.ui RESOURCES = subsurface.qrc |