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 .Add(fVersionField->CreateMenuBarLayoutItem(), 1, 0) 84 .Add(fCompressionField->CreateLabelLayoutItem(), 0, 1) 85 .Add(fCompressionField->CreateMenuBarLayoutItem(), 1, 1) 86 .End() 87 .AddGlue() 88 .Add(copyright2View); 89 90 91 SetExplicitPreferredSize(GroupLayout()->MinSize()); 92 } 93 94 95 ConfigView::~ConfigView() 96 { 97 fSettings->Release(); 98 } 99 100 101 void 102 ConfigView::AllAttached() 103 { 104 fCompressionField->Menu()->SetTargetForItems(this); 105 fVersionField->Menu()->SetTargetForItems(this); 106 } 107 108 109 void 110 ConfigView::MessageReceived(BMessage* message) 111 { 112 switch (message->what) { 113 case MSG_COMPRESSION_CHANGED: { 114 int32 value; 115 if (message->FindInt32("value", &value) >= B_OK) { 116 fSettings->SetGetInt32(PSD_SETTING_COMPRESSION, &value); 117 fSettings->SaveSettings(); 118 } 119 break; 120 } 121 case MSG_VERSION_CHANGED: { 122 int32 value; 123 if (message->FindInt32("value", &value) >= B_OK) { 124 fSettings->SetGetInt32(PSD_SETTING_VERSION, &value); 125 fSettings->SaveSettings(); 126 } 127 break; 128 } 129 default: 130 BView::MessageReceived(message); 131 } 132 } 133 134 135 void 136 ConfigView::_AddItemToMenu(BMenu* menu, const char* label, 137 uint32 mess, uint32 value, uint32 current_value) 138 { 139 BMessage* message = new BMessage(mess); 140 message->AddInt32("value", value); 141 BMenuItem* item = new BMenuItem(label, message); 142 item->SetMarked(value == current_value); 143 menu->AddItem(item); 144 } 145