[haiku-commits] haiku: hrev47180 - src/apps/showimage

  • From: pulkomandy@xxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 28 Apr 2014 22:04:37 +0200 (CEST)

hrev47180 adds 3 changesets to branch 'master'
old head: 273109e0048442ba5f6361d6e683e5b4a69a472b
new head: 554e2073842e023e35e1523fba025f30574fe137
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=554e207+%5E273109e

----------------------------------------------------------------------------

711ffc4: ShowImage: use BButton icon support.
  
  * BIconButton is not needed anymore, now that BButton supports icons.
  * Slight look changes. These buttons are a bit bigger, with extra
  whitespace. I compensated this by reducing the insets and spacing, which
  looks the same when no button is hovered, but a bit different when one
  is, as the button frame is bigger. Maybe we need to tweak BButton to
  have smaller margins like BIconButton did.

9494b43: Revert attempt to fix stretch-to-window.
  
  Turns out the option shouldn't do what I need. Let's add another option.

554e207: ShowImage: add feature to force original size.
  
  * This is enabled by shift+click on the Original Size toolbar button.
  * The button stays pressed as long as the feature is enabled. Clicking
  it again disables it.
  * When this is enabled, all images will be shown at original size,
  instead of being scaled up or down to fit the window.
  * This is not persistent, and only affects the current session/window.

                             [ Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

5 files changed, 80 insertions(+), 33 deletions(-)
src/apps/showimage/ShowImageView.cpp   |  3 +-
src/apps/showimage/ShowImageView.h     |  3 ++
src/apps/showimage/ShowImageWindow.cpp | 28 ++++++++-----
src/apps/showimage/ToolBarView.cpp     | 65 +++++++++++++++++++++++-------
src/apps/showimage/ToolBarView.h       | 14 +++----

############################################################################

Commit:      711ffc458092f61b54aae40c927b893fed8f4bc0
URL:         http://cgit.haiku-os.org/haiku/commit/?id=711ffc4
Author:      Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Date:        Mon Apr 28 16:13:20 2014 UTC

ShowImage: use BButton icon support.

* BIconButton is not needed anymore, now that BButton supports icons.
* Slight look changes. These buttons are a bit bigger, with extra
whitespace. I compensated this by reducing the insets and spacing, which
looks the same when no button is hovered, but a bit different when one
is, as the button frame is bigger. Maybe we need to tweak BButton to
have smaller margins like BIconButton did.

----------------------------------------------------------------------------

diff --git a/src/apps/showimage/ToolBarView.cpp 
b/src/apps/showimage/ToolBarView.cpp
index a1ec2e2..3c15408 100644
--- a/src/apps/showimage/ToolBarView.cpp
+++ b/src/apps/showimage/ToolBarView.cpp
@@ -4,8 +4,8 @@
  */
 #include "ToolBarView.h"
 
+#include <Button.h>
 #include <ControlLook.h>
-#include <IconButton.h>
 #include <Message.h>
 #include <SeparatorView.h>
 #include <SpaceLayoutItem.h>
@@ -16,8 +16,8 @@ ToolBarView::ToolBarView(BRect frame)
        BGroupView(B_HORIZONTAL)
 {
        float inset = ceilf(be_control_look->DefaultItemSpacing() / 2);
-       GroupLayout()->SetInsets(inset, 2, inset, 3);
-       GroupLayout()->SetSpacing(inset);
+       GroupLayout()->SetInsets(inset, 0, inset, 0);
+       GroupLayout()->SetSpacing(1);
 
        SetFlags(Flags() | B_FRAME_EVENTS | B_PULSE_NEEDED);
 
@@ -37,7 +37,7 @@ ToolBarView::Hide()
 {
        BView::Hide();
        // TODO: This could be fixed in BView instead. Looking from the 
-       // BIconButtons, they are not hidden though, only their parent is...
+       // BButtons, they are not hidden though, only their parent is...
        _HideToolTips();
 }
 
@@ -54,11 +54,13 @@ void
 ToolBarView::AddAction(BMessage* message, BHandler* target,
        const BBitmap* icon, const char* toolTipText)
 {
-       BIconButton* button = new BIconButton(NULL, NULL, message, target);
+       BButton* button = new BButton(NULL, NULL, message);
        button->SetIcon(icon);
+       button->SetFlat(true);
        if (toolTipText != NULL)
                button->SetToolTip(toolTipText);
        _AddView(button);
+       button->SetTarget(target);
 }
 
 
@@ -79,7 +81,7 @@ ToolBarView::AddGlue()
 void
 ToolBarView::SetActionEnabled(uint32 command, bool enabled)
 {
-       if (BIconButton* button = _FindIconButton(command))
+       if (BButton* button = _FindButton(command))
                button->SetEnabled(enabled);
 }
 
@@ -87,15 +89,15 @@ ToolBarView::SetActionEnabled(uint32 command, bool enabled)
 void
 ToolBarView::SetActionPressed(uint32 command, bool pressed)
 {
-       if (BIconButton* button = _FindIconButton(command))
-               button->SetPressed(pressed);
+       if (BButton* button = _FindButton(command))
+               button->SetValue(pressed);
 }
 
 
 void
 ToolBarView::SetActionVisible(uint32 command, bool visible)
 {
-       BIconButton* button = _FindIconButton(command);
+       BButton* button = _FindButton(command);
        if (button == NULL)
                return;
        for (int32 i = 0; BLayoutItem* item = GroupLayout()->ItemAt(i); i++) {
@@ -133,11 +135,11 @@ ToolBarView::_AddView(BView* view)
 }
 
 
-BIconButton*
-ToolBarView::_FindIconButton(uint32 command) const
+BButton*
+ToolBarView::_FindButton(uint32 command) const
 {
        for (int32 i = 0; BView* view = ChildAt(i); i++) {
-               BIconButton* button = dynamic_cast<BIconButton*>(view);
+               BButton* button = dynamic_cast<BButton*>(view);
                if (button == NULL)
                        continue;
                BMessage* message = button->Message();
diff --git a/src/apps/showimage/ToolBarView.h b/src/apps/showimage/ToolBarView.h
index b89d295..63c6f0b 100644
--- a/src/apps/showimage/ToolBarView.h
+++ b/src/apps/showimage/ToolBarView.h
@@ -8,11 +8,7 @@
 #include <GroupView.h>
 
 
-namespace BPrivate {
-class BIconButton;
-}
-
-using BPrivate::BIconButton;
+class BButton;
 
 
 class ToolBarView : public BGroupView {
@@ -40,7 +36,7 @@ private:
        virtual void                            FrameResized(float width, float 
height);
 
                        void                            _AddView(BView* view);
-                       BIconButton*            _FindIconButton(uint32 command) 
const;
+                       BButton*                        _FindButton(uint32 
command) const;
                        void                            _HideToolTips() const;
 };
 

############################################################################

Commit:      9494b43adcaf0d0da58f85d6bc0425de4718a07a
URL:         http://cgit.haiku-os.org/haiku/commit/?id=9494b43
Author:      Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Date:        Mon Apr 28 19:25:52 2014 UTC

Revert attempt to fix stretch-to-window.

Turns out the option shouldn't do what I need. Let's add another option.

----------------------------------------------------------------------------

diff --git a/src/apps/showimage/ShowImageView.cpp 
b/src/apps/showimage/ShowImageView.cpp
index f09bc8d..1a0faa4 100644
--- a/src/apps/showimage/ShowImageView.cpp
+++ b/src/apps/showimage/ShowImageView.cpp
@@ -1630,7 +1630,7 @@ ShowImageView::FitToBounds()
                return;
 
        float fitToBoundsZoom = _FitToBoundsZoom();
-       if (!fStretchToBounds || fitToBoundsZoom > 1.0f)
+       if (!fStretchToBounds && fitToBoundsZoom > 1.0f)
                SetZoom(1.0f);
        else
                SetZoom(fitToBoundsZoom);

############################################################################

Revision:    hrev47180
Commit:      554e2073842e023e35e1523fba025f30574fe137
URL:         http://cgit.haiku-os.org/haiku/commit/?id=554e207
Author:      Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Date:        Mon Apr 28 20:00:45 2014 UTC

ShowImage: add feature to force original size.

* This is enabled by shift+click on the Original Size toolbar button.
* The button stays pressed as long as the feature is enabled. Clicking
it again disables it.
* When this is enabled, all images will be shown at original size,
instead of being scaled up or down to fit the window.
* This is not persistent, and only affects the current session/window.

----------------------------------------------------------------------------

diff --git a/src/apps/showimage/ShowImageView.cpp 
b/src/apps/showimage/ShowImageView.cpp
index 1a0faa4..efc58ef 100644
--- a/src/apps/showimage/ShowImageView.cpp
+++ b/src/apps/showimage/ShowImageView.cpp
@@ -186,6 +186,7 @@ ShowImageView::ShowImageView(BRect rect, const char* name, 
uint32 resizingMode,
        fBitmapLocationInView(0.0, 0.0),
 
        fStretchToBounds(false),
+       fForceOriginalSize(false),
        fHideCursor(false),
        fScrollingBitmap(false),
        fCreatingSelection(false),
@@ -1630,7 +1631,7 @@ ShowImageView::FitToBounds()
                return;
 
        float fitToBoundsZoom = _FitToBoundsZoom();
-       if (!fStretchToBounds && fitToBoundsZoom > 1.0f)
+       if (!fStretchToBounds && fitToBoundsZoom > 1.0f || fForceOriginalSize)
                SetZoom(1.0f);
        else
                SetZoom(fitToBoundsZoom);
diff --git a/src/apps/showimage/ShowImageView.h 
b/src/apps/showimage/ShowImageView.h
index 33f3127..a0d207e 100644
--- a/src/apps/showimage/ShowImageView.h
+++ b/src/apps/showimage/ShowImageView.h
@@ -87,6 +87,8 @@ public:
                        void                            
CopySelectionToClipboard();
 
                        void                            FitToBounds();
+                       void                            ForceOriginalSize(bool 
force)
+                                                                       { 
fForceOriginalSize = force; }
                        void                            SetZoom(float zoom,
                                                                        BPoint 
where = BPoint(-1, -1));
                        float                           Zoom() const
@@ -194,6 +196,7 @@ private:
                        BPoint                          fBitmapLocationInView;
 
                        bool                            fStretchToBounds;
+                       bool                            fForceOriginalSize;
                        bool                            fHideCursor;
                        bool                            fScrollingBitmap;
                        bool                            fCreatingSelection;
diff --git a/src/apps/showimage/ShowImageWindow.cpp 
b/src/apps/showimage/ShowImageWindow.cpp
index ca7b5a3..46efa71 100644
--- a/src/apps/showimage/ShowImageWindow.cpp
+++ b/src/apps/showimage/ShowImageWindow.cpp
@@ -25,6 +25,7 @@
 #include <Application.h>
 #include <Bitmap.h>
 #include <BitmapStream.h>
+#include <Button.h>
 #include <Catalog.h>
 #include <Clipboard.h>
 #include <Entry.h>
@@ -176,29 +177,31 @@ ShowImageWindow::ShowImageWindow(BRect frame, const 
entry_ref& ref,
 //     fToolBarView->AddAction(MSG_FILE_OPEN, be_app,
 //             tool_bar_icon(kIconDocumentOpen), 
B_TRANSLATE("Open"B_UTF8_ELLIPSIS));
        fToolBarView->AddAction(MSG_FILE_PREV, this,
-               tool_bar_icon(kIconGoPrevious), B_TRANSLATE("Previous file"));
+               tool_bar_icon(kIconGoPrevious), B_TRANSLATE("Previous file"), 
false);
        fToolBarView->AddAction(MSG_FILE_NEXT, this, tool_bar_icon(kIconGoNext),
-               B_TRANSLATE("Next file"));
+               B_TRANSLATE("Next file"), false);
        BMessage* fullScreenSlideShow = new BMessage(MSG_SLIDE_SHOW);
        fullScreenSlideShow->AddBool("full screen", true);
        fToolBarView->AddAction(fullScreenSlideShow, this,
-               tool_bar_icon(kIconMediaMovieLibrary), B_TRANSLATE("Slide 
show"));
+               tool_bar_icon(kIconMediaMovieLibrary), B_TRANSLATE("Slide 
show"),
+               false);
        fToolBarView->AddSeparator();
        fToolBarView->AddAction(MSG_SELECTION_MODE, this,
                tool_bar_icon(kIconDrawRectangularSelection),
-               B_TRANSLATE("Selection mode"));
+               B_TRANSLATE("Selection mode"), false);
        fToolBarView->AddSeparator();
        fToolBarView->AddAction(kMsgOriginalSize, this,
-               tool_bar_icon(kIconZoomOriginal), B_TRANSLATE("Original size"));
+               tool_bar_icon(kIconZoomOriginal), B_TRANSLATE("Original size"), 
true);
        fToolBarView->AddAction(kMsgFitToWindow, this,
-               tool_bar_icon(kIconZoomFitBest), B_TRANSLATE("Fit to window"));
+               tool_bar_icon(kIconZoomFitBest), B_TRANSLATE("Fit to window"), 
false);
        fToolBarView->AddAction(MSG_ZOOM_IN, this, tool_bar_icon(kIconZoomIn),
-               B_TRANSLATE("Zoom in"));
+               B_TRANSLATE("Zoom in"), false);
        fToolBarView->AddAction(MSG_ZOOM_OUT, this, tool_bar_icon(kIconZoomOut),
-               B_TRANSLATE("Zoom out"));
+               B_TRANSLATE("Zoom out"), false);
        fToolBarView->AddGlue();
        fToolBarView->AddAction(MSG_FULL_SCREEN, this,
-               tool_bar_icon(kIconViewWindowed), B_TRANSLATE("Leave full 
screen"));
+               tool_bar_icon(kIconViewWindowed), B_TRANSLATE("Leave full 
screen"),
+               false);
        fToolBarView->SetActionVisible(MSG_FULL_SCREEN, false);
 
        fToolBarView->ResizeTo(viewFrame.Width(), 
fToolBarView->MinSize().height);
@@ -966,6 +969,13 @@ ShowImageWindow::MessageReceived(BMessage* message)
                        break;
 
                case kMsgOriginalSize:
+                       if (message->FindInt32("behavior") == 
BButton::B_TOGGLE_BEHAVIOR)
+                       {
+                               bool force = message->FindInt32("be:value");
+                               fImageView->ForceOriginalSize(force);
+                               if (!force)
+                                       break;
+                       }
                        fImageView->SetZoom(1.0);
                        break;
 
diff --git a/src/apps/showimage/ToolBarView.cpp 
b/src/apps/showimage/ToolBarView.cpp
index 3c15408..58c37f2 100644
--- a/src/apps/showimage/ToolBarView.cpp
+++ b/src/apps/showimage/ToolBarView.cpp
@@ -10,6 +10,34 @@
 #include <SeparatorView.h>
 #include <SpaceLayoutItem.h>
 
+class LockableButton: public BButton
+{
+public:
+       LockableButton(const char* name, const char* label, BMessage* message);
+
+       void MouseDown(BPoint point);
+};
+
+
+LockableButton::LockableButton(const char* name, const char* label,
+       BMessage* message)
+       : BButton(name, label, message)
+{
+}
+
+
+void
+LockableButton::MouseDown(BPoint point)
+{
+       if (modifiers() & B_SHIFT_KEY || Value() == B_CONTROL_ON)
+               SetBehavior(B_TOGGLE_BEHAVIOR);
+       else
+               SetBehavior(B_BUTTON_BEHAVIOR);
+
+       Message()->SetInt32("behavior", Behavior());
+       BButton::MouseDown(point);
+}
+
 
 ToolBarView::ToolBarView(BRect frame)
        :
@@ -44,17 +72,22 @@ ToolBarView::Hide()
 
 void
 ToolBarView::AddAction(uint32 command, BHandler* target, const BBitmap* icon,
-       const char* toolTipText)
+       const char* toolTipText, bool lockable)
 {
-       AddAction(new BMessage(command), target, icon, toolTipText);
+       AddAction(new BMessage(command), target, icon, toolTipText, lockable);
 }
 
 
 void
 ToolBarView::AddAction(BMessage* message, BHandler* target,
-       const BBitmap* icon, const char* toolTipText)
+       const BBitmap* icon, const char* toolTipText, bool lockable)
 {
-       BButton* button = new BButton(NULL, NULL, message);
+
+       BButton* button;
+       if (lockable)
+               button = new LockableButton(NULL, NULL, message);
+       else
+               button = new BButton(NULL, NULL, message);
        button->SetIcon(icon);
        button->SetFlat(true);
        if (toolTipText != NULL)
diff --git a/src/apps/showimage/ToolBarView.h b/src/apps/showimage/ToolBarView.h
index 63c6f0b..6273d33 100644
--- a/src/apps/showimage/ToolBarView.h
+++ b/src/apps/showimage/ToolBarView.h
@@ -20,10 +20,12 @@ public:
 
                        void                            AddAction(uint32 
command, BHandler* target,
                                                                        const 
BBitmap* icon,
-                                                                       const 
char* toolTipText = NULL);
+                                                                       const 
char* toolTipText = NULL,
+                                                                       bool 
lockable = false);
                        void                            AddAction(BMessage* 
message, BHandler* target,
                                                                        const 
BBitmap* icon,
-                                                                       const 
char* toolTipText = NULL);
+                                                                       const 
char* toolTipText = NULL,
+                                                                       bool 
lockable = false);
                        void                            AddSeparator();
                        void                            AddGlue();
 


Other related posts: