1 /* 2 * Copyright 2013, Gerasim Troeglazov, 3dEyes@gmail.com. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #include "ConfigView.h" 7 8 #include <Catalog.h> 9 #include <LayoutBuilder.h> 10 #include <MenuItem.h> 11 #include <PopUpMenu.h> 12 #include <StringView.h> 13 14 #include <stdio.h> 15 16 #include "PSDLoader.h" 17 #include "PSDTranslator.h" 18 19 #undef B_TRANSLATION_CONTEXT 20 #define B_TRANSLATION_CONTEXT "PSDConfig" 21 22 23 ConfigView::ConfigView(TranslatorSettings *settings) 24 : BGroupView(B_TRANSLATE("PSDTranslator Settings"), B_VERTICAL, 0) 25 { 26 fSettings = settings; 27 28 BPopUpMenu* compressionPopupMenu = new BPopUpMenu("popup_compression"); 29 30 uint32 currentCompression = 31 fSettings->SetGetInt32(PSD_SETTING_COMPRESSION); 32 33 _AddItemToMenu(compressionPopupMenu, B_TRANSLATE("Uncompressed"), 34 MSG_COMPRESSION_CHANGED, PSD_COMPRESSED_RAW, currentCompression); 35 _AddItemToMenu(compressionPopupMenu, B_TRANSLATE("RLE"), 36 MSG_COMPRESSION_CHANGED, PSD_COMPRESSED_RLE, currentCompression); 37 38 fCompressionField = new BMenuField("compression", 39 B_TRANSLATE("Compression: "), compressionPopupMenu); 40 fCompressionField->SetAlignment(B_ALIGN_RIGHT); 41 42 BPopUpMenu* versionPopupMenu = new BPopUpMenu("popup_version"); 43 44 uint32 currentVersion = 45 fSettings->SetGetInt32(PSD_SETTING_VERSION); 46 47 _AddItemToMenu(versionPopupMenu, 48 B_TRANSLATE("Photoshop Document (PSD file)"), MSG_VERSION_CHANGED, 49 PSD_FILE, currentVersion); 50 _AddItemToMenu(versionPopupMenu, 51 B_TRANSLATE("Photoshop Big Document (PSB file)"), MSG_VERSION_CHANGED, 52 PSB_FILE, currentVersion); 53 54 fVersionField = new BMenuField("version", 55 B_TRANSLATE("Format: "), versionPopupMenu); 56 fVersionField->SetAlignment(B_ALIGN_RIGHT); 57 58 BStringView *titleView = new BStringView("title", 59 B_TRANSLATE("Photoshop image translator")); 60 titleView->SetFont(be_bold_font); 61 62 char version[256]; 63 sprintf(version, B_TRANSLATE("Version %d.%d.%d, %s"), 64 int(B_TRANSLATION_MAJOR_VERSION(PSD_TRANSLATOR_VERSION)), 65 int(B_TRANSLATION_MINOR_VERSION(PSD_TRANSLATOR_VERSION)), 66 int(B_TRANSLATION_REVISION_VERSION(PSD_TRANSLATOR_VERSION)), 67 __DATE__); 68 69 BStringView *versionView = new BStringView("version", version); 70 BStringView *copyrightView = new BStringView("copyright", 71 B_UTF8_COPYRIGHT "2005-2013 Haiku Inc."); 72 BStringView *copyright2View = new BStringView("my_copyright", 73 B_UTF8_COPYRIGHT "2012-2013 Gerasim Troeglazov <3dEyes@gmail.com>"); 74 75 BLayoutBuilder::Group<>(this, B_VERTICAL, 0) 76 .SetInsets(B_USE_DEFAULT_SPACING) 77 .Add(titleView) 78 .Add(versionView) 79 .Add(copyrightView) 80 .AddGlue() 81 .AddGrid(10.0f, 5.0f) 82 .Add(fVersionField->CreateLabelLayoutItem(), 0, 0) 83 .AddGroup(B_HORIZONTAL, 0.0f, 1, 0) 84 .Add(fVersionField->CreateMenuBarLayoutItem(), 0.0f) 85 .AddGlue() 86 .End() 87 .Add(fCompressionField->CreateLabelLayoutItem(), 0, 1) 88 .AddGroup(B_HORIZONTAL, 0.0f, 1, 1) 89 .Add(fCompressionField->CreateMenuBarLayoutItem(), 0.0f) 90 .AddGlue() 91 .End() 92 .End() 93 .AddGlue() 94 .Add(copyright2View); 95 96 97 SetExplicitPreferredSize(GroupLayout()->MinSize()); 98 } 99 100 101 ConfigView::~ConfigView() 102 { 103 fSettings->Release(); 104 } 105 106 107 void 108 ConfigView::AllAttached() 109 { 110 fCompressionField->Menu()->SetTargetForItems(this); 111 fVersionField->Menu()->SetTargetForItems(this); 112 } 113 114 115 void 116 ConfigView::MessageReceived(BMessage* message) 117 { 118 switch (message->what) { 119 case MSG_COMPRESSION_CHANGED: { 120 int32 value; 121 if (message->FindInt32("value", &value) >= B_OK) { 122 fSettings->SetGetInt32(PSD_SETTING_COMPRESSION, &value); 123 fSettings->SaveSettings(); 124 } 125 break; 126 } 127 case MSG_VERSION_CHANGED: { 128 int32 value; 129 if (message->FindInt32("value", &value) >= B_OK) { 130 fSettings->SetGetInt32(PSD_SETTING_VERSION, &value); 131 fSettings->SaveSettings(); 132 } 133 break; 134 } 135 default: 136 BView::MessageReceived(message); 137 } 138 } 139 140 141 void 142 ConfigView::_AddItemToMenu(BMenu* menu, const char* label, 143 uint32 mess, uint32 value, uint32 current_value) 144 { 145 BMessage* message = new BMessage(mess); 146 message->AddInt32("value", value); 147 BMenuItem* item = new BMenuItem(label, message); 148 item->SetMarked(value == current_value); 149 menu->AddItem(item); 150 } 151