Two unrelated features mangled into one commit:

* Added a Rating menu to the ShowImage window, to easily
   give the current image a rating (uses same attribute as other
   types of media, i.e. MediaPlayer).
 * ShowImage no longer tries to adapt the window size of newly
   opened windows to the image that is loaded into them. I've found
   that the most annoying ShowImage misbehavior. I don't know why
   this was thought to be a good idea, maybe it was useful in
   BeOS presentations when you select 20 images in a folder and
   make them pop up all at once. I however use ShowImage mainly
   to view at fotos, all of which are larger than my screen, so
   ShowImage would basically _aÃlways_cover up everything, even
   though there is the fullscreen mode for that. Now, ShowImage
   remembers the last used window position, new windows will open
   at an offset. In another words, you can now have a Tracker
   folder of images open, view one, close the window, view another,
   ShowImage will open at the previous location, all very convenient
   and expected.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40556 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2011-02-19 11:28:07 +00:00
parent 3b693801a9
commit 5b76e505e5
4 changed files with 108 additions and 15 deletions
+27 -6
View File
@@ -21,6 +21,7 @@
#include <FilePanel.h> #include <FilePanel.h>
#include <Locale.h> #include <Locale.h>
#include <Path.h> #include <Path.h>
#include <Screen.h>
#include <String.h> #include <String.h>
#include "ShowImageConstants.h" #include "ShowImageConstants.h"
@@ -38,10 +39,12 @@ const int32 kWindowsToIgnore = 1;
ShowImageApp::ShowImageApp() ShowImageApp::ShowImageApp()
: :
BApplication(kApplicationSignature) BApplication(kApplicationSignature),
fOpenPanel(new BFilePanel(B_OPEN_PANEL)),
fPulseStarted(false),
fLastWindowFrame(BRect(30, 30, 430, 330))
{ {
fPulseStarted = false; _UpdateLastWindowFrame();
fOpenPanel = new BFilePanel(B_OPEN_PANEL);
} }
@@ -121,6 +124,12 @@ ShowImageApp::MessageReceived(BMessage* message)
_CheckClipboard(); _CheckClipboard();
break; break;
case MSG_WINDOW_HAS_QUIT:
// Make sure that new windows open with the location/size of the
// last closed window.
_UpdateLastWindowFrame();
break;
default: default:
BApplication::MessageReceived(message); BApplication::MessageReceived(message);
break; break;
@@ -167,9 +176,8 @@ ShowImageApp::RefsReceived(BMessage* message)
message->FindMessenger("TrackerViewToken", &trackerMessenger); message->FindMessenger("TrackerViewToken", &trackerMessenger);
entry_ref ref; entry_ref ref;
for (int32 i = 0; message->FindRef("refs", i, &ref) == B_OK; i++) { for (int32 i = 0; message->FindRef("refs", i, &ref) == B_OK; i++)
_Open(ref, trackerMessenger); _Open(ref, trackerMessenger);
}
} }
@@ -203,7 +211,11 @@ ShowImageApp::_StartPulse()
void void
ShowImageApp::_Open(const entry_ref& ref, const BMessenger& trackerMessenger) ShowImageApp::_Open(const entry_ref& ref, const BMessenger& trackerMessenger)
{ {
new ShowImageWindow(ref, trackerMessenger); fLastWindowFrame.OffsetBy(20, 20);
if (!BScreen(B_MAIN_SCREEN_ID).Frame().Contains(fLastWindowFrame))
fLastWindowFrame.OffsetTo(50, 50);
new ShowImageWindow(fLastWindowFrame, ref, trackerMessenger);
} }
@@ -245,6 +257,15 @@ ShowImageApp::_CheckClipboard()
} }
void
ShowImageApp::_UpdateLastWindowFrame()
{
fLastWindowFrame = fSettings.GetRect("WindowFrame", fLastWindowFrame);
// Compensate the offset which we always add to new windows.
fLastWindowFrame.OffsetBy(-20, -20);
}
// #pragma mark - // #pragma mark -
+2
View File
@@ -44,11 +44,13 @@ private:
const BMessenger& trackerMessenger); const BMessenger& trackerMessenger);
void _BroadcastToWindows(BMessage* message); void _BroadcastToWindows(BMessage* message);
void _CheckClipboard(); void _CheckClipboard();
void _UpdateLastWindowFrame();
private: private:
BFilePanel* fOpenPanel; BFilePanel* fOpenPanel;
bool fPulseStarted; bool fPulseStarted;
ShowImageSettings fSettings; ShowImageSettings fSettings;
BRect fLastWindowFrame;
}; };
+71 -7
View File
@@ -90,6 +90,7 @@ enum {
MSG_SHOW_CAPTION = 'mSCP', MSG_SHOW_CAPTION = 'mSCP',
MSG_PAGE_SETUP = 'mPSU', MSG_PAGE_SETUP = 'mPSU',
MSG_PREPARE_PRINT = 'mPPT', MSG_PREPARE_PRINT = 'mPPT',
MSG_SET_RATING = 'mSRT',
kMsgFitToWindow = 'mFtW', kMsgFitToWindow = 'mFtW',
kMsgOriginalSize = 'mOSZ', kMsgOriginalSize = 'mOSZ',
kMsgStretchToWindow = 'mStW', kMsgStretchToWindow = 'mStW',
@@ -116,10 +117,10 @@ bs_printf(BString* string, const char* format, ...)
// #pragma mark -- ShowImageWindow // #pragma mark -- ShowImageWindow
ShowImageWindow::ShowImageWindow(const entry_ref& ref, ShowImageWindow::ShowImageWindow(BRect frame, const entry_ref& ref,
const BMessenger& trackerMessenger) const BMessenger& trackerMessenger)
: :
BWindow(BRect(5, 24, 250, 100), "", B_DOCUMENT_WINDOW, 0), BWindow(frame, "", B_DOCUMENT_WINDOW, 0),
fNavigator(ref, trackerMessenger), fNavigator(ref, trackerMessenger),
fSavePanel(NULL), fSavePanel(NULL),
fBar(NULL), fBar(NULL),
@@ -198,6 +199,8 @@ ShowImageWindow::ShowImageWindow(const entry_ref& ref,
_BuildViewMenu(menu, false); _BuildViewMenu(menu, false);
fBar->AddItem(menu); fBar->AddItem(menu);
fBar->AddItem(_BuildRatingMenu());
SetPulseRate(100000); SetPulseRate(100000);
// every 1/10 second; ShowImageView needs it for marching ants // every 1/10 second; ShowImageView needs it for marching ants
@@ -295,6 +298,23 @@ ShowImageWindow::_BuildViewMenu(BMenu* menu, bool popupMenu)
} }
BMenu*
ShowImageWindow::_BuildRatingMenu()
{
fRatingMenu = new BMenu(B_TRANSLATE("Rating"));
for (int32 i = 1; i <= 10; i++) {
BString label;
label << i;
BMessage* message = new BMessage(MSG_SET_RATING);
message->AddInt32("rating", i);
fRatingMenu->AddItem(new BMenuItem(label.String(), message));
}
// NOTE: We may want to encapsulate the Rating menu within a more
// general "Attributes" menu.
return fRatingMenu;
}
void void
ShowImageWindow::_AddMenus(BMenuBar* bar) ShowImageWindow::_AddMenus(BMenuBar* bar)
{ {
@@ -557,15 +577,13 @@ ShowImageWindow::MessageReceived(BMessage* message)
fNavigator.SetTo(ref, message->FindInt32("page"), fNavigator.SetTo(ref, message->FindInt32("page"),
message->FindInt32("pageCount")); message->FindInt32("pageCount"));
if (first || (!fImageView->StretchesToBounds() && !fFullScreen)) { fImageView->FitToBounds();
_ResizeWindowToImage();
fImageView->FitToBounds();
}
if (first) { if (first) {
fImageView->MakeFocus(true); fImageView->MakeFocus(true);
// to receive key messages // to receive key messages
Show(); Show();
} }
_UpdateRatingMenu();
break; break;
} }
@@ -892,6 +910,20 @@ ShowImageWindow::MessageReceived(BMessage* message)
break; break;
} }
case MSG_SET_RATING:
{
int32 rating;
if (message->FindInt32("rating", &rating) != B_OK)
break;
BFile file(&fNavigator.CurrentRef(), B_WRITE_ONLY);
if (file.InitCheck() != B_OK)
break;
file.WriteAttr("Media:Rating", B_INT32_TYPE, 0, &rating,
sizeof(rating));
_UpdateRatingMenu();
break;
}
default: default:
BWindow::MessageReceived(message); BWindow::MessageReceived(message);
break; break;
@@ -1303,6 +1335,27 @@ ShowImageWindow::_StopSlideShow()
} }
void
ShowImageWindow::_UpdateRatingMenu()
{
BFile file(&fNavigator.CurrentRef(), B_READ_ONLY);
if (file.InitCheck() != B_OK)
return;
int32 rating;
ssize_t size = sizeof(rating);
if (file.ReadAttr("Media:Rating", B_INT32_TYPE, 0, &rating, size) != size)
rating = 0;
// TODO: Finding the correct item could be more robust, like by looking
// at the message of each item.
for (int32 i = 1; i <= 10; i++) {
BMenuItem* item = fRatingMenu->ItemAt(i - 1);
if (item == NULL)
break;
item->SetMarked(i == rating);
}
}
bool bool
ShowImageWindow::QuitRequested() ShowImageWindow::QuitRequested()
{ {
@@ -1311,5 +1364,16 @@ ShowImageWindow::QuitRequested()
return false; return false;
} }
return _ClosePrompt(); if (!_ClosePrompt())
return false;
ShowImageSettings* settings = my_app->Settings();
if (settings->Lock()) {
settings->SetRect("WindowFrame", Frame());
settings->Unlock();
}
be_app->PostMessage(MSG_WINDOW_HAS_QUIT);
return true;
} }
+8 -2
View File
@@ -38,13 +38,15 @@ enum {
kMsgDeleteCurrentFile = 'mDcF', kMsgDeleteCurrentFile = 'mDcF',
MSG_SLIDE_SHOW = 'mSSW', MSG_SLIDE_SHOW = 'mSSW',
kMsgStopSlideShow = 'msss', kMsgStopSlideShow = 'msss',
MSG_EXIT_FULL_SCREEN = 'mEFS' MSG_EXIT_FULL_SCREEN = 'mEFS',
MSG_WINDOW_HAS_QUIT = 'wndq'
}; };
class ShowImageWindow : public BWindow { class ShowImageWindow : public BWindow {
public: public:
ShowImageWindow(const entry_ref& ref, ShowImageWindow(BRect frame,
const entry_ref& ref,
const BMessenger& trackerMessenger); const BMessenger& trackerMessenger);
virtual ~ShowImageWindow(); virtual ~ShowImageWindow();
@@ -59,6 +61,7 @@ private:
void _AddMenus(BMenuBar* bar); void _AddMenus(BMenuBar* bar);
void _ResizeWindowToImage(); void _ResizeWindowToImage();
void _BuildViewMenu(BMenu* menu, bool popupMenu); void _BuildViewMenu(BMenu* menu, bool popupMenu);
BMenu* _BuildRatingMenu();
BMenuItem* _AddItemMenu(BMenu* menu, const char* label, BMenuItem* _AddItemMenu(BMenu* menu, const char* label,
uint32 what, char shortcut, uint32 modifier, uint32 what, char shortcut, uint32 modifier,
const BHandler* target, const BHandler* target,
@@ -93,6 +96,8 @@ private:
void _StartSlideShow(); void _StartSlideShow();
void _StopSlideShow(); void _StopSlideShow();
void _UpdateRatingMenu();
private: private:
ImageFileNavigator fNavigator; ImageFileNavigator fNavigator;
BFilePanel* fSavePanel; BFilePanel* fSavePanel;
@@ -100,6 +105,7 @@ private:
BMenu* fBrowseMenu; BMenu* fBrowseMenu;
BMenu* fGoToPageMenu; BMenu* fGoToPageMenu;
BMenu* fSlideShowDelayMenu; BMenu* fSlideShowDelayMenu;
BMenu* fRatingMenu;
ShowImageView* fImageView; ShowImageView* fImageView;
ShowImageStatusView* fStatusView; ShowImageStatusView* fStatusView;
ProgressWindow* fProgressWindow; ProgressWindow* fProgressWindow;