diff --git a/src/add-ons/translators/jpeg/JPEGTranslator.cpp b/src/add-ons/translators/jpeg/JPEGTranslator.cpp index e89902e4ba..6eb294426b 100644 --- a/src/add-ons/translators/jpeg/JPEGTranslator.cpp +++ b/src/add-ons/translators/jpeg/JPEGTranslator.cpp @@ -469,55 +469,19 @@ translate_8(uint8* in, uint8* out, int32 inRowBytes, int32 xStep) // #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) +SView::SView(BRect frame, const char *name) + : BView(frame, name, B_FOLLOW_ALL, 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) +SView::AttachedToWindow() { - 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) -{ - BView::AddChild(child, before); - child->ResizeToPreferred(); - BRect frame = child->Frame(); - - if (frame.right > fPreferredWidth) - fPreferredWidth = frame.right; - if (frame.bottom > fPreferredHeight) - fPreferredHeight = frame.bottom; + BView::AttachedToWindow(); + ResizeTo(Parent()->Bounds().Width(), Parent()->Bounds().Height()); } @@ -536,7 +500,7 @@ SSlider::SSlider(BRect frame, const char *name, const char *label, //! Update status string - show actual value -char* +const char* SSlider::UpdateText() const { snprintf(fStatusLabel, sizeof(fStatusLabel), "%ld", Value()); @@ -561,31 +525,33 @@ SSlider::ResizeToPreferred() // #pragma mark - -TranslatorReadView::TranslatorReadView(const char *name, jpeg_settings *settings, - float x, float y) - : SView(name, x, y), +TranslatorReadView::TranslatorReadView(BRect frame, const char *name, + jpeg_settings *settings) + : SView(frame, name), fSettings(settings) { - fAlwaysRGB32 = new BCheckBox(BRect(10, GetPreferredHeight(), 10, - GetPreferredHeight()), "alwaysrgb32", VIEW_LABEL_ALWAYSRGB32, + BRect rect(5, 5, 30, 30); + fAlwaysRGB32 = new BCheckBox(rect, "alwaysrgb32", VIEW_LABEL_ALWAYSRGB32, new BMessage(VIEW_MSG_SET_ALWAYSRGB32)); fAlwaysRGB32->SetFont(be_plain_font); if (fSettings->Always_B_RGB32) fAlwaysRGB32->SetValue(1); AddChild(fAlwaysRGB32); - - fPhotoshopCMYK = new BCheckBox(BRect(10, GetPreferredHeight(), 10, - GetPreferredHeight()), "photoshopCMYK", VIEW_LABEL_PHOTOSHOPCMYK, + fAlwaysRGB32->ResizeToPreferred(); + rect.OffsetBy(0, fAlwaysRGB32->Bounds().Height() + 5); + + fPhotoshopCMYK = new BCheckBox(rect, "photoshopCMYK", VIEW_LABEL_PHOTOSHOPCMYK, new BMessage(VIEW_MSG_SET_PHOTOSHOPCMYK)); fPhotoshopCMYK->SetFont(be_plain_font); if (fSettings->PhotoshopCMYK) fPhotoshopCMYK->SetValue(1); AddChild(fPhotoshopCMYK); - - fShowErrorBox = new BCheckBox(BRect(10, GetPreferredHeight(), 10, - GetPreferredHeight()), "error", VIEW_LABEL_SHOWREADERRORBOX, + fPhotoshopCMYK->ResizeToPreferred(); + rect.OffsetBy(0, fPhotoshopCMYK->Bounds().Height() + 5); + + fShowErrorBox = new BCheckBox(rect, "error", VIEW_LABEL_SHOWREADERRORBOX, new BMessage(VIEW_MSG_SET_SHOWREADERRORBOX)); fShowErrorBox->SetFont(be_plain_font); if (fSettings->ShowReadWarningBox) @@ -593,13 +559,15 @@ TranslatorReadView::TranslatorReadView(const char *name, jpeg_settings *settings AddChild(fShowErrorBox); - ResizeToPreferred(); + fShowErrorBox->ResizeToPreferred(); } void TranslatorReadView::AttachedToWindow() { + SView::AttachedToWindow(); + fAlwaysRGB32->SetTarget(this); fPhotoshopCMYK->SetTarget(this); fShowErrorBox->SetTarget(this); @@ -647,13 +615,13 @@ TranslatorReadView::MessageReceived(BMessage* message) // #pragma mark - TranslatorWriteView -TranslatorWriteView::TranslatorWriteView(const char *name, jpeg_settings *settings, - float x, float y) - : SView(name, x, y), +TranslatorWriteView::TranslatorWriteView(BRect frame, const char *name, + jpeg_settings *settings) + : SView(frame, name), fSettings(settings) { - fQualitySlider = new SSlider(BRect(10, GetPreferredHeight(), 10, - GetPreferredHeight()), "quality", VIEW_LABEL_QUALITY, + BRect rect(10, 10, 20, 30); + fQualitySlider = new SSlider(rect, "quality", VIEW_LABEL_QUALITY, new BMessage(VIEW_MSG_SET_QUALITY), 0, 100); fQualitySlider->SetHashMarks(B_HASH_MARKS_BOTTOM); fQualitySlider->SetHashMarkCount(10); @@ -661,9 +629,11 @@ TranslatorWriteView::TranslatorWriteView(const char *name, jpeg_settings *settin fQualitySlider->SetFont(be_plain_font); fQualitySlider->SetValue(fSettings->Quality); AddChild(fQualitySlider); + fQualitySlider->ResizeToPreferred(); - fSmoothingSlider = new SSlider(BRect(10, GetPreferredHeight()+10, 10, - GetPreferredHeight()), "smoothing", VIEW_LABEL_SMOOTHING, + rect.OffsetBy(0, fQualitySlider->Bounds().Height() + 5); + + fSmoothingSlider = new SSlider(rect, "smoothing", VIEW_LABEL_SMOOTHING, new BMessage(VIEW_MSG_SET_SMOOTHING), 0, 100); fSmoothingSlider->SetHashMarks(B_HASH_MARKS_BOTTOM); fSmoothingSlider->SetHashMarkCount(10); @@ -671,27 +641,32 @@ TranslatorWriteView::TranslatorWriteView(const char *name, jpeg_settings *settin fSmoothingSlider->SetFont(be_plain_font); fSmoothingSlider->SetValue(fSettings->Smoothing); AddChild(fSmoothingSlider); + fSmoothingSlider->ResizeToPreferred(); - fProgress = new BCheckBox(BRect(10, GetPreferredHeight()+10, 10, - GetPreferredHeight()), "progress", VIEW_LABEL_PROGRESSIVE, + rect.OffsetBy(0, fSmoothingSlider->Bounds().Height() + 5); + + fProgress = new BCheckBox(rect, "progress", VIEW_LABEL_PROGRESSIVE, new BMessage(VIEW_MSG_SET_PROGRESSIVE)); fProgress->SetFont(be_plain_font); if (fSettings->Progressive) fProgress->SetValue(1); AddChild(fProgress); - - fOptimizeColors = new BCheckBox(BRect(10, GetPreferredHeight()+5, 10, - GetPreferredHeight() + 5), "optimizecolors", VIEW_LABEL_OPTIMIZECOLORS, + fProgress->ResizeToPreferred(); + + rect.OffsetBy(0, fProgress->Bounds().Height() + 5); + + fOptimizeColors = new BCheckBox(rect, "optimizecolors", VIEW_LABEL_OPTIMIZECOLORS, new BMessage(VIEW_MSG_SET_OPTIMIZECOLORS)); fOptimizeColors->SetFont(be_plain_font); if (fSettings->OptimizeColors) fOptimizeColors->SetValue(1); AddChild(fOptimizeColors); - - fSmallerFile = new BCheckBox(BRect(25, GetPreferredHeight()+5, 25, - GetPreferredHeight() + 5), "smallerfile", VIEW_LABEL_SMALLERFILE, + fOptimizeColors->ResizeToPreferred(); + rect.OffsetBy(0, fOptimizeColors->Bounds().Height() + 5); + + fSmallerFile = new BCheckBox(rect, "smallerfile", VIEW_LABEL_SMALLERFILE, new BMessage(VIEW_MSG_SET_SMALLERFILE)); fSmallerFile->SetFont(be_plain_font); if (fSettings->SmallerFile) @@ -700,9 +675,10 @@ TranslatorWriteView::TranslatorWriteView(const char *name, jpeg_settings *settin fSmallerFile->SetEnabled(false); AddChild(fSmallerFile); - - fGrayAsRGB24 = new BCheckBox(BRect(10, GetPreferredHeight()+5, 25, - GetPreferredHeight()+5), "gray1asrgb24", VIEW_LABEL_GRAY1ASRGB24, + fSmallerFile->ResizeToPreferred(); + rect.OffsetBy(0, fSmallerFile->Bounds().Height() + 5); + + fGrayAsRGB24 = new BCheckBox(rect, "gray1asrgb24", VIEW_LABEL_GRAY1ASRGB24, new BMessage(VIEW_MSG_SET_GRAY1ASRGB24)); fGrayAsRGB24->SetFont(be_plain_font); if (fSettings->B_GRAY1_as_B_RGB24) @@ -710,13 +686,15 @@ TranslatorWriteView::TranslatorWriteView(const char *name, jpeg_settings *settin AddChild(fGrayAsRGB24); - ResizeToPreferred(); + fGrayAsRGB24->ResizeToPreferred(); } void TranslatorWriteView::AttachedToWindow() { + SView::AttachedToWindow(); + fQualitySlider->SetTarget(this); fSmoothingSlider->SetTarget(this); fProgress->SetTarget(this); @@ -795,14 +773,15 @@ TranslatorWriteView::MessageReceived(BMessage *message) // #pragma mark - -TranslatorAboutView::TranslatorAboutView(const char *name, float x, float y) - : SView(name, x, y) +TranslatorAboutView::TranslatorAboutView(BRect frame, const char *name) + : SView(frame, name) { BStringView *title = new BStringView(BRect(10, 0, 10, 0), "Title", translatorName); title->SetFont(be_bold_font); AddChild(title); + title->ResizeToPreferred(); BRect rect = title->Bounds(); float space = title->StringWidth(" "); @@ -811,7 +790,7 @@ TranslatorAboutView::TranslatorAboutView(const char *name, float x, float y) sprintf(versionString, "v%d.%d.%d", (int)(translatorVersion >> 8), (int)((translatorVersion >> 4) & 0xf), (int)(translatorVersion & 0xf)); - BStringView *version = new BStringView(BRect(rect.right+space, rect.top, + BStringView *version = new BStringView(BRect(rect.right + space, rect.top, rect.right+space, rect.top), "Version", versionString); version->SetFont(be_plain_font); version->SetFontSize(9); @@ -824,6 +803,7 @@ TranslatorAboutView::TranslatorAboutView(const char *name, float x, float y) // Now for each line in translatorInfo add a BStringView char* current = translatorInfo; int32 index = 1; + BRect stringFrame = title->Frame(); while (current != NULL && current[0]) { char text[128]; char* newLine = strchr(current, '\n'); @@ -834,12 +814,12 @@ TranslatorAboutView::TranslatorAboutView(const char *name, float x, float y) strlcpy(text, current, min_c((int32)sizeof(text), newLine + 1 - current)); current = newLine + 1; } - - BStringView* string = new BStringView(BRect(10, GetPreferredHeight(), - 10, GetPreferredHeight()), "copyright", text); + stringFrame.OffsetBy(0, stringFrame.Height() + 2); + BStringView* string = new BStringView(stringFrame, "copyright", text); if (index > 3) string->SetFontSize(9); AddChild(string); + string->ResizeToPreferred(); index++; } @@ -851,10 +831,8 @@ TranslatorAboutView::TranslatorAboutView(const char *name, float x, float y) // #pragma mark - -TranslatorView::TranslatorView(const char *name) - : SView(name), - fTabWidth(30), - fActiveChild(0) +TranslatorView::TranslatorView(BRect frame, const char *name) + : BTabView(frame, name) { // Set global var to true gAreSettingsRunning = true; @@ -862,39 +840,13 @@ TranslatorView::TranslatorView(const char *name) // Load settings to global settings struct LoadSettings(&fSettings); - font_height fontHeight; - GetFontHeight(&fontHeight); - fTabHeight = (int32)ceilf(fontHeight.ascent + fontHeight.descent + fontHeight.leading) + 7; - // Add left and top margins - float top = fTabHeight + 20; - float left = 0; - - // This will remember longest string width - int32 nameWidth = 0; - - SView *view = new TranslatorWriteView("Write", &fSettings, left, top); - AddChild(view); - nameWidth = (int32)StringWidth(view->Name()); - fTabs.AddItem(new BTab(view)); - - view = new TranslatorReadView("Read", &fSettings, left, top); - AddChild(view); - if (nameWidth < StringWidth(view->Name())) - nameWidth = (int32)StringWidth(view->Name()); - fTabs.AddItem(new BTab(view)); - - view = new TranslatorAboutView("About", left, top); - AddChild(view); - if (nameWidth < StringWidth(view->Name())) - nameWidth = (int32)StringWidth(view->Name()); - fTabs.AddItem(new BTab(view)); - - fTabWidth += nameWidth; - if (fTabWidth * CountChildren() > GetPreferredWidth()) - ResizePreferredBy((fTabWidth * CountChildren()) - GetPreferredWidth(), 0); - - // Add right and bottom margins - ResizePreferredBy(10, 15); + BRect contentSize = ContainerView()->Bounds(); + SView *view = new TranslatorWriteView(contentSize, "Write", &fSettings); + AddTab(view); + view = new TranslatorReadView(contentSize, "Read", &fSettings); + AddTab(view); + view = new TranslatorAboutView(contentSize, "About"); + AddTab(view); ResizeToPreferred(); @@ -906,11 +858,6 @@ TranslatorView::TranslatorView(const char *name) TranslatorView::~TranslatorView() { gAreSettingsRunning = false; - - BTab* tab; - while ((tab = (BTab*)fTabs.RemoveItem((int32)0)) != NULL) { - delete tab; - } } @@ -918,96 +865,14 @@ TranslatorView::~TranslatorView() void TranslatorView::AttachedToWindow() { - // Hide all children except first one - BView *child; - int32 index = 1; - while ((child = ChildAt(index++)) != NULL) - child->Hide(); - -} - - -BRect -TranslatorView::_TabFrame(int32 index) const -{ - return BRect(index * fTabWidth, 10, (index + 1) * fTabWidth, 10 + fTabHeight); + BTabView::AttachedToWindow(); } void -TranslatorView::Draw(BRect updateRect) +TranslatorView::Select(int32 index) { - // This is needed because DataTranslations app hides children - // after user changes translator - if (ChildAt(fActiveChild)->IsHidden()) - ChildAt(fActiveChild)->Show(); - - // Clear - SetHighColor(ViewColor()); - BRect frame = _TabFrame(0); - FillRect(BRect(frame.left, frame.top, Bounds().right, frame.bottom - 1)); - - int32 index = 0; - BTab* tab; - while ((tab = (BTab*)fTabs.ItemAt(index)) != NULL) { - tab_position position; - if (fActiveChild == index) - position = B_TAB_FRONT; - else if (index == 0) - position = B_TAB_FIRST; - else - position = B_TAB_ANY; - - tab->DrawTab(this, _TabFrame(index), position, index + 1 != fActiveChild); - index++; - } - - // Draw bottom edge - 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)); - } -} - - -//! MouseDown, check if on tab, if so change tab if needed -void -TranslatorView::MouseDown(BPoint where) -{ - BRect frame = _TabFrame(fTabs.CountItems() - 1); - frame.left = 0; - if (!frame.Contains(where)) - return; - - for (int32 index = fTabs.CountItems(); index-- > 0;) { - if (!_TabFrame(index).Contains(where)) - continue; - - if (fActiveChild != index) { - // Hide current visible child - ChildAt(fActiveChild)->Hide(); - - // This loop is needed because it looks like in DataTranslations - // view gets hidden more than one time when user changes translator - while (ChildAt(index)->IsHidden()) { - ChildAt(index)->Show(); - } - - // Remember which one is currently visible - fActiveChild = index; - Invalidate(frame); - break; - } - } + BTabView::Select(index); } @@ -1039,7 +904,7 @@ TranslatorWindow::TranslatorWindow(bool quitOnClose) status_t MakeConfig(BMessage *ioExtension, BView **outView, BRect *outExtent) { - *outView = new TranslatorView("TranslatorView"); + *outView = new TranslatorView(BRect(0, 0, 320, 300), "TranslatorView"); *outExtent = (*outView)->Frame(); return B_OK; } diff --git a/src/add-ons/translators/jpeg/JPEGTranslator.h b/src/add-ons/translators/jpeg/JPEGTranslator.h index 4a23cb8850..beac07e020 100644 --- a/src/add-ons/translators/jpeg/JPEGTranslator.h +++ b/src/add-ons/translators/jpeg/JPEGTranslator.h @@ -39,6 +39,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include #include @@ -104,39 +105,24 @@ class SSlider : public BSlider { 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; + virtual const char* UpdateText() const; void ResizeToPreferred(); private: mutable char fStatusLabel[12]; }; -//! Basic view class with resizing to needed size + class SView : public BView { - public: - SView(const char* name, float x = 0, float y = 0); - - virtual void GetPreferredSize(float* _width, float* _height); - virtual void ResizeToPreferred(); - - void AddChild(BView* child, BView* before = NULL); - - float GetPreferredWidth() - { return fPreferredWidth; } - float GetPreferredHeight() - { return fPreferredHeight; } - void ResizePreferredBy(float width, float height); - - private: - float fPreferredWidth; - float fPreferredHeight; +public: + SView(BRect frame, const char *name); + virtual void AttachedToWindow(); }; //! Configuration view for reading settings class TranslatorReadView : public SView { public: - TranslatorReadView(const char* name, jpeg_settings* settings, - float x = 0, float y = 0); + TranslatorReadView(BRect frame, const char* name, jpeg_settings* settings); virtual void AttachedToWindow(); virtual void MessageReceived(BMessage* message); @@ -148,11 +134,11 @@ class TranslatorReadView : public SView { BCheckBox* fShowErrorBox; }; + //! Configuration view for writing settings class TranslatorWriteView : public SView { public: - TranslatorWriteView(const char* name, jpeg_settings* settings, - float x = 0, float y = 0); + TranslatorWriteView(BRect frame, const char* name, jpeg_settings* settings); virtual void AttachedToWindow(); virtual void MessageReceived(BMessage* message); @@ -169,27 +155,20 @@ class TranslatorWriteView : public SView { class TranslatorAboutView : public SView { public: - TranslatorAboutView(const char* name, float x = 0, float y = 0); + TranslatorAboutView(BRect frame, const char* name); }; //! Configuration view -class TranslatorView : public SView { +class TranslatorView : public BTabView { public: - TranslatorView(const char *name); + TranslatorView(BRect frame, const char *name); virtual ~TranslatorView(); virtual void AttachedToWindow(); - virtual void Draw(BRect updateRect); - virtual void MouseDown(BPoint where); + virtual void Select(int32 index); private: - BRect _TabFrame(int32 index) const; - jpeg_settings fSettings; - BList fTabs; - int32 fTabWidth; - int32 fTabHeight; - int32 fActiveChild; }; //! Window used for configuration