repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / haikudepot / ui_generic / MarkupTextView.cpp
blob68f81aeb7ec0ae060ba275c092e593abc6cf57c6
1 /*
2 * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
7 #include "MarkupTextView.h"
10 static const rgb_color kLightBlack = (rgb_color){ 60, 60, 60, 255 };
13 MarkupTextView::MarkupTextView(const char* name)
15 TextDocumentView(name)
17 SetEditingEnabled(false);
18 CharacterStyle regularStyle;
20 float fontSize = regularStyle.Font().Size();
22 ParagraphStyle paragraphStyle;
23 paragraphStyle.SetJustify(true);
24 paragraphStyle.SetSpacingTop(ceilf(fontSize * 0.3f));
25 paragraphStyle.SetLineSpacing(ceilf(fontSize * 0.2f));
27 fMarkupParser.SetStyles(regularStyle, paragraphStyle);
31 void
32 MarkupTextView::SetText(const BString& markupText)
34 SetTextDocument(fMarkupParser.CreateDocumentFromMarkup(markupText));
38 void
39 MarkupTextView::SetText(const BString heading, const BString& markupText)
41 TextDocumentRef document(new(std::nothrow) TextDocument(), true);
43 Paragraph paragraph(fMarkupParser.HeadingParagraphStyle());
44 paragraph.Append(TextSpan(heading,
45 fMarkupParser.HeadingCharacterStyle()));
46 document->Append(paragraph);
48 fMarkupParser.AppendMarkup(document, markupText);
50 SetTextDocument(document);
54 void
55 MarkupTextView::SetDisabledText(const BString& text)
57 TextDocumentRef document(new(std::nothrow) TextDocument(), true);
59 ParagraphStyle paragraphStyle;
60 paragraphStyle.SetAlignment(ALIGN_CENTER);
62 CharacterStyle disabledStyle(fMarkupParser.NormalCharacterStyle());
63 disabledStyle.SetForegroundColor(kLightBlack);
65 Paragraph paragraph(paragraphStyle);
66 paragraph.Append(TextSpan(text, disabledStyle));
67 document->Append(paragraph);
69 SetTextDocument(document);