~ubuntu-branches/ubuntu/wily/kid3/wily

« back to all changes in this revision

Viewing changes to src/gui/dialogs/browserdialog.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell, Patrick Matthäi, Mark Purcell
  • Date: 2013-11-30 15:44:59 UTC
  • mfrom: (1.1.16) (2.1.18 sid)
  • Revision ID: package-import@ubuntu.com-20131130154459-s6lpalx8yy2zq7gx
Tags: 3.0.2-1
* New upstream release 

[ Patrick Matthäi ]
* New upstream release.
  - Add new libreadline-dev build dependency.
* Don't explicitly request xz compression - dpkg 1.17 does this by default.
* Bump Standards-Version to 3.9.5 (no changes needed).
* Fix Vcs-Browser control field.

[ Mark Purcell ]
* Switch to dh - reduce debian/rules bloat
* kid3 Replaces kid3-qt - low popcon, reduce archive bloat
* Fix vcs-field-not-canonical
* debian/compat -> 9
* Update Description:

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * \file browserdialog.cpp
3
 
 * Help browser.
4
 
 *
5
 
 * \b Project: Kid3
6
 
 * \author Urs Fleisch
7
 
 * \date 10 Jun 2009
8
 
 *
9
 
 * Copyright (C) 2003-2013  Urs Fleisch
10
 
 *
11
 
 * This file is part of Kid3.
12
 
 *
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.
17
 
 *
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.
22
 
 *
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/>.
25
 
 */
26
 
 
27
 
#include "browserdialog.h"
28
 
 
29
 
#ifndef CONFIG_USE_KDE
30
 
#include <QTextBrowser>
31
 
#include <QLocale>
32
 
#include <QDir>
33
 
#include <QPushButton>
34
 
#include <QVBoxLayout>
35
 
#include <QLabel>
36
 
#include <QLineEdit>
37
 
#include <QToolButton>
38
 
#include <QStyle>
39
 
#include <QAction>
40
 
#include "qtcompatmac.h"
41
 
 
42
 
/**
43
 
 * Constructor.
44
 
 *
45
 
 * @param parent parent widget
46
 
 * @param caption dialog title
47
 
 */
48
 
BrowserDialog::BrowserDialog(QWidget* parent, QString& caption)
49
 
  : QDialog(parent)
50
 
{
51
 
  setObjectName(QLatin1String("BrowserDialog"));
52
 
  setWindowTitle(caption);
53
 
  QVBoxLayout* vlayout = new QVBoxLayout(this);
54
 
 
55
 
  QLocale locale;
56
 
  QStringList docPaths;
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");
61
 
#ifdef CFG_DOCDIR
62
 
    docPaths += QLatin1String(CFG_DOCDIR) + QLatin1String("/kid3_") + lang + QLatin1String(".html");
63
 
#endif
64
 
  }
65
 
#endif
66
 
  QString lang(locale.name().left(2));
67
 
#ifdef CFG_DOCDIR
68
 
  docPaths += QLatin1String(CFG_DOCDIR) + QLatin1String("/kid3_") + lang + QLatin1String(".html");
69
 
  docPaths += QLatin1String(CFG_DOCDIR) + QLatin1String("/kid3_en.html");
70
 
#endif
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();
74
 
       it != docPaths.end();
75
 
       ++it) {
76
 
    m_filename = *it;
77
 
    if (QFile::exists(m_filename)) break;
78
 
  }
79
 
  m_textBrowser = new QTextBrowser(this);
80
 
  m_textBrowser->setSource(QUrl::fromLocalFile(m_filename));
81
 
  vlayout->addWidget(m_textBrowser);
82
 
 
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);
131
 
  resize(500, 500);
132
 
}
133
 
 
134
 
/**
135
 
 * Destructor.
136
 
 */
137
 
BrowserDialog::~BrowserDialog()
138
 
{}
139
 
 
140
 
/**
141
 
 * Display help document at anchor.
142
 
 *
143
 
 * @param anchor anchor
144
 
 */
145
 
void BrowserDialog::goToAnchor(const QString& anchor)
146
 
{
147
 
  QUrl url = QUrl::fromLocalFile(m_filename);
148
 
  url.setFragment(anchor);
149
 
  m_textBrowser->setSource(url);
150
 
}
151
 
 
152
 
/**
153
 
 * Find previous occurrence of search text.
154
 
 */
155
 
void BrowserDialog::findPrevious()
156
 
{
157
 
  m_textBrowser->find(m_findLineEdit->text(), QTextDocument::FindBackward);
158
 
}
159
 
 
160
 
/**
161
 
 * Find next occurrence of search text.
162
 
 */
163
 
void BrowserDialog::findNext()
164
 
{
165
 
  m_textBrowser->find(m_findLineEdit->text());
166
 
}
167
 
 
168
 
#endif // CONFIG_USE_KDE