repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / haikudepot / textview / TextDocumentTest.cpp
blobe9aaf0f43792ba15254b0a1455ea544a9b5f78a6
1 /*
2 * Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
6 #include "TextDocumentTest.h"
8 #include <math.h>
9 #include <stdio.h>
11 #include <LayoutBuilder.h>
12 #include <ScrollView.h>
13 #include <Window.h>
15 #include "MarkupParser.h"
16 #include "TextDocumentView.h"
18 TextDocumentTest::TextDocumentTest()
20 BApplication("application/x-vnd.Haiku-TextDocumentTest")
25 TextDocumentTest::~TextDocumentTest()
30 void
31 TextDocumentTest::ReadyToRun()
33 BRect frame(50.0, 50.0, 749.0, 549.0);
35 BWindow* window = new BWindow(frame, "Text document test",
36 B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE | B_AUTO_UPDATE_SIZE_LIMITS);
38 TextDocumentView* documentView = new TextDocumentView("text document view");
40 BScrollView* scrollView = new BScrollView("text scroll view", documentView,
41 false, true, B_NO_BORDER);
43 BLayoutBuilder::Group<>(window, B_VERTICAL)
44 .Add(scrollView)
47 CharacterStyle regularStyle;
49 float fontSize = regularStyle.Font().Size();
51 ParagraphStyle paragraphStyle;
52 paragraphStyle.SetJustify(true);
53 paragraphStyle.SetSpacingTop(ceilf(fontSize * 0.6f));
54 paragraphStyle.SetLineSpacing(ceilf(fontSize * 0.2f));
56 // CharacterStyle boldStyle(regularStyle);
57 // boldStyle.SetBold(true);
59 // CharacterStyle italicStyle(regularStyle);
60 // italicStyle.SetItalic(true);
62 // CharacterStyle italicAndBoldStyle(boldStyle);
63 // italicAndBoldStyle.SetItalic(true);
65 // CharacterStyle bigStyle(regularStyle);
66 // bigStyle.SetFontSize(24);
67 // bigStyle.SetForegroundColor(255, 50, 50);
69 // TextDocumentRef document(new TextDocument(), true);
71 // Paragraph paragraph(paragraphStyle);
72 // paragraph.Append(TextSpan("This is a", regularStyle));
73 // paragraph.Append(TextSpan(" test ", bigStyle));
74 // paragraph.Append(TextSpan("to see if ", regularStyle));
75 // paragraph.Append(TextSpan("different", boldStyle));
76 // paragraph.Append(TextSpan(" character styles already work.", regularStyle));
77 // document->Append(paragraph);
79 // paragraphStyle.SetSpacingTop(8.0f);
80 // paragraphStyle.SetAlignment(ALIGN_CENTER);
81 // paragraphStyle.SetJustify(false);
83 // paragraph = Paragraph(paragraphStyle);
84 // paragraph.Append(TextSpan("Different alignment styles ", regularStyle));
85 // paragraph.Append(TextSpan("are", boldStyle));
86 // paragraph.Append(TextSpan(" supported as of now!", regularStyle));
87 // document->Append(paragraph);
89 // // Test a bullet list
90 // paragraphStyle.SetSpacingTop(8.0f);
91 // paragraphStyle.SetAlignment(ALIGN_LEFT);
92 // paragraphStyle.SetJustify(true);
93 // paragraphStyle.SetBullet(Bullet("•", 12.0f));
94 // paragraphStyle.SetLineInset(10.0f);
96 // paragraph = Paragraph(paragraphStyle);
97 // paragraph.Append(TextSpan("Even bullet lists are supported.", regularStyle));
98 // document->Append(paragraph);
100 // paragraph = Paragraph(paragraphStyle);
101 // paragraph.Append(TextSpan("The wrapping in ", regularStyle));
102 // paragraph.Append(TextSpan("this", italicStyle));
104 // paragraph.Append(TextSpan(" bullet item should look visually "
105 // "pleasing. And ", regularStyle));
106 // paragraph.Append(TextSpan("why", italicAndBoldStyle));
107 // paragraph.Append(TextSpan(" should it not?", regularStyle));
108 // document->Append(paragraph);
110 MarkupParser parser(regularStyle, paragraphStyle);
112 TextDocumentRef document = parser.CreateDocumentFromMarkup(
113 "== Text document test ==\n"
114 "This is a test to see if '''different''' "
115 "character styles already work.\n"
116 "Different alignment styles '''are''' supported as of now!\n"
117 " * Even bullet lists are supported.\n"
118 " * The wrapping in ''this'' bullet item should look visually "
119 "pleasing. And ''why'' should it not?\n"
122 documentView->SetTextDocument(document);
123 documentView->SetTextEditor(TextEditorRef(new TextEditor(), true));
124 documentView->MakeFocus();
126 window->Show();
131 main(int argc, char* argv[])
133 TextDocumentTest().Run();
134 return 0;