~ubuntu-branches/ubuntu/jaunty/bibletime/jaunty

« back to all changes in this revision

Viewing changes to bibletime/frontend/display/cdisplay.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ralph Janke
  • Date: 2008-05-10 15:18:16 UTC
  • mfrom: (1.1.6 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080510151816-bqp8y1to705zd0fm
Tags: 1.6.5.1-1
* New upstream version (Closes: #441161, #271502)
* fixes for new autotools and gcc 4.3 (Closes: #407291)
* added poxml to Build-Depends
* No DFSG necessary anymore since biblestudy howto has 
  now Commons Licence 
* Added libclucene-dev to dev-depends (Closes: #436677)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********
 
2
*
 
3
* This file is part of BibleTime's source code, http://www.bibletime.info/.
 
4
*
 
5
* Copyright 1999-2006 by the BibleTime developers.
 
6
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
 
7
*
 
8
**********/
 
9
 
 
10
 
 
11
 
 
12
#include "cdisplay.h"
 
13
#include "chtmlreaddisplay.h"
 
14
#include "cplainwritedisplay.h"
 
15
#include "chtmlwritedisplay.h"
 
16
 
 
17
#include "backend/creferencemanager.h"
 
18
 
 
19
#include "util/ctoolclass.h"
 
20
 
 
21
 
 
22
//Qt includes
 
23
#include <qclipboard.h>
 
24
#include <qpopupmenu.h>
 
25
#include <qtimer.h>
 
26
 
 
27
//KDE includes
 
28
#include <kapplication.h>
 
29
#include <kfiledialog.h>
 
30
#include <klocale.h>
 
31
 
 
32
 
 
33
CDisplayConnections::CDisplayConnections( CDisplay* display ) : m_display(display) {}
 
34
 
 
35
void CDisplayConnections::selectAll() {
 
36
        m_display->selectAll();
 
37
}
 
38
 
 
39
void CDisplayConnections::saveAsHTML() {
 
40
        m_display->save(CDisplay::HTMLText, CDisplay::Document);
 
41
}
 
42
 
 
43
void CDisplayConnections::saveAsPlain() {
 
44
        m_display->save(CDisplay::PlainText, CDisplay::Document);
 
45
}
 
46
 
 
47
/** Emits the signal. */
 
48
void CDisplayConnections::emitReferenceClicked( const QString& module, const QString& key) {
 
49
        emit referenceClicked( module, key );
 
50
}
 
51
 
 
52
/** Emits the signal. */
 
53
void CDisplayConnections::emitReferenceDropped( const QString& key) {
 
54
        emit referenceDropped(key);
 
55
}
 
56
 
 
57
/** Emits the signal. */
 
58
void CDisplayConnections::emitTextChanged() {
 
59
        emit textChanged();
 
60
}
 
61
 
 
62
void CDisplayConnections::copyAll() {
 
63
        m_display->copy(CDisplay::PlainText, CDisplay::Document);
 
64
}
 
65
 
 
66
/** No descriptions */
 
67
void CDisplayConnections::copySelection() {
 
68
        qWarning("copyign the selected text");
 
69
        m_display->copy(CDisplay::PlainText, CDisplay::SelectedText);
 
70
}
 
71
 
 
72
void CDisplayConnections::printAll(CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions) {
 
73
        m_display->print(CDisplay::Document, displayOptions, filterOptions);
 
74
}
 
75
 
 
76
void CDisplayConnections::printAnchorWithText(CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions) {
 
77
        m_display->print(CDisplay::AnchorWithText, displayOptions, filterOptions);
 
78
}
 
79
 
 
80
void CDisplayConnections::copyAnchorOnly() {
 
81
        m_display->copy(CDisplay::PlainText, CDisplay::AnchorOnly);
 
82
}
 
83
 
 
84
void CDisplayConnections::copyAnchorTextOnly() {
 
85
        m_display->copy(CDisplay::PlainText, CDisplay::AnchorTextOnly);
 
86
}
 
87
 
 
88
void CDisplayConnections::copyAnchorWithText() {
 
89
        m_display->copy(CDisplay::PlainText, CDisplay::AnchorWithText);
 
90
}
 
91
 
 
92
void CDisplayConnections::saveAnchorWithText() {
 
93
        m_display->save(CDisplay::PlainText, CDisplay::AnchorWithText);
 
94
}
 
95
 
 
96
void CDisplayConnections::clear() {
 
97
        m_display->setText(QString::null);
 
98
}
 
99
 
 
100
void CDisplayConnections::zoomIn() {
 
101
        m_display->zoomIn();
 
102
}
 
103
 
 
104
void CDisplayConnections::zoomOut() {
 
105
        m_display->zoomOut();
 
106
}
 
107
 
 
108
void CDisplayConnections::openFindTextDialog() {
 
109
        m_display->openFindTextDialog();
 
110
}
 
111
 
 
112
 
 
113
/*----------------------*/
 
114
 
 
115
CReadDisplay* CDisplay::createReadInstance( CReadWindow* readWindow, QWidget* parent ) {
 
116
        return new CHTMLReadDisplay(readWindow, parent);
 
117
}
 
118
 
 
119
CWriteDisplay* CDisplay::createWriteInstance( CWriteWindow* writeWindow, const CWriteDisplay::WriteDisplayType& type, QWidget* parent ) {
 
120
        //  qWarning("CDisplay::createWriteInstance");
 
121
        if (type == PlainTextDisplay) {
 
122
                return new CPlainWriteDisplay(writeWindow, parent);
 
123
        }
 
124
        else {
 
125
                return new CHTMLWriteDisplay(writeWindow, parent);
 
126
        };
 
127
}
 
128
 
 
129
 
 
130
CDisplay::CDisplay(CDisplayWindow* parent) :
 
131
m_parentWindow(parent),
 
132
m_connections( new CDisplayConnections( this ) ),
 
133
m_popup(0) {}
 
134
 
 
135
CDisplay::~CDisplay() {
 
136
        delete m_connections;
 
137
}
 
138
 
 
139
const bool CDisplay::copy( const CDisplay::TextType format, const CDisplay::TextPart part  ) {
 
140
        const QString content = text(format, part);
 
141
 
 
142
        QClipboard* cb = KApplication::clipboard();
 
143
        cb->setText(content);
 
144
        return true;
 
145
}
 
146
 
 
147
const bool CDisplay::save( const CDisplay::TextType format, const CDisplay::TextPart part ) {
 
148
        //  qWarning("CDisplay::save( const CDisplay::TextType format, const CDisplay::TextPart part  )");
 
149
        const QString content = text(format, part);
 
150
        QString filter = QString::null;
 
151
 
 
152
        switch (format) {
 
153
                case HTMLText:
 
154
                filter = QString("*.html *.htm | ") + i18n("HTML files") + QString("\n *.* | All files (*.*)");
 
155
                break;
 
156
                case PlainText:
 
157
                filter = QString("*.txt | ") + i18n("Text files") + QString("\n *.* | All files (*.*)");
 
158
                break;
 
159
        };
 
160
 
 
161
        const QString filename = KFileDialog::getSaveFileName(QString::null, filter, 0, i18n("Save document ..."));
 
162
 
 
163
        if (!filename.isEmpty()) {
 
164
                CToolClass::savePlainFile(filename, content);
 
165
        }
 
166
        return true;
 
167
}
 
168
 
 
169
/** Emits the signal which used when a reference was clicked. */
 
170
void CDisplay::emitReferenceClicked( const QString& reference ) {
 
171
        qWarning("reference clicked %s", reference.latin1());
 
172
        QString module;
 
173
        QString key;
 
174
        CReferenceManager::Type type;
 
175
        /*const bool ok = */
 
176
        CReferenceManager::decodeHyperlink(reference, module, key, type);
 
177
        if (module.isEmpty()) {
 
178
                module = CReferenceManager::preferredModule( type );
 
179
        }
 
180
        m_connections->emitReferenceClicked(module, key);
 
181
}
 
182
 
 
183
/** Used when a reference was dropped onto the widget. */
 
184
void CDisplay::emitReferenceDropped( const QString& reference ) {
 
185
        QString module;
 
186
        QString key;
 
187
        CReferenceManager::Type type;
 
188
        /*const bool ok = */
 
189
        CReferenceManager::decodeHyperlink(reference, module, key, type);
 
190
        //  if (module.isEmpty()) {
 
191
        //    module = CReferenceManager::preferredModule( type );
 
192
        //  }
 
193
 
 
194
        m_connections->emitReferenceDropped(key);
 
195
}
 
196
 
 
197
/** Returns the connections obect used for signas and slots. */
 
198
CDisplayConnections* const CDisplay::connectionsProxy() const {
 
199
        return m_connections;
 
200
}
 
201
 
 
202
CDisplayWindow* const CDisplay::parentWindow() const {
 
203
        return m_parentWindow;
 
204
}
 
205
 
 
206
/** Installs the popup which should be opened when the right mouse button was pressed. */
 
207
void CDisplay::installPopup( QPopupMenu* popup ) {
 
208
        m_popup = popup;
 
209
}
 
210
 
 
211
/** Returns the popup menu which was set by installPopupMenu() */
 
212
QPopupMenu* const CDisplay::installedPopup() {
 
213
        Q_ASSERT(m_popup);
 
214
        return m_popup;
 
215
}
 
216