//**************************************************************************** //! \file wtexter.cpp //! \date 17-10-2004 //**************************************************************************** // This file is part of Weird Reader. // // The Weird Reader is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // The Weird Reader is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Weird Reader; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //**************************************************************************** #include "wtexter.hpp" //*************************************************************************** // WTextHandler methods //*************************************************************************** // public methods //*************************************************************************** //*************************************************************************** WTextHandler::WTextHandler( QWidget *parent, char const *name) : KTextEdit ( parent, name) //*************************************************************************** { this->setReadOnly( true); this->setVScrollBarMode( QScrollView::AlwaysOff); this->setWordWrap( KTextEdit::NoWrap); } //*************************************************************************** // public slots //*************************************************************************** //*************************************************************************** int WTextHandler::open( QString &fname) //*************************************************************************** { QFile file( fname); if ( file.open( IO_ReadOnly)) { QTextStream stream( &file ); this->setText( stream.read() ); } QFontMetrics fm( this->currentFont()); vlines = this->visibleHeight()/fm.lineSpacing()-1; std::cout<visibleHeight()<<" "<lines()<<" "<lines()/vlines<setCursorPosition( 0, 0); tlines = this->lines(); tend = false; return tlines/vlines; } //*************************************************************************** void WTextHandler::close() //*************************************************************************** { this->clear(); } //*************************************************************************** void WTextHandler::pgUp() //*************************************************************************** { this->moveCursor( KTextEdit::MovePgUp, false); } //*************************************************************************** void WTextHandler::pgDown() //*************************************************************************** { this->moveCursor( KTextEdit::MovePgDown, false); } //*************************************************************************** void WTextHandler::moveCursor( CursorAction action, bool select) //*************************************************************************** { if( action==KTextEdit::MovePgUp) { int p, i; this->getCursorPosition( &p, &i); // std::cout<setCursorPosition( p-vlines, 0); tend = false; return; } if( action==KTextEdit::MovePgDown)if( !tend) { int p, i; this->getCursorPosition( &p, &i); if( p+2*vlines-1< tlines-1)this->setCursorPosition( p+2*vlines-1, 0); else { tend = true; this->setCursorPosition( tlines-1, 0); } this->setCursorPosition( p+vlines, 0); return; }else return; KTextEdit::moveCursor( action, select); } //*************************************************************************** // protected methods //*************************************************************************** //*************************************************************************** void WTextHandler::sort() //*************************************************************************** { std::sort(comments.begin (), comments.end ()); }