2
* \file browserdialog.cpp
9
* Copyright (C) 2003-2013 Urs Fleisch
11
* This file is part of Kid3.
13
* Kid3 is free software; you can redistribute it and/or modify
14
* it under the terms of the GNU General Public License as published by
15
* the Free Software Foundation; either version 2 of the License, or
16
* (at your option) any later version.
18
* Kid3 is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU General Public License for more details.
23
* You should have received a copy of the GNU General Public License
24
* along with this program. If not, see <http://www.gnu.org/licenses/>.
27
#include "browserdialog.h"
29
#ifndef CONFIG_USE_KDE
30
#include <QTextBrowser>
33
#include <QPushButton>
34
#include <QVBoxLayout>
37
#include <QToolButton>
40
#include "qtcompatmac.h"
45
* @param parent parent widget
46
* @param caption dialog title
48
BrowserDialog::BrowserDialog(QWidget* parent, QString& caption)
51
setObjectName(QLatin1String("BrowserDialog"));
52
setWindowTitle(caption);
53
QVBoxLayout* vlayout = new QVBoxLayout(this);
57
#if QT_VERSION >= 0x040800 && !defined Q_OS_WIN32
58
foreach (const QString& uiLang, locale.uiLanguages()) {
59
QString lang(uiLang.left(2));
60
docPaths += QDir::currentPath() + QLatin1String("/kid3_") + lang + QLatin1String(".html");
62
docPaths += QLatin1String(CFG_DOCDIR) + QLatin1String("/kid3_") + lang + QLatin1String(".html");
66
QString lang(locale.name().left(2));
68
docPaths += QLatin1String(CFG_DOCDIR) + QLatin1String("/kid3_") + lang + QLatin1String(".html");
69
docPaths += QLatin1String(CFG_DOCDIR) + QLatin1String("/kid3_en.html");
71
docPaths += QDir::currentPath() + QLatin1String("/kid3_") + lang + QLatin1String(".html");
72
docPaths += QDir::currentPath() + QLatin1String("/kid3_en.html");
73
for (QStringList::const_iterator it = docPaths.begin();
77
if (QFile::exists(m_filename)) break;
79
m_textBrowser = new QTextBrowser(this);
80
m_textBrowser->setSource(QUrl::fromLocalFile(m_filename));
81
vlayout->addWidget(m_textBrowser);
83
QHBoxLayout* hlayout = new QHBoxLayout;
84
QPushButton* backButton = new QPushButton(i18n("&Back"), this);
85
backButton->setEnabled(false);
86
connect(backButton, SIGNAL(clicked()), m_textBrowser, SLOT(backward()));
87
connect(m_textBrowser, SIGNAL(backwardAvailable(bool)), backButton, SLOT(setEnabled(bool)));
88
hlayout->addWidget(backButton);
89
QPushButton* forwardButton = new QPushButton(i18n("&Forward"), this);
90
forwardButton->setEnabled(false);
91
connect(forwardButton, SIGNAL(clicked()), m_textBrowser, SLOT(forward()));
92
connect(m_textBrowser, SIGNAL(forwardAvailable(bool)), forwardButton, SLOT(setEnabled(bool)));
93
hlayout->addWidget(forwardButton);
94
QLabel* findLabel = new QLabel(i18n("&Find:"), this);
95
hlayout->addWidget(findLabel);
96
m_findLineEdit = new QLineEdit(this);
97
m_findLineEdit->setFocus();
98
findLabel->setBuddy(m_findLineEdit);
99
connect(m_findLineEdit, SIGNAL(returnPressed()), this, SLOT(findNext()));
100
hlayout->addWidget(m_findLineEdit);
101
QAction* findAction = new QAction(this);
102
findAction->setShortcut(QKeySequence::Find);
103
connect(findAction, SIGNAL(triggered()), m_findLineEdit, SLOT(setFocus()));
104
m_findLineEdit->addAction(findAction);
105
QAction* findPreviousAction = new QAction(this);
106
findPreviousAction->setIcon(
107
QIcon(style()->standardIcon(QStyle::SP_ArrowBack)));
108
findPreviousAction->setText(i18n("Find Previous"));
109
findPreviousAction->setShortcut(QKeySequence::FindPrevious);
110
connect(findPreviousAction, SIGNAL(triggered()),
111
this, SLOT(findPrevious()));
112
QToolButton* findPreviousButton = new QToolButton(this);
113
findPreviousButton->setDefaultAction(findPreviousAction);
114
hlayout->addWidget(findPreviousButton);
115
QAction* findNextAction = new QAction(this);
116
findNextAction->setIcon(
117
QIcon(style()->standardIcon(QStyle::SP_ArrowForward)));
118
findNextAction->setText(i18n("Find Next"));
119
findNextAction->setShortcut(QKeySequence::FindNext);
120
connect(findNextAction, SIGNAL(triggered()),
121
this, SLOT(findNext()));
122
QToolButton* findNextButton = new QToolButton(this);
123
findNextButton->setDefaultAction(findNextAction);
124
hlayout->addWidget(findNextButton);
125
hlayout->addStretch();
126
QPushButton* closeButton = new QPushButton(i18n("&Close"), this);
127
closeButton->setAutoDefault(false);
128
connect(closeButton, SIGNAL(clicked()), this, SLOT(accept()));
129
hlayout->addWidget(closeButton);
130
vlayout->addLayout(hlayout);
137
BrowserDialog::~BrowserDialog()
141
* Display help document at anchor.
143
* @param anchor anchor
145
void BrowserDialog::goToAnchor(const QString& anchor)
147
QUrl url = QUrl::fromLocalFile(m_filename);
148
url.setFragment(anchor);
149
m_textBrowser->setSource(url);
153
* Find previous occurrence of search text.
155
void BrowserDialog::findPrevious()
157
m_textBrowser->find(m_findLineEdit->text(), QTextDocument::FindBackward);
161
* Find next occurrence of search text.
163
void BrowserDialog::findNext()
165
m_textBrowser->find(m_findLineEdit->text());
168
#endif // CONFIG_USE_KDE