Refactor cRecMenuConfirmTimer

This commit is contained in:
kamel5 2019-11-09 11:22:02 +01:00
parent 9565eda1aa
commit ce690366f8
5 changed files with 71 additions and 25 deletions

View File

@ -94,6 +94,18 @@ void cRecMenu::CreatePixmap(void) {
pixmapScrollBar = NULL; pixmapScrollBar = NULL;
} }
void cRecMenu::AddHeader(cRecMenuItem *header) {
this->header = header;
headerHeight = header->GetHeight();
height += headerHeight;
}
void cRecMenu::AddFooter(cRecMenuItem *footer) {
this->footer = footer;
footerHeight = footer->GetHeight();
height += footerHeight;
}
void cRecMenu::SetHeader(cRecMenuItem *header) { void cRecMenu::SetHeader(cRecMenuItem *header) {
this->header = header; this->header = header;
headerHeight = header->GetHeight(); headerHeight = header->GetHeight();

View File

@ -37,6 +37,8 @@ protected:
int CalculateOptimalWidth(void); int CalculateOptimalWidth(void);
bool CalculateHeight(bool reDraw = false); bool CalculateHeight(bool reDraw = false);
void CreatePixmap(void); void CreatePixmap(void);
void AddHeader(cRecMenuItem *header);
void AddFooter(cRecMenuItem *footer);
void SetHeader(cRecMenuItem *header); void SetHeader(cRecMenuItem *header);
void SetFooter(cRecMenuItem *footer); void SetFooter(cRecMenuItem *footer);
void ClearMenuItems(bool destructor = false); void ClearMenuItems(bool destructor = false);

View File

@ -266,15 +266,41 @@ cRecMenuItemInfo::cRecMenuItemInfo(const char *text, bool largeFont) {
selectable = false; selectable = false;
active = false; active = false;
this->text = text; this->text = text;
this->line1 = "";
this->line2 = "";
this->line3 = "";
this->line4 = "";
this->numLines = 1;
fontInfo = (largeFont) ? fontLarge : font; fontInfo = (largeFont) ? fontLarge : font;
border = 10; border = 10;
} }
cRecMenuItemInfo::cRecMenuItemInfo(std::string line1, int numLines, std::string line2, std::string line3, std::string line4, int width, bool largeFont) {
selectable = false;
fontInfo = (largeFont) ? fontLarge : font;
border = 10;
this->numLines = numLines;
this->line2 = line2;
this->line3 = line3;
this->line4 = line4;
if (numLines == 1) {
this->line1 = line1;
} else if (numLines == 2) {
this->line1 = cString::sprintf("%s\n%s", line1.c_str(), line2.c_str());
} else if (numLines == 3) {
this->line1 = cString::sprintf("%s\n%s\n%s", line1.c_str(), line2.c_str(), line3.c_str());
} else if (numLines == 4) {
this->line1 = cString::sprintf("%s\n%s\n%s\n%s", line1.c_str(), line2.c_str(), line3.c_str(), line4.c_str());
}
this->active = false;
CalculateHeight(width);
}
cRecMenuItemInfo::~cRecMenuItemInfo(void) { cRecMenuItemInfo::~cRecMenuItemInfo(void) {
} }
void cRecMenuItemInfo::CalculateHeight(int textWidth) { void cRecMenuItemInfo::CalculateHeight(int textWidth) {
wrapper.Set(*text, fontInfo, textWidth); wrapper.Set((line1 == "") ? *text : line1.c_str(), fontInfo, textWidth);
height = fontInfo->Height() * wrapper.Lines() + 2 * border; height = fontInfo->Height() * wrapper.Lines() + 2 * border;
} }

View File

@ -175,12 +175,18 @@ public:
// --- cRecMenuItemInfo ------------------------------------------------------- // --- cRecMenuItemInfo -------------------------------------------------------
class cRecMenuItemInfo : public cRecMenuItem { class cRecMenuItemInfo : public cRecMenuItem {
private: private:
int numLines;
cString text; cString text;
std::string line1;
std::string line2;
std::string line3;
std::string line4;
cTextWrapper wrapper; cTextWrapper wrapper;
int border; int border;
const cFont *fontInfo; const cFont *fontInfo;
public: public:
cRecMenuItemInfo(const char *text, bool largeFont = false); cRecMenuItemInfo(const char *text, bool largeFont = false);
cRecMenuItemInfo(std::string line1, int numLines = 1, std::string line2 = "", std::string line3 = "", std::string line4 = "", int width = 80, bool largeFont = false);
virtual ~cRecMenuItemInfo(void); virtual ~cRecMenuItemInfo(void);
void setBackground(void); void setBackground(void);
void CalculateHeight(int textWidth); void CalculateHeight(int textWidth);

View File

@ -104,14 +104,9 @@ std::string cRecMenuAskFolder::GetFolder(void) {
} }
// --- cRecMenuConfirmTimer --------------------------------------------------------- // --- cRecMenuConfirmTimer ---------------------------------------------------------
cRecMenuConfirmTimer::cRecMenuConfirmTimer(const cEvent *event, bool timerChanged) { cRecMenuConfirmTimer::cRecMenuConfirmTimer(const cEvent *event, bool timerChanged) { // OK
SetWidthPercent(50); SetWidthPercent(50);
#if VDRVERSNUM >= 20301
LOCK_CHANNELS_READ;
const cString channelName = Channels->GetByChannelID(event->ChannelID())->Name();
#else
const cString channelName = Channels.GetByChannelID(event->ChannelID())->Name();
#endif
bool eventHasTimer = false; bool eventHasTimer = false;
if (config.useRemoteTimers && pRemoteTimers) { if (config.useRemoteTimers && pRemoteTimers) {
RemoteTimers_GetMatch_v1_0 rtMatch; RemoteTimers_GetMatch_v1_0 rtMatch;
@ -123,21 +118,26 @@ cRecMenuConfirmTimer::cRecMenuConfirmTimer(const cEvent *event, bool timerChange
} else { } else {
eventHasTimer = event->HasTimer(); eventHasTimer = event->HasTimer();
} }
const cString message = (eventHasTimer) ? (timerChanged) ? tr("Timer changed")
const cChannels *channels = NULL;
#if VDRVERSNUM >= 20301
{
LOCK_CHANNELS_READ;
channels = Channels;
}
#else
channels = &Channels;
#endif
const cString channelName = channels->GetByChannelID(event->ChannelID())->Name();
const cString line1 = (eventHasTimer) ? (timerChanged) ? tr("Timer changed")
: tr("Timer created") : tr("Timer created")
: tr("Timer NOT created"); : tr("Timer NOT created");
cString text = cString::sprintf("%s\n%s\n%s %s - %s\n%s", const cString line3 = cString::sprintf("%s %s - %s", *event->GetDateString(), *event->GetTimeString(), *event->GetEndTimeString());
*message, const cString line4 = (event && event->Title()) ? cString::sprintf("\"%s\"", event->Title()) : "";
*channelName,
*event->GetDateString(), AddHeader(new cRecMenuItemInfo(*line1, 4, *channelName, *line3, *line4, width - 2 * border));
*event->GetTimeString(), AddFooter(new cRecMenuItemButton(tr("OK"), rmsClose, true, true));
*event->GetEndTimeString(),
event->Title()
);
cRecMenuItemInfo *infoItem = new cRecMenuItemInfo(*text);
infoItem->CalculateHeight(width - 2 * border);
AddMenuItem(infoItem);
AddMenuItem(new cRecMenuItemButton(tr("OK"), rmsClose, true, true));
CalculateHeight(); CalculateHeight();
CreatePixmap(); CreatePixmap();
Arrange(); Arrange();