From 5b76e505e566ce5eeff43dea561e94f787a230e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sat, 19 Feb 2011 11:28:07 +0000 Subject: [PATCH] =?UTF-8?q?Two=20unrelated=20features=20mangled=20into=20o?= =?UTF-8?q?ne=20commit:=20=20*=20Added=20a=20Rating=20menu=20to=20the=20Sh?= =?UTF-8?q?owImage=20window,=20to=20easily=20=20=20=20give=20the=20current?= =?UTF-8?q?=20image=20a=20rating=20(uses=20same=20attribute=20as=20other?= =?UTF-8?q?=20=20=20=20types=20of=20media,=20i.e.=20MediaPlayer).=20=20*?= =?UTF-8?q?=20ShowImage=20no=20longer=20tries=20to=20adapt=20the=20window?= =?UTF-8?q?=20size=20of=20newly=20=20=20=20opened=20windows=20to=20the=20i?= =?UTF-8?q?mage=20that=20is=20loaded=20into=20them.=20I've=20found=20=20?= =?UTF-8?q?=20=20that=20the=20most=20annoying=20ShowImage=20misbehavior.?= =?UTF-8?q?=20I=20don't=20know=20why=20=20=20=20this=20was=20thought=20to?= =?UTF-8?q?=20be=20a=20good=20idea,=20maybe=20it=20was=20useful=20in=20=20?= =?UTF-8?q?=20=20BeOS=20presentations=20when=20you=20select=2020=20images?= =?UTF-8?q?=20in=20a=20folder=20and=20=20=20=20make=20them=20pop=20up=20al?= =?UTF-8?q?l=20at=20once.=20I=20however=20use=20ShowImage=20mainly=20=20?= =?UTF-8?q?=20=20to=20view=20at=20fotos,=20all=20of=20which=20are=20larger?= =?UTF-8?q?=20than=20my=20screen,=20so=20=20=20=20ShowImage=20would=20basi?= =?UTF-8?q?cally=20=5Fa=C3=83lways=5Fcover=20up=20everything,=20even=20=20?= =?UTF-8?q?=20=20though=20there=20is=20the=20fullscreen=20mode=20for=20tha?= =?UTF-8?q?t.=20Now,=20ShowImage=20=20=20=20remembers=20the=20last=20used?= =?UTF-8?q?=20window=20position,=20new=20windows=20will=20open=20=20=20=20?= =?UTF-8?q?at=20an=20offset.=20In=20another=20words,=20you=20can=20now=20h?= =?UTF-8?q?ave=20a=20Tracker=20=20=20=20folder=20of=20images=20open,=20vie?= =?UTF-8?q?w=20one,=20close=20the=20window,=20view=20another,=20=20=20=20S?= =?UTF-8?q?howImage=20will=20open=20at=20the=20previous=20location,=20all?= =?UTF-8?q?=20very=20convenient=20=20=20=20and=20expected.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40556 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/showimage/ShowImageApp.cpp | 33 +++++++++-- src/apps/showimage/ShowImageApp.h | 2 + src/apps/showimage/ShowImageWindow.cpp | 78 +++++++++++++++++++++++--- src/apps/showimage/ShowImageWindow.h | 10 +++- 4 files changed, 108 insertions(+), 15 deletions(-) diff --git a/src/apps/showimage/ShowImageApp.cpp b/src/apps/showimage/ShowImageApp.cpp index 506d140616..300adfa70c 100644 --- a/src/apps/showimage/ShowImageApp.cpp +++ b/src/apps/showimage/ShowImageApp.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include "ShowImageConstants.h" @@ -38,10 +39,12 @@ const int32 kWindowsToIgnore = 1; ShowImageApp::ShowImageApp() : - BApplication(kApplicationSignature) + BApplication(kApplicationSignature), + fOpenPanel(new BFilePanel(B_OPEN_PANEL)), + fPulseStarted(false), + fLastWindowFrame(BRect(30, 30, 430, 330)) { - fPulseStarted = false; - fOpenPanel = new BFilePanel(B_OPEN_PANEL); + _UpdateLastWindowFrame(); } @@ -121,6 +124,12 @@ ShowImageApp::MessageReceived(BMessage* message) _CheckClipboard(); break; + case MSG_WINDOW_HAS_QUIT: + // Make sure that new windows open with the location/size of the + // last closed window. + _UpdateLastWindowFrame(); + break; + default: BApplication::MessageReceived(message); break; @@ -167,9 +176,8 @@ ShowImageApp::RefsReceived(BMessage* message) message->FindMessenger("TrackerViewToken", &trackerMessenger); 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); - } } @@ -203,7 +211,11 @@ ShowImageApp::_StartPulse() void 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 - diff --git a/src/apps/showimage/ShowImageApp.h b/src/apps/showimage/ShowImageApp.h index 3b676d59fe..2b9df85fb3 100644 --- a/src/apps/showimage/ShowImageApp.h +++ b/src/apps/showimage/ShowImageApp.h @@ -44,11 +44,13 @@ private: const BMessenger& trackerMessenger); void _BroadcastToWindows(BMessage* message); void _CheckClipboard(); + void _UpdateLastWindowFrame(); private: BFilePanel* fOpenPanel; bool fPulseStarted; ShowImageSettings fSettings; + BRect fLastWindowFrame; }; diff --git a/src/apps/showimage/ShowImageWindow.cpp b/src/apps/showimage/ShowImageWindow.cpp index 6d0de39f45..57660679a8 100644 --- a/src/apps/showimage/ShowImageWindow.cpp +++ b/src/apps/showimage/ShowImageWindow.cpp @@ -90,6 +90,7 @@ enum { MSG_SHOW_CAPTION = 'mSCP', MSG_PAGE_SETUP = 'mPSU', MSG_PREPARE_PRINT = 'mPPT', + MSG_SET_RATING = 'mSRT', kMsgFitToWindow = 'mFtW', kMsgOriginalSize = 'mOSZ', kMsgStretchToWindow = 'mStW', @@ -116,10 +117,10 @@ bs_printf(BString* string, const char* format, ...) // #pragma mark -- ShowImageWindow -ShowImageWindow::ShowImageWindow(const entry_ref& ref, +ShowImageWindow::ShowImageWindow(BRect frame, const entry_ref& ref, const BMessenger& trackerMessenger) : - BWindow(BRect(5, 24, 250, 100), "", B_DOCUMENT_WINDOW, 0), + BWindow(frame, "", B_DOCUMENT_WINDOW, 0), fNavigator(ref, trackerMessenger), fSavePanel(NULL), fBar(NULL), @@ -198,6 +199,8 @@ ShowImageWindow::ShowImageWindow(const entry_ref& ref, _BuildViewMenu(menu, false); fBar->AddItem(menu); + fBar->AddItem(_BuildRatingMenu()); + SetPulseRate(100000); // 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 ShowImageWindow::_AddMenus(BMenuBar* bar) { @@ -557,15 +577,13 @@ ShowImageWindow::MessageReceived(BMessage* message) fNavigator.SetTo(ref, message->FindInt32("page"), message->FindInt32("pageCount")); - if (first || (!fImageView->StretchesToBounds() && !fFullScreen)) { - _ResizeWindowToImage(); - fImageView->FitToBounds(); - } + fImageView->FitToBounds(); if (first) { fImageView->MakeFocus(true); // to receive key messages Show(); } + _UpdateRatingMenu(); break; } @@ -892,6 +910,20 @@ ShowImageWindow::MessageReceived(BMessage* message) 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: BWindow::MessageReceived(message); 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 ShowImageWindow::QuitRequested() { @@ -1311,5 +1364,16 @@ ShowImageWindow::QuitRequested() 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; } diff --git a/src/apps/showimage/ShowImageWindow.h b/src/apps/showimage/ShowImageWindow.h index 4139584b0d..29a78f1aa1 100644 --- a/src/apps/showimage/ShowImageWindow.h +++ b/src/apps/showimage/ShowImageWindow.h @@ -38,13 +38,15 @@ enum { kMsgDeleteCurrentFile = 'mDcF', MSG_SLIDE_SHOW = 'mSSW', kMsgStopSlideShow = 'msss', - MSG_EXIT_FULL_SCREEN = 'mEFS' + MSG_EXIT_FULL_SCREEN = 'mEFS', + MSG_WINDOW_HAS_QUIT = 'wndq' }; class ShowImageWindow : public BWindow { public: - ShowImageWindow(const entry_ref& ref, + ShowImageWindow(BRect frame, + const entry_ref& ref, const BMessenger& trackerMessenger); virtual ~ShowImageWindow(); @@ -59,6 +61,7 @@ private: void _AddMenus(BMenuBar* bar); void _ResizeWindowToImage(); void _BuildViewMenu(BMenu* menu, bool popupMenu); + BMenu* _BuildRatingMenu(); BMenuItem* _AddItemMenu(BMenu* menu, const char* label, uint32 what, char shortcut, uint32 modifier, const BHandler* target, @@ -93,6 +96,8 @@ private: void _StartSlideShow(); void _StopSlideShow(); + void _UpdateRatingMenu(); + private: ImageFileNavigator fNavigator; BFilePanel* fSavePanel; @@ -100,6 +105,7 @@ private: BMenu* fBrowseMenu; BMenu* fGoToPageMenu; BMenu* fSlideShowDelayMenu; + BMenu* fRatingMenu; ShowImageView* fImageView; ShowImageStatusView* fStatusView; ProgressWindow* fProgressWindow;