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 <GroupLayoutBuilder.h> 13 #include <String.h> 14 #include <StringView.h> 15 16 #include <stdio.h> 17 18 #define HVIF_SETTING_RENDER_SIZE_CHANGED 'rsch' 19 20 21 HVIFView::HVIFView(const char* name, uint32 flags, TranslatorSettings *settings) 22 : 23 BView(name, flags, new BGroupLayout(B_VERTICAL)), 24 fSettings(settings) 25 { 26 BAlignment labelAlignment(B_ALIGN_LEFT, B_ALIGN_NO_VERTICAL); 27 28 BStringView* title= new BStringView("title", 29 "Native Haiku icon format translator"); 30 title->SetFont(be_bold_font); 31 title->SetExplicitAlignment(labelAlignment); 32 33 char versionString[256]; 34 snprintf(versionString, sizeof(versionString), "Version %d.%d.%d, %s", 35 int(B_TRANSLATION_MAJOR_VERSION(HVIF_TRANSLATOR_VERSION)), 36 int(B_TRANSLATION_MINOR_VERSION(HVIF_TRANSLATOR_VERSION)), 37 int(B_TRANSLATION_REVISION_VERSION(HVIF_TRANSLATOR_VERSION)), 38 __DATE__); 39 BStringView* version = new BStringView("version", versionString); 40 version->SetExplicitAlignment(labelAlignment); 41 42 BStringView* copyright = new BStringView("copyright", 43 B_UTF8_COPYRIGHT"2009 Haiku Inc."); 44 copyright->SetExplicitAlignment(labelAlignment); 45 46 47 int32 renderSize = fSettings->SetGetInt32(HVIF_SETTING_RENDER_SIZE); 48 BString label = "Render size: "; 49 label << renderSize; 50 51 fRenderSize = new BSlider("renderSize", label.String(), 52 NULL, 1, 32, B_HORIZONTAL); 53 fRenderSize->SetValue(renderSize / 8); 54 fRenderSize->SetHashMarks(B_HASH_MARKS_BOTTOM); 55 fRenderSize->SetHashMarkCount(16); 56 fRenderSize->SetModificationMessage( 57 new BMessage(HVIF_SETTING_RENDER_SIZE_CHANGED)); 58 fRenderSize->SetExplicitAlignment(labelAlignment); 59 60 float padding = 5.0f; 61 AddChild(BGroupLayoutBuilder(B_VERTICAL, padding) 62 .Add(title) 63 .Add(version) 64 .Add(copyright) 65 .Add(fRenderSize) 66 .AddGlue() 67 .SetInsets(padding, padding, padding, padding) 68 ); 69 70 BFont font; 71 GetFont(&font); 72 SetExplicitPreferredSize( 73 BSize((font.Size() * 270) / 12, (font.Size() * 100) / 12)); 74 } 75 76 77 HVIFView::~HVIFView() 78 { 79 fSettings->Release(); 80 } 81 82 83 void 84 HVIFView::AttachedToWindow() 85 { 86 fRenderSize->SetTarget(this); 87 } 88 89 90 void 91 HVIFView::MessageReceived(BMessage *message) 92 { 93 switch (message->what) { 94 case HVIF_SETTING_RENDER_SIZE_CHANGED: 95 { 96 int32 value = fRenderSize->Value(); 97 if (value <= 0 || value > 32) 98 break; 99 100 value *= 8; 101 fSettings->SetGetInt32(HVIF_SETTING_RENDER_SIZE, &value); 102 fSettings->SaveSettings(); 103 104 BString newLabel = "Render size: "; 105 newLabel << value; 106 fRenderSize->SetLabel(newLabel.String()); 107 return; 108 } 109 } 110 111 BView::MessageReceived(message); 112 } 113