Fixed SearchBar layout and icons

This is almost a rewrite of the Search function on the WebView
the old code had a few uneeded things, mostly being a subclass
of QMainWindow instead of the QWebView - this makes the code
use a tiny bit less ram.

The SearchBox was also moved to an own class ( we can use it
later to filter the contents of the DiveList for instance )

and a forced use of the pixmaps for the Mac and Windows platform
was added.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-06-30 17:45:52 -03:00 committed by Dirk Hohndel
parent 4c7ea24921
commit 927bc5d601
7 changed files with 197 additions and 221 deletions

View file

@ -706,7 +706,7 @@ void MainWindow::on_actionUserManual_triggered()
{ {
#ifndef NO_USERMANUAL #ifndef NO_USERMANUAL
if (!helpView) { if (!helpView) {
helpView = new UserManual(this); helpView = new UserManual();
} }
helpView->show(); helpView->show();
#endif #endif

View file

@ -29,6 +29,7 @@ class ProfileGraphicsView;
class QWebView; class QWebView;
class QSettings; class QSettings;
class UpdateManager; class UpdateManager;
class UserManual;
enum MainWindowTitleFormat { enum MainWindowTitleFormat {
MWTF_DEFAULT, MWTF_DEFAULT,
@ -163,7 +164,7 @@ private:
Ui::MainWindow ui; Ui::MainWindow ui;
QAction *actionNextDive; QAction *actionNextDive;
QAction *actionPreviousDive; QAction *actionPreviousDive;
QMainWindow *helpView; UserManual *helpView;
QTreeView *yearlyStats; QTreeView *yearlyStats;
QAbstractItemModel *yearlyStatsModel; QAbstractItemModel *yearlyStatsModel;
CurrentState state; CurrentState state;

121
qt-ui/searchbar.ui Normal file
View file

@ -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>

View file

@ -4,19 +4,43 @@
#include <QDebug> #include <QDebug>
#include "usermanual.h" #include "usermanual.h"
#include "ui_usermanual.h"
#include "helpers.h" #include "helpers.h"
UserManual::UserManual(QWidget *parent) : QMainWindow(parent), SearchBar::SearchBar(QWidget *parent): QWidget(parent)
ui(new Ui::UserManual)
{ {
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); QShortcut *closeKey = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this);
connect(closeKey, SIGNAL(activated()), this, SLOT(close())); connect(closeKey, SIGNAL(activated()), this, SLOT(close()));
QShortcut *quitKey = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this); 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); QAction *actionShowSearch = new QAction(this);
actionShowSearch->setShortcut(Qt::CTRL + Qt::Key_F); actionShowSearch->setShortcut(Qt::CTRL + Qt::Key_F);
@ -30,7 +54,7 @@ UserManual::UserManual(QWidget *parent) : QMainWindow(parent),
setWindowTitle(tr("User Manual")); setWindowTitle(tr("User Manual"));
ui->webView->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks); page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks);
QString searchPath = getSubsurfaceDataPath("Documentation"); QString searchPath = getSubsurfaceDataPath("Documentation");
if (searchPath.size()) { if (searchPath.size()) {
// look for localized versions of the manual first // look for localized versions of the manual first
@ -42,65 +66,48 @@ UserManual::UserManual(QWidget *parent) : QMainWindow(parent),
if (!manual.exists()) if (!manual.exists())
manual.setFileName(prefix + ".html"); manual.setFileName(prefix + ".html");
if (!manual.exists()) { if (!manual.exists()) {
ui->webView->setHtml(tr("Cannot find the Subsurface manual")); setHtml(tr("Cannot find the Subsurface manual"));
} else { } else {
QString urlString = QString("file:///") + manual.fileName(); QString urlString = QString("file:///") + manual.fileName();
QUrl url(urlString, QUrl::TolerantMode); setUrl(QUrl(urlString, QUrl::TolerantMode));
ui->webView->setUrl(url);
} }
} else { } 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())); searchBar = new SearchBar(this);
connect(actionHideSearch, SIGNAL(triggered(bool)), this, SLOT(hideSearchPanel())); searchBar->hide();
connect(ui->webView, SIGNAL(linkClicked(QUrl)), this, SLOT(linkClickedSlot(QUrl))); connect(actionShowSearch, SIGNAL(triggered(bool)), searchBar, SLOT(show()));
connect(ui->searchEdit, SIGNAL(textChanged(QString)), this, SLOT(searchTextChanged(QString))); connect(actionHideSearch, SIGNAL(triggered(bool)), searchBar, SLOT(hide()));
connect(ui->findNext, SIGNAL(clicked()), this, SLOT(searchNext())); connect(this, SIGNAL(linkClicked(QUrl)), this, SLOT(linkClickedSlot(QUrl)));
connect(ui->findPrev, SIGNAL(clicked()), this, SLOT(searchPrev())); 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::showSearchPanel()
{
ui->searchPanel->show();
ui->searchEdit->setFocus();
ui->searchEdit->selectAll();
}
void UserManual::hideSearchPanel()
{
ui->searchPanel->hide();
} }
void UserManual::search(QString text, QWebPage::FindFlags flags = 0) void UserManual::search(QString text, QWebPage::FindFlags flags = 0)
{ {
if (ui->webView->findText(text, QWebPage::FindWrapsAroundDocument | flags) || text.length() == 0) { if (findText(text, QWebPage::FindWrapsAroundDocument | flags) || text.length() == 0) {
ui->searchEdit->setStyleSheet(""); searchBar->setStyleSheet("");
} else { } 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; mLastText = text;
ui->findPrev->setEnabled(hasText);
ui->findNext->setEnabled(hasText);
search(text); search(text);
} }
void UserManual::searchNext() void UserManual::searchNext()
{ {
search(ui->searchEdit->text()); search(mLastText);
} }
void UserManual::searchPrev() void UserManual::searchPrev()
{ {
search(ui->searchEdit->text(), QWebPage::FindBackward); search(mLastText, QWebPage::FindBackward);
} }
void UserManual::linkClickedSlot(QUrl url) void UserManual::linkClickedSlot(QUrl url)
@ -110,5 +117,4 @@ void UserManual::linkClickedSlot(QUrl url)
UserManual::~UserManual() UserManual::~UserManual()
{ {
delete ui;
} }

View file

@ -1,31 +1,42 @@
#ifndef USERMANUAL_H #ifndef USERMANUAL_H
#define USERMANUAL_H #define USERMANUAL_H
#include <QMainWindow> #include <QWebView>
#include <QWebPage>
namespace Ui { #include "ui_searchbar.h"
class UserManual;
}
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 Q_OBJECT
public: public:
explicit UserManual(QWidget *parent = 0); explicit UserManual(QWidget *parent = 0);
~UserManual(); ~UserManual();
private private
slots: slots:
void showSearchPanel(); void searchTextChanged(const QString& s);
void hideSearchPanel();
void searchTextChanged(QString);
void searchNext(); void searchNext();
void searchPrev(); void searchPrev();
void linkClickedSlot(QUrl url); void linkClickedSlot(QUrl url);
private: private:
Ui::UserManual *ui; SearchBar *searchBar;
QString mLastText;
void search(QString, QWebPage::FindFlags); void search(QString, QWebPage::FindFlags);
}; };
#endif // USERMANUAL_H #endif // USERMANUAL_H

View file

@ -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>

View file

@ -4,7 +4,7 @@ QT = core gui network svg concurrent
lessThan(QT_MAJOR_VERSION, 5) { lessThan(QT_MAJOR_VERSION, 5) {
QT += webkit QT += webkit
} else { } else {
!android: QT += webkitwidgets !android: QT += webkitwidgets webkit
android: QT += androidextras android: QT += androidextras
} }
INCLUDEPATH += qt-ui $$PWD INCLUDEPATH += qt-ui $$PWD
@ -191,13 +191,13 @@ FORMS = \
qt-ui/webservices.ui \ qt-ui/webservices.ui \
qt-ui/tableview.ui \ qt-ui/tableview.ui \
qt-ui/divelogimportdialog.ui \ qt-ui/divelogimportdialog.ui \
qt-ui/usermanual.ui \ qt-ui/searchbar.ui \
qt-ui/divelogexportdialog.ui \ qt-ui/divelogexportdialog.ui \
qt-ui/plannerSettings.ui \ qt-ui/plannerSettings.ui \
qt-ui/usersurvey.ui qt-ui/usersurvey.ui
# Nether usermanual or printing is supported on android right now # 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 RESOURCES = subsurface.qrc