source: visorpdf/sources/helpdialog.cpp @ 8964fdc

Last change on this file since 8964fdc was 8964fdc, checked in by Pedro Buitrago <pbuitrago@…>, 8 years ago

Se realiza las modificaciones para agregar el nombre del proyecto murrupuy y la información sobre el proyecto

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2
3Copyright 2013 Benjamin Eltzner
4Copyright 2013 Adam Reichold
5
6This file is part of qpdfview.
7
8qpdfview is free software: you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation, either version 2 of the License, or
11(at your option) any later version.
12
13qpdfview is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along 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
35namespace qpdfview
36{
37
38HelpDialog::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
92HelpDialog::~HelpDialog()
93{
94    Settings::instance()->mainWindow().setContentsDialogSize(size());
95}
96
97void 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
111void 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
126void HelpDialog::on_search_textEdited()
127{
128    m_searchLineEdit->setStyleSheet(QString());
129}
130
131} // qpdfview
Note: See TracBrowser for help on using the repository browser.