xref: /haiku/src/add-ons/translators/stxt/STXTView.cpp (revision d3d8b26997fac34a84981e6d2b649521de2cc45a)
1 /*
2  * Copyright 2002-2006, Haiku, Inc.
3  * Distributed under the terms of the MIT license.
4  *
5  * Authors:
6  *		Michael Wilber
7  *		Axel Dörfler, axeld@pinc-software.de
8  */
9 
10 /*! A view with information about the STXTTranslator. */
11 
12 
13 #include "STXTView.h"
14 #include "STXTTranslator.h"
15 
16 #include <StringView.h>
17 
18 #include <stdio.h>
19 
20 
21 STXTView::STXTView(const BRect &frame, const char *name, uint32 resizeMode,
22 		uint32 flags, TranslatorSettings *settings)
23 	: BView(frame, name, resizeMode, flags)
24 {
25 	fSettings = settings;
26 	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
27 
28 	font_height fontHeight;
29 	be_bold_font->GetHeight(&fontHeight);
30 	float height = fontHeight.descent + fontHeight.ascent + fontHeight.leading;
31 
32 	BRect rect(10, 10, 200, 10 + height);
33 	BStringView *stringView = new BStringView(rect, "title", "StyledEdit Files Translator");
34 	stringView->SetFont(be_bold_font);
35 	stringView->ResizeToPreferred();
36 	AddChild(stringView);
37 
38 	float maxWidth = stringView->Bounds().Width();
39 
40 	rect.OffsetBy(0, height + 10);
41 	char version[256];
42 	snprintf(version, sizeof(version), "Version %d.%d.%d, %s",
43 		int(B_TRANSLATION_MAJOR_VERSION(STXT_TRANSLATOR_VERSION)),
44 		int(B_TRANSLATION_MINOR_VERSION(STXT_TRANSLATOR_VERSION)),
45 		int(B_TRANSLATION_REVISION_VERSION(STXT_TRANSLATOR_VERSION)),
46 		__DATE__);
47 	stringView = new BStringView(rect, "version", version);
48 	stringView->ResizeToPreferred();
49 	AddChild(stringView);
50 
51 	if (stringView->Bounds().Width() > maxWidth)
52 		maxWidth = stringView->Bounds().Width();
53 
54 	GetFontHeight(&fontHeight);
55 	height = fontHeight.descent + fontHeight.ascent + fontHeight.leading;
56 
57 	rect.OffsetBy(0, height + 5);
58 	stringView = new BStringView(rect, "Copyright", B_UTF8_COPYRIGHT "2002-2006 Haiku Inc.");
59 	stringView->ResizeToPreferred();
60 	AddChild(stringView);
61 
62 	if (maxWidth + 20 > Bounds().Width())
63 		ResizeTo(maxWidth + 20, Bounds().Height());
64 }
65 
66 
67 STXTView::~STXTView()
68 {
69 	fSettings->Release();
70 }
71