From 962bcf7da154e9ccf723bd28fb1e36b2f59ed075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Wed, 15 Apr 2009 14:49:06 +0000 Subject: [PATCH] Patch by stpere: * Make DiskUsage use Tracker's "Get Info" panel instead of it's own (still falls back to it's own when Tracker isn't running...) * Fixed some drawing issues. * Removed the window aspect constraints. Thanks a lot! Philippe, please have a look how I changed the license, and the only coding style violation is that you need to watch out for the 80 chars per line limit. :-) Great work! git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30171 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/diskusage/Jamfile | 3 ++ src/apps/diskusage/MainWindow.cpp | 52 ++----------------------------- src/apps/diskusage/MainWindow.h | 9 ++---- src/apps/diskusage/PieView.cpp | 48 ++++++++++++++++++++++------ src/apps/diskusage/PieView.h | 9 +++--- 5 files changed, 53 insertions(+), 68 deletions(-) diff --git a/src/apps/diskusage/Jamfile b/src/apps/diskusage/Jamfile index 985c825db5..977da34979 100644 --- a/src/apps/diskusage/Jamfile +++ b/src/apps/diskusage/Jamfile @@ -1,5 +1,8 @@ SubDir HAIKU_TOP src apps diskusage ; +UsePrivateHeaders tracker ; +SubDirHdrs $(HAIKU_TOP) src kits tracker ; + Application DiskUsage : App.cpp Common.cpp diff --git a/src/apps/diskusage/MainWindow.cpp b/src/apps/diskusage/MainWindow.cpp index 8a57e838fe..ee831f6f6b 100644 --- a/src/apps/diskusage/MainWindow.cpp +++ b/src/apps/diskusage/MainWindow.cpp @@ -1,6 +1,7 @@ /* - * Copyright (c) 2008 Stephan Aßmus . All rights reserved. - * Distributed under the terms of the MIT/X11 license. + * Copyright (c) 2008 Stephan Aßmus . + * Copyright (c) 2009 Philippe Saint-Pierre, stpere@gmail.com + * All rights reserved. Distributed under the terms of the MIT license. * * Copyright (c) 1999 Mike Steed. You are free to use and distribute this software * as long as it is accompanied by it's documentation and this copyright notice. @@ -92,26 +93,6 @@ MainWindow::MessageReceived(BMessage* message) } -void -MainWindow::Zoom(BPoint origin, float width, float height) -{ - width = Frame().Width(); - height = Frame().Height(); - if (_FixAspectRatio(&width, &height)) - SetZoomLimits(width, height); - - BWindow::Zoom(Frame().LeftTop(), width, height); -} - - -void -MainWindow::FrameResized(float width, float height) -{ - if (_FixAspectRatio(&width, &height)) - ResizeTo(width, height); -} - - bool MainWindow::QuitRequested() { @@ -142,30 +123,3 @@ MainWindow::FindDeviceFor(dev_t device, bool invoke) { return fControlsView->FindDeviceFor(device, invoke); } - - -// #pragma mark - - - -bool -MainWindow::_FixAspectRatio(float* width, float* height) -{ - float ctrlViewHeight = fControlsView->Bounds().Height(); - float statusViewHeight = fStatusView->Bounds().Height(); - - float newPieSize = *height - ctrlViewHeight - statusViewHeight; - if (*width < newPieSize) - newPieSize = *width; - - float newWidth = newPieSize; - float newHeight = newPieSize + ctrlViewHeight + statusViewHeight; - if (*width != newWidth || *height != newHeight) { - *width = newWidth; - *height = newHeight; - return true; - } - - return false; -} - - diff --git a/src/apps/diskusage/MainWindow.h b/src/apps/diskusage/MainWindow.h index 0333cddb38..8e8562f4b4 100644 --- a/src/apps/diskusage/MainWindow.h +++ b/src/apps/diskusage/MainWindow.h @@ -1,6 +1,7 @@ /* - * Copyright (c) 2008 Stephan Aßmus . All rights reserved. - * Distributed under the terms of the MIT/X11 license. + * Copyright (c) 2008 Stephan Aßmus . + * Copyright (c) 2009 Philippe Saint-Pierre, stpere@gmail.com + * All rights reserved. Distributed under the terms of the MIT license. * * Copyright (c) 1999 Mike Steed. You are free to use and distribute this software * as long as it is accompanied by it's documentation and this copyright notice. @@ -24,8 +25,6 @@ public: virtual ~MainWindow(); virtual void MessageReceived(BMessage* message); - virtual void Zoom(BPoint origin, float width, float height); - virtual void FrameResized(float width, float height); virtual bool QuitRequested(); void ShowInfo(const FileInfo* info); @@ -34,8 +33,6 @@ public: bool invoke = false); private: - bool _FixAspectRatio(float* width, float* height); - ControlsView* fControlsView; PieView* fPieView; StatusView* fStatusView; diff --git a/src/apps/diskusage/PieView.cpp b/src/apps/diskusage/PieView.cpp index 794f46169f..a79261bf23 100644 --- a/src/apps/diskusage/PieView.cpp +++ b/src/apps/diskusage/PieView.cpp @@ -1,6 +1,7 @@ /* - * Copyright (c) 2008 Stephan Aßmus . All rights reserved. - * Distributed under the terms of the MIT/X11 license. + * Copyright (c) 2008 Stephan Aßmus . + * Copyright (c) 2009 Philippe Saint-Pierre, stpere@gmail.com + * All rights reserved. Distributed under the terms of the MIT license. * * Copyright (c) 1999 Mike Steed. You are free to use and distribute this software * as long as it is accompanied by it's documentation and this copyright notice. @@ -16,12 +17,17 @@ #include #include #include +#include #include #include #include #include #include +#include +#include + +#include "Commands.h" #include "Common.h" #include "InfoWindow.h" #include "MainWindow.h" @@ -433,13 +439,24 @@ void PieView::_DrawPieChart(BRect updateRect) { BRect pieRect = Bounds(); - pieRect.InsetBy(kPieOuterMargin, kPieOuterMargin); if (!updateRect.Intersects(pieRect)) return; + pieRect.InsetBy(kPieOuterMargin, kPieOuterMargin); + SetHighColor(kPieBGColor); FillRect(updateRect); + // constraint proportions + if (pieRect.Width() > pieRect.Height()) { + float moveBy = (pieRect.Width() - pieRect.Height()) / 2; + pieRect.left += moveBy; + pieRect.right -= moveBy; + } else { + float moveBy = (pieRect.Height() - pieRect.Width()) / 2; + pieRect.top -= moveBy; + pieRect.bottom += moveBy; + } int colorIdx = 0; FileInfo* currentDir = fScanners[fCurrentVolume]->CurrentDir(); FileInfo* parent = currentDir; @@ -447,7 +464,8 @@ PieView::_DrawPieChart(BRect updateRect) parent = parent->parent; colorIdx++; } - _DrawDirectory(currentDir, 0.0, 0.0, colorIdx % kBasePieColorCount, 0); + _DrawDirectory(pieRect, currentDir, 0.0, 0.0, colorIdx % kBasePieColorCount, + 0); // This is just for the case when the mouse hovers over the view // while the scanning process is running and then does not move @@ -462,10 +480,9 @@ PieView::_DrawPieChart(BRect updateRect) float -PieView::_DrawDirectory(FileInfo* info, float parentSpan, float beginAngle, - int colorIdx, int level) +PieView::_DrawDirectory(BRect b, FileInfo* info, float parentSpan, + float beginAngle, int colorIdx, int level) { - BRect b = Bounds(); if (b.Width() < 2.0 * (kPieCenterSize + level * kPieRingSize + kPieOuterMargin + kPieInnerMargin)) { return 0.0; @@ -602,7 +619,7 @@ PieView::_DrawDirectory(FileInfo* info, float parentSpan, float beginAngle, vector::iterator i = info->children.begin(); while (i != info->children.end()) { float childSpan - = _DrawDirectory(*i, mySpan, beginAngle, colorIdx, level + 1); + = _DrawDirectory(b, *i, mySpan, beginAngle, colorIdx, level + 1); if (childSpan >= kMinSegmentSpan) { beginAngle += childSpan; colorIdx = (colorIdx + 1) % kBasePieColorCount; @@ -767,7 +784,7 @@ PieView::_ShowContextMenu(FileInfo* info, BPoint p) if (item != NULL) { switch (fMouseOverMenu->IndexOf(item)) { case kIdxGetInfo: - new InfoWin(p, info, Window()); + _OpenInfo(info, p); break; case kIdxOpen: _Launch(info); @@ -814,4 +831,17 @@ PieView::_Launch(FileInfo* info, const entry_ref* appRef) } } +void +PieView::_OpenInfo(FileInfo* info, BPoint p) +{ + BMessenger tracker(kTrackerSignature); + if (!tracker.IsValid()) { + new InfoWin(p, info, Window()); + } else { + BMessage message(kGetInfo); + message.AddRef("refs", &info->ref); + tracker.SendMessage(&message); + } +} + diff --git a/src/apps/diskusage/PieView.h b/src/apps/diskusage/PieView.h index 7dc5e15f4d..e9146117e5 100644 --- a/src/apps/diskusage/PieView.h +++ b/src/apps/diskusage/PieView.h @@ -1,6 +1,7 @@ /* - * Copyright (c) 2008 Stephan Aßmus . All rights reserved. - * Distributed under the terms of the MIT/X11 license. + * Copyright (c) 2008 Stephan Aßmus . + * Copyright (c) 2009 Philippe Saint-Pierre, stpere@gmail.com + * All rights reserved. Distributed under the terms of the MIT license. * * Copyright (c) 1999 Mike Steed. You are free to use and distribute this software * as long as it is accompanied by it's documentation and this copyright notice. @@ -45,7 +46,7 @@ private: void _ShowVolume(BVolume* volume); void _DrawProgressBar(BRect updateRect); void _DrawPieChart(BRect updateRect); - float _DrawDirectory(FileInfo* info, + float _DrawDirectory(BRect b, FileInfo* info, float parentSpan, float beginAngle, int colorIdx, int level); FileInfo* _FileAt(const BPoint& where); @@ -55,7 +56,7 @@ private: void _ShowContextMenu(FileInfo* info, BPoint where); void _Launch(FileInfo* info, const entry_ref* ref = NULL); - + void _OpenInfo(FileInfo* info, BPoint p); private: struct Segment { Segment()