Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

textwidget.cpp

Go to the documentation of this file.
00001 /*
00002 Dagger - A Bible study program utilizing the Sword library.
00003 Copyright (c) 2004 Dan Williams <drw@handhelds.org>
00004 
00005 This file is free software; you can redistribute it and/or modify it under
00006 the terms of the GNU General Public License as published by the Free Software
00007 Foundation; either version 2 of the License, or (at your option) any later version.
00008 
00009 This file is distributed in the hope that it will be useful, but WITHOUT ANY
00010 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
00011 PARTICULAR PURPOSE. See the GNU General Public License for more details.
00012 
00013 You should have received a copy of the GNU General Public License along with this
00014 file; see the file COPYING. If not, write to the Free Software Foundation, Inc.,
00015 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 */
00017 
00018 #include "textwidget.h"
00019 
00020 #include <qlayout.h>
00021 #include <qtextbrowser.h>
00022 
00023 #include <versekey.h>
00024 
00025 TextWidget::TextWidget( QWidget *parent, sword::SWModule *module, int numVerses, const QFont *font )
00026     : QWidget( parent, 0x0, 0x0 )
00027     , m_module( module )
00028     , m_numVerses( numVerses )
00029 {
00030     if ( parent )
00031         installEventFilter( parent );
00032 
00033     QVBoxLayout *layout = new QVBoxLayout( this, 2, 2 );
00034 
00035     m_textView = new QTextBrowser( this );
00036     m_textView->installEventFilter( parent );
00037     m_textView->setMinimumHeight( 20 );
00038     m_textView->setHScrollBarMode( QTextView::AlwaysOff );
00039     m_textView->setTextFormat( QTextView::RichText );
00040     connect( m_textView, SIGNAL(highlighted(const QString &)),
00041              this, SIGNAL(sigRefClicked(const QString &)) );
00042     layout->addWidget( m_textView );
00043 
00044     // Set font
00045     if ( font )
00046         setFont( *font );
00047 
00048     // Set initial text
00049     if ( m_module )
00050     {
00051         m_isBibleText = !strcmp( module->Type(), "Biblical Texts" );
00052         if ( m_isBibleText )
00053         {
00054             m_key = new sword::VerseKey( "g" );
00055 
00056             //connect( m_textView, SIGNAL(highlighted(const QString&)),
00057             //         this, SLOT(slotReferenceClicked(const QString&)) );
00058             //connect( parent, SIGNAL( strongsNumbers( bool ) ), this, SLOT( slotStrongsNumbers( bool ) ) );
00059         }
00060         else
00061         {
00062             m_key = new sword::SWKey( "" );
00063         }
00064         m_module->SetKey( m_key );
00065         setText();
00066     }
00067 }
00068 
00069 TextWidget::~TextWidget()
00070 {
00071     // TODO - why does this cause a SIGSEV???
00072     //delete m_key;
00073 }
00074 
00075 QString TextWidget::getCurrVerse()
00076 {
00077     m_module->SetKey( m_key->getText() );
00078     return ( QString ) m_module->StripText();
00079 }
00080 
00081 void TextWidget::prevPage()
00082 {
00083     (*m_key) -= m_numVerses;
00084     setText();
00085 }
00086 
00087 void TextWidget::prevVerse()
00088 {
00089     (*m_key)--;
00090     setText();
00091 }
00092 
00093 void TextWidget::setKey( const QString &newKey )
00094 {
00095     m_key->setText( newKey.latin1() );
00096     setText();
00097 }
00098 
00099 void TextWidget::nextVerse()
00100 {
00101     (*m_key)++;
00102     setText();
00103 }
00104 
00105 void TextWidget::nextPage()
00106 {
00107     (*m_key) += m_numVerses;
00108     setText();
00109 }
00110 
00111 void TextWidget::slotNumVersesChanged( int numVerses )
00112 {
00113     m_numVerses = numVerses;
00114     setText();
00115 }
00116 
00117 void TextWidget::slotFontChanged( const QFont *newFont )
00118 {
00119     setFont( *newFont );
00120     // TODO - shouldn't have to reset text, but couldn't get repaint() to work
00121     setText();
00122 }
00123 
00124 void TextWidget::slotOptionChanged()
00125 {
00126     setText();
00127 }
00128 
00129 void TextWidget::setText()
00130 {
00131     if ( m_key->Error() )
00132         return;
00133 
00134     m_module->SetKey( m_key->getText() );
00135     m_fullKey = QString( "%1 (%2)" ).arg( m_key->getShortText() ).arg( m_module->Name() );
00136 
00137     if ( m_isBibleText )
00138     {
00139         m_textView->setVScrollBarMode( QTextView::AlwaysOff );
00140 
00141         m_abbrevKey = m_key->getShortText();
00142 
00143         QString fullText;
00144 
00145         for ( int i = 0; i < m_numVerses; i++ )
00146         {
00147             QString key = ( QString ) m_module->KeyText();
00148             QString verseStr = QString::fromUtf8( *m_module );
00149 
00150             // Format current verse (adding chapter and/or book headings if necessary)
00151             int verse = static_cast<sword::VerseKey>(m_module->Key()).Verse();
00152             if ( verse == 1 )
00153             {
00154                 int chapter = static_cast<sword::VerseKey>(m_module->Key()).Chapter();
00155                 if ( chapter == 1 )
00156                 {
00157                     QString book = static_cast<sword::VerseKey>(m_module->Key()).getBookName();
00158                     verseStr = QString( "<p><center><big><b>%1</b></big></center><br><center><b>Chapter %1</b></center><p><b>%2</b>&nbsp;%3<p>" )
00159                                        .arg( book ).arg( chapter ).arg( verse ).arg( verseStr );
00160                 }
00161                 else
00162                 {
00163                     verseStr = QString( "<center><b>Chapter %1</b></center><p><b>%2</b>&nbsp;%3<p>" )
00164                                        .arg( chapter ).arg( verse ).arg( verseStr );
00165                 }
00166             }
00167             else
00168             {
00169                 verseStr = QString( "<b>%1</b>&nbsp;%2<p>" ).arg( verse ).arg( verseStr );
00170             }
00171 
00172             fullText.append( verseStr );
00173 
00174             m_module->Key()++;
00175 
00176             if ( m_module->Key().Error() )
00177                 break;
00178         }
00179 
00180         m_textView->setText( fullText );
00181     }
00182     else // !isBibleText
00183     {
00184         m_abbrevKey = m_key->getText();
00185         m_textView->setText( ( QString ) *m_module );
00186     }
00187 }

Generated on Sat Nov 5 16:16:48 2005 for OPIE by  doxygen 1.4.2