[haiku-commits] r41055 - haiku/trunk/src/apps/showimage

Author: stippi
Date: 2011-03-20 13:53:38 +0100 (Sun, 20 Mar 2011)
New Revision: 41055
Changeset: https://dev.haiku-os.org/changeset/41055

Added:
   haiku/trunk/src/apps/showimage/ToolBarView.cpp
   haiku/trunk/src/apps/showimage/ToolBarView.h
Modified:
   haiku/trunk/src/apps/showimage/Jamfile
   haiku/trunk/src/apps/showimage/ShowImageWindow.cpp
   haiku/trunk/src/apps/showimage/ShowImageWindow.h
Log:
 * Display a tool bar by default (setting can be toggled in the
   View menu)
 * The previous/next, selection mode, zoom actions and full screen
   mode are accessible via tool bar.
 * The tool bar can currently not be shown in full screen mode.
   Eventually, I want it to work like in MediaPlayer when it is
   generally enabled.
 * Fixed capitalization "Selection Mode" into "Selection mode"
   (needs catalogs update for all languages).
 * When leaving selection mode, clear the selection. Especially
   with the new tool bar icon, it looked really weird and irritating
   when the selection persisted.


Modified: haiku/trunk/src/apps/showimage/Jamfile
===================================================================
--- haiku/trunk/src/apps/showimage/Jamfile      2011-03-20 01:36:21 UTC (rev 
41054)
+++ haiku/trunk/src/apps/showimage/Jamfile      2011-03-20 12:53:38 UTC (rev 
41055)
@@ -21,6 +21,7 @@
        ShowImageView.cpp
        ShowImageWindow.cpp
        ToolBarIcons.cpp
+       ToolBarView.cpp
        : libshared.a be tracker translation $(HAIKU_LOCALE_LIBS)
                $(TARGET_LIBSTDC++) $(TARGET_LIBSUPC++)
        : ShowImage.rdef

Modified: haiku/trunk/src/apps/showimage/ShowImageWindow.cpp
===================================================================
--- haiku/trunk/src/apps/showimage/ShowImageWindow.cpp  2011-03-20 01:36:21 UTC 
(rev 41054)
+++ haiku/trunk/src/apps/showimage/ShowImageWindow.cpp  2011-03-20 12:53:38 UTC 
(rev 41055)
@@ -52,6 +52,8 @@
 #include "ShowImageConstants.h"
 #include "ShowImageStatusView.h"
 #include "ShowImageView.h"
+#include "ToolBarIcons.h"
+#include "ToolBarView.h"
 
 
 // BMessage field names used in Save messages
@@ -94,7 +96,8 @@
        kMsgFitToWindow                         = 'mFtW',
        kMsgOriginalSize                        = 'mOSZ',
        kMsgStretchToWindow                     = 'mStW',
-       kMsgNextSlide                           = 'mNxS'
+       kMsgNextSlide                           = 'mNxS',
+       kMsgToggleToolBar                       = 'mTTB'
 };
 
 
@@ -117,6 +120,10 @@
 //     #pragma mark -- ShowImageWindow
 
 
+#undef B_TRANSLATE_CONTEXT
+#define B_TRANSLATE_CONTEXT "Menus"
+
+
 ShowImageWindow::ShowImageWindow(BRect frame, const entry_ref& ref,
        const BMessenger& trackerMessenger)
        :
@@ -127,12 +134,14 @@
        fBrowseMenu(NULL),
        fGoToPageMenu(NULL),
        fSlideShowDelayMenu(NULL),
+       fToolBarView(NULL),
        fImageView(NULL),
        fStatusView(NULL),
        fProgressWindow(new ProgressWindow()),
        fModified(false),
        fFullScreen(false),
        fShowCaption(true),
+       fShowToolBar(true),
        fPrintSettings(NULL),
        fSlideShowRunner(NULL),
        fSlideShowDelay(kDefaultSlideShowDelay)
@@ -146,6 +155,45 @@
 
        BRect viewFrame = Bounds();
        viewFrame.top = fBar->Bounds().Height() + 1;
