xref: /haiku/src/add-ons/translators/hvif/HVIFView.cpp (revision 4bd0c1066b227cec4b79883bdef697c7a27f2e90)
1 /*
2  * Copyright 2009, Haiku, Inc.
3  * Distributed under the terms of the MIT license.
4  *
5  * Authors:
6  *		Michael Lotz, mmlr@mlotz.ch
7  */
8 
9 #include "HVIFView.h"
10 #include "HVIFTranslator.h"
11 
12 #include <Catalog.h>
13 #include <LayoutBuilder.h>
14 #include <String.h>
15 #include <StringView.h>
16 
17 #include <stdio.h>
18 
19 #define HVIF_SETTING_RENDER_SIZE_CHANGED	'rsch'
20 
21 #undef B_TRANSLATION_CONTEXT
22 #define B_TRANSLATION_CONTEXT "HVIFView"
23 
24 
25 HVIFView::HVIFView(const char* name, uint32 flags, TranslatorSettings *settings)
26 	:
27 	BView(name, flags, new BGroupLayout(B_VERTICAL)),
28 	fSettings(settings)
29 {
30 	BAlignment labelAlignment(B_ALIGN_LEFT, B_ALIGN_NO_VERTICAL);
31 
32 	BStringView* title= new BStringView("title",
33 		B_TRANSLATE("Haiku vector icon translator"));
34 	title->SetFont(be_bold_font);
35 	title->SetExplicitAlignment(labelAlignment);
36 
37 	char versionString[256];
38 	snprintf(versionString, sizeof(versionString),
39 		B_TRANSLATE("Version %d.%d.%d, %s"),
40 		int(B_TRANSLATION_MAJOR_VERSION(HVIF_TRANSLATOR_VERSION)),
41 		int(B_TRANSLATION_MINOR_VERSION(HVIF_TRANSLATOR_VERSION)),
42 		int(B_TRANSLATION_REVISION_VERSION(HVIF_TRANSLATOR_VERSION)),
43 		__DATE__);
44 	BStringView* version = new BStringView("version", versionString);
45 	version->SetExplicitAlignment(labelAlignment);
46 
47 	BStringView* copyright = new BStringView("copyright",
48 		B_UTF8_COPYRIGHT"2009 Haiku Inc.");
49 	copyright->SetExplicitAlignment(labelAlignment);
50 
51 
52 	int32 renderSize = fSettings->SetGetInt32(HVIF_SETTING_RENDER_SIZE);
53 	BString label = B_TRANSLATE("Render size:");
54 	label << " " << renderSize;
55 
56 	fRenderSize = new BSlider("renderSize", label.String(),
57 		NULL, 1, 32, B_HORIZONTAL);
58 	fRenderSize->SetValue(renderSize / 8);
59 	fRenderSize->SetHashMarks(B_HASH_MARKS_BOTTOM);
60 	fRenderSize->SetHashMarkCount(16);
61 	fRenderSize->SetModificationMessage(
62 		new BMessage(HVIF_SETTING_RENDER_SIZE_CHANGED));
63 	fRenderSize->SetExplicitAlignment(labelAlignment);
64 
65 	BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
66 		.SetInsets(B_USE_DEFAULT_SPACING)
67 		.Add(title)
68 		.Add(version)
69 		.Add(copyright)
70 		.AddGlue()
71 		.Add(fRenderSize)
72 		.AddGlue();
73 
74  	BFont font;
75  	GetFont(&font);
76  	SetExplicitPreferredSize(
77 		BSize((font.Size() * 270) / 12, (font.Size() * 100) / 12));
78 }
79 
80 
81 HVIFView::~HVIFView()
82 {
83 	fSettings->Release();
84 }
85 
86 
87 void
88 HVIFView::AttachedToWindow()
89 {
90 	fRenderSize->SetTarget(this);
91 }
92 
93 
94 void
95 HVIFView::MessageReceived(BMessage *message)
96 {
97 	switch (message->what) {
98 		case HVIF_SETTING_RENDER_SIZE_CHANGED:
99 		{
100 			int32 value = fRenderSize->Value();
101 			if (value <= 0 || value > 32)
102 				break;
103 
104 			value *= 8;
105 			fSettings->SetGetInt32(HVIF_SETTING_RENDER_SIZE, &value);
106 			fSettings->SaveSettings();
107 
108 			BString newLabel = B_TRANSLATE("Render size:");
109 			newLabel << " " << value;
110 			fRenderSize->SetLabel(newLabel.String());
111 			return;
112 		}
113 	}
114 
115 	BView::MessageReceived(message);
116 }
117