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: 471be0928855
Choose a base ref
...
head repository: HaikuArchives/Calendar
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9d8b43a78922
Choose a head ref
  • 1 commit
  • 12 files changed
  • 1 contributor

Commits on Dec 16, 2021

  1. View option for displaying "hidden" events

    This option displays hidden and deleted events in the list, allowing
    the user to undelete/unhide. Hidden/deleted events are marked
    with a label and tinted background color. Deleted events use the
    strikeout font-face, cancelled use italics.
    JadedCtrl authored and pulkomandy committed Dec 16, 2021
    Copy the full SHA
    9d8b43a View commit details
Showing with 182 additions and 117 deletions.
  1. +33 −51 src/CalendarView.cpp
  2. +16 −10 src/CalendarView.h
  3. +32 −14 src/EventListItem.cpp
  4. +26 −20 src/EventTabView.cpp
  5. +2 −1 src/EventTabView.h
  6. +11 −4 src/MainWindow.cpp
  7. +2 −0 src/Preferences.cpp
  8. +2 −0 src/Preferences.h
  9. +12 −12 src/SidePanelView.cpp
  10. +2 −2 src/db/QueryDBManager.cpp
  11. +39 −1 src/utils/ColorConverter.cpp
  12. +5 −2 src/utils/ColorConverter.h
84 changes: 33 additions & 51 deletions src/CalendarView.cpp
Original file line number Diff line number Diff line change
@@ -8,51 +8,50 @@

#include "CalendarView.h"

#include <stdlib.h>

#include <CalendarView.h>
#include <DateFormat.h>
#include <stdlib.h>

#include "ColorConverter.h"
#include "QueryDBManager.h"


CalendarView::CalendarView(BRect frame, const char* name,
uint32 resizeMask, uint32 flags)
CalendarView::CalendarView(BRect frame, const char* name, uint32 resizeMask,
uint32 flags)
:
BCalendarView(frame, name, resizeMask, flags)
{
_Init();
}

CalendarView::CalendarView (const char* text)

CalendarView::CalendarView(BMessage* archive)
:
BCalendarView(text)
BCalendarView(archive)
{
_Init();
}

CalendarView::CalendarView (BMessage* archive)

CalendarView::CalendarView(const char* text)
:
BCalendarView(archive)
BCalendarView(text)
{
_Init();
}

CalendarView::CalendarView (const char* name, uint32 flags)

CalendarView::CalendarView(const char* name, uint32 flags)
:
BCalendarView(name, flags)
{
_Init();
}

void
CalendarView::_Init ()
{
fDBManager = new QueryDBManager();
}


