From bdc05156983bccd8f7ad725c612280a46b612876 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Sat, 18 Jun 2016 23:33:21 +0100 Subject: [PATCH] Initial version of the XCCalendarDayEntry widget Basic version. Will be changed as progress is made on Xestia Calendar. --- source/widgets/XCCalendarDayEntry.cpp | 232 ++++++++++++++++++++++++++ source/widgets/XCCalendarDayEntry.h | 78 +++++++++ 2 files changed, 310 insertions(+) create mode 100644 source/widgets/XCCalendarDayEntry.cpp create mode 100644 source/widgets/XCCalendarDayEntry.h diff --git a/source/widgets/XCCalendarDayEntry.cpp b/source/widgets/XCCalendarDayEntry.cpp new file mode 100644 index 0000000..f5f31b4 --- /dev/null +++ b/source/widgets/XCCalendarDayEntry.cpp @@ -0,0 +1,232 @@ +// XCCalendarDayEntry.cpp - Xestia Calendar XCCalendarDayEntry widget class. +// +// (c) 2016 Xestia Software Development. +// +// This file is part of Xestia Calendar. +// +// Xestia Address Book is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by the +// Free Software Foundation, version 3 of the license. +// +// Xestia Address Book is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with Xestia Calendar. If not, see + +#include "XCCalendarDayEntry.h" + +BEGIN_EVENT_TABLE(XCCalendarDayEntry, wxPanel) +EVT_PAINT(XCCalendarDayEntry::PaintFrameEvent) +EVT_SIZE(XCCalendarDayEntry::ResizeFrameEvent) +EVT_LEFT_DOWN(XCCalendarDayEntry::LeftClick) +END_EVENT_TABLE() + +using namespace std; + +XCCalendarDayEntry::XCCalendarDayEntry(wxWindow* parent, const wxString& title, const wxPoint& pos, const wxSize& size, const int id) + : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title) +{ + + Connect(wxID_ANY, XCCALENDARDAYENTRY_DESELECT, wxCommandEventHandler(XCCalendarDayEntry::Deselect)); + + DayPanel = parent->GetParent(); + EntryID = id; + + this->SetMinSize(wxSize(65, 30)); + + EventTextData = title.mb_str(); + EventText = new wxStaticText(this, wxID_ANY, title, wxPoint(49, 8), wxDefaultSize, wxST_ELLIPSIZE_END); + + AlarmIconBitmap.LoadFile("AlertIcon.png", wxBITMAP_DEFAULT_TYPE); + PriorityIconBitmap.LoadFile("PriorityIcon.png", wxBITMAP_DEFAULT_TYPE); + + AlarmIcon->SetBitmap(AlarmIconBitmap); + HighPriorityIcon->SetBitmap(PriorityIconBitmap); + + UpdateInformation(); + +} + +XCCalendarDayEntry::~XCCalendarDayEntry(){ + + // Destory the controls from the widget. + +} + +void XCCalendarDayEntry::Repaint(){ + + wxPaintDC dc(this); + + // Get the wxSizerItem for the top date and the entries part. + + dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT)); + + /*wxRect Test; + + Test.SetX(this->GetClientRect().GetX()); + Test.SetY(this->GetClientRect().GetY()); + Test.SetHeight(this->GetClientRect().GetHeight()); + Test.SetWidth(this->GetClientRect().GetWidth()); + + cout << Test.GetX() << "|" << Test.GetY() << "|" << Test.GetHeight() << "|" << Test.GetWidth() << "|" << endl;*/ + + dc.DrawRectangle(this->GetClientRect()); + + // Draw the calendar colour. + + dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT)); + dc.SetBrush(wxBrush(wxColor(EntryColour.red, + EntryColour.green, + EntryColour.blue), wxBRUSHSTYLE_SOLID)); + dc.DrawRectangle(wxRect(1,1,10,28)); + +} + +void XCCalendarDayEntry::UpdateInformation(){ + + PositionMode = 0; + + // Check if the high priority icon needs to be displayed. + + if (HasHighPriority == true){ + + HighPriorityIcon->SetPosition(wxPoint(FirstPosition,7)); + + HighPriorityIcon->Show(true); + + PositionMode++; + + } else { + + HighPriorityIcon->Show(false); + + } + + // Check if the alarm icon needs to be displayed. + + if (HasAlarm == true){ + + switch(PositionMode){ + case 0: + AlarmIcon->SetPosition(wxPoint(FirstPosition,7)); + break; + case 1: + AlarmIcon->SetPosition(wxPoint(SecondPosition,7)); + break; + } + + AlarmIcon->Show(true); + + PositionMode++; + + } else { + + AlarmIcon->Show(false); + + } + + // Now set the text. + + switch(PositionMode){ + case 0: + EventText->SetPosition(wxPoint(FirstPosition,8)); + break; + case 1: + EventText->SetPosition(wxPoint(SecondPosition,8)); + break; + case 2: + EventText->SetPosition(wxPoint(ThirdPosition,8)); + break; + } + +} + +void XCCalendarDayEntry::PaintFrameEvent(wxPaintEvent &PaintEvent) +{ + + Repaint(); + +} + +void XCCalendarDayEntry::ResizeFrameEvent(wxSizeEvent &SizeEvent) +{ + + // Adjust the Event text so it is displayed properly. + + switch(PositionMode){ + case 0: + EventText->SetSize(wxSize((this->GetClientRect().width - FirstPosition - 5),15)); + break; + case 1: + EventText->SetSize(wxSize((this->GetClientRect().width - SecondPosition - 5),15)); + break; + case 2: + EventText->SetSize(wxSize((this->GetClientRect().width - ThirdPosition - 5),15)); + break; + } + + // Refresh the window. + + this->Refresh(); + +} + +void XCCalendarDayEntry::LeftClick(wxMouseEvent &MouseEvent) +{ + + // Change the background of the widget to mark + // the entry as selected. + + this->SetBackgroundColour(wxColor(255,215,0)); + wxCommandEvent DeselectOthersEvent(XCCALENDARDAY_DESELECTOTHERENTRIES); + DeselectOthersEvent.SetInt(EntryID); + wxPostEvent(DayPanel, DeselectOthersEvent); + +} + +void XCCalendarDayEntry::Deselect(wxCommandEvent &DeselectEvent){ + + this->SetBackgroundColour(wxNullColour); + +} + +void XCCalendarDayEntry::SetColour(Colour *ColourIn){ + + EntryColour = *ColourIn; + +} + +void XCCalendarDayEntry::SetDisplayAlarm(bool DisplayValue){ + + HasAlarm = DisplayValue; + UpdateInformation(); + +} + +void XCCalendarDayEntry::SetDisplayHighPriority(bool DisplayValue){ + + HasHighPriority = DisplayValue; + UpdateInformation(); + +} + +bool XCCalendarDayEntry::GetDisplayAlarm(){ + + return HasAlarm; + +} + +bool XCCalendarDayEntry::GetDisplayHighPriority(){ + + return HasHighPriority; + +} + +int XCCalendarDayEntry::GetID(){ + + return EntryID; + +} \ No newline at end of file diff --git a/source/widgets/XCCalendarDayEntry.h b/source/widgets/XCCalendarDayEntry.h new file mode 100644 index 0000000..de30c90 --- /dev/null +++ b/source/widgets/XCCalendarDayEntry.h @@ -0,0 +1,78 @@ +// XCCalendarDayEntry.h - Xestia Calendar XCCalendarDayEntry widget class. +// +// (c) 2016 Xestia Software Development. +// +// This file is part of Xestia Calendar. +// +// Xestia Address Book is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by the +// Free Software Foundation, version 3 of the license. +// +// Xestia Address Book is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with Xestia Calendar. If not, see + +#ifndef __WIDGETS_XCCALENDARDAYENTRY_H__ +#define __WIDGETS_XCCALENDARDAYENTRY_H__ + +#include +#include "../common/colour.h" +#include "../common/text.h" +#include "../common/events.h" + +enum XCCalendarDayEntryMode { + XCCALENDARDAYENTRY_NORMAL, + XCCALENDARDAYENTRY_SMALL, +}; + +class XCCalendarDayEntry: public wxPanel +{ + + private: + wxWindow *DayPanel = nullptr; + string EventTextData = ""; + wxStaticText *EventText = nullptr; + wxStaticBitmap *HighPriorityIcon = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxPoint(14,7), wxDefaultSize, 0 ); + wxStaticBitmap *AlarmIcon = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxPoint(30,7), wxDefaultSize, 0 ); + wxBitmap AlarmIconBitmap; + wxBitmap PriorityIconBitmap; + + Colour EntryColour; + + bool HasAlarm = false; + bool HasHighPriority = false; + int PositionMode = 0; + int EntryID = 0; + const int FirstPosition = 14; + const int SecondPosition = 30; + const int ThirdPosition = 49; + + void Repaint(); + void RepaintSelected(); + + void UpdateInformation(); + + public: + XCCalendarDayEntry(wxWindow* parent, const wxString& title, const wxPoint& pos, const wxSize& size, const int id); + ~XCCalendarDayEntry(); + + void PaintFrameEvent(wxPaintEvent &PaintEvent); + void ResizeFrameEvent(wxSizeEvent &SizeEvent); + void LeftClick(wxMouseEvent &MouseEvent); + void Deselect(wxCommandEvent &DeselectEvent); + + void SetColour(Colour *ColourIn); + void SetDisplayAlarm(bool DisplayValue); + void SetDisplayHighPriority(bool DisplayValue); + int GetID(); + bool GetDisplayAlarm(); + bool GetDisplayHighPriority(); + + DECLARE_EVENT_TABLE() +}; + +#endif \ No newline at end of file -- 2.39.5