PSDTranslator: Add compression settings
This commit is contained in:
parent
b43bd42518
commit
a47ae0d08e
@ -9,18 +9,36 @@
|
||||
#include <StringView.h>
|
||||
#include <SpaceLayoutItem.h>
|
||||
#include <ControlLook.h>
|
||||
#include <PopUpMenu.h>
|
||||
#include <MenuItem.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "PSDLoader.h"
|
||||
|
||||
|
||||
ConfigView::ConfigView(TranslatorSettings *settings)
|
||||
: BGroupView("PSDTranslator Settings", B_VERTICAL, 0)
|
||||
{
|
||||
fSettings = settings;
|
||||
|
||||
BPopUpMenu* popupMenu = new BPopUpMenu("popup_compression");
|
||||
|
||||
uint32 currentCompression =
|
||||
fSettings->SetGetInt32(PSD_SETTING_COMPRESSION);
|
||||
|
||||
_AddItemToMenu(popupMenu, "Uncompressed",
|
||||
PSD_COMPRESSED_RAW, currentCompression);
|
||||
_AddItemToMenu(popupMenu, "RLE",
|
||||
PSD_COMPRESSED_RLE, currentCompression);
|
||||
|
||||
fCompressionField = new BMenuField("compression",
|
||||
"Compression: ", popupMenu);
|
||||
|
||||
BAlignment leftAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_UNSET);
|
||||
|
||||
BStringView *stringView = new BStringView("title", "Photoshop image translator");
|
||||
BStringView *stringView = new BStringView("title",
|
||||
"Photoshop image translator");
|
||||
stringView->SetFont(be_bold_font);
|
||||
stringView->SetExplicitAlignment(leftAlignment);
|
||||
AddChild(stringView);
|
||||
@ -47,6 +65,8 @@ ConfigView::ConfigView(TranslatorSettings *settings)
|
||||
B_UTF8_COPYRIGHT "2012-2013 Gerasim Troeglazov <3dEyes@gmail.com>");
|
||||
stringView->SetExplicitAlignment(leftAlignment);
|
||||
AddChild(stringView);
|
||||
|
||||
AddChild(fCompressionField);
|
||||
|
||||
AddChild(BSpaceLayoutItem::CreateGlue());
|
||||
GroupLayout()->SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING,
|
||||
@ -65,6 +85,7 @@ ConfigView::~ConfigView()
|
||||
void
|
||||
ConfigView::AllAttached()
|
||||
{
|
||||
fCompressionField->Menu()->SetTargetForItems(this);
|
||||
}
|
||||
|
||||
|
||||
@ -72,7 +93,27 @@ void
|
||||
ConfigView::MessageReceived(BMessage* message)
|
||||
{
|
||||
switch (message->what) {
|
||||
case MSG_COMPRESSION_CHANGED: {
|
||||
int32 value;
|
||||
if (message->FindInt32("value", &value) >= B_OK) {
|
||||
fSettings->SetGetInt32(PSD_SETTING_COMPRESSION, &value);
|
||||
fSettings->SaveSettings();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BView::MessageReceived(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ConfigView::_AddItemToMenu(BMenu* menu, const char* label,
|
||||
uint32 value, uint32 current_value)
|
||||
{
|
||||
BMessage* message = new BMessage(MSG_COMPRESSION_CHANGED);
|
||||
message->AddInt32("value", value);
|
||||
BMenuItem* item = new BMenuItem(label, message);
|
||||
item->SetMarked(value == current_value);
|
||||
menu->AddItem(item);
|
||||
}
|
||||
|
@ -13,7 +13,10 @@
|
||||
#include <String.h>
|
||||
#include <GroupView.h>
|
||||
#include <CheckBox.h>
|
||||
|
||||
#include <MenuField.h>
|
||||
|
||||
#define MSG_COMPRESSION_CHANGED 'cchg'
|
||||
|
||||
class ConfigView : public BGroupView {
|
||||
public:
|
||||
ConfigView(TranslatorSettings *settings);
|
||||
@ -23,7 +26,12 @@ class ConfigView : public BGroupView {
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
private:
|
||||
void _AddItemToMenu(BMenu* menu, const char* label,
|
||||
uint32 value, uint32 current_value);
|
||||
|
||||
BTextView* fCopyrightView;
|
||||
BMenuField* fCompressionField;
|
||||
|
||||
TranslatorSettings *fSettings;
|
||||
};
|
||||
|
||||
|
@ -60,7 +60,8 @@ static const translation_format sOutputFormats[] = {
|
||||
|
||||
static const TranSetting sDefaultSettings[] = {
|
||||
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
||||
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false}
|
||||
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false},
|
||||
{PSD_SETTING_COMPRESSION, TRAN_SETTING_INT32, PSD_COMPRESSED_RLE}
|
||||
};
|
||||
|
||||
const uint32 kNumInputFormats = sizeof(sInputFormats)
|
||||
@ -142,8 +143,11 @@ PSDTranslator::DerivedTranslate(BPositionIO *source,
|
||||
{
|
||||
if (outType == PSD_IMAGE_FORMAT) {
|
||||
PSDWriter psdFile(source);
|
||||
psdFile.SetCompression(PSD_COMPRESSED_RLE);
|
||||
return psdFile.Encode(target);
|
||||
uint32 compression =
|
||||
fSettings->SetGetInt32(PSD_SETTING_COMPRESSION);
|
||||
psdFile.SetCompression(compression);
|
||||
if (psdFile.IsReady())
|
||||
return psdFile.Encode(target);
|
||||
}
|
||||
return B_NO_TRANSLATOR;
|
||||
}
|
||||
|
@ -21,6 +21,8 @@
|
||||
#define DOCUMENT_COUNT "/documentCount"
|
||||
#define DOCUMENT_INDEX "/documentIndex"
|
||||
|
||||
#define PSD_SETTING_COMPRESSION "psd /compression"
|
||||
|
||||
#define PSD_TRANSLATOR_VERSION B_TRANSLATION_MAKE_VERSION(1, 2, 1)
|
||||
#define PSD_IMAGE_FORMAT 'PSD '
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user