Skip to content

Commit

Permalink
Merge branch 'master' into new-logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Beirdo committed May 29, 2011
2 parents d3675b5 + 4bc6b75 commit e1211ae
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 70 deletions.
5 changes: 5 additions & 0 deletions mythtv/libs/libmythui/mythrect.cpp
Expand Up @@ -263,6 +263,7 @@ MythPoint::MythPoint(const QString &sX, const QString &sY)
Init();
setX(sX);
setY(sY);
valid = true;
}

MythPoint::MythPoint(QPoint point)
Expand All @@ -275,6 +276,7 @@ void MythPoint::Init()
{
m_needsUpdate = true;
m_percentX = m_percentY = 0.0;
valid = false;
}

void MythPoint::CalculatePoint(MythRect parentArea)
Expand All @@ -297,6 +299,7 @@ void MythPoint::CalculatePoint(MythRect parentArea)
QPoint::setY(Y);

m_needsUpdate = false;
valid = true;
}

void MythPoint::NormPoint(void)
Expand All @@ -319,6 +322,7 @@ void MythPoint::setX(const QString &sX)
}
else
QPoint::setX(X.toInt());
valid = true;
}

void MythPoint::setY(const QString &sY)
Expand All @@ -332,6 +336,7 @@ void MythPoint::setY(const QString &sY)
}
else
QPoint::setY(Y.toInt());
valid = true;
}

QString MythPoint::getX(void) const
Expand Down
3 changes: 3 additions & 0 deletions mythtv/libs/libmythui/mythrect.h
Expand Up @@ -82,6 +82,7 @@ class MUI_PUBLIC MythPoint : public QPoint
MythPoint(QPoint point);

void Init(void);
bool isValid(void) const { return valid; }
void CalculatePoint(MythRect parentArea);

void NormPoint(void);
Expand All @@ -103,6 +104,8 @@ class MUI_PUBLIC MythPoint : public QPoint
bool m_needsUpdate;

QRect m_parentArea;

bool valid;
};

#endif
132 changes: 89 additions & 43 deletions mythtv/libs/libmythui/mythuitext.cpp
Expand Up @@ -31,6 +31,9 @@ MythUIText::MythUIText(MythUIType *parent, const QString &name)
curR(0.0), curG(0.0), curB(0.0),
incR(0.0), incG(0.0), incB(0.0)
{
m_Initiator = true;
m_usingAltArea = false;
m_ShrinkNarrow = true;
m_MultiLine = false;
m_scrolling = false;
m_scrollDirection = ScrollLeft;
Expand All @@ -55,6 +58,9 @@ MythUIText::MythUIText(const QString &text, const MythFontProperties &font,
curR(0.0), curG(0.0), curB(0.0),
incR(0.0), incG(0.0), incB(0.0)
{
m_Initiator = true;
m_usingAltArea = false;
m_ShrinkNarrow = true;
m_MultiLine = false;
m_scrolling = false;
m_scrollDirection = ScrollLeft;
Expand Down Expand Up @@ -96,7 +102,7 @@ void MythUIText::SetText(const QString &text)

m_Message = newtext;
m_CutMessage.clear();
FillCutMessage();
FillCutMessage(true);

if (m_scrolling)
{
Expand Down Expand Up @@ -163,7 +169,7 @@ void MythUIText::SetFontProperties(const MythFontProperties &fontProps)
{
m_FontStates.insert("default", fontProps);
*m_Font = m_FontStates["default"];
FillCutMessage();
FillCutMessage(false);
SetRedraw();
}

Expand All @@ -174,17 +180,24 @@ void MythUIText::SetFontState(const QString &state)
else
*m_Font = m_FontStates["default"];

FillCutMessage();
FillCutMessage(false);
SetRedraw();
}

void MythUIText::UseAlternateArea(bool useAlt)
{
if (useAlt && m_AltDisplayRect.width() > 1)
{
MythUIType::SetArea(m_AltDisplayRect);
m_usingAltArea = true;
}
else
{
MythUIType::SetArea(m_OrigDisplayRect);
FillCutMessage();
m_usingAltArea = false;
}

FillCutMessage(false);
}

void MythUIText::SetJustification(int just)
Expand All @@ -194,7 +207,7 @@ void MythUIText::SetJustification(int just)
// preserve the wordbreak attribute, drop everything else
m_Justification = m_Justification & Qt::TextWordWrap;
m_Justification |= just;
FillCutMessage();
FillCutMessage(false);
SetRedraw();
}
}
Expand All @@ -207,7 +220,7 @@ int MythUIText::GetJustification(void)
void MythUIText::SetCutDown(bool cut)
{
m_Cutdown = cut;
FillCutMessage();
FillCutMessage(false);
SetRedraw();
}

Expand All @@ -218,7 +231,7 @@ void MythUIText::SetMultiLine(bool multiline)
m_Justification |= Qt::TextWordWrap;
else
m_Justification &= ~Qt::TextWordWrap;
FillCutMessage();
FillCutMessage(false);
SetRedraw();
}

Expand All @@ -234,7 +247,7 @@ void MythUIText::SetArea(const MythRect &rect)
QSize stringSize = fm.size(Qt::TextSingleLine, m_Message);
SetDrawRectSize(stringSize.width(), m_Area.height());
}
FillCutMessage();
FillCutMessage(false);
}

void MythUIText::SetPosition(const MythPoint &pos)
Expand Down Expand Up @@ -363,7 +376,7 @@ bool MythUIText::MakeNarrow(QRect &min_rect)

if (min_width == INT_MAX)
{
// won't fit, even when the ara is the maxium size
// won't fit, even when the area is the maxium size
min_rect = fm.boundingRect(m_Area, m_Justification, m_CutMessage);
return false;
}
Expand All @@ -380,7 +393,21 @@ bool MythUIText::MakeNarrow(QRect &min_rect)
}
}

void MythUIText::FillCutMessage()
/*
* If minsize and multiline are defined, minimize the height by using
* as many columns as possible.
*/
bool MythUIText::MakeShort(QRect &min_rect)
{
QFontMetrics fm(GetFontProperties()->face());

min_rect = fm.boundingRect(m_Area, m_Justification, m_CutMessage);
min_rect.setWidth(m_Area.width());

return true;
}

void MythUIText::FillCutMessage(bool reset_size)
{
m_CutMessage.clear();

Expand All @@ -405,47 +432,60 @@ void MythUIText::FillCutMessage()

if (m_CutMessage.isEmpty())
m_CutMessage = m_Message;
if (m_CutMessage.isEmpty())

if (!reset_size && m_CutMessage.isEmpty())
return;

QStringList templist;
QStringList::iterator it;
switch (m_textCase)
{
case CaseUpper :
m_CutMessage = m_CutMessage.toUpper();
break;
case CaseLower :
m_CutMessage = m_CutMessage.toLower();
break;
case CaseCapitaliseFirst :
//m_CutMessage = m_CutMessage.toLower();
templist = m_CutMessage.split(". ");
for (it = templist.begin(); it != templist.end(); ++it)
(*it).replace(0,1,(*it).left(1).toUpper());
m_CutMessage = templist.join(". ");
break;
case CaseCapitaliseAll :
//m_CutMessage = m_CutMessage.toLower();
templist = m_CutMessage.split(" ");
for (it = templist.begin(); it != templist.end(); ++it)
(*it).replace(0,1,(*it).left(1).toUpper());
m_CutMessage = templist.join(" ");
break;
}

if (m_MinSize.x() > 0)
if (!m_CutMessage.isEmpty())
{

QStringList templist;
QStringList::iterator it;
switch (m_textCase)
{
case CaseUpper :
m_CutMessage = m_CutMessage.toUpper();
break;
case CaseLower :
m_CutMessage = m_CutMessage.toLower();
break;
case CaseCapitaliseFirst :
//m_CutMessage = m_CutMessage.toLower();
templist = m_CutMessage.split(". ");
for (it = templist.begin(); it != templist.end(); ++it)
(*it).replace(0,1,(*it).left(1).toUpper());
m_CutMessage = templist.join(". ");
break;
case CaseCapitaliseAll :
//m_CutMessage = m_CutMessage.toLower();
templist = m_CutMessage.split(" ");
for (it = templist.begin(); it != templist.end(); ++it)
(*it).replace(0,1,(*it).left(1).toUpper());
m_CutMessage = templist.join(" ");
break;
}
}

if (m_MinSize.isValid())
{
QRect rect;
MakeNarrow(rect);

if (!m_CutMessage.isEmpty())
{
if (m_ShrinkNarrow)
MakeNarrow(rect);
else
MakeShort(rect);
}

// Record the minimal area needed for the message.
SetMinArea(rect.size());
if (m_MinArea.width() > 0)

if (m_MinArea.isValid())
SetDrawRectSize(m_MinArea.width(), m_MinArea.height());
}

if (m_Cutdown)
if (m_Cutdown && !m_CutMessage.isEmpty())
m_CutMessage = cutDown(m_CutMessage, m_Font, m_MultiLine);
}

Expand Down Expand Up @@ -648,6 +688,11 @@ bool MythUIText::ParseElement(
{
m_TemplateText = parseText(element);
}
else if (element.tagName() == "shrink")
{
// When minsize is used, select if are should be made narrow or short
m_ShrinkNarrow = (parseText(element).toLower() != "short");
}
else if (element.tagName() == "cutdown")
{
SetCutDown(parseBool(element));
Expand Down Expand Up @@ -719,7 +764,7 @@ bool MythUIText::ParseElement(
m_textCase = CaseCapitaliseAll;
else
m_textCase = CaseNormal;
FillCutMessage();
FillCutMessage(true);
}
else
{
Expand Down Expand Up @@ -748,6 +793,7 @@ void MythUIText::CopyFrom(MythUIType *base)
m_CutMessage = text->m_CutMessage;
m_TemplateText = text->m_TemplateText;

m_ShrinkNarrow = text->m_ShrinkNarrow;
m_Cutdown = text->m_Cutdown;
m_MultiLine = text->m_MultiLine;

Expand Down Expand Up @@ -788,6 +834,6 @@ void MythUIText::CreateCopy(MythUIType *parent)

void MythUIText::Finalize(void)
{
FillCutMessage();
FillCutMessage(true);
}

5 changes: 4 additions & 1 deletion mythtv/libs/libmythui/mythuitext.h
Expand Up @@ -84,7 +84,8 @@ class MUI_PUBLIC MythUIText : public MythUIType, public StorageUser
void MoveDrawRect(const int x, const int y);

bool MakeNarrow(QRect &min_rect);
void FillCutMessage(void);
bool MakeShort(QRect &min_rect);
void FillCutMessage(bool reset_size = false);
QString cutDown(const QString &data, MythFontProperties *font,
bool multiline = false);

Expand All @@ -98,6 +99,8 @@ class MUI_PUBLIC MythUIText : public MythUIType, public StorageUser
QString m_DefaultMessage;
QString m_TemplateText;

bool m_usingAltArea;
bool m_ShrinkNarrow;
bool m_Cutdown;
bool m_MultiLine;

Expand Down

0 comments on commit e1211ae

Please sign in to comment.