* The tab view now uses the native look.

* Big code cleanup.
* The same changes has to be applied to the JPEG2000 translator...


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19136 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-10-28 19:50:04 +00:00
parent 1ab21a021c
commit 8687ff64ab
2 changed files with 327 additions and 287 deletions
+236 -178
View File
@@ -32,6 +32,8 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "JPEGTranslator.h" #include "JPEGTranslator.h"
#include <TabView.h>
// Set these accordingly // Set these accordingly
#define JPEG_ACRONYM "JPEG" #define JPEG_ACRONYM "JPEG"
@@ -45,18 +47,19 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Translation Kit required globals // Translation Kit required globals
char translatorName[] = "JPEG Images"; char translatorName[] = "JPEG Images";
char translatorInfo[] = "© 2002-2003, Shard\n" char translatorInfo[] =
"©2002-2003, Marcin Konicki\n"
"©2005-2006, Haiku\n"
"\n" "\n"
"Based on IJG library © 1991-1998, Thomas G. Lane\"\n" "Based on IJG library © 1991-1998, Thomas G. Lane\n"
" http://www.ijg.org/files/\n" " http://www.ijg.org/files/\n"
"with \"Lossless\" encoding support patch by Ken Murchison\n" "with \"Lossless\" encoding support patch by Ken Murchison\n"
" http://www.oceana.com/ftp/ljpeg/\n" " http://www.oceana.com/ftp/ljpeg/\n"
"\n" "\n"
"With some colorspace conversion routines by Magnus Hellman\n" "With some colorspace conversion routines by Magnus Hellman\n"
" http://www.bebits.com/app/802\n" " http://www.bebits.com/app/802\n";
"";
int32 translatorVersion = 273; // 256 = v1.0.0 int32 translatorVersion = 0x111;
// Define the formats we know how to read // Define the formats we know how to read
translation_format inputFormats[] = { translation_format inputFormats[] = {
@@ -400,6 +403,61 @@ convert_from_24_to_32(uchar *in, uchar *out, int out_bytes)
} }
// #pragma mark - SView
SView::SView(const char *name, float x, float y)
: BView(BRect(x, y, x, y), name, B_FOLLOW_NONE, B_WILL_DRAW)
{
fPreferredWidth = 0;
fPreferredHeight = 0;
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
SetLowColor(ViewColor());
SetFont(be_plain_font);
}
void
SView::GetPreferredSize(float* _width, float* _height)
{
if (_width)
*_width = fPreferredWidth;
if (_height)
*_height = fPreferredHeight;
}
void
SView::ResizeToPreferred()
{
ResizeTo(fPreferredWidth, fPreferredHeight);
}
void
SView::ResizePreferredBy(float width, float height)
{
fPreferredWidth += width;
fPreferredHeight += height;
}
void
SView::AddChild(BView *child, BView *before = NULL)
{
BView::AddChild(child, before);
child->ResizeToPreferred();
BRect frame = child->Frame();
if (frame.right > fPreferredWidth)
fPreferredWidth = frame.right;
if (frame.bottom > fPreferredHeight)
fPreferredHeight = frame.bottom;
}
// #pragma mark - // #pragma mark -
@@ -409,28 +467,28 @@ SSlider::SSlider(BRect frame, const char *name, const char *label,
: BSlider(frame, name, label, message, minValue, maxValue, : BSlider(frame, name, label, message, minValue, maxValue,
posture, thumbType, resizingMode, flags) posture, thumbType, resizingMode, flags)
{ {
rgb_color bar_color = { 0, 0, 229, 255 }; rgb_color barColor = { 0, 0, 229, 255 };
UseFillColor(true, &bar_color); UseFillColor(true, &barColor);
} }
//---------------------------------------------------
// Update status string - show actual value //! Update status string - show actual value
//---------------------------------------------------
char* char*
SSlider::UpdateText() const SSlider::UpdateText() const
{ {
sprintf( (char*)statusLabel, "%ld", Value()); snprintf(fStatusLabel, sizeof(fStatusLabel), "%ld", Value());
return (char*)statusLabel; return fStatusLabel;
} }
//---------------------------------------------------
// BSlider::ResizeToPreferred + Resize width if it's too small to show label and status //! BSlider::ResizeToPreferred + Resize width if it's too small to show label and status
//---------------------------------------------------
void void
SSlider::ResizeToPreferred() SSlider::ResizeToPreferred()
{ {
int32 width = (int32)ceil(StringWidth( Label()) + StringWidth("9999")); int32 width = (int32)ceil(StringWidth( Label()) + StringWidth("9999"));
if (width < 230) width = 230; if (width < 230)
width = 230;
float w, h; float w, h;
GetPreferredSize(&w, &h); GetPreferredSize(&w, &h);
ResizeTo(width, h); ResizeTo(width, h);
@@ -445,51 +503,50 @@ TranslatorReadView::TranslatorReadView(const char *name, jpeg_settings *settings
: SView(name, x, y), : SView(name, x, y),
fSettings(settings) fSettings(settings)
{ {
alwaysrgb32 = new BCheckBox( BRect(10, GetPreferredHeight(), 10, fAlwaysRGB32 = new BCheckBox( BRect(10, GetPreferredHeight(), 10,
GetPreferredHeight()), "alwaysrgb32", VIEW_LABEL_ALWAYSRGB32, GetPreferredHeight()), "alwaysrgb32", VIEW_LABEL_ALWAYSRGB32,
new BMessage(VIEW_MSG_SET_ALWAYSRGB32)); new BMessage(VIEW_MSG_SET_ALWAYSRGB32));
alwaysrgb32->SetFont(be_plain_font); fAlwaysRGB32->SetFont(be_plain_font);
if (fSettings->Always_B_RGB32) if (fSettings->Always_B_RGB32)
alwaysrgb32->SetValue(1); fAlwaysRGB32->SetValue(1);
AddChild(alwaysrgb32); AddChild(fAlwaysRGB32);
photoshopCMYK = new BCheckBox( BRect(10, GetPreferredHeight(), 10, GetPreferredHeight()), "photoshopCMYK", VIEW_LABEL_PHOTOSHOPCMYK, new BMessage(VIEW_MSG_SET_PHOTOSHOPCMYK)); fPhotoshopCMYK = new BCheckBox( BRect(10, GetPreferredHeight(), 10,
photoshopCMYK->SetFont(be_plain_font); GetPreferredHeight()), "photoshopCMYK", VIEW_LABEL_PHOTOSHOPCMYK,
new BMessage(VIEW_MSG_SET_PHOTOSHOPCMYK));
fPhotoshopCMYK->SetFont(be_plain_font);
if (fSettings->PhotoshopCMYK) if (fSettings->PhotoshopCMYK)
photoshopCMYK->SetValue(1); fPhotoshopCMYK->SetValue(1);
AddChild(photoshopCMYK); AddChild(fPhotoshopCMYK);
showerrorbox = new BCheckBox( BRect(10, GetPreferredHeight(), 10, GetPreferredHeight()), "progress", VIEW_LABEL_SHOWREADERRORBOX, new BMessage(VIEW_MSG_SET_SHOWREADERRORBOX)); fShowErrorBox = new BCheckBox( BRect(10, GetPreferredHeight(), 10,
showerrorbox->SetFont(be_plain_font); GetPreferredHeight()), "error", VIEW_LABEL_SHOWREADERRORBOX,
new BMessage(VIEW_MSG_SET_SHOWREADERRORBOX));
fShowErrorBox->SetFont(be_plain_font);
if (fSettings->ShowReadWarningBox) if (fSettings->ShowReadWarningBox)
showerrorbox->SetValue(1); fShowErrorBox->SetValue(1);
AddChild(showerrorbox); AddChild(fShowErrorBox);
ResizeToPreferred(); ResizeToPreferred();
} }
//---------------------------------------------------
// Attached to window - set children target
//---------------------------------------------------
void void
TranslatorReadView::AttachedToWindow() TranslatorReadView::AttachedToWindow()
{ {
alwaysrgb32->SetTarget(this); fAlwaysRGB32->SetTarget(this);
photoshopCMYK->SetTarget(this); fPhotoshopCMYK->SetTarget(this);
showerrorbox->SetTarget(this); fShowErrorBox->SetTarget(this);
} }
//---------------------------------------------------
// MessageReceived - receive GUI changes, save settings
//---------------------------------------------------
void void
TranslatorReadView::MessageReceived(BMessage* message) TranslatorReadView::MessageReceived(BMessage* message)
{ {
switch (message->what) switch (message->what) {
{
case VIEW_MSG_SET_ALWAYSRGB32: case VIEW_MSG_SET_ALWAYSRGB32:
{ {
int32 value; int32 value;
@@ -524,92 +581,92 @@ TranslatorReadView::MessageReceived(BMessage *message)
} }
//---------------------------------------------------------------------------- // #pragma mark - TranslatorWriteView
//
// Functions :: TranslatorWriteView
//
//----------------------------------------------------------------------------
//---------------------------------------------------
// Constructor TranslatorWriteView::TranslatorWriteView(const char *name, jpeg_settings *settings,
//--------------------------------------------------- float x, float y)
TranslatorWriteView::TranslatorWriteView(const char *name, jpeg_settings *settings, float x, float y)
: SView(name, x, y), : SView(name, x, y),
fSettings(settings) fSettings(settings)
{ {
quality = new SSlider( BRect(10, GetPreferredHeight(), 10, GetPreferredHeight()), "quality", VIEW_LABEL_QUALITY, new BMessage(VIEW_MSG_SET_QUALITY), 0, 100); fQualitySlider = new SSlider(BRect(10, GetPreferredHeight(), 10,
quality->SetHashMarks(B_HASH_MARKS_BOTTOM); GetPreferredHeight()), "quality", VIEW_LABEL_QUALITY,
quality->SetHashMarkCount(10); new BMessage(VIEW_MSG_SET_QUALITY), 0, 100);
quality->SetLimitLabels("Low", "High"); fQualitySlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
quality->SetFont(be_plain_font); fQualitySlider->SetHashMarkCount(10);
quality->SetValue(fSettings->Quality); fQualitySlider->SetLimitLabels("Low", "High");
fQualitySlider->SetFont(be_plain_font);
fQualitySlider->SetValue(fSettings->Quality);
AddChild(fQualitySlider);
AddChild(quality); fSmoothingSlider = new SSlider(BRect(10, GetPreferredHeight()+10, 10,
GetPreferredHeight()), "smoothing", VIEW_LABEL_SMOOTHING,
new BMessage(VIEW_MSG_SET_SMOOTHING), 0, 100);
fSmoothingSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
fSmoothingSlider->SetHashMarkCount(10);
fSmoothingSlider->SetLimitLabels("None", "High");
fSmoothingSlider->SetFont(be_plain_font);
fSmoothingSlider->SetValue(fSettings->Smoothing);
AddChild(fSmoothingSlider);
smoothing = new SSlider( BRect(10, GetPreferredHeight()+10, 10, GetPreferredHeight()), "smoothing", VIEW_LABEL_SMOOTHING, new BMessage(VIEW_MSG_SET_SMOOTHING), 0, 100); fProgress = new BCheckBox( BRect(10, GetPreferredHeight()+10, 10,
smoothing->SetHashMarks(B_HASH_MARKS_BOTTOM); GetPreferredHeight()), "progress", VIEW_LABEL_PROGRESSIVE,
smoothing->SetHashMarkCount(10); new BMessage(VIEW_MSG_SET_PROGRESSIVE));
smoothing->SetLimitLabels("None", "High"); fProgress->SetFont(be_plain_font);
smoothing->SetFont(be_plain_font);
smoothing->SetValue(fSettings->Smoothing);
AddChild(smoothing);
progress = new BCheckBox( BRect(10, GetPreferredHeight()+10, 10, GetPreferredHeight()), "progress", VIEW_LABEL_PROGRESSIVE, new BMessage(VIEW_MSG_SET_PROGRESSIVE));
progress->SetFont(be_plain_font);
if (fSettings->Progressive) if (fSettings->Progressive)
progress->SetValue(1); fProgress->SetValue(1);
AddChild(progress); AddChild(fProgress);
optimizecolors = new BCheckBox( BRect(10, GetPreferredHeight()+5, 10, GetPreferredHeight()+5), "optimizecolors", VIEW_LABEL_OPTIMIZECOLORS, new BMessage(VIEW_MSG_SET_OPTIMIZECOLORS)); fOptimizeColors = new BCheckBox( BRect(10, GetPreferredHeight()+5, 10,
optimizecolors->SetFont(be_plain_font); GetPreferredHeight()+5), "optimizecolors", VIEW_LABEL_OPTIMIZECOLORS,
new BMessage(VIEW_MSG_SET_OPTIMIZECOLORS));
fOptimizeColors->SetFont(be_plain_font);
if (fSettings->OptimizeColors) if (fSettings->OptimizeColors)
optimizecolors->SetValue(1); fOptimizeColors->SetValue(1);
AddChild(optimizecolors); AddChild(fOptimizeColors);
smallerfile = new BCheckBox( BRect(25, GetPreferredHeight()+5, 25, GetPreferredHeight()+5), "smallerfile", VIEW_LABEL_SMALLERFILE, new BMessage(VIEW_MSG_SET_SMALLERFILE)); fSmallerFile = new BCheckBox( BRect(25, GetPreferredHeight()+5, 25,
smallerfile->SetFont(be_plain_font); GetPreferredHeight()+5), "smallerfile", VIEW_LABEL_SMALLERFILE,
new BMessage(VIEW_MSG_SET_SMALLERFILE));
fSmallerFile->SetFont(be_plain_font);
if (fSettings->SmallerFile) if (fSettings->SmallerFile)
smallerfile->SetValue(1); fSmallerFile->SetValue(1);
if (!fSettings->OptimizeColors) if (!fSettings->OptimizeColors)
smallerfile->SetEnabled(false); fSmallerFile->SetEnabled(false);
AddChild(smallerfile); AddChild(fSmallerFile);
gray1asrgb24 = new BCheckBox( BRect(10, GetPreferredHeight()+5, 25, GetPreferredHeight()+5), "gray1asrgb24", VIEW_LABEL_GRAY1ASRGB24, new BMessage(VIEW_MSG_SET_GRAY1ASRGB24)); fGrayAsRGB24 = new BCheckBox( BRect(10, GetPreferredHeight()+5, 25,
gray1asrgb24->SetFont(be_plain_font); GetPreferredHeight()+5), "gray1asrgb24", VIEW_LABEL_GRAY1ASRGB24,
new BMessage(VIEW_MSG_SET_GRAY1ASRGB24));
fGrayAsRGB24->SetFont(be_plain_font);
if (fSettings->B_GRAY1_as_B_RGB24) if (fSettings->B_GRAY1_as_B_RGB24)
gray1asrgb24->SetValue(1); fGrayAsRGB24->SetValue(1);
AddChild(gray1asrgb24); AddChild(fGrayAsRGB24);
ResizeToPreferred(); ResizeToPreferred();
} }
//---------------------------------------------------
// Attached to window - set children target
//---------------------------------------------------
void void
TranslatorWriteView::AttachedToWindow() TranslatorWriteView::AttachedToWindow()
{ {
quality->SetTarget(this); fQualitySlider->SetTarget(this);
smoothing->SetTarget(this); fSmoothingSlider->SetTarget(this);
progress->SetTarget(this); fProgress->SetTarget(this);
optimizecolors->SetTarget(this); fOptimizeColors->SetTarget(this);
smallerfile->SetTarget(this); fSmallerFile->SetTarget(this);
gray1asrgb24->SetTarget(this); fGrayAsRGB24->SetTarget(this);
} }
//---------------------------------------------------
// MessageReceived - receive GUI changes, save settings
//---------------------------------------------------
void void
TranslatorWriteView::MessageReceived(BMessage *message) TranslatorWriteView::MessageReceived(BMessage *message)
{ {
switch (message->what) switch (message->what) {
{
case VIEW_MSG_SET_QUALITY: case VIEW_MSG_SET_QUALITY:
{ {
int32 value; int32 value;
@@ -644,7 +701,7 @@ TranslatorWriteView::MessageReceived(BMessage *message)
fSettings->OptimizeColors = value; fSettings->OptimizeColors = value;
SaveSettings(fSettings); SaveSettings(fSettings);
} }
smallerfile->SetEnabled(fSettings->OptimizeColors); fSmallerFile->SetEnabled(fSettings->OptimizeColors);
break; break;
} }
case VIEW_MSG_SET_SMALLERFILE: case VIEW_MSG_SET_SMALLERFILE:
@@ -678,7 +735,8 @@ TranslatorWriteView::MessageReceived(BMessage *message)
TranslatorAboutView::TranslatorAboutView(const char *name, float x, float y) TranslatorAboutView::TranslatorAboutView(const char *name, float x, float y)
: SView(name, x, y) : SView(name, x, y)
{ {
BStringView *title = new BStringView( BRect(10, 0, 10, 0), "Title", translatorName); BStringView *title = new BStringView(BRect(10, 0, 10, 0), "Title",
translatorName);
title->SetFont(be_bold_font); title->SetFont(be_bold_font);
AddChild(title); AddChild(title);
@@ -700,30 +758,27 @@ TranslatorAboutView::TranslatorAboutView(const char *name, float x, float y)
AddChild(version); AddChild(version);
// Now for each line in translatorInfo add BStringView // Now for each line in translatorInfo add a BStringView
BStringView *copyright; char* current = translatorInfo;
const char *current = translatorInfo; int32 index = 1;
char *temp = translatorInfo; while (current != NULL && current[0]) {
while (*current != 0) { char text[128];
// Find next line char char* newLine = strchr(current, '\n');
temp = strchr(current, 0x0a); if (newLine == NULL) {
// If found replace it with 0 so current will look like ending here strlcpy(text, current, sizeof(text));
if (temp) current = NULL;
*temp = 0; } else {
// Add BStringView showing what's under current strlcpy(text, current, min_c((int32)sizeof(text), newLine + 1 - current));
copyright = new BStringView(BRect(10, GetPreferredHeight(), current = newLine + 1;
10, GetPreferredHeight()), "Copyright", current); }
copyright->SetFont(be_plain_font);
copyright->SetFontSize( 9);
AddChild(copyright);
// If there was next line, move current there and put next line char back BStringView* string = new BStringView(BRect(10, GetPreferredHeight(),
if (temp) { 10, GetPreferredHeight()), "copyright", text);
current = temp+1; if (index > 3)
*temp = 0x0a; string->SetFontSize(9);
} else AddChild(string);
// If there was no next line char break loop
break; index++;
} }
ResizeToPreferred(); ResizeToPreferred();
@@ -736,22 +791,19 @@ TranslatorAboutView::TranslatorAboutView(const char *name, float x, float y)
TranslatorView::TranslatorView(const char *name) TranslatorView::TranslatorView(const char *name)
: SView(name), : SView(name),
fTabWidth(30), fTabWidth(30),
fTabHeight(7 + (int32)be_plain_font->Size()),
// TODO: this apparently uses BFont::Size() as height in pixels!!!
fActiveChild(0) fActiveChild(0)
{ {
// Set global var to true // Set global var to true
gAreSettingsRunning = true; gAreSettingsRunning = true;
// Without this strings are not correctly aliased
// THX to Jack Burton for info :)
SetLowColor( ViewColor());
// Load settings to global settings struct // Load settings to global settings struct
LoadSettings(&fSettings); LoadSettings(&fSettings);
font_height fontHeight;
GetFontHeight(&fontHeight);
fTabHeight = (int32)ceilf(fontHeight.ascent + fontHeight.descent + fontHeight.leading) + 7;
// Add left and top margins // Add left and top margins
float top = fTabHeight+15; float top = fTabHeight + 20;
float left = 0; float left = 0;
// This will remember longest string width // This will remember longest string width
@@ -760,16 +812,19 @@ TranslatorView::TranslatorView(const char *name)
SView *view = new TranslatorWriteView("Write", &fSettings, left, top); SView *view = new TranslatorWriteView("Write", &fSettings, left, top);
AddChild(view); AddChild(view);
nameWidth = (int32)StringWidth(view->Name()); nameWidth = (int32)StringWidth(view->Name());
fTabs.AddItem(new BTab(view));
view = new TranslatorReadView("Read", &fSettings, left, top); view = new TranslatorReadView("Read", &fSettings, left, top);
AddChild(view); AddChild(view);
if (nameWidth < StringWidth(view->Name())) if (nameWidth < StringWidth(view->Name()))
nameWidth = (int32)StringWidth(view->Name()); nameWidth = (int32)StringWidth(view->Name());
fTabs.AddItem(new BTab(view));
view = new TranslatorAboutView("About", left, top); view = new TranslatorAboutView("About", left, top);
AddChild(view); AddChild(view);
if (nameWidth < StringWidth(view->Name())) if (nameWidth < StringWidth(view->Name()))
nameWidth = (int32)StringWidth(view->Name()); nameWidth = (int32)StringWidth(view->Name());
fTabs.AddItem(new BTab(view));
fTabWidth += nameWidth; fTabWidth += nameWidth;
if (fTabWidth * CountChildren() > GetPreferredWidth()) if (fTabWidth * CountChildren() > GetPreferredWidth())
@@ -788,6 +843,11 @@ TranslatorView::TranslatorView(const char *name)
TranslatorView::~TranslatorView() TranslatorView::~TranslatorView()
{ {
gAreSettingsRunning = false; gAreSettingsRunning = false;
BTab* tab;
while ((tab = (BTab*)fTabs.RemoveItem((int32)0)) != NULL) {
delete tab;
}
} }
@@ -801,6 +861,7 @@ TranslatorView::AttachedToWindow()
while ((child = ChildAt(index++)) != NULL) while ((child = ChildAt(index++)) != NULL)
child->Hide(); child->Hide();
#if 0
// Hack for DataTranslations which doesn't resize visible area to requested by view // 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 // which makes some parts of bigger than usual translationviews out of visible area
// so if it was loaded to DataTranslations resize window if needed // so if it was loaded to DataTranslations resize window if needed
@@ -847,6 +908,14 @@ TranslatorView::AttachedToWindow()
} }
} }
} }
#endif
}
BRect
TranslatorView::_TabFrame(int32 index) const
{
return BRect(index * fTabWidth, 10, (index + 1) * fTabWidth, 10 + fTabHeight);
} }
@@ -858,55 +927,40 @@ TranslatorView::Draw(BRect updateRect)
if (ChildAt(fActiveChild)->IsHidden()) if (ChildAt(fActiveChild)->IsHidden())
ChildAt(fActiveChild)->Show(); ChildAt(fActiveChild)->Show();
// Prepare colors used for drawing "tabs"
rgb_color dark_line_color = tint_color( ViewColor(), B_DARKEN_2_TINT);
rgb_color darkest_line_color = tint_color( ViewColor(), B_DARKEN_3_TINT);
rgb_color light_line_color = tint_color( ViewColor(), B_LIGHTEN_MAX_TINT);
rgb_color text_color = ui_color(B_MENU_ITEM_TEXT_COLOR);
// Clear // Clear
SetHighColor(ViewColor()); SetHighColor(ViewColor());
FillRect(BRect(0, 0, Frame().right, fTabHeight)); BRect frame = _TabFrame(0);
FillRect(BRect(frame.left, frame.top, Bounds().right, frame.bottom - 1));
int32 index = 0; int32 index = 0;
float left = 0; BTab* tab;
BView *child; while ((tab = (BTab*)fTabs.ItemAt(index)) != NULL) {
while ((child = ChildAt(index)) != NULL) { tab_position position;
// TODO: this apparently uses BFont::Size() as height in pixels!!! if (fActiveChild == index)
// Draw outline position = B_TAB_FRONT;
SetHighColor(dark_line_color); else if (index == 0)
StrokeLine(BPoint(left, 10), BPoint(left, fTabHeight)); position = B_TAB_FIRST;
StrokeArc(BPoint(left + 10, 10), 10, 10, 90, 90);
StrokeLine(BPoint(left + 10, 0), BPoint(left + fTabWidth - 10, 0));
StrokeArc(BPoint(left + fTabWidth - 10, 10), 9, 10, 0, 90);
StrokeLine(BPoint(left + fTabWidth - 1, 10),
BPoint(left + fTabWidth - 1, fTabHeight));
// Draw "shadow" on the right side
SetHighColor(darkest_line_color);
StrokeArc( BPoint(left+fTabWidth-10, 10), 10, 10, 0, 50);
StrokeLine( BPoint(left+fTabWidth, 10), BPoint(left + fTabWidth, fTabHeight - 1));
// Draw label
SetHighColor(text_color);
DrawString(child->Name(), BPoint(left + (fTabWidth / 2)
- (StringWidth(child->Name()) / 2), 3 + be_plain_font->Size()));
// Draw "light" on left and top side
SetHighColor(light_line_color);
StrokeArc(BPoint(left + 10, 10), 9, 9, 90, 90);
StrokeLine(BPoint(left + 1, 10), BPoint(left + 1, fTabHeight));
StrokeLine(BPoint(left + 10, 1), BPoint(left + fTabWidth - 8, 1));
// Draw bottom edge
if (fActiveChild != index)
StrokeLine(BPoint(left - 2, fTabHeight), BPoint(left + fTabWidth, fTabHeight));
else else
StrokeLine(BPoint(left - 2, fTabHeight), BPoint(left + 1, fTabHeight)); position = B_TAB_ANY;
left += fTabWidth + 2; tab->DrawTab(this, _TabFrame(index), position, index + 1 != fActiveChild);
index++; index++;
} }
// Draw bottom edge to the rigth side // Draw bottom edge
StrokeLine(BPoint(left - 2, fTabHeight), BPoint(Bounds().Width(), fTabHeight)); SetHighColor(tint_color(ViewColor(), B_LIGHTEN_MAX_TINT));
BRect selectedFrame = _TabFrame(fActiveChild);
float offset = ceilf(frame.Height() / 2.0);
if (selectedFrame.left > frame.left) {
StrokeLine(BPoint(frame.left, frame.bottom),
BPoint(selectedFrame.left, frame.bottom));
}
if (selectedFrame.right + offset < Bounds().right) {
StrokeLine(BPoint(selectedFrame.right + offset, frame.bottom),
BPoint(Bounds().right, frame.bottom));
}
} }
@@ -914,24 +968,29 @@ TranslatorView::Draw(BRect updateRect)
void void
TranslatorView::MouseDown(BPoint where) TranslatorView::MouseDown(BPoint where)
{ {
// If user clicked on tabs part of view BRect frame = _TabFrame(fTabs.CountItems() - 1);
if (where.y <= fTabHeight) { frame.left = 0;
// If there is a tab (not whole width is occupied by tabs) if (!frame.Contains(where))
if (where.x < fTabWidth*CountChildren()) { return;
// Which tab was selected?
int32 index = int32(where.x / fTabWidth); for (int32 index = fTabs.CountItems(); index-- > 0;) {
if (!_TabFrame(index).Contains(where))
continue;
if (fActiveChild != index) { if (fActiveChild != index) {
// Hide current visible child // Hide current visible child
ChildAt(fActiveChild)->Hide(); ChildAt(fActiveChild)->Hide();
// This loop is needed because it looks like in DataTranslations // This loop is needed because it looks like in DataTranslations
// view gets hidden more than one time when user changes translator // view gets hidden more than one time when user changes translator
while (ChildAt(index)->IsHidden()) while (ChildAt(index)->IsHidden()) {
ChildAt(index)->Show(); ChildAt(index)->Show();
}
// Remember which one is currently visible // Remember which one is currently visible
fActiveChild = index; fActiveChild = index;
// Redraw Invalidate(frame);
Draw( Frame()); break;
}
} }
} }
} }
@@ -974,7 +1033,6 @@ status_t
Identify(BPositionIO *inSource, const translation_format *inFormat, Identify(BPositionIO *inSource, const translation_format *inFormat,
BMessage *ioExtension, translator_info *outInfo, uint32 outType) BMessage *ioExtension, translator_info *outInfo, uint32 outType)
{ {
if (outType != 0 && outType != B_TRANSLATOR_BITMAP && outType != JPEG_FORMAT) if (outType != 0 && outType != B_TRANSLATOR_BITMAP && outType != JPEG_FORMAT)
return B_NO_TRANSLATOR; return B_NO_TRANSLATOR;
+61 -79
View File
@@ -28,17 +28,10 @@ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _JPEGTRANSLATOR_H_ #ifndef _JPEGTRANSLATOR_H_
#define _JPEGTRANSLATOR_H_ #define _JPEGTRANSLATOR_H_
//----------------------------------------------------------------------------
//
// Include
//
//----------------------------------------------------------------------------
#include <Alert.h> #include <Alert.h>
#include <Application.h> #include <Application.h>
#include <CheckBox.h> #include <CheckBox.h>
@@ -83,9 +76,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define VIEW_LABEL_SHOWREADERRORBOX "Show warning messages" #define VIEW_LABEL_SHOWREADERRORBOX "Show warning messages"
//--------------------------------------------------- //! Settings storage structure
// Settings storage structure
//---------------------------------------------------
struct jpeg_settings { struct jpeg_settings {
// compression // compression
uchar Smoothing; // default: 0 uchar Smoothing; // default: 0
@@ -100,116 +91,107 @@ struct jpeg_settings {
bool ShowReadWarningBox; // default: true bool ShowReadWarningBox; // default: true
}; };
//---------------------------------------------------
// Slider used in TranslatorView /*!
// With status showing actual value Slider used in TranslatorView
//--------------------------------------------------- With status showing actual value
*/
class SSlider : public BSlider { class SSlider : public BSlider {
public: public:
SSlider(BRect frame, const char *name, const char *label, BMessage *message, int32 minValue, int32 maxValue, orientation posture = B_HORIZONTAL, thumb_style thumbType = B_BLOCK_THUMB, uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS); SSlider(BRect frame, const char *name, const char *label,
BMessage *message, int32 minValue, int32 maxValue,
orientation posture = B_HORIZONTAL,
thumb_style thumbType = B_BLOCK_THUMB,
uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS);
char* UpdateText() const; char* UpdateText() const;
void ResizeToPreferred(); void ResizeToPreferred();
private: private:
char statusLabel[12]; mutable char fStatusLabel[12];
}; };
//--------------------------------------------------- //! Basic view class with resizing to needed size
// Basic view class with resizing to needed size
//---------------------------------------------------
class SView : public BView { class SView : public BView {
public: public:
SView(const char *name, float x = 0, float y = 0) SView(const char* name, float x = 0, float y = 0);
:BView( BRect(x,y,x,y), name, B_FOLLOW_NONE, B_WILL_DRAW)
{ virtual void GetPreferredSize(float* _width, float* _height);
preferredWidth = 0; virtual void ResizeToPreferred();
preferredHeight = 0;
SetViewColor( ui_color(B_PANEL_BACKGROUND_COLOR)); void AddChild(BView* child, BView* before = NULL);
SetFont(be_plain_font);
}; float GetPreferredWidth()
void GetPreferredSize(float *width, float *height) { return fPreferredWidth; }
{ float GetPreferredHeight()
*width = preferredWidth; { return fPreferredHeight; }
*height = preferredHeight; void ResizePreferredBy(float width, float height);
}
inline float GetPreferredWidth() { return preferredWidth; };
inline float GetPreferredHeight() { return preferredHeight; };
inline void ResizePreferredBy(float width, float height) { preferredWidth += width; preferredHeight += height; };
inline void ResizeToPreferred() { ResizeTo(preferredWidth, preferredHeight); };
void AddChild(BView *child, BView *before = NULL)
{
BView::AddChild(child, before);
child->ResizeToPreferred();
BRect frame = child->Frame();
if (frame.right > preferredWidth)
preferredWidth = frame.right;
if (frame.bottom > preferredHeight)
preferredHeight = frame.bottom;
}
private: private:
float preferredWidth; float fPreferredWidth;
float preferredHeight; float fPreferredHeight;
}; };
//---------------------------------------------------
// Configuration view for reading settings //! Configuration view for reading settings
//---------------------------------------------------
class TranslatorReadView : public SView { class TranslatorReadView : public SView {
public: public:
TranslatorReadView(const char *name, jpeg_settings *settings, float x = 0, float y = 0); TranslatorReadView(const char* name, jpeg_settings* settings,
void AttachedToWindow(); float x = 0, float y = 0);
void MessageReceived(BMessage *message);
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage* message);
private: private:
jpeg_settings* fSettings; jpeg_settings* fSettings;
BCheckBox *alwaysrgb32; BCheckBox* fAlwaysRGB32;
BCheckBox *photoshopCMYK; BCheckBox* fPhotoshopCMYK;
BCheckBox *showerrorbox; BCheckBox* fShowErrorBox;
}; };
//---------------------------------------------------
// Configuration view for writing settings // !Configuration view for writing settings
//---------------------------------------------------
class TranslatorWriteView : public SView { class TranslatorWriteView : public SView {
public: public:
TranslatorWriteView(const char *name, jpeg_settings *settings, float x = 0, float y = 0); TranslatorWriteView(const char* name, jpeg_settings* settings,
void AttachedToWindow(); float x = 0, float y = 0);
void MessageReceived(BMessage *message);
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage* message);
private: private:
jpeg_settings* fSettings; jpeg_settings* fSettings;
SSlider *quality; SSlider* fQualitySlider;
SSlider *smoothing; SSlider* fSmoothingSlider;
BCheckBox *progress; BCheckBox* fProgress;
BCheckBox *optimizecolors; BCheckBox* fOptimizeColors;
BCheckBox *smallerfile; BCheckBox* fSmallerFile;
BCheckBox *gray1asrgb24; BCheckBox* fGrayAsRGB24;
}; };
//---------------------------------------------------
// About view
//---------------------------------------------------
class TranslatorAboutView : public SView { class TranslatorAboutView : public SView {
public: public:
TranslatorAboutView(const char* name, float x = 0, float y = 0); TranslatorAboutView(const char* name, float x = 0, float y = 0);
}; };
//---------------------------------------------------
// Configuration view //! Configuration view
//---------------------------------------------------
class TranslatorView : public SView { class TranslatorView : public SView {
public: public:
TranslatorView(const char *name); TranslatorView(const char *name);
~TranslatorView(); virtual ~TranslatorView();
void AttachedToWindow(); virtual void AttachedToWindow();
void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
void MouseDown(BPoint where); virtual void MouseDown(BPoint where);
private: private:
BRect _TabFrame(int32 index) const;
jpeg_settings fSettings; jpeg_settings fSettings;
BList fTabs;
int32 fTabWidth; int32 fTabWidth;
int32 fTabHeight; int32 fTabHeight;
int32 fActiveChild; int32 fActiveChild;