+       viewFrame.bottom = viewFrame.top + 30;
+
+       fToolBarView = new ToolBarView(viewFrame);
+
+       // Add the tool icons.
+       
+//     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(kIconGoUp),
+               B_TRANSLATE("Previous file"));
+       fToolBarView->AddAction(MSG_FILE_NEXT, this, tool_bar_icon(kIconGoDown),
+               B_TRANSLATE("Next file"));
+       fToolBarView->AddSeparator();
+       fToolBarView->AddAction(MSG_SELECTION_MODE, this,
+               tool_bar_icon(kIconDrawRectangularSelection),
+               B_TRANSLATE("Selection mode"));
+       fToolBarView->AddSeparator();
+       fToolBarView->AddAction(kMsgOriginalSize, this,
+               tool_bar_icon(kIconZoomOriginal), B_TRANSLATE("Original size"));
+       fToolBarView->AddAction(kMsgFitToWindow, this,
+               tool_bar_icon(kIconZoomFitBest), B_TRANSLATE("Fit to window"));
+       fToolBarView->AddAction(MSG_ZOOM_IN, this, tool_bar_icon(kIconZoomIn),
+               B_TRANSLATE("Zoom in"));
+       fToolBarView->AddAction(MSG_ZOOM_OUT, this, tool_bar_icon(kIconZoomOut),
+               B_TRANSLATE("Zoom out"));
+       fToolBarView->AddSeparator();
+       fToolBarView->AddAction(MSG_FULL_SCREEN, this,
+               tool_bar_icon(kIconViewFullScreen), B_TRANSLATE("Full screen"));
+
+       fToolBarView->ResizeTo(viewFrame.Width(), 
fToolBarView->MinSize().height);
+
+       AddChild(fToolBarView);
+
+       if (fShowToolBar)
+               viewFrame.top = fToolBarView->Frame().bottom + 1;
+       else
+               fToolBarView->Hide();
+
+       viewFrame.bottom = Bounds().bottom;
        viewFrame.right -= B_V_SCROLL_BAR_WIDTH;
        viewFrame.bottom -= B_H_SCROLL_BAR_HEIGHT;
 
@@ -154,9 +202,9 @@
                B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_PULSE_NEEDED
                        | B_FRAME_EVENTS);
        // wrap a scroll view around the view
-       BScrollView* scrollView = new BScrollView("image_scroller", fImageView,
+       fScrollView = new BScrollView("image_scroller", fImageView,
                B_FOLLOW_ALL, 0, false, false, B_PLAIN_BORDER);
-       AddChild(scrollView);
+       AddChild(fScrollView);
 
        const int32 kstatusWidth = 190;
        BRect rect;
@@ -181,9 +229,9 @@
        rect.left = viewFrame.right + 1;
        rect.bottom = viewFrame.bottom + 1;
        rect.right += 1;
-       BScrollBar* verticalScrollBar = new BScrollBar(rect, "vscroll", 
fImageView,
+       fVerticalScrollBar = new BScrollBar(rect, "vscroll", fImageView,
                0, 150, B_VERTICAL);
-       AddChild(verticalScrollBar);
+       AddChild(fVerticalScrollBar);
 
        SetSizeLimits(250, 100000, 100, 100000);
 
@@ -232,10 +280,6 @@
 }
 
 
-#undef B_TRANSLATE_CONTEXT
-#define B_TRANSLATE_CONTEXT "Menus"
-
-
 void
 ShowImageWindow::_BuildViewMenu(BMenu* menu, bool popupMenu)
 {
@@ -290,6 +334,13 @@
        _MarkMenuItem(menu, MSG_SCALE_BILINEAR, fImageView->ScaleBilinear());
        _MarkMenuItem(menu, kMsgStretchToWindow, 
fImageView->StretchesToBounds());
 
+       if (!popupMenu) {
+               _AddItemMenu(menu, B_TRANSLATE("Show tool bar"), 
kMsgToggleToolBar, 0,
+                       0, this);
+               _MarkMenuItem(menu, kMsgToggleToolBar,
+                       !fToolBarView->IsHidden(fToolBarView));
+       }
+
        if (popupMenu) {
                menu->AddSeparatorItem();
                _AddItemMenu(menu, B_TRANSLATE("Use as background" 
B_UTF8_ELLIPSIS),
@@ -353,7 +404,7 @@
        menu->AddSeparatorItem();
        _AddItemMenu(menu, B_TRANSLATE("Copy"), B_COPY, 'C', 0, this, false);
        menu->AddSeparatorItem();
-       _AddItemMenu(menu, B_TRANSLATE("Selection Mode"), MSG_SELECTION_MODE, 
0, 0,
+       _AddItemMenu(menu, B_TRANSLATE("Selection mode"), MSG_SELECTION_MODE, 
0, 0,
                this);
        _AddItemMenu(menu, B_TRANSLATE("Clear selection"),
                MSG_CLEAR_SELECT, 0, 0, this, false);
@@ -482,6 +533,7 @@
                marked = !item->IsMarked();
                item->SetMarked(marked);
        }
+       fToolBarView->SetActionPressed(what, marked);
        return marked;
 }
 
@@ -492,6 +544,7 @@
        BMenuItem* item = menu->FindItem(what);
        if (item && item->IsEnabled() != enable)
                item->SetEnabled(enable);
+       fToolBarView->SetActionEnabled(what, enable);
 }
 
 
@@ -501,6 +554,7 @@
        BMenuItem* item = menu->FindItem(what);
        if (item && item->IsMarked() != marked)
                item->SetMarked(marked);
+       fToolBarView->SetActionPressed(what, marked);
 }
 
 
@@ -712,8 +766,13 @@
                        break;
 
                case MSG_SELECTION_MODE:
-                       
fImageView->SetSelectionMode(_ToggleMenuItem(MSG_SELECTION_MODE));
+               {
+                       bool selectionMode = 
_ToggleMenuItem(MSG_SELECTION_MODE);
+                       fImageView->SetSelectionMode(selectionMode);
+                       if (!selectionMode)
+                               fImageView->ClearSelection();
                        break;
+               }
 
                case MSG_CLEAR_SELECT:
                        fImageView->ClearSelection();
@@ -860,7 +919,8 @@
                                _ToggleFullScreen();
                        break;
 
-               case MSG_SHOW_CAPTION: {
+               case MSG_SHOW_CAPTION:
+               {
                        fShowCaption = _ToggleMenuItem(message->what);
                        ShowImageSettings* settings = my_app->Settings();
 
@@ -924,6 +984,20 @@
                        break;
                }
 
+               case kMsgToggleToolBar:
+               {
+                       fShowToolBar = _ToggleMenuItem(message->what);
+                       _SetToolBarVisible(fShowToolBar);
+
+                       ShowImageSettings* settings = my_app->Settings();
+
+                       if (settings->Lock()) {
+                               settings->SetBool("ShowToolBar", fShowToolBar);
+                               settings->Unlock();
+                       }
+                       break;
+               }
+
                default:
                        BWindow::MessageReceived(message);
                        break;
@@ -1140,6 +1214,9 @@
                SetFlags(Flags() & ~(B_NOT_RESIZABLE | B_NOT_MOVABLE));
        }
 
+       fToolBarView->SetActionPressed(MSG_FULL_SCREEN, fFullScreen);
+       _SetToolBarVisible(!fFullScreen && fShowToolBar);
+
        MoveTo(frame.left, frame.top);
        ResizeTo(frame.Width(), frame.Height());
 
@@ -1170,6 +1247,8 @@
                fPrintOptions.SetHeight(
                        settings->GetFloat("PO:Height", 
fPrintOptions.Height()));
 
+               fShowToolBar = settings->GetBool("ShowToolBar", fShowToolBar);
+
                settings->Unlock();
        }
 }
@@ -1356,6 +1435,28 @@
 }
 
 
+void
+ShowImageWindow::_SetToolBarVisible(bool visible)
+{
+       if (visible == !fToolBarView->IsHidden())
+               return;
+
+       float diff = fToolBarView->Bounds().Height() + 1;
+       if (!visible) {
+               diff = -diff;
+               fToolBarView->Hide();
+       }
+
+       fScrollView->ResizeBy(0, -diff);
+       fScrollView->MoveBy(0, diff);
+       fVerticalScrollBar->ResizeBy(0, -diff);
+       fVerticalScrollBar->MoveBy(0, diff);
+
+       if (visible)
+               fToolBarView->Show();
+}
+
+
 bool
 ShowImageWindow::QuitRequested()
 {

Modified: haiku/trunk/src/apps/showimage/ShowImageWindow.h
===================================================================
--- haiku/trunk/src/apps/showimage/ShowImageWindow.h    2011-03-20 01:36:21 UTC 
(rev 41054)
+++ haiku/trunk/src/apps/showimage/ShowImageWindow.h    2011-03-20 12:53:38 UTC 
(rev 41055)
@@ -22,9 +22,12 @@
 class BMenuBar;
 class BMenuItem;
 class BMessageRunner;
+class BScrollBar;
+class BScrollView;
 class ProgressWindow;
 class ShowImageView;
 class ShowImageStatusView;
+class ToolBarView;
 
 
 // public message constants
@@ -98,6 +101,8 @@
 
                        void                            _UpdateRatingMenu();
 
+                       void                            _SetToolBarVisible(bool 
visible);
+
 private:
                        ImageFileNavigator      fNavigator;
                        BFilePanel*                     fSavePanel;
@@ -106,12 +111,16 @@
                        BMenu*                          fGoToPageMenu;
                        BMenu*                          fSlideShowDelayMenu;
                        BMenu*                          fRatingMenu;
+                       ToolBarView*            fToolBarView;
+                       BScrollView*            fScrollView;
+                       BScrollBar*                     fVerticalScrollBar;
                        ShowImageView*          fImageView;
                        ShowImageStatusView* fStatusView;
                        ProgressWindow*         fProgressWindow;
                        bool                            fModified;
                        bool                            fFullScreen;
                        bool                            fShowCaption;
+                       bool                            fShowToolBar;
                        BRect                           fWindowFrame;
                        BMessage*                       fPrintSettings;
                        PrintOptions            fPrintOptions;

Added: haiku/trunk/src/apps/showimage/ToolBarView.cpp
===================================================================
--- haiku/trunk/src/apps/showimage/ToolBarView.cpp                              
(rev 0)
+++ haiku/trunk/src/apps/showimage/ToolBarView.cpp      2011-03-20 12:53:38 UTC 
(rev 41055)
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2011 Stephan Aßmus <superstippi@xxxxxx>
+ * All rights reserved. Distributed under the terms of the MIT license.
+ */
+#include "ToolBarView.h"
+
+#include <ControlLook.h>
+#include <IconButton.h>
+#include <Message.h>
+#include <SeparatorView.h>
+#include <SpaceLayoutItem.h>
+
+
+ToolBarView::ToolBarView(BRect frame)
+       :
+       BGroupView(B_HORIZONTAL)
+{
+       float inset = ceilf(be_control_look->DefaultItemSpacing() / 2);
+       GroupLayout()->SetInsets(inset, inset, inset, inset);
+
+       GroupLayout()->AddItem(BSpaceLayoutItem::CreateGlue());
+
+       MoveTo(frame.LeftTop());
+       ResizeTo(frame.Width(), frame.Height());
+       SetResizingMode(B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
+}
+
+
+ToolBarView::~ToolBarView()
+{
+}
+
+
+void
+ToolBarView::AddAction(uint32 command, BHandler* target, const BBitmap* icon,
+       const char* toolTipText)
+{
+       AddAction(new BMessage(command), target, icon, toolTipText);
+}
+
+
+void
+ToolBarView::AddAction(BMessage* message, BHandler* target, const BBitmap* 
icon,
+       const char* toolTipText)
+{
+       BIconButton* button = new BIconButton(NULL, 0, NULL, message, target);
+       button->SetIcon(icon);
+       if (toolTipText != NULL)
+               button->SetToolTip(toolTipText);
+       _AddView(button);
+}
+
+
+void
+ToolBarView::AddSeparator()
+{
+       _AddView(new BSeparatorView(B_VERTICAL, B_PLAIN_BORDER));
+}
+
+
+void
+ToolBarView::SetActionEnabled(uint32 command, bool enabled)
+{
+       if (BIconButton* button = _FindIconButton(command))
+               button->SetEnabled(enabled);
+}
+
+
+void
+ToolBarView::SetActionPressed(uint32 command, bool pressed)
+{
+       if (BIconButton* button = _FindIconButton(command))
+               button->SetPressed(pressed);
+}
+
+
+void
+ToolBarView::_AddView(BView* view)
+{
+       // Add before the space layout item at the end
+       GroupLayout()->AddView(GroupLayout()->CountItems() - 1, view);
+}
+
+
+BIconButton*
+ToolBarView::_FindIconButton(uint32 command) const
+{
+       for (int32 i = 0; BView* view = ChildAt(i); i++) {
+               BIconButton* button = dynamic_cast<BIconButton*>(view);
+               if (button == NULL)
+                       continue;
+               BMessage* message = button->Message();
+               if (message == NULL)
+                       continue;
+               if (message->what == command) {
+                       return button;
+                       // Assumes there is only one button with this message...
+                       break;
+               }
+       }
+       return NULL;
+}
+
+

Added: haiku/trunk/src/apps/showimage/ToolBarView.h
===================================================================
--- haiku/trunk/src/apps/showimage/ToolBarView.h                                
(rev 0)
+++ haiku/trunk/src/apps/showimage/ToolBarView.h        2011-03-20 12:53:38 UTC 
(rev 41055)
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2011 Stephan Aßmus <superstippi@xxxxxx>
+ * All rights reserved. Distributed under the terms of the MIT license.
+ */
+#ifndef TOOL_BAR_VIEW_H
+#define TOOL_BAR_VIEW_H
+
+#include <GroupView.h>
+
+
+namespace BPrivate {
+class BIconButton;
+}
+
+using BPrivate::BIconButton;
+
+
+class ToolBarView : public BGroupView {
+public:
+                                                               
ToolBarView(BRect frame);
+       virtual                                         ~ToolBarView();
+
+                       void                            AddAction(uint32 
command, BHandler* target,
+                                                                       const 
BBitmap* icon,
+                                                                       const 
char* toolTipText = NULL);
+                       void                            AddAction(BMessage* 
message, BHandler* target,
+                                                                       const 
BBitmap* icon,
+                                                                       const 
char* toolTipText = NULL);
+                       void                            AddSeparator();
+
+                       void                            SetActionEnabled(uint32 
command, bool enabled);
+                       void                            SetActionPressed(uint32 
command, bool pressed);
+
+private:
+                       void                            _AddView(BView* view);
+                       BIconButton*            _FindIconButton(uint32 command) 
const;
+};
+
+#endif // TOOL_BAR_VIEW_H


Other related posts: