diff --git a/src/preferences/time/AnalogClock.cpp b/src/preferences/time/AnalogClock.cpp index 14d67f50a9..037c44b1fc 100644 --- a/src/preferences/time/AnalogClock.cpp +++ b/src/preferences/time/AnalogClock.cpp @@ -4,169 +4,190 @@ * * Authors: * Mike Berg (inseculous) + * Julun + * Stephan Aßmus */ -/*! Notes: OffscreenClock borrows heavily from the clock source. */ - - #include "AnalogClock.h" -#include "Bitmaps.h" #include "TimeMessages.h" -#include + #include -#include -#include -#include +#include class OffscreenClock : public BView { public: - OffscreenClock(BRect frame, const char *name); - virtual ~OffscreenClock(); + OffscreenClock(BRect frame, const char *name); + ~OffscreenClock(); - void DrawClock(); - BPoint Position(); - - void SetTo(int32 hour, int32 minute, int32 second); + void SetTo(int32 hour, int32 minute, int32 second); + bool IsDirty() const + { return fDirty; } + void DrawClock(); private: - BBitmap *fBitmap; - BBitmap *fCenterBitmap; - BBitmap *fCapBitmap; - BPoint fCenter; + void _DrawHands(float x, float y, float radius, + rgb_color hourMinuteColor, rgb_color secondsColor); - BPoint fMinutePoints[60]; - BPoint fHourPoints[60]; - short fHours; - short fMinutes; - short fSeconds; + int32 fHours; + int32 fMinutes; + int32 fSeconds; + bool fDirty; }; -const BRect kClockRect(0, 0, kClockFaceWidth -1, kClockFaceHeight -1); -const BRect kCenterRect(0, 0, kCenterWidth -1, kCenterHeight -1); -const BRect kCapRect(0, 0, kCapWidth -1, kCapHeight -1); -/*! - Analog Clock face rendering view. -*/ OffscreenClock::OffscreenClock(BRect frame, const char *name) - : BView(frame, name, B_NOT_RESIZABLE, B_WILL_DRAW) + : BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW), + fHours(0), + fMinutes(0), + fSeconds(0), + fDirty(true) { - fBitmap = new BBitmap(kClockRect, kClockFaceColorSpace); - fBitmap->SetBits(kClockFaceBits, (kClockFaceWidth) *(kClockFaceHeight +3), 0, kClockFaceColorSpace); - - ReplaceTransparentColor(fBitmap, ui_color(B_PANEL_BACKGROUND_COLOR)); - - fCenterBitmap = new BBitmap(kCenterRect, kCenterColorSpace); - fCenterBitmap->SetBits(kCenterBits, (kCenterWidth) *(kCenterHeight +1), 0, kCenterColorSpace); - - fCapBitmap = new BBitmap(kCapRect, kCapColorSpace); - fCapBitmap->SetBits(kCapBits, (kCapWidth +1) *(kCapHeight +1) +1, 0, kCapColorSpace); - - fCenter = BPoint(42, 42); - - float counter; - short index; - float x, y, mRadius, hRadius; - - mRadius = fCenter.x - 12; - hRadius = mRadius - 10; - index = 0; - - // - // Generate minutes/hours points array - // - for (counter = 90; counter >= 0; counter -= 6,index++) { - x = mRadius * cos(((360 - counter)/180.0) * 3.1415); - x += fCenter.x; - y = mRadius * sin(((360 - counter)/180.0) * 3.1415); - y += fCenter.x; - fMinutePoints[index].Set(x,y); - x = hRadius * cos(((360 - counter)/180.0) * 3.1415); - x += fCenter.x; - y = hRadius * sin(((360 - counter)/180.0) * 3.1415); - y += fCenter.x; - fHourPoints[index].Set(x,y); - } - - for (counter = 354; counter > 90; counter -= 6,index++) { - x = mRadius * cos(((360 - counter)/180.0) * 3.1415); - x += fCenter.x; - y = mRadius * sin(((360 - counter)/180.0) * 3.1415); - y += fCenter.x; - fMinutePoints[index].Set(x,y); - x = hRadius * cos(((360 - counter)/180.0) * 3.1415); - x += fCenter.x; - y = hRadius * sin(((360 - counter)/180.0) * 3.1415); - y += fCenter.x; - fHourPoints[index].Set(x,y); - } + SetFlags(Flags() | B_SUBPIXEL_PRECISE); } OffscreenClock::~OffscreenClock() -{ - delete fBitmap; - delete fCenterBitmap; - delete fCapBitmap; +{ } void OffscreenClock::SetTo(int32 hour, int32 minute, int32 second) { - if (fSeconds != second || fMinutes != minute || fHours != hour) { - fHours = hour; - fMinutes = minute; - fSeconds = second; - } + if (fHours == hour && fMinutes == minute && fSeconds == second) + return; + + fHours = hour; + fMinutes = minute; + fSeconds = second; + + fDirty = true; } void OffscreenClock::DrawClock() { - ASSERT(Window()->IsLocked()); + if (!LockLooper()) + return; - // draw clockface - SetDrawingMode(B_OP_COPY); - DrawBitmap(fBitmap, BPoint(0, 0)); + BRect bounds = Bounds(); + // clear background + rgb_color background = ui_color(B_PANEL_BACKGROUND_COLOR); + SetHighColor(background); + FillRect(bounds); - SetHighColor(0, 0, 0, 255); + float radius = floorf((MIN(bounds.Width(), bounds.Height()) / 2.0)) - 2.5; + float x = floorf((bounds.left + bounds.right) / 2 + 0.5) + 0.5; + float y = floorf((bounds.top + bounds.bottom) / 2 + 0.5) + 0.5; + // + 0.5 is for the offset to pixel centers + // (important when drawing with B_SUBPIXEL_PRECISE) - short hours = fHours; - if (hours >= 12) - hours -= 12; + bounds.Set(x - radius, y - radius, x + radius, y + radius); - hours *= 5; - hours += (fMinutes / 12); + SetPenSize(2.0); - // draw center hub - SetDrawingMode(B_OP_OVER); - DrawBitmap(fCenterBitmap, fCenter - BPoint(kCenterWidth/2.0, kCenterHeight/2.0)); + SetHighColor(tint_color(background, B_DARKEN_1_TINT)); + StrokeEllipse(bounds.OffsetByCopy(-1, -1)); - // draw hands - StrokeLine(fCenter, fHourPoints[hours]); - StrokeLine(fCenter, fMinutePoints[fMinutes]); - SetHighColor(tint_color(HighColor(), B_LIGHTEN_1_TINT)); - StrokeLine(fCenter, fMinutePoints[fSeconds]); + SetHighColor(tint_color(background, B_LIGHTEN_2_TINT)); + StrokeEllipse(bounds.OffsetByCopy(1, 1)); - // draw center cap - DrawBitmap(fCapBitmap, fCenter -BPoint(kCapWidth/2.0, kCapHeight/2.0)); + SetHighColor(tint_color(background, B_DARKEN_3_TINT)); + StrokeEllipse(bounds); + + SetLowColor(255, 255, 255); + FillEllipse(bounds, B_SOLID_LOW); + radius -= 3; + + SetHighColor(tint_color(HighColor(), B_DARKEN_2_TINT)); + + // minutes + SetPenSize(1.0); + SetLineMode(B_BUTT_CAP, B_MITER_JOIN); + for (int32 minute = 1; minute < 60; minute++) { + if (minute % 5 == 0) + continue; + float x1 = x + sinf(minute * PI / 30.0) * radius; + float y1 = y + cosf(minute * PI / 30.0) * radius; + float x2 = x + sinf(minute * PI / 30.0) * (radius * 0.95); + float y2 = y + cosf(minute * PI / 30.0) * (radius * 0.95); + StrokeLine(BPoint(x1, y1), BPoint(x2, y2)); + } + + SetHighColor(tint_color(HighColor(), B_DARKEN_1_TINT)); + + // hours + SetPenSize(2.0); + SetLineMode(B_ROUND_CAP, B_MITER_JOIN); + for (int32 hour = 0; hour < 12; hour++) { + float x1 = x + sinf(hour * PI / 6.0) * radius; + float y1 = y + cosf(hour * PI / 6.0) * radius; + float x2 = x + sinf(hour * PI / 6.0) * (radius * 0.9); + float y2 = y + cosf(hour * PI / 6.0) * (radius * 0.9); + StrokeLine(BPoint(x1, y1), BPoint(x2, y2)); + } + + rgb_color hourMinutColor = tint_color(HighColor(), B_DARKEN_2_TINT); + rgb_color secondsColor = (rgb_color){ 255, 0, 0, 255 }; + rgb_color shadowColor = tint_color(LowColor(), + (B_DARKEN_1_TINT + B_DARKEN_2_TINT) / 2); + + _DrawHands(x + 1.5, y + 1.5, radius, shadowColor, shadowColor); + _DrawHands(x, y, radius, hourMinutColor, secondsColor); Sync(); + + UnlockLooper(); +} + + +void +OffscreenClock::_DrawHands(float x, float y, float radius, + rgb_color hourMinuteColor, rgb_color secondsColor) +{ + SetHighColor(hourMinuteColor); + + float offsetX; + float offsetY; + + // calc, draw hour hand + SetPenSize(4.0); + float hours = fHours + float(fMinutes) / 60.0; + offsetX = (radius * 0.7) * sinf((hours * PI) / 6.0); + offsetY = (radius * 0.7) * cosf((hours * PI) / 6.0); + StrokeLine(BPoint(x, y), BPoint(x + offsetX, y - offsetY)); + + // calc, draw minute hand + SetPenSize(3.0); + float minutes = fMinutes + float(fSeconds) / 60.0; + offsetX = (radius * 0.9) * sinf((minutes * PI) / 30.0); + offsetY = (radius * 0.9) * cosf((minutes * PI) / 30.0); + StrokeLine(BPoint(x, y), BPoint(x + offsetX, y - offsetY)); + + SetHighColor(secondsColor); + + // calc, draw second hand + SetPenSize(1.0); + offsetX = (radius * 0.95) * sinf((fSeconds * PI) / 30.0); + offsetY = (radius * 0.95) * cosf((fSeconds * PI) / 30.0); + StrokeLine(BPoint(x, y), BPoint(x + offsetX, y - offsetY)); + + // draw the center knob + SetHighColor(hourMinuteColor); + FillEllipse(BPoint(x, y), radius * 0.06, radius * 0.06); } // #pragma mark - -/*! - BView to display clock face of current time. -*/ -TAnalogClock::TAnalogClock(BRect frame, const char *name, uint32 resizingmode, uint32 flags) - : BView(frame, name, resizingmode, flags | B_DRAW_ON_CHILDREN) +TAnalogClock::TAnalogClock(BRect frame, const char *name, uint32 resizeMask, uint32 flags) + : BView(frame, name, resizeMask, flags | B_DRAW_ON_CHILDREN), + fBitmap(NULL), + fClock(NULL) { _InitView(frame); } @@ -181,8 +202,8 @@ TAnalogClock::~TAnalogClock() void TAnalogClock::_InitView(BRect rect) { - fClock = new OffscreenClock(kClockRect, "offscreen"); - fBitmap = new BBitmap(kClockRect, B_CMAP8, true); + fClock = new OffscreenClock(Bounds(), "offscreen"); + fBitmap = new BBitmap(Bounds(), B_RGB32, true); fBitmap->Lock(); fBitmap->AddChild(fClock); fBitmap->Unlock(); @@ -230,12 +251,10 @@ TAnalogClock::MessageReceived(BMessage *message) void TAnalogClock::Draw(BRect /*updateRect*/) { - SetHighColor(0, 100, 10); - - if (fBitmap->Lock()) { - fClock->DrawClock(); + if (fBitmap) { + if (fClock->IsDirty()) + fClock->DrawClock(); DrawBitmap(fBitmap, BPoint(0, 0)); - fBitmap->Unlock(); } } @@ -243,6 +262,9 @@ TAnalogClock::Draw(BRect /*updateRect*/) void TAnalogClock::SetTo(int32 hour, int32 minute, int32 second) { - fClock->SetTo(hour, minute, second); + if (fClock) + fClock->SetTo(hour, minute, second); + Invalidate(); } + diff --git a/src/preferences/time/AnalogClock.h b/src/preferences/time/AnalogClock.h index 84027b5e41..30e72c5ae2 100644 --- a/src/preferences/time/AnalogClock.h +++ b/src/preferences/time/AnalogClock.h @@ -1,34 +1,40 @@ /* - * Copyright 2004-2006, Haiku, Inc. All Rights Reserved. + * Copyright 2004-2007, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: * Mike Berg (inseculous) + * Julun */ #ifndef ANALOG_CLOCK_H #define ANALOG_CLOCK_H -#include + #include + +class BBitmap; class OffscreenClock; -class TAnalogClock: public BView { + +class TAnalogClock : public BView { public: - TAnalogClock(BRect frame, const char *name, uint32 resizingmode, uint32 flags); - virtual ~TAnalogClock(); + TAnalogClock(BRect frame, const char *name, + uint32 resizeMask, uint32 flags); + virtual ~TAnalogClock(); - virtual void AttachedToWindow(); - virtual void Draw(BRect updaterect); - virtual void MessageReceived(BMessage *); + virtual void AttachedToWindow(); + virtual void Draw(BRect updateRect); + virtual void MessageReceived(BMessage *message); - void SetTo(int32 hour, int32 minute, int32 second); + void SetTo(int32 hour, int32 minute, int32 second); private: - void _InitView(BRect frame); + void _InitView(BRect frame); - BBitmap *fBitmap; - OffscreenClock *fClock; + BBitmap *fBitmap; + OffscreenClock *fClock; }; #endif // ANALOG_CLOCK_H + diff --git a/src/preferences/time/Jamfile b/src/preferences/time/Jamfile index 496ed5c303..e1a5222e8a 100644 --- a/src/preferences/time/Jamfile +++ b/src/preferences/time/Jamfile @@ -1,6 +1,7 @@ SubDir HAIKU_TOP src preferences time ; SetSubDirSupportedPlatformsBeOSCompatible ; +AddSubDirSupportedPlatforms libbe_test ; Preference Time : AnalogClock.cpp @@ -20,3 +21,7 @@ Preference Time : : Time.rdef ; +if $(TARGET_PLATFORM) = libbe_test { + HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : Time + : tests!apps ; +} diff --git a/src/preferences/time/SettingsView.cpp b/src/preferences/time/SettingsView.cpp index 509c3fcf25..4fe85fa93b 100644 --- a/src/preferences/time/SettingsView.cpp +++ b/src/preferences/time/SettingsView.cpp @@ -1,6 +1,18 @@ /* - SettingsView.cpp -*/ + * Copyright 2004-2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * + * Julun + */ + +#include "SettingsView.h" +#include "AnalogClock.h" +#include "CalendarView.h" +#include "DateTimeEdit.h" +#include "TimeMessages.h" + #include #include #include @@ -9,17 +21,12 @@ #include #include -#include "Bitmaps.h" -#include "SettingsView.h" -#include "TimeMessages.h" - - -/*=====> TSettingsView <=====*/ TSettingsView::TSettingsView(BRect frame) : BView(frame,"Settings", B_FOLLOW_ALL, - B_WILL_DRAW|B_FRAME_EVENTS|B_NAVIGABLE_JUMP) -{ + B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP), + fGmtTime(NULL) +{ InitView(); } @@ -63,75 +70,101 @@ TSettingsView::MessageReceived(BMessage *message) } +void +TSettingsView::GetPreferredSize(float *width, float *height) +{ + // hardcode in TimeWindow ... + *width = 361.0f; + *height = 227.0f; + + if (fGmtTime) { + // we are initialized + *width = Bounds().Width(); + *height = fGmtTime->Frame().bottom; + } +} + + void TSettingsView::InitView() { - ReadFiles(); + ReadRTCSettings(); - font_height finfo; - be_plain_font->GetHeight(&finfo); - float text_height = finfo.descent +finfo.ascent +finfo.leading; + font_height fontHeight; + be_plain_font->GetHeight(&fontHeight); + float textHeight = fontHeight.descent + fontHeight.ascent + fontHeight.leading; - BRect bounds(Bounds()); - bounds.right = (bounds.Width()/2.0) -5; - - BRect frame(bounds); - // left side - frame.InsetBy(6, 6); - frame.bottom = frame.top +text_height +6; - f_dateedit = new TDateEdit(frame, "date_edit", 3); - - frame.top = f_dateedit->Frame().bottom; - frame.bottom = bounds.bottom; - frame.InsetBy(10, 8); - - f_calendar = new TCalendarView(frame, "calendar", B_FOLLOW_NONE, B_WILL_DRAW); - - AddChild(f_dateedit); - AddChild(f_calendar); - + BRect frameLeft(Bounds()); + frameLeft.right = frameLeft.Width() / 2; + frameLeft.InsetBy(10.0f, 10.0f); + frameLeft.bottom = frameLeft.top + textHeight +6; + + fDateEdit = new TDateEdit(frameLeft, "date_edit", 3); + AddChild(fDateEdit); + + frameLeft.top = fDateEdit->Frame().bottom + 10; + frameLeft.bottom = Bounds().bottom - 10; + + fCalendar = new TCalendarView(frameLeft, "calendar", B_FOLLOW_NONE, B_WILL_DRAW); + AddChild(fCalendar); + + frameLeft.top = fCalendar->Frame().bottom + 10; + BStringView *text = new BStringView(frameLeft, "timezone", "Timezone:"); + AddChild(text); + text->ResizeToPreferred(); + + frameLeft.left += 20.0f; + frameLeft.top = text->Frame().bottom + 5; + + fTimeZone = new BStringView(frameLeft, "label", " "); + AddChild(fTimeZone); + // right side - bounds.OffsetBy(bounds.Width() +9, 0); - f_temp = bounds; - frame = bounds; - frame.InsetBy(26, 6); - frame.bottom = frame.top +text_height +6; - frame.right += 4; - f_timeedit = new TTimeEdit(frame, "time_edit", 4); - AddChild(f_timeedit); + BRect frameRight(Bounds()); + frameRight.left = frameRight.Width() / 2; + frameRight.InsetBy(10.0f, 10.0f); + frameRight.bottom = frameRight.top + textHeight +6; + + fTimeEdit = new TTimeEdit(frameRight, "time_edit", 4); + AddChild(fTimeEdit); + + frameRight.top = fTimeEdit->Frame().bottom + 10; + frameRight.bottom = Bounds().bottom - 10; + + float left = fTimeEdit->Frame().left; + float tmp = MIN(frameRight.Width(), frameRight.Height()); + frameRight.left = left + (fTimeEdit->Bounds().Width() - tmp) /2; + frameRight.bottom = frameRight.top + tmp; + frameRight.right = frameRight.left + tmp; - frame.top = f_timeedit->Frame().bottom; - frame.bottom = bounds.bottom -(text_height *3); - frame.InsetBy((frame.Width() - kClockFaceWidth + 1)/2.0, (frame.Height() - kClockFaceHeight + 1)/2.0); - f_clock = new TAnalogClock(frame, "analog clock", - B_FOLLOW_NONE, B_WILL_DRAW); - AddChild(f_clock); + fClock = new TAnalogClock(frameRight, "analog clock", B_FOLLOW_NONE, B_WILL_DRAW); + AddChild(fClock); // clock radio buttons - frame = bounds.InsetByCopy(6, 10); - frame.top = f_clock->Frame().bottom +12; - frame.bottom = frame.top +text_height +2; - BString label = "Clock set to:"; - float width = be_plain_font->StringWidth(label.String()); - frame.right = frame.left +width; - BStringView *text = new BStringView(frame, "clockis", "Clock set to:"); + frameRight.left = left; + frameRight.top = fClock->Frame().bottom + 10; + text = new BStringView(frameRight, "clockis", "Clock set to:"); AddChild(text); - - frame.OffsetBy(frame.Width() +9, -1); - frame.right = bounds.right-2; - - f_local = new BRadioButton(frame, "local", "Local time", new BMessage(H_RTC_CHANGE)); - AddChild(f_local); - - frame.OffsetBy(0, text_height +4); - f_gmt = new BRadioButton(frame, "gmt", "GMT", new BMessage(H_RTC_CHANGE)); - AddChild(f_gmt); - - if (f_islocal) - f_local->SetValue(1); + text->ResizeToPreferred(); + + frameRight.left += 20.0f; + frameRight.top = text->Frame().bottom + 5; + + fLocalTime = new BRadioButton(frameRight, "local", "Local time", new BMessage(H_RTC_CHANGE)); + AddChild(fLocalTime); + fLocalTime->ResizeToPreferred(); + + frameRight.left = fLocalTime->Frame().right +10.0f; + + fGmtTime = new BRadioButton(frameRight, "gmt", "GMT", new BMessage(H_RTC_CHANGE)); + AddChild(fGmtTime); + fGmtTime->ResizeToPreferred(); + + if (fIsLocalTime) + fLocalTime->SetValue(B_CONTROL_ON); else - f_gmt->SetValue(1); + fGmtTime->SetValue(B_CONTROL_ON); } @@ -145,8 +178,8 @@ TSettingsView::Draw(BRect /*updateRect*/) rgb_color dark = tint_color(viewcolor, B_DARKEN_4_TINT); rgb_color light = tint_color(viewcolor, B_LIGHTEN_MAX_TINT); - BPoint start(bounds.Width()/2.0 +2.0, bounds.top +1); - BPoint end(bounds.Width()/2.0 +2.0, bounds.bottom -1); + BPoint start(bounds.Width() / 2.0f +2.0f, bounds.top +1.0f); + BPoint end(bounds.Width() / 2.0 +2.0f, bounds.bottom -1.0f); BeginLineArray(2); AddLine(start, end, dark); @@ -155,77 +188,80 @@ TSettingsView::Draw(BRect /*updateRect*/) AddLine(start, end, light); EndLineArray(); - f_timeedit->Draw(bounds); - f_dateedit->Draw(bounds); + fTimeEdit->Draw(bounds); + fDateEdit->Draw(bounds); } bool TSettingsView::GMTime() { - return f_gmt->Value() == 1; + return fGmtTime->Value() == B_CONTROL_ON; +} + + +void +TSettingsView::SetTimeZone(const char *timezone) +{ + fTimeZone->SetText(timezone); + fTimeZone->ResizeToPreferred(); } void TSettingsView::UpdateDateTime(BMessage *message) { - int32 month, day, year, hour, minute, second; - + int32 day; + int32 month; + int32 year; if (message->FindInt32("month", &month) == B_OK && message->FindInt32("day", &day) == B_OK && message->FindInt32("year", &year) == B_OK) { - f_dateedit->SetTo(year, month, day); - f_calendar->SetTo(year, month, day); + fDateEdit->SetTo(year, month, day); + fCalendar->SetTo(year, month, day); } + int32 hour; + int32 minute; + int32 second; if (message->FindInt32("hour", &hour) == B_OK && message->FindInt32("minute", &minute) == B_OK && message->FindInt32("second", &second) == B_OK) { - f_timeedit->SetTo(hour, minute, second); - f_clock->SetTo(hour, minute, second); + fTimeEdit->SetTo(hour, minute, second); + fClock->SetTo(hour, minute, second); } } void -TSettingsView::ReadFiles() +TSettingsView::ReadRTCSettings() { - // do all file reading here - - // read RTC_time_settings - BPath path; if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) { return; // NO USER SETTINGS DIRECTORY!!! } path.Append("RTC_time_settings"); - BEntry entry(path.Path()); BFile file; - + BEntry entry(path.Path()); if (entry.Exists()) { - //read file file.SetTo(&entry, B_READ_ONLY); - status_t err = file.InitCheck(); - if (err == B_OK) { + if (file.InitCheck() == B_OK) { char buff[6]; file.Read(buff, 6); - BString text; - text << buff; + BString text(buff); if (text.Compare("local\n", 5) == 0) - f_islocal = true; + fIsLocalTime = true; else - f_islocal = false; + fIsLocalTime = false; } } else { // create set to local - f_islocal = true; - file.SetTo(&entry, B_CREATE_FILE|B_READ_WRITE); + fIsLocalTime = true; + file.SetTo(&entry, B_CREATE_FILE | B_READ_WRITE); file.Write("local\n", 6); } - - // done reading RTC_time_settings } + diff --git a/src/preferences/time/SettingsView.h b/src/preferences/time/SettingsView.h index 8292f5a89d..8ee3d6c4b2 100644 --- a/src/preferences/time/SettingsView.h +++ b/src/preferences/time/SettingsView.h @@ -1,43 +1,53 @@ /* - - SettingsView.h -*/ - + * Copyright 2004-2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * + * Julun + */ #ifndef SETTINGS_VIEW_H #define SETTINGS_VIEW_H -#include + #include -#include "AnalogClock.h" -#include "CalendarView.h" -#include "DateTimeEdit.h" -class TSettingsView:public BView { +class TDateEdit; +class TTimeEdit; +class TCalendarView; +class TAnalogClock; +class BRadioButton; +class BStringView; + +class TSettingsView : public BView { public: - TSettingsView(BRect frame); - virtual ~TSettingsView(); + TSettingsView(BRect frame); + virtual ~TSettingsView(); - virtual void AttachedToWindow(); - virtual void Draw(BRect updaterect); - virtual void MessageReceived(BMessage *message); - - void ChangeRTCSetting(); - - bool GMTime(); + virtual void AttachedToWindow(); + virtual void Draw(BRect updaterect); + virtual void MessageReceived(BMessage *message); + virtual void GetPreferredSize(float *width, float *height); + + void ChangeRTCSetting(); + bool GMTime(); + void SetTimeZone(const char *timezone); + private: - void InitView(); - void ReadFiles(); // reads RTC_time_settings - void UpdateDateTime(BMessage *message); - - BRect f_temp; - BRadioButton *f_local; - BRadioButton *f_gmt; - TDateEdit *f_dateedit; - TTimeEdit *f_timeedit; - TCalendarView *f_calendar; - TAnalogClock *f_clock; - bool f_islocal; // local or gmt? + void InitView(); + void ReadRTCSettings(); + void UpdateDateTime(BMessage *message); + + BRadioButton *fLocalTime; + BRadioButton *fGmtTime; + TDateEdit *fDateEdit; + TTimeEdit *fTimeEdit; + TCalendarView *fCalendar; + TAnalogClock *fClock; + bool fIsLocalTime; + BStringView *fTimeZone; }; #endif + diff --git a/src/preferences/time/TimeMessages.h b/src/preferences/time/TimeMessages.h index ef8171bcb8..ab2e64ecba 100644 --- a/src/preferences/time/TimeMessages.h +++ b/src/preferences/time/TimeMessages.h @@ -39,3 +39,4 @@ const uint32 H_USER_CHANGE = 'obUC'; const uint32 H_RTC_CHANGE = 'obRC'; #endif //TIME_MESSAGES_H + diff --git a/src/preferences/time/TimeWindow.cpp b/src/preferences/time/TimeWindow.cpp index d88cc59d29..82eef99efa 100644 --- a/src/preferences/time/TimeWindow.cpp +++ b/src/preferences/time/TimeWindow.cpp @@ -1,7 +1,10 @@ /* - * TTimeWindow.cpp - * Time mccall@@digitalparadise.co.uk - * + * Copyright 2004-2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * mccall@@digitalparadise.co.uk + * Julun */ #include @@ -19,7 +22,7 @@ #include "TimeSettings.h" #include "ZoneView.h" -#define TIME_WINDOW_RIGHT 361 //332 +#define TIME_WINDOW_RIGHT 400 //332 #define TIME_WINDOW_BOTTOM 227 //208 @@ -29,10 +32,13 @@ TTimeWindow::TTimeWindow() { MoveTo(dynamic_cast(be_app)->WindowCorner()); - BScreen screen; + BRect frame = Frame(); + BRect bounds = Bounds(); + BRect screenFrame = BScreen().Frame(); // Code to make sure that the window doesn't get drawn off screen... - if (!(screen.Frame().right >= Frame().right && screen.Frame().bottom >= Frame().bottom)) - MoveTo((screen.Frame().right-Bounds().right)*.5,(screen.Frame().bottom-Bounds().bottom)*.5); + if (!(screenFrame.right >= frame.right && screenFrame.bottom >= frame.bottom)) + MoveTo((screenFrame.right - bounds.right) * 0.5f, + (screenFrame.bottom - bounds.bottom) * 0.5f); InitWindow(); SetPulseRate(500000); @@ -99,7 +105,7 @@ TTimeWindow::InitWindow() fTimeZones = new TZoneView(bounds); if (fBaseView->StartWatchingAll(fTimeZones) != B_OK) printf("TimeZones->StartWatchingAll(TimeZone) failed!!!\n"); - + // add tabs BTab *tab = new BTab(); tabview->AddTab(fTimeSettings, tab); @@ -110,4 +116,11 @@ TTimeWindow::InitWindow() tab->SetLabel("Time Zone"); fBaseView->AddChild(tabview); + + float width; + float height; + fTimeSettings->GetPreferredSize(&width, &height); + // width/ height from settingsview + all InsetBy etc.. + ResizeTo(width +10, height + tabview->TabHeight() +25); } + diff --git a/src/preferences/time/TimeWindow.h b/src/preferences/time/TimeWindow.h index c58dd0889e..05db1a6913 100644 --- a/src/preferences/time/TimeWindow.h +++ b/src/preferences/time/TimeWindow.h @@ -1,3 +1,7 @@ +/* + * Copyright 2004-2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ #ifndef TIME_WINDOW_H #define TIME_WINDOW_H diff --git a/src/preferences/time/ZoneView.cpp b/src/preferences/time/ZoneView.cpp index d24ddcf0aa..b27a4cd7eb 100644 --- a/src/preferences/time/ZoneView.cpp +++ b/src/preferences/time/ZoneView.cpp @@ -1,12 +1,20 @@ /* - ZoneView.cpp - by Mike Berg (inseculous) - - Status: mimics original Time Zone tab of Time Pref App - Exceptions: doesn't calc "Time in" time. - Issues: After experimenting with both Time Prefs, it seems the original doesn't - use the link file in the users settings file to get the current Timezone. - Need to find the call it uses to get its inital info so I can get exact duplication. + * Copyright 2004-2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Mike Berg (inseculous) + * Julun + */ +/* + Exceptions: + doesn't calc "Time in" time. + + Issues: + After experimenting with both Time Prefs, it seems the original + doesn't use the link file in the users settings file to get the + current Timezone. Need to find the call it uses to get its + inital info so I can get exact duplication. */ #include @@ -144,6 +152,13 @@ TZoneView::MessageReceived(BMessage *message) } +const char* +TZoneView::TimeZone() +{ + return f_current->Text(); +} + + void TZoneView::UpdateDateTime(BMessage *message) { diff --git a/src/preferences/time/ZoneView.h b/src/preferences/time/ZoneView.h index df4638db23..483632ac28 100644 --- a/src/preferences/time/ZoneView.h +++ b/src/preferences/time/ZoneView.h @@ -1,7 +1,11 @@ /* - ZoneView.h - Header file for the base class of the Time Zone tab in Time Pref App. -*/ + * Copyright 2004-2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Mike Berg (inseculous) + * Julun + */ #ifndef ZONE_VIEW_H #define ZONE_VIEW_H @@ -37,6 +41,9 @@ class TZoneView: public BView { virtual void AttachedToWindow(); virtual void AllAttached(); virtual void MessageReceived(BMessage *message); + + const char* TimeZone(); + protected: void UpdateDateTime(BMessage *message); void ChangeRegion(BMessage *);