From 2bda8f7717adf28da4af0d34fb82f63d2868c31d Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeutils@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kjots/kjotsedit.cpp | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 kjots/kjotsedit.cpp (limited to 'kjots/kjotsedit.cpp') diff --git a/kjots/kjotsedit.cpp b/kjots/kjotsedit.cpp new file mode 100644 index 0000000..0a61c62 --- /dev/null +++ b/kjots/kjotsedit.cpp @@ -0,0 +1,150 @@ +// +// kjots +// +// Copyright (C) 1997 Christoph Neerfeld +// Copyright (C) 2002, 2003 Aaron J. Seigo +// Copyright (C) 2003 Stanislav Kljuhhin +// +// This program 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. +// +// This program 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 this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "kjotsedit.h" +#include "kjotsentry.h" + +//---------------------------------------------------------------------- +// MYMULTIEDIT +//---------------------------------------------------------------------- +KJotsEdit::KJotsEdit (QWidget* parent, const char* name) + : KEdit(parent, name), + m_entry(0) +{ + // no rich text until printing and other such issues are worked out + setTextFormat(Qt::PlainText); + setWordWrap(QTextEdit::WidgetWidth); + setLinkUnderline(true); + web_menu = new KPopupMenu(this);; + web_menu->insertItem(i18n("Open URL"), this, SLOT(openUrl()) ); +} + +KJotsEdit::~KJotsEdit() +{ + +} + +void KJotsEdit::mousePressEvent( QMouseEvent *e ) +{ + if(e->button() == RightButton && + hasSelectedText()) + { + KURL url(selectedText()); + + if(url.isValid()) + { + web_menu->popup(QCursor::pos()); + return; + } + } + + KEdit::mousePressEvent(e); +} + +void KJotsEdit::openUrl() +{ + if (hasSelectedText()) + { + KURL url(selectedText()); + if(url.isValid()) + { + new KRun(url); + } + } +} + +void KJotsEdit::print(QString title) +{ + KPrinter printer; + printer.setDocName(title); + printer.setFullPage(false); + printer.setCreator("KJots"); + + if (printer.setup(this)) + { + QFont printFont = font(); + QPainter painter( &printer ); + QPaintDeviceMetrics metrics( &printer ); + int y = 0; + int maxWidth = metrics.width(); + int maxHeight = metrics.height(); + QString currentParagraph; + + for (int paragraphCount = 0; paragraphCount < paragraphs(); ++paragraphCount ) + { + currentParagraph = text(paragraphCount); + QRect r = painter.boundingRect(0, y, maxWidth, maxHeight, + QPainter::ExpandTabs | QPainter::WordBreak, + currentParagraph); + + if ((y + r.height()) > maxHeight) + { + printer.newPage(); + y = 0; + } + + painter.drawText(0, y, maxWidth, maxHeight - y, + QPainter::ExpandTabs | QPainter::WordBreak, + currentParagraph); + y += r.height(); + } + painter.end(); + } +} + +void KJotsEdit::setEntry (KJotsPage *entry) +{ + //tell the old entry to take a hike + if ( m_entry ) + { + m_entry->setEditor(0); + } + + //load up the new entry (assuming there is one) + if ( entry ) + { + m_entry = entry; + setText(entry->body()); + removeSelection(); + repaint(); + setEnabled(true); + setFocus(); + entry->setEditor(this); + } else { + clear(); + } + + m_entry = entry; +} + +#include "kjotsedit.moc" +/* ex: set tabstop=4 softtabstop=4 shiftwidth=4 expandtab: */ -- cgit v1.2.1