Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: HaikuArchives/Calendar
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 73a6fcc53ffd
Choose a base ref
...
head repository: HaikuArchives/Calendar
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 889e457c51c9
Choose a head ref
  • 1 commit
  • 9 files changed
  • 1 contributor

Commits on Nov 14, 2021

  1. Make date header the "Today" button

    This replaces the toolbar's "Today" button with the date header
    functioning as the "Today" button.
    
    Fixes #66
    JadedCtrl authored and humdinger committed Nov 14, 2021
    Copy the full SHA
    889e457 View commit details
Showing with 234 additions and 164 deletions.
  1. +1 −1 Makefile
  2. +0 −1 src/CalendarView.h
  3. +195 −0 src/DateHeaderButton.cpp
  4. +32 −0 src/DateHeaderButton.h
  5. +0 −126 src/DateHeaderView.cpp
  6. +0 −27 src/DateHeaderView.h
  7. +0 −3 src/MainWindow.cpp
  8. +4 −4 src/SidePanelView.cpp
  9. +2 −2 src/SidePanelView.h
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ SRCS = \
src/CategoryEditWindow.cpp \
src/CategoryListItem.cpp \
src/CalendarMenuWindow.cpp \
src/DateHeaderView.cpp \
src/DateHeaderButton.cpp \
src/DayView.cpp \
src/EventListView.cpp \
src/EventListItem.cpp \
1 change: 0 additions & 1 deletion src/CalendarView.h
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
#include <DateTime.h>
#include <View.h>

#include "DateHeaderView.h"
#include "QueryDBManager.h"


195 changes: 195 additions & 0 deletions src/DateHeaderButton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/*
* Copyright 2017 Akshay Agarwal, agarwal.akshay.akshay8@gmail.com
* Copyright 2021 Jaidyn Levesque, jadedctrl@teknik.io
* All rights reserved. Distributed under the terms of the MIT license.
*/

#include "DateHeaderButton.h"

#include <Catalog.h>
#include <ControlLook.h>
#include <DateFormat.h>
#include <Font.h>
#include <LayoutBuilder.h>
#include <LocaleRoster.h>
#include <StringView.h>

#include "MainView.h"
#include "SidePanelView.h"

#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "DateHeaderButton"


DateHeaderButton::DateHeaderButton()
: BControl("DateHeaderButton", NULL,
new BMessage(kSetCalendarToCurrentDate), B_WILL_DRAW)
{
fMouseInView = false;
fMouseDown = false;

SetToolTip(B_TRANSLATE("Go to today"));
SetExplicitMinSize(BSize(B_SIZE_UNSET, be_plain_font->Size() * 4.4));
_UpdateDateHeader();
}


void
DateHeaderButton::Draw(BRect updateRect)
{
BRect bounds = Bounds();

if (fMouseInView == true && IsEnabled() == true) {
BRect buttonBound = bounds;
int32 flags = BControlLook::B_HOVER;
if (fMouseDown == true)
flags = BControlLook::B_ACTIVATED;

be_control_look->DrawButtonFrame(this, buttonBound, updateRect,
LowColor(), ViewColor(), flags);
be_control_look->DrawButtonBackground(this, buttonBound, updateRect,
LowColor(), flags);

if (fMouseDown == true)
bounds = buttonBound;
// DrawButtonBackground will apply the proper inset if button is
// activated
}

float spacing = be_control_look->DefaultLabelSpacing();

float dayFontSize = be_plain_font->Size() * 3.6;
float dayTextTop = (bounds.top / 2) + (dayFontSize / 4);
float dayTextBottom = (bounds.top / 2) + dayFontSize;
float dayOffset_x = (bounds.left / 2) + spacing;

BFont font;
font.SetSize(dayFontSize);
SetFont(&font);
MovePenTo(dayOffset_x, dayTextBottom);
DrawString(fDayText);

float monthWeekOffset_x = dayOffset_x + font.StringWidth(fDayText) + spacing;

font.SetSize(be_plain_font->Size() * 1.2);
SetFont(&font);
MovePenTo(monthWeekOffset_x, dayTextTop + font.Size());
DrawString(fDayOfWeekText);

font.SetSize(be_plain_font->Size());
SetFont(&font);
MovePenTo(monthWeekOffset_x, dayTextBottom);
DrawString(fMonthYearText);
}


void
DateHeaderButton::MessageReceived(BMessage* message)
{
int32 change;
switch (message->what) {
case B_OBSERVER_NOTICE_CHANGE:
{ message->FindInt32(B_OBSERVE_WHAT_CHANGE, &change);
switch (change) {
case kSystemDateChangeMessage:
_UpdateDateHeader();
break;

default:
BView::MessageReceived(message);
break;
}
break;
}
case B_LOCALE_CHANGED:
_UpdateDateHeader();
break;
default:
BView::MessageReceived(message);
break;
}
}


void
DateHeaderButton::MouseDown(BPoint where)
{
if (fMouseInView == true && fMouseDown == false) {
fMouseDown = true;
Invalidate();
}
}


void
DateHeaderButton::MouseUp(BPoint where)
{
if (fMouseDown == true && IsEnabled() == true) {
Invoke();
Invalidate();
}
fMouseDown = false;
}


void
DateHeaderButton::MouseMoved(BPoint where, uint32 code, const BMessage* drag)
{
bool inView = (Bounds().Contains(where) == true);
if (inView != fMouseInView) {
// Toggle fMouseDown if button was released since last in view
if (fMouseDown == true && Window() != NULL
&& Window()->CurrentMessage() != NULL)
fMouseDown = (Window()->CurrentMessage()->FindInt32("buttons") != 0);

fMouseInView = inView;
Invalidate();
}
}


void
DateHeaderButton::_UpdateDateHeader()
{
time_t timeValue = (time_t)time(NULL);

BString dateString;
BString dayString;
BString dayOfWeekString;
BString monthString;
BString yearString;
BString monthYearString;

int* fieldPositions;
int positionCount;
BDateElement* fields;
int fieldCount;
BDateFormat dateFormat;

dateFormat.Format(dateString, fieldPositions, positionCount,
timeValue, B_FULL_DATE_FORMAT);
dateFormat.GetFields(fields, fieldCount, B_FULL_DATE_FORMAT);

for (int i = 0; i < fieldCount; ++i) {
if (fields[i] == B_DATE_ELEMENT_WEEKDAY)
dateString.CopyCharsInto(dayOfWeekString, fieldPositions[i * 2],
fieldPositions[i * 2 + 1] - fieldPositions[i * 2]);
else if (fields[i] == B_DATE_ELEMENT_DAY)
dateString.CopyCharsInto(dayString, fieldPositions[i * 2],
fieldPositions[i * 2 + 1] - fieldPositions[i * 2]);
else if (fields[i] == B_DATE_ELEMENT_MONTH)
dateString.CopyCharsInto(monthString, fieldPositions[i * 2],
fieldPositions[i * 2 + 1] - fieldPositions[i * 2]);
else if (fields[i] == B_DATE_ELEMENT_YEAR)
dateString.CopyCharsInto(yearString, fieldPositions[i * 2],
fieldPositions[i * 2 + 1] - fieldPositions[i * 2]);
}

monthYearString.AppendChars(monthString, monthString.CountChars());
monthYearString += " ";
monthYearString.AppendChars(yearString, yearString.CountChars());

fDayOfWeekText = dayOfWeekString;
fDayText = dayString;
fMonthYearText = monthYearString;
}
32 changes: 32 additions & 0 deletions src/DateHeaderButton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2017 Akshay Agarwal, agarwal.akshay.akshay8@gmail.com
* Copyright 2021 Jaidyn Levesque, jadedctrl@teknik.io
* All rights reserved. Distributed under the terms of the MIT license.
*/
#ifndef _DATEHEADERBUTTON_H_
#define _DATEHEADERBUTTON_H_

#include <Control.h>


class DateHeaderButton: public BControl {
public:
DateHeaderButton();
virtual void Draw(BRect updateRect);
virtual void MessageReceived(BMessage* message);
virtual void MouseDown(BPoint where);
virtual void MouseUp(BPoint where);
virtual void MouseMoved(BPoint where, uint32 code, const BMessage* drag);

private:
void _UpdateDateHeader();

BString fDayText;
BString fDayOfWeekText;
BString fMonthYearText;

bool fMouseInView;
bool fMouseDown;
};

#endif
126 changes: 0 additions & 126 deletions src/DateHeaderView.cpp

This file was deleted.

Loading