xref: /haiku/src/add-ons/translators/hvif/HVIFView.cpp (revision f2b4344867e97c3f4e742a1b4a15e6879644601a)
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 <GroupLayoutBuilder.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_TRANSLATE_CONTEXT
22 #define B_TRANSLATE_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("Native Haiku icon format 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 	float padding = 5.0f;
66 	AddChild(BGroupLayoutBuilder(B_VERTICAL, padding)
67 		.Add(title)
68 		.Add(version)
69 		.Add(copyright)
70 		.Add(fRenderSize)
71 		.AddGlue()
72 		.SetInsets(padding, padding, padding, padding)
73 	);
74 
75  	BFont font;
76  	GetFont(&font);
77  	SetExplicitPreferredSize(
78 		BSize((font.Size() * 270) / 12, (font.Size() * 100) / 12));
79 }
80 
81 
82 HVIFView::~HVIFView()
83 {
84 	fSettings->Release();
85 }
86 
87 
88 void
89 HVIFView::AttachedToWindow()
90 {
91 	fRenderSize->SetTarget(this);
92 }
93 
94 
95 void
96 HVIFView::MessageReceived(BMessage *message)
97 {
98 	switch (message->what) {
99 		case HVIF_SETTING_RENDER_SIZE_CHANGED:
100 		{
101 			int32 value = fRenderSize->Value();
102 			if (value <= 0 || value > 32)
103 				break;
104 
105 			value *= 8;
106 			fSettings->SetGetInt32(HVIF_SETTING_RENDER_SIZE, &value);
107 			fSettings->SaveSettings();
108 
109 			BString newLabel = B_TRANSLATE("Render size:");
110 			newLabel << " " << value;
111 			fRenderSize->SetLabel(newLabel.String());
112 			return;
113 		}
114 	}
115 
116 	BView::MessageReceived(message);
117 }
118