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 75 76 HVIFView::~HVIFView() 77 { 78 fSettings->Release(); 79 } 80 81 82 void 83 HVIFView::AttachedToWindow() 84 { 85 fRenderSize->SetTarget(this); 86 } 87 88 89 void 90 HVIFView::MessageReceived(BMessage *message) 91 { 92 switch (message->what) { 93 case HVIF_SETTING_RENDER_SIZE_CHANGED: 94 { 95 int32 value = fRenderSize->Value(); 96 if (value <= 0 || value > 32) 97 break; 98 99 value *= 8; 100 fSettings->SetGetInt32(HVIF_SETTING_RENDER_SIZE, &value); 101 fSettings->SaveSettings(); 102 103 BString newLabel = B_TRANSLATE("Render size:"); 104 newLabel << " " << value; 105 fRenderSize->SetLabel(newLabel.String()); 106 return; 107 } 108 } 109 110 BView::MessageReceived(message); 111 } 112