Patch by Alex Wilson (yourpalal): Converted the remaining two translators to use

layout management. Fixed a bug in the HVIFTranslator which did not release
the TranslatorSettings in it's destructor. Thanks a bunch!


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36501 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2010-04-27 10:39:39 +00:00
parent da72ff2672
commit c497ec3773
6 changed files with 105 additions and 225 deletions

View File

@ -169,6 +169,5 @@ HVIFTranslator::DerivedTranslate(BPositionIO *inSource,
BView *
HVIFTranslator::NewConfigView(TranslatorSettings *settings)
{
return new HVIFView(BRect(0, 0, 250, 150), "HVIFTranslator Settings",
B_FOLLOW_ALL, B_WILL_DRAW, settings);
return new HVIFView("HVIFTranslator Settings", B_WILL_DRAW, settings);
}

View File

@ -9,6 +9,7 @@
#include "HVIFView.h"
#include "HVIFTranslator.h"
#include <GroupLayoutBuilder.h>
#include <String.h>
#include <StringView.h>
@ -17,57 +18,65 @@
#define HVIF_SETTING_RENDER_SIZE_CHANGED 'rsch'
HVIFView::HVIFView(const BRect &frame, const char *name, uint32 resizeMode,
uint32 flags, TranslatorSettings *settings)
: BView(frame, name, resizeMode, flags),
fSettings(settings)
HVIFView::HVIFView(const char* name, uint32 flags, TranslatorSettings *settings)
:
BView(name, flags, new BGroupLayout(B_VERTICAL)),
fSettings(settings)
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
BAlignment labelAlignment(B_ALIGN_LEFT, B_ALIGN_NO_VERTICAL);
font_height fontHeight;
be_bold_font->GetHeight(&fontHeight);
float height = fontHeight.descent + fontHeight.ascent + fontHeight.leading;
BRect rect(10, 10, 200, 10 + height);
BStringView *stringView = new BStringView(rect, "title",
BStringView* title= new BStringView("title",
"Native Haiku icon format translator");
stringView->SetFont(be_bold_font);
stringView->ResizeToPreferred();
AddChild(stringView);
title->SetFont(be_bold_font);
title->SetExplicitAlignment(labelAlignment);
rect.OffsetBy(0, height + 10);
char version[256];
snprintf(version, sizeof(version), "Version %d.%d.%d, %s",
char versionString[256];
snprintf(versionString, sizeof(versionString), "Version %d.%d.%d, %s",
int(B_TRANSLATION_MAJOR_VERSION(HVIF_TRANSLATOR_VERSION)),
int(B_TRANSLATION_MINOR_VERSION(HVIF_TRANSLATOR_VERSION)),
int(B_TRANSLATION_REVISION_VERSION(HVIF_TRANSLATOR_VERSION)),
__DATE__);
stringView = new BStringView(rect, "version", version);
stringView->ResizeToPreferred();
AddChild(stringView);
BStringView* version = new BStringView("version", versionString);
version->SetExplicitAlignment(labelAlignment);
GetFontHeight(&fontHeight);
height = fontHeight.descent + fontHeight.ascent + fontHeight.leading;
rect.OffsetBy(0, height + 5);
stringView = new BStringView(rect, "copyright",
BStringView* copyright = new BStringView("copyright",
B_UTF8_COPYRIGHT"2009 Haiku Inc.");
stringView->ResizeToPreferred();
AddChild(stringView);
copyright->SetExplicitAlignment(labelAlignment);
rect.OffsetBy(0, height + 5);
int32 renderSize = fSettings->SetGetInt32(HVIF_SETTING_RENDER_SIZE);
BString label = "Render size: ";
label << renderSize;
fRenderSize = new BSlider(rect, "renderSize", label.String(), NULL, 1, 32);
fRenderSize->ResizeToPreferred();
fRenderSize = new BSlider("renderSize", label.String(),
NULL, 1, 32, B_HORIZONTAL);
fRenderSize->SetValue(renderSize / 8);
fRenderSize->SetHashMarks(B_HASH_MARKS_BOTTOM);
fRenderSize->SetHashMarkCount(16);
fRenderSize->SetModificationMessage(
new BMessage(HVIF_SETTING_RENDER_SIZE_CHANGED));
AddChild(fRenderSize);
fRenderSize->SetExplicitAlignment(labelAlignment);
float padding = 5.0f;
AddChild(BGroupLayoutBuilder(B_VERTICAL, padding)
.Add(title)
.Add(version)
.Add(copyright)
.Add(fRenderSize)
.AddGlue()
.SetInsets(padding, padding, padding, padding)
);
BFont font;
GetFont(&font);
SetExplicitPreferredSize(
BSize((font.Size() * 270) / 12, (font.Size() * 100) / 12));
}
HVIFView::~HVIFView()
{
fSettings->Release();
}

View File

@ -15,16 +15,15 @@
class HVIFView : public BView {
public:
HVIFView(const BRect &frame, const char *name,
uint32 resizeMode, uint32 flags,
TranslatorSettings *settings);
HVIFView(const char *name, uint32 flags, TranslatorSettings *settings);
~HVIFView();
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage *message);
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage *message);
private:
BSlider * fRenderSize;
TranslatorSettings *fSettings;
BSlider* fRenderSize;
TranslatorSettings* fSettings;
};
#endif // HVIF_VIEW_H

View File

@ -146,7 +146,8 @@ make_nth_translator(int32 n, image_id you, uint32 flags, ...)
// Returns:
// ---------------------------------------------------------------
SGITranslator::SGITranslator()
: BaseTranslator("SGI images", "SGI image translator",
:
BaseTranslator("SGI images", "SGI image translator",
SGI_TRANSLATOR_VERSION,
gInputFormats, sizeof(gInputFormats) / sizeof(translation_format),
gOutputFormats, sizeof(gOutputFormats) / sizeof(translation_format),
@ -732,6 +733,5 @@ SGITranslator::DerivedTranslate(BPositionIO *inSource,
BView *
SGITranslator::NewConfigView(TranslatorSettings *settings)
{
return new SGIView(BRect(0, 0, 225, 175), "SGITranslator Settings",
B_FOLLOW_ALL, B_WILL_DRAW, settings);
return new SGIView("SGITranslator Settings", B_WILL_DRAW, settings);
}

View File

@ -33,10 +33,14 @@
#include <stdio.h>
#include <string.h>
#include <GroupLayoutBuilder.h>
#include <MenuBar.h>
#include <MenuField.h>
#include <MenuItem.h>
#include <PopUpMenu.h>
#include <String.h>
#include <StringView.h>
#include <TextView.h>
#include <Window.h>
#include "SGIImage.h"
@ -72,14 +76,11 @@ add_menu_item(BMenu* menu,
//
// Returns:
// ---------------------------------------------------------------
SGIView::SGIView(const BRect &frame, const char *name,
uint32 resize, uint32 flags, TranslatorSettings *settings)
: BView(frame, name, resize, flags),
fSettings(settings)
SGIView::SGIView(const char* name, uint32 flags, TranslatorSettings* settings)
:
BView(name, flags, new BGroupLayout(B_VERTICAL)),
fSettings(settings)
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
SetLowColor(ViewColor());
BPopUpMenu* menu = new BPopUpMenu("pick compression");
uint32 currentCompression = fSettings->SetGetInt32(SGI_SETTING_COMPRESSION);
@ -96,36 +97,57 @@ SGIView::SGIView(const BRect &frame, const char *name,
// add_menu_item(menu, SGI_COMP_ARLE, "Agressive RLE", currentCompression);
BRect menuFrame = Bounds();
menuFrame.bottom = menuFrame.top + menu->Bounds().Height();
fCompressionMF = new BMenuField(menuFrame, "compression",
"Use compression:", menu, true/*,
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP*/);
if (fCompressionMF->MenuBar())
fCompressionMF->MenuBar()->ResizeToPreferred();
fCompressionMF->ResizeToPreferred();
fCompressionMF = new BMenuField("compression", "Use compression:", menu);
// figure out where the text ends
font_height fh;
be_bold_font->GetHeight(&fh);
float xbold, ybold;
xbold = fh.descent + 1;
ybold = fh.ascent + fh.descent * 2 + fh.leading;
BAlignment labelAlignment(B_ALIGN_LEFT, B_ALIGN_NO_VERTICAL);
font_height plainh;
be_plain_font->GetHeight(&plainh);
float yplain;
yplain = plainh.ascent + plainh.descent * 2 + plainh.leading;
BStringView* titleView = new BStringView("title", "SGI image translator");
titleView->SetFont(be_bold_font);
titleView->SetExplicitAlignment(labelAlignment);
// position the menu field below all the text we draw in Draw()
BPoint textOffset(0.0, yplain * 2 + ybold);
fCompressionMF->MoveTo(textOffset);
char detail[100];
sprintf(detail, "Version %d.%d.%d %s",
static_cast<int>(B_TRANSLATION_MAJOR_VERSION(SGI_TRANSLATOR_VERSION)),
static_cast<int>(B_TRANSLATION_MINOR_VERSION(SGI_TRANSLATOR_VERSION)),
static_cast<int>(B_TRANSLATION_REVISION_VERSION(SGI_TRANSLATOR_VERSION)),
__DATE__);
BStringView* detailView = new BStringView("details", detail);
detailView->SetExplicitAlignment(labelAlignment);
AddChild(fCompressionMF);
BTextView* infoView = new BTextView("info");
infoView->SetText(BString("written by:\n")
.Append(author)
.Append("\n\nbased on GIMP SGI plugin v1.5:\n")
.Append(kSGICopyright).String());
infoView->SetExplicitAlignment(labelAlignment);
infoView->SetWordWrap(false);
infoView->MakeEditable(false);
infoView->MakeResizable(true);
infoView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
float padding = 5.0f;
AddChild(BGroupLayoutBuilder(B_VERTICAL, padding)
.Add(titleView)
.Add(detailView)
.Add(fCompressionMF)
.Add(infoView)
.AddGlue()
.SetInsets(padding, padding, padding, padding)
);
ResizeToPreferred();
BFont font;
GetFont(&font);
SetExplicitPreferredSize(
BSize((font.Size() * 390) / 12, (font.Size() * 180) / 12));
// TODO: remove this workaround for ticket #4217
infoView->SetExplicitPreferredSize(
BSize(infoView->LineWidth(4), infoView->TextHeight(0, 80)));
infoView->SetExplicitMaxSize(infoView->ExplicitPreferredSize());
infoView->SetExplicitMinSize(infoView->ExplicitPreferredSize());
}
// ---------------------------------------------------------------
// Destructor
//
@ -192,148 +214,5 @@ void
SGIView::AllAttached()
{
fCompressionMF->Menu()->SetTargetForItems(this);
fCompressionMF->ResizeToPreferred();
fCompressionMF->SetDivider(fCompressionMF->StringWidth(fCompressionMF->Label()) + 3);
}
// ---------------------------------------------------------------
// AttachedToWindow
//
// hack to make the window recognize our size
//
// Preconditions:
//
// Parameters: area, not used
//
// Postconditions:
//
// Returns:
// ---------------------------------------------------------------
void
SGIView::AttachedToWindow()
{
// Hack for DataTranslations which doesn't resize visible area to requested by view
// which makes some parts of bigger than usual translationviews out of visible area
// so if it was loaded to DataTranslations resize window if needed
BWindow *window = Window();
if (!strcmp(window->Name(), "DataTranslations")) {
BView *view = Parent();
if (view) {
BRect frame = view->Frame();
float x, y;
GetPreferredSize(&x, &y);
if (frame.Width() < x || (frame.Height() - 48) < y) {
x -= frame.Width();
y -= frame.Height() - 48;
if (x < 0) x = 0;
if (y < 0) y = 0;
// DataTranslations has main view called "Background"
// change it's resizing mode so it will always resize with window
// also make sure view will be redrawed after resize
view = window->FindView("Background");
if (view) {
view->SetResizingMode(B_FOLLOW_ALL);
view->SetFlags(B_FULL_UPDATE_ON_RESIZE);
}
// The same with "Info..." button, except redrawing, which isn't needed
view = window->FindView("Info" B_UTF8_ELLIPSIS);
if (view)
view->SetResizingMode(B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
window->ResizeBy( x, y);
}
}
}
}
// ---------------------------------------------------------------
// Draw
//
// Draws information about the SGITranslator to this view.
//
// Preconditions:
//
// Parameters: area, not used
//
// Postconditions:
//
// Returns:
// ---------------------------------------------------------------
void
SGIView::Draw(BRect area)
{
SetFont(be_bold_font);
font_height fh;
GetFontHeight(&fh);
float xbold, ybold;
xbold = fh.descent + 1;
ybold = fh.ascent + fh.descent * 2 + fh.leading;
const char* text = "SGI image translator";
DrawString(text, BPoint(xbold, ybold));
SetFont(be_plain_font);
font_height plainh;
GetFontHeight(&plainh);
float yplain;
yplain = plainh.ascent + plainh.descent * 2 + plainh.leading;
char detail[100];
sprintf(detail, "Version %d.%d.%d %s",
static_cast<int>(B_TRANSLATION_MAJOR_VERSION(SGI_TRANSLATOR_VERSION)),
static_cast<int>(B_TRANSLATION_MINOR_VERSION(SGI_TRANSLATOR_VERSION)),
static_cast<int>(B_TRANSLATION_REVISION_VERSION(SGI_TRANSLATOR_VERSION)),
__DATE__);
DrawString(detail, BPoint(xbold, yplain + ybold));
BPoint offset = fCompressionMF->Frame().LeftBottom();
offset.x += xbold;
offset.y += 2 * ybold;
text = "written by:";
DrawString(text, offset);
offset.y += ybold;
DrawString(author, offset);
offset.y += 2 * ybold;
text = "based on GIMP SGI plugin v1.5:";
DrawString(text, offset);
offset.y += ybold;
DrawString(kSGICopyright, offset);
}
// ---------------------------------------------------------------
// Draw
//
// calculated the preferred size of this view
//
// Preconditions:
//
// Parameters: width and height
//
// Postconditions:
//
// Returns: in width and height, the preferred size...
// ---------------------------------------------------------------
void
SGIView::GetPreferredSize(float* width, float* height)
{
*width = fCompressionMF->Bounds().Width();
// look at the two biggest strings
float width1 = StringWidth(kSGICopyright) + 15.0;
if (*width < width1)
*width = width1;
float width2 = be_plain_font->StringWidth(author) + 15.0;
if (*width < width2)
*width = width2;
font_height fh;
be_bold_font->GetHeight(&fh);
float ybold = fh.ascent + fh.descent * 2 + fh.leading;
*height = fCompressionMF->Bounds().bottom + 7 * ybold;
}

View File

@ -40,20 +40,14 @@ class BMenuField;
class SGIView : public BView {
public:
SGIView(const BRect &frame, const char *name, uint32 resize,
uint32 flags, TranslatorSettings *settings);
SGIView(const char* name, uint32 flags, TranslatorSettings* settings);
// sets up the view
~SGIView();
// releases the SGITranslator settings
virtual void AllAttached();
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage *message);
virtual void Draw(BRect area);
// draws information about the SGITranslator
virtual void GetPreferredSize(float* width, float* height);
virtual void MessageReceived(BMessage* message);
enum {
MSG_COMPRESSION_CHANGED = 'cmch',
@ -62,7 +56,7 @@ public:
private:
BMenuField* fCompressionMF;
TranslatorSettings *fSettings;
TranslatorSettings* fSettings;
// the actual settings for the translator,
// shared with the translator
};