BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / translators / psd / ConfigView.cpp
blobe380d461371d15efc5ff4e7acc160e1404dccfbc
1 /*
2 * Copyright 2013, Gerasim Troeglazov, 3dEyes@gmail.com. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
6 #include "ConfigView.h"
8 #include <Catalog.h>
9 #include <LayoutBuilder.h>
10 #include <MenuItem.h>
11 #include <PopUpMenu.h>
12 #include <StringView.h>
14 #include <stdio.h>
16 #include "PSDLoader.h"
17 #include "PSDTranslator.h"
19 #undef B_TRANSLATION_CONTEXT
20 #define B_TRANSLATION_CONTEXT "PSDConfig"
23 ConfigView::ConfigView(TranslatorSettings *settings)
24 : BGroupView(B_TRANSLATE("PSDTranslator Settings"), B_VERTICAL, 0)
26 fSettings = settings;
28 BPopUpMenu* compressionPopupMenu = new BPopUpMenu("popup_compression");
30 uint32 currentCompression =
31 fSettings->SetGetInt32(PSD_SETTING_COMPRESSION);
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);
38 fCompressionField = new BMenuField("compression",
39 B_TRANSLATE("Compression: "), compressionPopupMenu);
40 fCompressionField->SetAlignment(B_ALIGN_RIGHT);
42 BPopUpMenu* versionPopupMenu = new BPopUpMenu("popup_version");
44 uint32 currentVersion =
45 fSettings->SetGetInt32(PSD_SETTING_VERSION);
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);
54 fVersionField = new BMenuField("version",
55 B_TRANSLATE("Format: "), versionPopupMenu);
56 fVersionField->SetAlignment(B_ALIGN_RIGHT);
58 BStringView *titleView = new BStringView("title",
59 B_TRANSLATE("Photoshop image translator"));
60 titleView->SetFont(be_bold_font);
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__);
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>");
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);
91 SetExplicitPreferredSize(GroupLayout()->MinSize());
95 ConfigView::~ConfigView()
97 fSettings->Release();
101 void
102 ConfigView::AllAttached()
104 fCompressionField->Menu()->SetTargetForItems(this);
105 fVersionField->Menu()->SetTargetForItems(this);
109 void
110 ConfigView::MessageReceived(BMessage* message)
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();
119 break;
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();
127 break;
129 default:
130 BView::MessageReceived(message);
135 void
136 ConfigView::_AddItemToMenu(BMenu* menu, const char* label,
137 uint32 mess, uint32 value, uint32 current_value)
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);