void
CalendarView::DrawDay (BView* owner, BRect frame, const char* text,
CalendarView::DrawDay(BView* owner, BRect frame, const char* text,
bool isSelected, bool isEnabled, bool focus, bool isHighlight)
{
int drawnYear = Date().Year();
@@ -66,7 +65,7 @@ CalendarView::DrawDay (BView* owner, BRect frame, const char* text,
if (drawnMonth > 12) { drawnMonth -= 12; drawnYear++; }
BDate drawnDate = BDate(Date().Year(), drawnMonth, drawnDay);

int eventCount = fDBManager->GetEventsOfDay(drawnDate)->CountItems();
int eventCount = fDBManager->GetEventsOfDay(drawnDate, !fMarkHidden)->CountItems();
if (isEnabled == false && eventCount != 0)
eventCount = 1;

@@ -97,6 +96,24 @@ CalendarView::DrawDay (BView* owner, BRect frame, const char* text,
}


void
CalendarView::SetMarkHidden(bool show)
{
if (fMarkHidden != show) {
fMarkHidden = show;
Invalidate();
}
}


void
CalendarView::_Init()
{
fDBManager = new QueryDBManager();
fMarkHidden = false;
}


void
CalendarView::_DrawItem(BView* owner, BRect frame, const char* text,
bool isHighlight, bool focus, rgb_color bgColor, rgb_color textColor)
@@ -135,41 +152,6 @@ CalendarView::_DrawItem(BView* owner, BRect frame, const char* text,
}


rgb_color
TintColor(rgb_color color, rgb_color base, int severity)
{
bool dark = false;
if (base.Brightness() < 127)
dark = true;

switch (severity) {
case 0:
return color;
case 1:
if (dark == true)
return tint_color(color, B_LIGHTEN_1_TINT + 0.1f);
else
return tint_color(color, B_DARKEN_1_TINT);
case 2:
if (dark == true)
return tint_color(color, B_LIGHTEN_1_TINT);
else
return tint_color(color, B_DARKEN_2_TINT);
case 3: // intentional fallthrough
case 4:
if (dark == true)
return tint_color(color, B_LIGHTEN_2_TINT);
else
return tint_color(color, B_DARKEN_3_TINT);
default:
if (dark == true)
return tint_color(color, B_LIGHTEN_2_TINT - 0.1f);
else
return tint_color(color, B_DARKEN_4_TINT);
}
}


float
FontHeight(const BView* view)
{
26 changes: 16 additions & 10 deletions src/CalendarView.h
Original file line number Diff line number Diff line change
@@ -24,23 +24,29 @@ using BPrivate::BCalendarView;

class CalendarView: public BCalendarView {
public:
CalendarView(BRect, const char*, uint32, uint32);
CalendarView(BMessage*);
CalendarView(const char*);
CalendarView(const char*, uint32);
CalendarView(BRect frame, const char* name,
uint32 resizeMask, uint32 flags);
CalendarView(BMessage* archive);
CalendarView(const char* text);
CalendarView(const char* name, uint32 flags);

virtual void DrawDay(BView* owner, BRect frame, const char* text,
bool isSelected, bool isEnabled, bool focus,
bool isHighlight);

void SetMarkHidden(bool show);

void DrawDay(BView*, BRect, const char*, bool, bool, bool, bool);
private:
void _Init();
void _DrawItem(BView* owner, BRect frame, const char* text,
bool isHighlight, bool focus, rgb_color bgColor,
rgb_color textColor);
void _Init();
void _DrawItem(BView* owner, BRect frame, const char* text,
bool isHighlight, bool focus, rgb_color bgColor,
rgb_color textColor);

bool fMarkHidden;
QueryDBManager* fDBManager;
};


rgb_color TintColor(rgb_color color, rgb_color base, int severity);
float FontHeight(const BView* view);


46 changes: 32 additions & 14 deletions src/EventListItem.cpp
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
#include <MenuItem.h>
#include <TimeFormat.h>

#include "ColorConverter.h"
#include "Event.h"
#include "EventTabView.h"

@@ -46,11 +47,21 @@ EventListItem::DrawItem(BView* view, BRect rect, bool complete)
BFont timefont;
font_height finfo;

uint16 status = fEvent->GetStatus();
int severity = 0;
if (status & EVENT_HIDDEN)
severity = 1;
if (status & EVENT_DELETED)
severity = 2;
if (IsSelected() == true)
severity = 0;

rgb_color bgColor;
if (IsSelected())
if (IsSelected() == true)
bgColor = ui_color(B_LIST_SELECTED_BACKGROUND_COLOR);
else
bgColor = ui_color(B_LIST_BACKGROUND_COLOR);
bgColor = TintColor(bgColor, bgColor, severity);

view->SetHighColor(bgColor);
view->SetLowColor(bgColor);
@@ -77,20 +88,17 @@ EventListItem::DrawItem(BView* view, BRect rect, bool complete)
offset += spacing + colorRect.Width() + 2;

// event time period
rgb_color color;
rgb_color textColor;

float tint = B_NO_TINT;
float lightTime = B_LIGHTEN_2_TINT;
float darkTime = B_DARKEN_3_TINT;

if (IsSelected())
color = ui_color(B_LIST_SELECTED_ITEM_TEXT_COLOR);
textColor = ui_color(B_LIST_SELECTED_ITEM_TEXT_COLOR);
else
color = ui_color(B_LIST_ITEM_TEXT_COLOR);

tint = color.red + color.green + color.blue > 128 * 3
? darkTime : lightTime;
view->SetHighColor(tint_color(color, tint));
textColor = ui_color(B_LIST_ITEM_TEXT_COLOR);
view->SetHighColor(TintColor(textColor, textColor, 1));

view->MovePenTo(offset,
rect.top + timefont.Size() - namefont.Size() + 6 + ((rect.Height()
@@ -102,12 +110,17 @@ EventListItem::DrawItem(BView* view, BRect rect, bool complete)
view->DrawString(timeText.String());

// event name
view->SetHighColor(color);
view->SetHighColor(textColor);

uint16 face = 0;
namefont.SetSize(timefont.Size() + 2);
namefont.GetHeight(&finfo);
if (fEvent->GetStatus() & EVENT_CANCELLED)
namefont.SetFace(0 | B_ITALIC_FACE | B_LIGHT_FACE | B_STRIKEOUT_FACE);
face |= B_ITALIC_FACE;
if (fEvent->GetStatus() & EVENT_DELETED)
face |= B_STRIKEOUT_FACE;
if (face != 0)
namefont.SetFace(face | B_LIGHT_FACE);
view->SetFont(&namefont);

view->MovePenTo(offset, rect.top + ((rect.Height()
@@ -153,6 +166,14 @@ EventListItem::_CalcTimeText(int32 mode)
BDateFormat dateFormat;
BDateTime now = BDateTime::CurrentDateTime(B_LOCAL_TIME);

uint16 status = fEvent->GetStatus();
if (status & EVENT_CANCELLED)
timePeriod << B_TRANSLATE("[Cancelled] ");
if (status & EVENT_HIDDEN)
timePeriod << B_TRANSLATE("[Hidden] ");
if (status & EVENT_DELETED)
timePeriod << B_TRANSLATE("[Deleted] ");

if (fEvent->IsAllDay() == true)
if ((mode & kAgendaView) || (mode & kDateView)) {
dateFormat.Format(startDay, fEvent->GetStartDateTime(),
@@ -162,7 +183,7 @@ EventListItem::_CalcTimeText(int32 mode)
timePeriod << startday;
}
else
timePeriod = B_TRANSLATE("All day");
timePeriod << B_TRANSLATE("All day");
else {
timeFormat.Format(startTime, fEvent->GetStartDateTime(),
B_SHORT_TIME_FORMAT);
@@ -196,8 +217,5 @@ EventListItem::_CalcTimeText(int32 mode)
timePeriod << startTime << " - " << endTime;
}

if (fEvent->GetStatus() & EVENT_CANCELLED)
timePeriod << " [Cancelled]";

fTimeText = timePeriod;
}
46 changes: 26 additions & 20 deletions src/EventTabView.cpp
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
#include <ScrollView.h>
#include <Window.h>

#include "App.h"
#include "Event.h"
#include "EventListItem.h"
#include "EventListView.h"
@@ -71,26 +72,16 @@ EventTabView::MessageReceived(BMessage* message)
return;
bool isCancelled = (event->GetStatus() & EVENT_CANCELLED);
bool isHidden = (event->GetStatus() & EVENT_HIDDEN);
bool isDeleted = (event->GetStatus() & EVENT_DELETED);

BString title(B_TRANSLATE("Confirm delete"));
BString label(B_TRANSLATE("Are you sure you want to move the selected event to Trash?"));
if (message->what == kCancelEventMessage) {
title = B_TRANSLATE("Confirm cancellation");
label = B_TRANSLATE("Are you sure you want to cancel the selected event?");
} else if (message->what == kHideEventMessage) {
title = B_TRANSLATE("Confirm hiding");
label = B_TRANSLATE("Are you sure you want to hide the selected event?\n"
"If you want to unhide it, you'll have to open the event file manually.");
}

// If disabling a previous cancellation or unhiding, the
// confirmation dialogue doesn't really make sense.
// If deleting an event, make sure user's prepared for the
// dire consequences!
int32 button_index = 0;
if (!(message->what == kCancelEventMessage && isCancelled == true)
&& !(message->what == kHideEventMessage && isHidden == true))
{
BAlert* alert = new BAlert(title, label, NULL, B_TRANSLATE("OK"),
B_TRANSLATE("Cancel"), B_WIDTH_AS_USUAL, B_WARNING_ALERT);
if (message->what == kDeleteEventMessage && isDeleted == false) {
BAlert* alert = new BAlert(B_TRANSLATE("Confirm delete"),
B_TRANSLATE("Are you sure you want to move the selected event to Trash?"),
NULL, B_TRANSLATE("OK"), B_TRANSLATE("Cancel"),
B_WIDTH_AS_USUAL, B_WARNING_ALERT);
alert->SetShortcut(1, B_ESCAPE);
button_index = alert->Go();
}
@@ -106,14 +97,27 @@ EventTabView::MessageReceived(BMessage* message)
newEvent.SetStatus(newEvent.GetStatus() | EVENT_HIDDEN);
else if (message->what == kHideEventMessage)
newEvent.SetStatus(newEvent.GetStatus() & ~EVENT_HIDDEN);
else
else if (message->what == kDeleteEventMessage && isDeleted == false)
newEvent.SetStatus(newEvent.GetStatus() | EVENT_DELETED);
else if (message->what == kDeleteEventMessage && isDeleted == true)
newEvent.SetStatus(newEvent.GetStatus() & ~EVENT_DELETED);

fDBManager->UpdateEvent(event, &newEvent);
Window()->LockLooper();
LoadEvents();
Window()->UnlockLooper();
}

if ((message->what == kDeleteEventMessage || message->what == kHideEventMessage)
&& ((App*)be_app)->GetPreferences()->fFirstDeletion == true)
{
((App*)be_app)->GetPreferences()->fFirstDeletion = false;
BAlert* alert = new BAlert(B_TRANSLATE("Managing events"),
B_TRANSLATE("Keep in mind, you can manage deleted and hidden events by "
"toggling \"Show hidden/deleted events\" in the \"View\" menu."),
B_TRANSLATE("OK"));
alert->Go();
}
break;
}
case kChangeListMode: {
@@ -261,8 +265,10 @@ EventTabView::_PopulateList()
if (event == NULL)
continue;

bool hidden = (fMode & kHiddenView);
uint16 eventStatus = event->GetStatus();
if ((eventStatus & EVENT_DELETED) || (eventStatus & EVENT_HIDDEN))
if (hidden == false &&
((eventStatus & EVENT_DELETED) || (eventStatus & EVENT_HIDDEN)))
continue;

EventListItem* item = new EventListItem(event, fMode);
3 changes: 2 additions & 1 deletion src/EventTabView.h
Original file line number Diff line number Diff line change
@@ -28,7 +28,8 @@ const uint32 kListTabChanged = 'ketc';

enum {
kAgendaView = 1,
kDateView = 2
kDateView = 2,
kHiddenView = 4
};

enum {
Loading