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(" - Terepaima")); |
---|
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 | // search files in /usr/share/terepaima |
---|
46 | m_textBrowser->setSearchPaths(QStringList() << "/usr/share/terepaima"); |
---|
47 | |
---|
48 | //: Please replace by file name of localized help if available, e.g. "help_fr.html". |
---|
49 | //m_textBrowser->setSource(QUrl::fromLocalFile(tr("help.html"))); |
---|
50 | m_textBrowser->setSource(QUrl::fromLocalFile(tr("help_es.html"))); |
---|
51 | |
---|
52 | if(m_textBrowser->document()->isEmpty()) |
---|
53 | { |
---|
54 | m_textBrowser->setSource(QUrl::fromLocalFile("help.html")); |
---|
55 | } |
---|
56 | |
---|
57 | m_dialogButtonBox = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, this); |
---|
58 | connect(m_dialogButtonBox, SIGNAL(accepted()), SLOT(accept())); |
---|
59 | connect(m_dialogButtonBox, SIGNAL(rejected()), SLOT(reject())); |
---|
60 | |
---|
61 | m_searchLineEdit = new QLineEdit(this); |
---|
62 | connect(m_searchLineEdit, SIGNAL(returnPressed()), SLOT(on_findNext_triggered())); |
---|
63 | connect(m_searchLineEdit, SIGNAL(textEdited(QString)), SLOT(on_search_textEdited())); |
---|
64 | |
---|
65 | m_findPreviousButton = m_dialogButtonBox->addButton(tr("Find previous"), QDialogButtonBox::ActionRole); |
---|
66 | m_findPreviousButton->setShortcut(QKeySequence::FindPrevious); |
---|
67 | connect(m_findPreviousButton, SIGNAL(clicked()), SLOT(on_findPrevious_triggered())); |
---|
68 | |
---|
69 | m_findNextButton = m_dialogButtonBox->addButton(tr("Find next"), QDialogButtonBox::ActionRole); |
---|
70 | m_findNextButton->setShortcut(QKeySequence::FindNext); |
---|
71 | connect(m_findNextButton, SIGNAL(clicked()), SLOT(on_findNext_triggered())); |
---|
72 | |
---|
73 | // Default buttons would interfere with search funtionality... |
---|
74 | foreach(QAbstractButton* abstractButton, m_dialogButtonBox->buttons()) |
---|
75 | { |
---|
76 | QPushButton* pushButton = qobject_cast< QPushButton* >(abstractButton); |
---|
77 | |
---|
78 | if(pushButton != 0) |
---|
79 | { |
---|
80 | pushButton->setAutoDefault(false); |
---|
81 | pushButton->setDefault(false); |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | setLayout(new QVBoxLayout(this)); |
---|
86 | layout()->addWidget(m_textBrowser); |
---|
87 | layout()->addWidget(m_searchLineEdit); |
---|
88 | layout()->addWidget(m_dialogButtonBox); |
---|
89 | |
---|
90 | resize(Settings::instance()->mainWindow().contentsDialogSize(sizeHint())); |
---|
91 | |
---|
92 | m_searchLineEdit->setFocus(); |
---|
93 | } |
---|
94 | |
---|
95 | HelpDialog::~HelpDialog() |
---|
96 | { |
---|
97 | Settings::instance()->mainWindow().setContentsDialogSize(size()); |
---|
98 | } |
---|
99 | |
---|
100 | void HelpDialog::on_findPrevious_triggered() |
---|
101 | { |
---|
102 | if(!m_searchLineEdit->text().isEmpty() && m_textBrowser->find(m_searchLineEdit->text(), QTextDocument::FindBackward)) |
---|
103 | { |
---|
104 | m_textBrowser->setFocus(); |
---|
105 | |
---|
106 | m_searchLineEdit->setStyleSheet(QLatin1String("background-color: #80ff80")); |
---|
107 | } |
---|
108 | else |
---|
109 | { |
---|
110 | m_searchLineEdit->setStyleSheet(QLatin1String("background-color: #ff8080")); |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | void HelpDialog::on_findNext_triggered() |
---|
115 | { |
---|
116 | if(!m_searchLineEdit->text().isEmpty() && m_textBrowser->find(m_searchLineEdit->text())) |
---|
117 | { |
---|
118 | m_textBrowser->setFocus(); |
---|
119 | |
---|
120 | m_searchLineEdit->setStyleSheet(QLatin1String("background-color: #80ff80")); |
---|
121 | } |
---|
122 | else |
---|
123 | { |
---|
124 | m_searchLineEdit->setStyleSheet(QLatin1String("background-color: #ff8080")); |
---|
125 | |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | void HelpDialog::on_search_textEdited() |
---|
130 | { |
---|
131 | m_searchLineEdit->setStyleSheet(QString()); |
---|
132 | } |
---|
133 | |
---|
134 | } // qpdfview |
---|