@ -16,15 +16,15 @@
* Free Software Foundation , Inc . , *
* 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA . *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include < qpainter.h>
# include < qevent.h>
# include < qimage.h>
# include < t qpainter.h>
# include < t qevent.h>
# include < t qimage.h>
# include <kdebug.h>
# include <kprogress.h>
# include < qfile.h>
# include < qtextstream.h>
# include < qtextcodec.h>
# include < qstring.h>
# include < t qfile.h>
# include < t qtextstream.h>
# include < t qtextcodec.h>
# include < t qstring.h>
# include <kglobal.h>
# include <kstandarddirs.h>
# include "bookwidget.h"
@ -33,12 +33,12 @@
# include "renderer.h"
//#include "ktextprogressdlg.h"
class QStringList;
class QRect;
class QPixmap;
class T QStringList;
class T QRect;
class T QPixmap;
BookWidget : : BookWidget ( QWidget * parent, const char * name )
: QWidget( parent, name ) ,
BookWidget : : BookWidget ( T QWidget * tq parent, const char * name )
: T QWidget( tq parent, name ) ,
m_modified ( true ) ,
m_currentPage ( 0 ) ,
m_left_margin ( 0 ) ,
@ -61,11 +61,11 @@ BookWidget::BookWidget(QWidget *parent, const char *name)
Theme : : self ( ) - > loadTheme ( " default " ) ;
setWFlags ( Qt: : WNoAutoErase ) ;
setFocusPolicy ( QWidget: : StrongFocus) ;
setWFlags ( T Qt: : WNoAutoErase ) ;
setFocusPolicy ( TQ_ StrongFocus) ;
connect ( & m_timer , SIGNAL( timeout ( ) ) , this , SLOT( loadLine ( ) ) ) ;
connect ( m_renderer . get ( ) , SIGNAL( renderingFinished ( ) ) , this , SLOT( renderingFinished ( ) ) ) ;
connect ( & m_timer , TQT_ SIGNAL( timeout ( ) ) , this , TQT_ SLOT( loadLine ( ) ) ) ;
connect ( m_renderer . get ( ) , TQT_ SIGNAL( renderingFinished ( ) ) , this , TQT_ SLOT( renderingFinished ( ) ) ) ;
}
@ -80,10 +80,10 @@ void BookWidget::openURL(const KURL & url)
if ( ! m_file . open ( IO_ReadOnly ) ) return ;
///@todo Write encoding detection
m_stream . reset ( new QTextStream( & m_file ) ) ;
m_textLines . reset ( new QStringList) ;
QString name ( encoding ( ) ) ;
QTextCodec * codec = QTextCodec: : codecForName ( encoding ( ) ) ; // get the codec
m_stream . reset ( new T QTextStream( & m_file ) ) ;
m_textLines . reset ( new T QStringList) ;
T QString name ( encoding ( ) ) ;
T QTextCodec * codec = T QTextCodec: : codecForName ( encoding ( ) ) ; // get the codec
if ( codec )
m_stream - > setCodec ( codec ) ;
//show progress dialog
@ -92,7 +92,7 @@ void BookWidget::openURL(const KURL & url)
m_progressDlg - > setLabel ( " Loading file " + m_url . path ( ) ) ;
m_progressDlg - > setAllowCancel ( true ) ;
m_progressDlg - > progressBar ( ) - > setTotalSteps ( 0 ) ;
connect ( m_progressDlg . get ( ) , SIGNAL( cancelClicked ( ) ) , SLOT( cancelLoading ( ) ) ) ;
connect ( m_progressDlg . get ( ) , TQT_ SIGNAL( cancelClicked ( ) ) , TQT_ SLOT( cancelLoading ( ) ) ) ;
KDialog : : centerOnScreen ( m_progressDlg . get ( ) ) ;
m_progressDlg - > show ( ) ;
//start timer for processing gui events
@ -103,90 +103,90 @@ void BookWidget::openURL(const KURL & url)
emit signalChangeStatusbar ( m_url . prettyURL ( ) ) ;
}
QString BookWidget : : currentURL ( )
T QString BookWidget : : currentURL ( )
{
return m_url . path ( ) ;
}
void BookWidget : : drawContent ( QPainter& paint )
void BookWidget : : drawContent ( T QPainter& paint )
{
const QRect lrect ( rectLeftPage ( ) ) ;
const QRect rrect ( rectRightPage ( ) ) ;
const T QRect lrect ( rectLeftPage ( ) ) ;
const T QRect rrect ( rectRightPage ( ) ) ;
const unsigned int curPage = currentPage ( ) ;
//draw pages
m_renderer - > drawPage ( paint , lrect , curPage ) ;
m_renderer - > drawPage ( paint , rrect , curPage + 1 ) ;
}
void BookWidget : : drawPageNumbers ( QPainter & paint )
void BookWidget : : drawPageNumbers ( T QPainter & paint )
{
if ( m_renderer - > isEmpty ( ) )
return ;
const QRect lrect ( rectLeftPage ( ) ) ;
const QRect rrect ( rectRightPage ( ) ) ;
const QString number = QString: : number ( currentPage ( ) + 2 ) ;
const T QRect lrect ( rectLeftPage ( ) ) ;
const T QRect rrect ( rectRightPage ( ) ) ;
const T QString number = T QString: : number ( currentPage ( ) + 2 ) ;
// setup font
QFont pageFont ( font ( ) ) ;
T QFont pageFont ( font ( ) ) ;
int pointSize = 10 ;
pageFont . setPointSize ( pointSize ) ;
pageFont . setBold ( false ) ;
pageFont . setItalic ( false ) ;
pageFont . setUnderline ( false ) ;
paint . setFont ( pageFont ) ;
const QFontMetrics fm ( pageFont ) ;
const T QFontMetrics fm ( pageFont ) ;
const int width = fm . width ( number ) ;
//paint page numbers
const int offset = 8 ;
paint . drawText ( lrect . left ( ) , QWidget: : height ( ) - offset ,
QString: : number ( currentPage ( ) + 1 ) ) ;
paint . drawText ( lrect . left ( ) , T QWidget: : height ( ) - offset ,
T QString: : number ( currentPage ( ) + 1 ) ) ;
paint . drawText ( rrect . left ( ) + rrect . width ( ) - width ,
QWidget: : height ( ) - offset , number ) ;
T QWidget: : height ( ) - offset , number ) ;
}
void BookWidget : : drawBookmark ( QPainter & paint , Bookmark const & bm )
void BookWidget : : drawBookmark ( T QPainter & paint , Bookmark const & bm )
{
const QRect lrect ( rectLeftPage ( ) ) ;
const QRect rrect ( rectRightPage ( ) ) ;
const QPixmap & bookmarkImage = Theme : : self ( ) - > bookmarkPixmap ( ) ;
const T QRect lrect ( rectLeftPage ( ) ) ;
const T QRect rrect ( rectRightPage ( ) ) ;
const T QPixmap & bookmarkImage = Theme : : self ( ) - > bookmarkPixmap ( ) ;
const int width = bookmarkImage . width ( ) ;
paint . drawPixmap ( QWidget: : width ( ) / 2 - width / 2 , 0 , bookmarkImage ) ;
paint . drawPixmap ( T QWidget: : width ( ) / 2 - width / 2 , 0 , bookmarkImage ) ;
if ( ! bm . name ( ) . isEmpty ( ) )
{
paint . save ( ) ;
paint . translate ( QWidget: : width ( ) / 2. , 20. ) ;
paint . translate ( T QWidget: : width ( ) / 2. , 20. ) ;
paint . rotate ( 90. ) ;
const QString text = bm . name ( ) + " ( " + bm . dateTime ( ) . toString ( Qt : : LocalDate ) + " ) " ;
const T QString text = bm . name ( ) + " ( " + bm . dateTime ( ) . toString ( Qt : : LocalDate ) + " ) " ;
paint . drawText ( 0 , 0 , text ) ;
paint . restore ( ) ;
}
}
void BookWidget : : paintEvent ( QPaintEvent* event )
void BookWidget : : paintEvent ( T QPaintEvent* event )
{
// use cached page pixmap if the page wasn't modified
if ( ! modified ( ) )
{
QRect rect ( event - > rect ( ) ) ;
T QRect rect ( event - > rect ( ) ) ;
bitBlt ( this , rect . x ( ) , rect . y ( ) , & m_cachePixmap , rect . x ( ) , rect . y ( ) , rect . width ( ) , rect . height ( ) ) ;
return ;
}
// do full painting otherwise
setupPageSize ( ) ;
const QRect lrect ( rectLeftPage ( ) ) ;
const QRect rrect ( rectRightPage ( ) ) ;
const T QRect lrect ( rectLeftPage ( ) ) ;
const T QRect rrect ( rectRightPage ( ) ) ;
const unsigned int curPage = currentPage ( ) ;
QPixmap pm ( size ( ) ) ;
QPainter paint ( & pm ) ;
T QPixmap pm ( size ( ) ) ;
T QPainter paint ( & pm ) ;
//draw background image
const QPixmap & image = Theme : : self ( ) - > bgPixmap ( QWidget: : size ( ) ) ;
const T QPixmap & image = Theme : : self ( ) - > bgPixmap ( T QWidget: : size ( ) ) ;
paint . drawPixmap ( 0 , 0 , image ) ;
if ( m_renderer - > busy ( ) )
{
QFont f ( font ( ) ) ;
T QFont f ( font ( ) ) ;
f . setPointSize ( 20 ) ;
paint . setFont ( f ) ;
const QFontMetrics fm ( f ) ;
QString text = tr ( " Rendering... " ) ;
const T QFontMetrics fm ( f ) ;
T QString text = tr ( " Rendering... " ) ;
const int w = fm . width ( text ) ;
const int h = fm . height ( ) ;
const int dx = ( lrect . width ( ) - w ) / 2 ;
@ -215,37 +215,37 @@ void BookWidget::paintEvent(QPaintEvent* event)
void BookWidget : : setupPageSize ( )
{
QSize size ( ( width ( ) - m_left_margin - m_right_margin - 2 * m_middle_margin ) / 2 ,
T QSize size ( ( width ( ) - m_left_margin - m_right_margin - 2 * m_middle_margin ) / 2 ,
( height ( ) - m_top_margin - m_bottom_margin ) ) ;
m_renderer - > setPageSize ( size ) ;
}
void BookWidget : : mousePressEvent ( QMouseEvent * event )
void BookWidget : : mousePressEvent ( T QMouseEvent * event )
{
if ( event - > button ( ) = = LeftButton)
if ( event - > button ( ) = = Qt: : LeftButton)
{
if ( rectLeftPage ( ) . contains( event - > pos ( ) ) )
if ( rectLeftPage ( ) . tq contains( event - > pos ( ) ) )
{
prevPage ( ) ;
}
else if ( rectRightPage ( ) . contains( event - > pos ( ) ) )
else if ( rectRightPage ( ) . tq contains( event - > pos ( ) ) )
{
nextPage ( ) ;
}
}
QWidget: : mousePressEvent ( event ) ;
T QWidget: : mousePressEvent ( event ) ;
}
const QRect BookWidget : : rectLeftPage ( ) const
const T QRect BookWidget : : rectLeftPage ( ) const
{
return QRect( m_left_margin , m_top_margin ,
return T QRect( m_left_margin , m_top_margin ,
m_renderer - > pageSize ( ) . width ( ) ,
m_renderer - > pageSize ( ) . height ( ) ) ;
}
const QRect BookWidget : : rectRightPage ( ) const
const T QRect BookWidget : : rectRightPage ( ) const
{
return QRect( m_left_margin + 2 * m_middle_margin + m_renderer - > pageSize ( ) . width ( ) ,
return T QRect( m_left_margin + 2 * m_middle_margin + m_renderer - > pageSize ( ) . width ( ) ,
m_top_margin ,
m_renderer - > pageSize ( ) . width ( ) ,
m_renderer - > pageSize ( ) . height ( ) ) ;
@ -277,7 +277,7 @@ void BookWidget::lastPage()
setCurrentPage ( m_renderer - > pageCount ( ) - 1 ) ;
}
void BookWidget : : wheelEvent ( QWheelEvent * e )
void BookWidget : : wheelEvent ( T QWheelEvent * e )
{
e - > accept ( ) ;
if ( e - > delta ( ) > 0 )
@ -285,7 +285,7 @@ void BookWidget::wheelEvent(QWheelEvent * e)
else nextPage ( ) ;
}
void BookWidget : : resizeEvent ( QResizeEvent * e )
void BookWidget : : resizeEvent ( T QResizeEvent * e )
{
m_modified = true ;
setupPageSize ( ) ;
@ -293,18 +293,18 @@ void BookWidget::resizeEvent(QResizeEvent * e)
// //if size become lower recalc current page
// if (currentPage() > m_renderer->pageCount())
// lastPage();
QWidget: : resizeEvent ( e ) ;
T QWidget: : resizeEvent ( e ) ;
}
QSize BookWidget : : minimumSizeHint( ) const
T QSize BookWidget : : tq minimumSizeHint( ) const
{
return QSize( 400 , 300 ) ;
return T QSize( 400 , 300 ) ;
}
void BookWidget : : setFont ( const QFont & font )
void BookWidget : : setFont ( const T QFont & font )
{
m_modified = true ;
QWidget: : setFont ( font ) ;
T QWidget: : setFont ( font ) ;
m_renderer - > setFont ( font ) ;
update ( ) ;
}
@ -325,27 +325,27 @@ void BookWidget::setCurrentPage(int number)
update ( ) ;
}
void BookWidget : : keyPressEvent ( QKeyEvent * e )
void BookWidget : : keyPressEvent ( T QKeyEvent * e )
{
if ( e - > key ( ) = = Qt: : Key_Right | | e - > key ( ) = = Qt: : Key_Down
| | e - > key ( ) = = Qt: : Key_Space )
if ( e - > key ( ) = = T Qt: : Key_Right | | e - > key ( ) = = T Qt: : Key_Down
| | e - > key ( ) = = T Qt: : Key_Space )
{
nextPage ( ) ;
}
else if ( e - > key ( ) = = Qt: : Key_Left | | e - > key ( ) = = Qt: : Key_Up )
else if ( e - > key ( ) = = T Qt: : Key_Left | | e - > key ( ) = = T Qt: : Key_Up )
{
prevPage ( ) ;
}
else if ( e - > key ( ) = = Qt: : Key_Home )
else if ( e - > key ( ) = = T Qt: : Key_Home )
{
firstPage ( ) ;
}
else if ( e - > key ( ) = = Qt: : Key_End )
else if ( e - > key ( ) = = T Qt: : Key_End )
{
lastPage ( ) ;
}
QWidget: : keyPressEvent ( e ) ;
T QWidget: : keyPressEvent ( e ) ;
}
void BookWidget : : loadLine ( )
@ -378,7 +378,7 @@ void BookWidget::cancelLoading()
{
m_timer . stop ( ) ;
if ( parentWidget ( ) )
parentWidget( ) - > setCaption ( " " ) ;
TQT_TQWIDGET( parentWidget( ) ) - > setCaption ( " " ) ;
//clean up
m_progressDlg - > hide ( ) ;
m_stream . reset ( 0 ) ;
@ -401,17 +401,17 @@ void BookWidget::setEncoding(int a_encoding)
m_encoding = a_encoding ;
}
void BookWidget : : setEncodings ( const QStringList & a_encodings )
void BookWidget : : setEncodings ( const T QStringList & a_encodings )
{
m_encodings = a_encodings ;
}
void BookWidget : : setEncoding ( const QString & a_encoding )
void BookWidget : : setEncoding ( const T QString & a_encoding )
{
m_encoding = ( m_encodings . findIndex( a_encoding ) ) ;
m_encoding = ( m_encodings . tq findIndex( a_encoding ) ) ;
}
void BookWidget : : addBookmark ( const QString& name )
void BookWidget : : addBookmark ( const T QString& name )
{
m_bookmarks . push_back ( Bookmark ( currentPage ( ) , name ) ) ;
std : : sort ( m_bookmarks . begin ( ) , m_bookmarks . end ( ) ) ;
@ -423,13 +423,13 @@ void BookWidget::addBookmark(const QString& name)
void BookWidget : : saveBookmarks ( )
{
const QString fileName = " bookreader/ " + m_url . fileName ( ) ;
QFile: : remove ( KGlobal : : dirs ( ) - > findResource ( " appdata " , m_url . fileName ( ) ) ) ;
const T QString fileName = " bookreader/ " + m_url . fileName ( ) ;
T QFile: : remove ( KGlobal : : dirs ( ) - > findResource ( " appdata " , m_url . fileName ( ) ) ) ;
KConfig config ( fileName , false , false , " data " ) ;
for ( Bookmarks : : size_type i = 0 ; i < m_bookmarks . size ( ) ; + + i )
{
const Bookmark & bm = m_bookmarks [ i ] ;
config . setGroup ( t r( " Bookmark %1 " ) . arg( i ) ) ;
config . setGroup ( t qt r( " Bookmark %1 " ) . tq arg( i ) ) ;
config . writeEntry ( " page " , bm . page ( ) ) ;
config . writeEntry ( " name " , bm . name ( ) ) ;
config . writeEntry ( " dateTime " , bm . dateTime ( ) ) ;
@ -439,16 +439,16 @@ void BookWidget::saveBookmarks( )
void BookWidget : : loadBookmarks ( )
{
m_bookmarks . clear ( ) ;
const QString fileName = " bookreader/ " + m_url . fileName ( ) ;
const T QString fileName = " bookreader/ " + m_url . fileName ( ) ;
KConfig config ( fileName , true , false , " data " ) ;
QStringList groups = config . groupList ( ) ;
typedef QStringList: : const_iterator IT ;
T QStringList groups = config . groupList ( ) ;
typedef T QStringList: : const_iterator IT ;
for ( IT it = groups . constBegin ( ) ; it ! = groups . constEnd ( ) ; + + it )
{
config . setGroup ( * it ) ;
const QString name = config . readEntry ( " name " ) ;
const T QString name = config . readEntry ( " name " ) ;
const unsigned int page = config . readUnsignedNumEntry ( " page " ) ;
const QDateTime dateTime = config . readDateTimeEntry ( " dateTime " ) ;
const T QDateTime dateTime = config . readDateTimeEntry ( " dateTime " ) ;
const Bookmark bm ( page , name , dateTime ) ;
m_bookmarks . push_back ( bm ) ;
}