2 * Copyright 2013, Gerasim Troeglazov, 3dEyes@gmail.com. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 #include "ConfigView.h"
9 #include <LayoutBuilder.h>
11 #include <PopUpMenu.h>
12 #include <StringView.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)
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
);
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
)),
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
)
82 .Add(fVersionField
->CreateLabelLayoutItem(), 0, 0)
83 .Add(fVersionField
->CreateMenuBarLayoutItem(), 1, 0)
84 .Add(fCompressionField
->CreateLabelLayoutItem(), 0, 1)
85 .Add(fCompressionField
->CreateMenuBarLayoutItem(), 1, 1)
91 SetExplicitPreferredSize(GroupLayout()->MinSize());
95 ConfigView::~ConfigView()
102 ConfigView::AllAttached()
104 fCompressionField
->Menu()->SetTargetForItems(this);
105 fVersionField
->Menu()->SetTargetForItems(this);
110 ConfigView::MessageReceived(BMessage
* message
)
112 switch (message
->what
) {
113 case MSG_COMPRESSION_CHANGED
: {
115 if (message
->FindInt32("value", &value
) >= B_OK
) {
116 fSettings
->SetGetInt32(PSD_SETTING_COMPRESSION
, &value
);
117 fSettings
->SaveSettings();
121 case MSG_VERSION_CHANGED
: {
123 if (message
->FindInt32("value", &value
) >= B_OK
) {
124 fSettings
->SetGetInt32(PSD_SETTING_VERSION
, &value
);
125 fSettings
->SaveSettings();
130 BView::MessageReceived(message
);
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
);