• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.1 API Reference
  • KDE Home
  • Contact Us
 

kpimtextedit/richtextbuilders

  • kpimtextedit
  • richtextbuilders
bbcodebuilder.cpp
1 /*
2  This file is part of KDE.
3 
4  Copyright (c) 2008 Stephen Kelly <steveire@gmail.com>
5 
6  This library is free software; you can redistribute it and/or modify it
7  under the terms of the GNU Library General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or (at your
9  option) any later version.
10 
11  This library is distributed in the hope that it will be useful, but WITHOUT
12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14  License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to the
18  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  02110-1301, USA.
20 */
21 
22 
23 
24 #include "bbcodebuilder.h"
25 #include <kdebug.h>
26 
27 BBCodeBuilder::BBCodeBuilder()
28 {
29 
30  currentAlignment = Qt::AlignLeft; //Default value
31 }
32 
33 void BBCodeBuilder::beginStrong()
34 {
35  m_text.append("[B]");
36 }
37 void BBCodeBuilder::endStrong()
38 {
39  m_text.append("[/B]");
40 }
41 void BBCodeBuilder::beginEmph()
42 {
43  m_text.append("[I]");
44 }
45 void BBCodeBuilder::endEmph()
46 {
47  m_text.append("[/I]");
48 }
49 void BBCodeBuilder::beginUnderline()
50 {
51  m_text.append("[U]");
52 }
53 void BBCodeBuilder::endUnderline()
54 {
55  m_text.append("[/U]");
56 }
57 void BBCodeBuilder::beginStrikeout()
58 {
59  m_text.append("[S]");
60 }
61 void BBCodeBuilder::endStrikeout()
62 {
63  m_text.append("[/S]");
64 }
65 void BBCodeBuilder::beginForeground(const QBrush &brush)
66 {
67  m_text.append(QString("[COLOR=%1]").arg(brush.color().name()));
68 }
69 void BBCodeBuilder::endForeground()
70 {
71  m_text.append("[/COLOR]");
72 }
73 
74 // Background colour not supported by BBCode.
75 
76 void BBCodeBuilder::beginAnchor(const QString &href, const QString &name)
77 {
78  m_text.append(QString("[URL=%1]").arg(href));
79 }
80 void BBCodeBuilder::endAnchor()
81 {
82  m_text.append("[/URL]");
83 }
84 
85 // Font family not supported by BBCode.
86 
87 void BBCodeBuilder::beginFontPointSize(int size)
88 {
89  m_text.append(QString("[SIZE=%1]").arg(QString::number(size)));
90 }
91 void BBCodeBuilder::endFontPointSize()
92 {
93  m_text.append("[/SIZE]");
94 }
95 
96 void BBCodeBuilder::beginParagraph(Qt::Alignment a, qreal top, qreal bottom, qreal left, qreal right)
97 {
98  Q_UNUSED(top);
99  Q_UNUSED(bottom);
100  Q_UNUSED(left);
101  Q_UNUSED(right);
102  if (a & Qt::AlignRight) {
103  m_text.append("\n[Right]");
104  } else if (a & Qt::AlignHCenter) {
105  m_text.append("\n[CENTER]");
106  }
107  // LEFT is also supported in BBCode, but ignored.
108  currentAlignment = a;
109 }
110 void BBCodeBuilder::endParagraph()
111 {
112  if (currentAlignment & Qt::AlignRight) {
113  m_text.append("\n[/Right]\n");
114  } else if (currentAlignment & Qt::AlignHCenter) {
115  m_text.append("\n[/CENTER]\n");
116  } else {
117  m_text.append("\n");
118  }
119  currentAlignment = Qt::AlignLeft;
120 
121 }
122 void BBCodeBuilder::addNewline()
123 {
124  m_text.append("\n");
125 }
126 
127 void BBCodeBuilder::insertImage(const QString &src, qreal width, qreal height)
128 {
129  Q_UNUSED(width);
130  Q_UNUSED(height);
131  m_text.append(QString("[IMG]%1[/IMG]").arg(src));
132 }
133 
134 void BBCodeBuilder::beginList(QTextListFormat::Style type)
135 {
136  switch (type) {
137  case QTextListFormat::ListDisc:
138  case QTextListFormat::ListCircle:
139  case QTextListFormat::ListSquare:
140  m_text.append("[LIST]\n"); // Unordered lists are all disc type in BBCode.
141  break;
142  case QTextListFormat::ListDecimal:
143  m_text.append("[LIST=1]\n");
144  break;
145  case QTextListFormat::ListLowerAlpha:
146  m_text.append("[LIST=a]\n");
147  break;
148  case QTextListFormat::ListUpperAlpha:
149  m_text.append("[LIST=A]\n");
150  break;
151  default:
152  break;
153  }
154 }
155 
156 void BBCodeBuilder::endList()
157 {
158  m_text.append("[/LIST]\n");
159 }
160 
161 
162 void BBCodeBuilder::beginListItem()
163 {
164  m_text.append("[*] ");
165 }
166 
167 void BBCodeBuilder::beginSuperscript()
168 {
169  m_text.append("[SUP]");
170 }
171 
172 void BBCodeBuilder::endSuperscript()
173 {
174  m_text.append("[/SUP]");
175 }
176 
177 void BBCodeBuilder::beginSubscript()
178 {
179  m_text.append("[SUB]");
180 }
181 
182 void BBCodeBuilder::endSubscript()
183 {
184  m_text.append("[/SUB]");
185 }
186 
187 
188 void BBCodeBuilder::beginTable(qreal, qreal, const QString &)
189 {
190  m_text.append("[TABLE]\n");
191 }
192 
193 void BBCodeBuilder::beginTableRow()
194 {
195  m_text.append("[/TABLE]");
196 }
197 
198 
199 void BBCodeBuilder::appendLiteralText(const QString &text)
200 {
201  m_text.append(escape(text));
202 }
203 
204 const QString BBCodeBuilder::escape(const QString &s)
205 {
206  if (s.contains("[")) {
207  return QString("[NOPARSE]" + s + "[/NOPARSE]");
208  }
209  return s;
210 }
211 
212 QString& BBCodeBuilder::getResult()
213 {
214  return m_text;
215 }
216 
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Sep 24 2012 09:03:57 by doxygen 1.8.1.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kpimtextedit/richtextbuilders

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

kdepimlibs-4.9.1 API Reference

Skip menu "kdepimlibs-4.9.1 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • 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
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal