* 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. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41055 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
b8296c286b
commit
cf0d830818
@ -21,6 +21,7 @@ Application ShowImage :
|
||||
ShowImageView.cpp
|
||||
ShowImageWindow.cpp
|
||||
ToolBarIcons.cpp
|
||||
ToolBarView.cpp
|
||||
: libshared.a be tracker translation $(HAIKU_LOCALE_LIBS)
|
||||
$(TARGET_LIBSTDC++) $(TARGET_LIBSUPC++)
|
||||
: ShowImage.rdef
|
||||
|
@ -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 @@ enum {
|
||||
kMsgFitToWindow = 'mFtW',
|
||||
kMsgOriginalSize = 'mOSZ',
|
||||
kMsgStretchToWindow = 'mStW',
|
||||
kMsgNextSlide = 'mNxS'
|
||||
kMsgNextSlide = 'mNxS',
|
||||
kMsgToggleToolBar = 'mTTB'
|
||||
};
|
||||
|
||||
|
||||
@ -117,6 +120,10 @@ bs_printf(BString* string, const char* format, ...)
|
||||
// #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 @@ ShowImageWindow::ShowImageWindow(BRect frame, const entry_ref& ref,
|
||||
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 @@ ShowImageWindow::ShowImageWindow(BRect frame, const entry_ref& ref,
|
||||
|
||||
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 @@ ShowImageWindow::ShowImageWindow(BRect frame, const entry_ref& ref,
|
||||
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 @@ ShowImageWindow::ShowImageWindow(BRect frame, const entry_ref& ref,
|
||||
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 @@ ShowImageWindow::BuildContextMenu(BMenu* menu)
|
||||
}
|
||||
|
||||
|
||||
#undef B_TRANSLATE_CONTEXT
|
||||
#define B_TRANSLATE_CONTEXT "Menus"
|
||||
|
||||
|
||||
void
|
||||
ShowImageWindow::_BuildViewMenu(BMenu* menu, bool popupMenu)
|
||||
{
|
||||
@ -290,6 +334,13 @@ ShowImageWindow::_BuildViewMenu(BMenu* menu, bool popupMenu)
|
||||
_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 @@ ShowImageWindow::_AddMenus(BMenuBar* bar)
|
||||
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 @@ ShowImageWindow::_ToggleMenuItem(uint32 what)
|
||||
marked = !item->IsMarked();
|
||||
item->SetMarked(marked);
|
||||
}
|
||||
fToolBarView->SetActionPressed(what, marked);
|
||||
return marked;
|
||||
}
|
||||
|
||||
@ -492,6 +544,7 @@ ShowImageWindow::_EnableMenuItem(BMenu* menu, uint32 what, bool enable)
|
||||
BMenuItem* item = menu->FindItem(what);
|
||||
if (item && item->IsEnabled() != enable)
|
||||
item->SetEnabled(enable);
|
||||
fToolBarView->SetActionEnabled(what, enable);
|
||||
}
|
||||
|
||||
|
||||
@ -501,6 +554,7 @@ ShowImageWindow::_MarkMenuItem(BMenu* menu, uint32 what, bool marked)
|
||||
BMenuItem* item = menu->FindItem(what);
|
||||
if (item && item->IsMarked() != marked)
|
||||
item->SetMarked(marked);
|
||||
fToolBarView->SetActionPressed(what, marked);
|
||||
}
|
||||
|
||||
|
||||
@ -712,8 +766,13 @@ ShowImageWindow::MessageReceived(BMessage* message)
|
||||
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 @@ ShowImageWindow::MessageReceived(BMessage* message)
|
||||
_ToggleFullScreen();
|
||||
break;
|
||||
|
||||
case MSG_SHOW_CAPTION: {
|
||||
case MSG_SHOW_CAPTION:
|
||||
{
|
||||
fShowCaption = _ToggleMenuItem(message->what);
|
||||
ShowImageSettings* settings = my_app->Settings();
|
||||
|
||||
@ -924,6 +984,20 @@ ShowImageWindow::MessageReceived(BMessage* message)
|
||||
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 @@ ShowImageWindow::_ToggleFullScreen()
|
||||
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 @@ ShowImageWindow::_ApplySettings()
|
||||
fPrintOptions.SetHeight(
|
||||
settings->GetFloat("PO:Height", fPrintOptions.Height()));
|
||||
|
||||
fShowToolBar = settings->GetBool("ShowToolBar", fShowToolBar);
|
||||
|
||||
settings->Unlock();
|
||||
}
|
||||
}
|
||||
@ -1356,6 +1435,28 @@ ShowImageWindow::_UpdateRatingMenu()
|
||||
}
|
||||
|
||||
|
||||
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()
|
||||
{
|
||||
|
@ -22,9 +22,12 @@ class BMenu;
|
||||
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 @@ private:
|
||||
|
||||
void _UpdateRatingMenu();
|
||||
|
||||
void _SetToolBarVisible(bool visible);
|
||||
|
||||
private:
|
||||
ImageFileNavigator fNavigator;
|
||||
BFilePanel* fSavePanel;
|
||||
@ -106,12 +111,16 @@ private:
|
||||
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;
|
||||
|
104
src/apps/showimage/ToolBarView.cpp
Normal file
104
src/apps/showimage/ToolBarView.cpp
Normal file
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright 2011 Stephan Aßmus <superstippi@gmx.de>
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
39
src/apps/showimage/ToolBarView.h
Normal file
39
src/apps/showimage/ToolBarView.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2011 Stephan Aßmus <superstippi@gmx.de>
|
||||
* 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
|
Loading…
x
Reference in New Issue
Block a user