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