• Skip to content
  • Skip to link menu
KDE 4.7 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • KDE Home
  • Contact Us
 

kpimtextedit/richtextbuilders

bbcodebuilder.cpp
00001 /*
00002     This file is part of KDE.
00003 
00004     Copyright (c) 2008 Stephen Kelly <steveire@gmail.com>
00005 
00006     This library is free software; you can redistribute it and/or modify it
00007     under the terms of the GNU Library General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or (at your
00009     option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful, but WITHOUT
00012     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014     License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to the
00018     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00019     02110-1301, USA.
00020 */
00021 
00022 
00023 
00024 #include "bbcodebuilder.h"
00025 #include <kdebug.h>
00026 
00027 BBCodeBuilder::BBCodeBuilder()
00028 {
00029 
00030     currentAlignment = Qt::AlignLeft; //Default value
00031 }
00032 
00033 void BBCodeBuilder::beginStrong()
00034 {
00035     m_text.append("[B]");
00036 }
00037 void BBCodeBuilder::endStrong()
00038 {
00039     m_text.append("[/B]");
00040 }
00041 void BBCodeBuilder::beginEmph()
00042 {
00043     m_text.append("[I]");
00044 }
00045 void BBCodeBuilder::endEmph()
00046 {
00047     m_text.append("[/I]");
00048 }
00049 void BBCodeBuilder::beginUnderline()
00050 {
00051     m_text.append("[U]");
00052 }
00053 void BBCodeBuilder::endUnderline()
00054 {
00055     m_text.append("[/U]");
00056 }
00057 void BBCodeBuilder::beginStrikeout()
00058 {
00059     m_text.append("[S]");
00060 }
00061 void BBCodeBuilder::endStrikeout()
00062 {
00063     m_text.append("[/S]");
00064 }
00065 void BBCodeBuilder::beginForeground(const QBrush &brush)
00066 {
00067     m_text.append(QString("[COLOR=%1]").arg(brush.color().name()));
00068 }
00069 void BBCodeBuilder::endForeground()
00070 {
00071     m_text.append("[/COLOR]");
00072 }
00073 
00074 // Background colour not supported by BBCode.
00075 
00076 void BBCodeBuilder::beginAnchor(const QString &href, const QString &name)
00077 {
00078     m_text.append(QString("[URL=%1]").arg(href));
00079 }
00080 void BBCodeBuilder::endAnchor()
00081 {
00082     m_text.append("[/URL]");
00083 }
00084 
00085 // Font family not supported by BBCode.
00086 
00087 void BBCodeBuilder::beginFontPointSize(int size)
00088 {
00089     m_text.append(QString("[SIZE=%1]").arg(QString::number(size)));
00090 }
00091 void BBCodeBuilder::endFontPointSize()
00092 {
00093     m_text.append("[/SIZE]");
00094 }
00095 
00096 void BBCodeBuilder::beginParagraph(Qt::Alignment a, qreal top, qreal bottom, qreal left, qreal right)
00097 {
00098     Q_UNUSED(top);
00099     Q_UNUSED(bottom);
00100     Q_UNUSED(left);
00101     Q_UNUSED(right);
00102     if (a & Qt::AlignRight) {
00103         m_text.append("\n[Right]");
00104     } else if (a & Qt::AlignHCenter) {
00105         m_text.append("\n[CENTER]");
00106     }
00107     // LEFT is also supported in BBCode, but ignored.
00108     currentAlignment = a;
00109 }
00110 void BBCodeBuilder::endParagraph()
00111 {
00112     if (currentAlignment & Qt::AlignRight) {
00113         m_text.append("\n[/Right]\n");
00114     } else if (currentAlignment & Qt::AlignHCenter) {
00115         m_text.append("\n[/CENTER]\n");
00116     } else {
00117         m_text.append("\n");
00118     }
00119     currentAlignment = Qt::AlignLeft;
00120 
00121 }
00122 void BBCodeBuilder::addNewline()
00123 {
00124     m_text.append("\n");
00125 }
00126 
00127 void BBCodeBuilder::insertImage(const QString &src, qreal width, qreal height)
00128 {
00129     Q_UNUSED(width);
00130     Q_UNUSED(height);
00131     m_text.append(QString("[IMG]%1[/IMG]").arg(src));
00132 }
00133 
00134 void BBCodeBuilder::beginList(QTextListFormat::Style type)
00135 {
00136     switch (type) {
00137     case QTextListFormat::ListDisc:
00138     case QTextListFormat::ListCircle:
00139     case QTextListFormat::ListSquare:
00140         m_text.append("[LIST]\n");    // Unordered lists are all disc type in BBCode.
00141         break;
00142     case QTextListFormat::ListDecimal:
00143         m_text.append("[LIST=1]\n");
00144         break;
00145     case QTextListFormat::ListLowerAlpha:
00146         m_text.append("[LIST=a]\n");
00147         break;
00148     case QTextListFormat::ListUpperAlpha:
00149         m_text.append("[LIST=A]\n");
00150         break;
00151     default:
00152         break;
00153     }
00154 }
00155 
00156 void BBCodeBuilder::endList()
00157 {
00158     m_text.append("[/LIST]\n");
00159 }
00160 
00161 
00162 void BBCodeBuilder::beginListItem()
00163 {
00164     m_text.append("[*] ");
00165 }
00166 
00167 void BBCodeBuilder::beginSuperscript()
00168 {
00169     m_text.append("[SUP]");
00170 }
00171 
00172 void BBCodeBuilder::endSuperscript()
00173 {
00174     m_text.append("[/SUP]");
00175 }
00176 
00177 void BBCodeBuilder::beginSubscript()
00178 {
00179     m_text.append("[SUB]");
00180 }
00181 
00182 void BBCodeBuilder::endSubscript()
00183 {
00184     m_text.append("[/SUB]");
00185 }
00186 
00187 
00188 void BBCodeBuilder::beginTable(qreal, qreal, const QString &)
00189 {
00190     m_text.append("[TABLE]\n");
00191 }
00192 
00193 void BBCodeBuilder::beginTableRow()
00194 {
00195     m_text.append("[/TABLE]");
00196 }
00197 
00198 
00199 void BBCodeBuilder::appendLiteralText(const QString &text)
00200 {
00201     m_text.append(escape(text));
00202 }
00203 
00204 const QString BBCodeBuilder::escape(const QString &s)
00205 {
00206     if (s.contains("[")) {
00207         return QString("[NOPARSE]" + s + "[/NOPARSE]");
00208     }
00209     return s;
00210 }
00211 
00212 QString& BBCodeBuilder::getResult()
00213 {
00214     return m_text;
00215 }
00216 

kpimtextedit/richtextbuilders

Skip menu "kpimtextedit/richtextbuilders"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.7.5
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal