summaryrefslogtreecommitdiff
path: root/noncore/apps/dagger/textwidget.cpp
Unidiff
Diffstat (limited to 'noncore/apps/dagger/textwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/dagger/textwidget.cpp183
1 files changed, 183 insertions, 0 deletions
diff --git a/noncore/apps/dagger/textwidget.cpp b/noncore/apps/dagger/textwidget.cpp
new file mode 100644
index 0000000..8ff620d
--- a/dev/null
+++ b/noncore/apps/dagger/textwidget.cpp
@@ -0,0 +1,183 @@
1/*
2Dagger - A Bible study program utilizing the Sword library.
3Copyright (c) 2004 Dan Williams <drw@handhelds.org>
4
5This file is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free Software
7Foundation; either version 2 of the License, or (at your option) any later version.
8
9This file is distributed in the hope that it will be useful, but WITHOUT ANY
10WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License along with this
14file; see the file COPYING. If not, write to the Free Software Foundation, Inc.,
1559 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16*/
17
18#include "textwidget.h"
19
20#include <qlayout.h>
21#include <qtextbrowser.h>
22
23#include <versekey.h>
24
25TextWidget::TextWidget( QWidget *parent, sword::SWModule *module, int numVerses, const QFont *font )
26 : QWidget( parent, 0x0, 0x0 )
27 , m_module( module )
28 , m_numVerses( numVerses )
29{
30 if ( parent )
31 installEventFilter( parent );
32
33 QVBoxLayout *layout = new QVBoxLayout( this, 2, 2 );
34
35 m_textView = new QTextBrowser( this );
36 m_textView->installEventFilter( parent );
37 m_textView->setMinimumHeight( 20 );
38 m_textView->setHScrollBarMode( QTextView::AlwaysOff );
39 m_textView->setTextFormat( QTextView::RichText );
40 connect( m_textView, SIGNAL(highlighted(const QString &)),
41 this, SIGNAL(sigRefClicked(const QString &)) );
42 layout->addWidget( m_textView );
43
44 // Set font
45 if ( font )
46 setFont( *font );
47
48 // Set initial text
49 if ( m_module )
50 {
51 m_isBibleText = !strcmp( module->Type(), "Biblical Texts" );
52 if ( m_isBibleText )
53 {
54 m_key = new sword::VerseKey( "g" );
55
56 //connect( m_textView, SIGNAL(highlighted(const QString&)),
57 // this, SLOT(slotReferenceClicked(const QString&)) );
58 //connect( parent, SIGNAL( strongsNumbers( bool ) ), this, SLOT( slotStrongsNumbers( bool ) ) );
59 }
60 else
61 {
62 m_key = new sword::SWKey( "" );
63 }
64 m_module->SetKey( m_key );
65 setText();
66 }
67}
68
69TextWidget::~TextWidget()
70{
71 // TODO - why does this cause a SIGSEV???
72 //delete m_key;
73}
74
75QString TextWidget::getCurrVerse()
76{
77 m_module->SetKey( m_key->getText() );
78 return ( QString ) m_module->StripText();
79}
80
81void TextWidget::prevChapter()
82{
83}
84
85void TextWidget::prevVerse()
86{
87 (*m_key)--;
88 setText();
89}
90
91void TextWidget::setKey( const QString &newKey )
92{
93 m_key->setText( newKey.latin1() );
94 setText();
95}
96
97void TextWidget::nextVerse()
98{
99 (*m_key)++;
100 setText();
101}
102
103void TextWidget::nextChapter()
104{
105}
106
107void TextWidget::slotNumVersesChanged( int numVerses )
108{
109 m_numVerses = numVerses;
110 setText();
111}
112
113void TextWidget::slotFontChanged( const QFont *newFont )
114{
115 setFont( *newFont );
116 // TODO - shouldn't have to reset text, but couldn't get repaint() to work
117 setText();
118}
119
120void TextWidget::slotOptionChanged()
121{
122 setText();
123}
124
125void TextWidget::setText()
126{
127 if ( m_key->Error() )
128 return;
129
130 m_module->SetKey( m_key->getText() );
131 m_fullKey = QString( "%1 (%2)" ).arg( m_key->getShortText() ).arg( m_module->Name() );
132
133 if ( m_isBibleText )
134 {
135 m_textView->setVScrollBarMode( QTextView::AlwaysOff );
136
137 m_abbrevKey = m_key->getShortText();
138
139 QString fullText;
140
141 for ( int i = 0; i < m_numVerses; i++ )
142 {
143 QString key = ( QString ) m_module->KeyText();
144 QString verseStr = ( QString ) *m_module;
145
146 // Format current verse (adding chapter and/or book headings if necessary)
147 int verse = static_cast<sword::VerseKey>(m_module->Key()).Verse();
148 if ( verse == 1 )
149 {
150 int chapter = static_cast<sword::VerseKey>(m_module->Key()).Chapter();
151 if ( chapter == 1 )
152 {
153 QString book = static_cast<sword::VerseKey>(m_module->Key()).getBookName();
154 verseStr = QString( "<p><center><big><b>%1</b></big></center><br><center><b>Chapter %1</b></center><p><b>%2</b>&nbsp;%3<p>" )
155 .arg( book ).arg( chapter ).arg( verse ).arg( verseStr );
156 }
157 else
158 {
159 verseStr = QString( "<center><b>Chapter %1</b></center><p><b>%2</b>&nbsp;%3<p>" )
160 .arg( chapter ).arg( verse ).arg( verseStr );
161 }
162 }
163 else
164 {
165 verseStr = QString( "<b>%1</b>&nbsp;%2<p>" ).arg( verse ).arg( verseStr );
166 }
167
168 fullText.append( verseStr );
169
170 m_module->Key()++;
171
172 if ( m_module->Key().Error() )
173 break;
174 }
175
176 m_textView->setText( fullText );
177 }
178 else // !isBibleText
179 {
180 m_abbrevKey = m_key->getText();
181 m_textView->setText( ( QString ) *m_module );
182 }
183}