1 | /* |
---|
2 | |
---|
3 | Copyright 2013 Benjamin Eltzner |
---|
4 | Copyright 2013 Adam Reichold |
---|
5 | |
---|
6 | This file is part of qpdfview. |
---|
7 | |
---|
8 | qpdfview is free software: you can redistribute it and/or modify |
---|
9 | it under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation, either version 2 of the License, or |
---|
11 | (at your option) any later version. |
---|
12 | |
---|
13 | qpdfview is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | GNU General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with qpdfview. If not, see <http://www.gnu.org/licenses/>. |
---|
20 | |
---|
21 | */ |
---|
22 | |
---|
23 | #include "helpdialog.h" |
---|
24 | |
---|
25 | #include <QApplication> |
---|
26 | #include <QDialogButtonBox> |
---|
27 | #include <QDir> |
---|
28 | #include <QLineEdit> |
---|
29 | #include <QPushButton> |
---|
30 | #include <QTextBrowser> |
---|
31 | #include <QVBoxLayout> |
---|
32 | |
---|
33 | #include "settings.h" |
---|
34 | |
---|
35 | namespace qpdfview |
---|
36 | { |
---|
37 | |
---|
38 | HelpDialog::HelpDialog(QWidget* parent) : QDialog(parent) |
---|
39 | { |
---|
40 | setWindowTitle(tr("Help") + QLatin1String(" - Murrupuy")); |
---|
41 | |
---|
42 | m_textBrowser = new QTextBrowser(this); |
---|
43 | m_textBrowser->setTextInteractionFlags(Qt::TextBrowserInteraction | Qt::TextSelectableByKeyboard); |
---|
44 | m_textBrowser->setSearchPaths(QStringList() << QDir(QApplication::applicationDirPath()).filePath("data") << DATA_INSTALL_PATH); |
---|
45 | |
---|
46 | //: Please replace by file name of localized help if available, e.g. "help_fr.html". |
---|
47 | m_textBrowser->setSource(QUrl::fromLocalFile(tr("help.html"))); |
---|
48 | |
---|
49 | if(m_textBrowser->document()->isEmpty()) |
---|
50 | { |
---|
51 | m_textBrowser->setSource(QUrl::fromLocalFile("help.html")); |
---|
52 | } |
---|
53 | |
---|
54 | m_dialogButtonBox = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, this); |
---|
55 | connect(m_dialogButtonBox, SIGNAL(accepted()), SLOT(accept())); |
---|
56 | connect(m_dialogButtonBox, SIGNAL(rejected()), SLOT(reject())); |
---|
57 | |
---|
58 | m_searchLineEdit = new QLineEdit(this); |
---|
59 | connect(m_searchLineEdit, SIGNAL(returnPressed()), SLOT(on_findNext_triggered())); |
---|
60 | connect(m_searchLineEdit, SIGNAL(textEdited(QString)), SLOT(on_search_textEdited())); |
---|
61 | |
---|
62 | m_findPreviousButton = m_dialogButtonBox->addButton(tr("Find previous"), QDialogButtonBox::ActionRole); |
---|
63 | m_findPreviousButton->setShortcut(QKeySequence::FindPrevious); |
---|
64 | connect(m_findPreviousButton, SIGNAL(clicked()), SLOT(on_findPrevious_triggered())); |
---|
65 | |
---|
66 | m_findNextButton = m_dialogButtonBox->addButton(tr("Find next"), QDialogButtonBox::ActionRole); |
---|
67 | m_findNextButton->setShortcut(QKeySequence::FindNext); |
---|
68 | connect(m_findNextButton, SIGNAL(clicked()), SLOT(on_findNext_triggered())); |
---|
69 | |
---|
70 | // Default buttons would interfere with search funtionality... |
---|
71 | foreach(QAbstractButton* abstractButton, m_dialogButtonBox->buttons()) |
---|
72 | { |
---|
73 | QPushButton* pushButton = qobject_cast< QPushButton* >(abstractButton); |
---|
74 | |
---|
75 | if(pushButton != 0) |
---|
76 | { |
---|
77 | pushButton->setAutoDefault(false); |
---|
78 | pushButton->setDefault(false); |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | setLayout(new QVBoxLayout(this)); |
---|
83 | layout()->addWidget(m_textBrowser); |
---|
84 | layout()->addWidget(m_searchLineEdit); |
---|
85 | layout()->addWidget(m_dialogButtonBox); |
---|
86 | |
---|
87 | resize(Settings::instance()->mainWindow().contentsDialogSize(sizeHint())); |
---|
88 | |
---|
89 | m_searchLineEdit->setFocus(); |
---|
90 | } |
---|
91 | |
---|
92 | HelpDialog::~HelpDialog() |
---|
93 | { |
---|
94 | Settings::instance()->mainWindow().setContentsDialogSize(size()); |
---|
95 | } |
---|
96 | |
---|
97 | void HelpDialog::on_findPrevious_triggered() |
---|
98 | { |
---|
99 | if(!m_searchLineEdit->text().isEmpty() && m_textBrowser->find(m_searchLineEdit->text(), QTextDocument::FindBackward)) |
---|
100 | { |
---|
101 | m_textBrowser->setFocus(); |
---|
102 | |
---|
103 | m_searchLineEdit->setStyleSheet(QLatin1String("background-color: #80ff80")); |
---|
104 | } |
---|
105 | else |
---|
106 | { |
---|
107 | m_searchLineEdit->setStyleSheet(QLatin1String("background-color: #ff8080")); |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | void HelpDialog::on_findNext_triggered() |
---|
112 | { |
---|
113 | if(!m_searchLineEdit->text().isEmpty() && m_textBrowser->find(m_searchLineEdit->text())) |
---|
114 | { |
---|
115 | m_textBrowser->setFocus(); |
---|
116 | |
---|
117 | m_searchLineEdit->setStyleSheet(QLatin1String("background-color: #80ff80")); |
---|
118 | } |
---|
119 | else |
---|
120 | { |
---|
121 | m_searchLineEdit->setStyleSheet(QLatin1String("background-color: #ff8080")); |
---|
122 | |
---|
123 | } |
---|
124 | } |
---|
125 | |
---|
126 | void HelpDialog::on_search_textEdited() |
---|
127 | { |
---|
128 | m_searchLineEdit->setStyleSheet(QString()); |
---|
129 | } |
---|
130 | |
---|
131 | } // qpdfview |
---|