# HG changeset patch # User sheepluva # Date 1335865151 -7200 # Node ID 59f33a6a4814a625c5fe2bb92087dd56b21bf696 # Parent 3273a2b983ca5db882a482ee137b79c0b479a944 display haxx0red teams colors correctly. also got rid of some casts and std:: iteration stuff diff -r 3273a2b983ca -r 59f33a6a4814 QTfrontend/ui/widget/frameTeam.cpp --- a/QTfrontend/ui/widget/frameTeam.cpp Tue May 01 00:22:10 2012 +0200 +++ b/QTfrontend/ui/widget/frameTeam.cpp Tue May 01 11:39:11 2012 +0200 @@ -56,15 +56,16 @@ void FrameTeams::resetColors() { - currentColor=availableColors.end() - 1; // ensure next color is the first one + currentColor = availableColors.last(); // ensure next color is the first one } QColor FrameTeams::getNextColor() const { - QList::ConstIterator nextColor=currentColor; - ++nextColor; - if (nextColor==availableColors.end()) nextColor=availableColors.begin(); - return *nextColor; + int idx = availableColors.indexOf(currentColor); + + idx = ++idx % availableColors.size(); + + return availableColors.at(idx); } void FrameTeams::addTeam(HWTeam team, bool willPlay) diff -r 3273a2b983ca -r 59f33a6a4814 QTfrontend/ui/widget/frameTeam.h --- a/QTfrontend/ui/widget/frameTeam.h Tue May 01 00:22:10 2012 +0200 +++ b/QTfrontend/ui/widget/frameTeam.h Tue May 01 11:39:11 2012 +0200 @@ -55,7 +55,7 @@ const int maxHedgehogsPerGame; int overallHedgehogs; QList availableColors; - QList::Iterator currentColor; + QColor currentColor; void emitTeamColorChanged(const HWTeam& team); diff -r 3273a2b983ca -r 59f33a6a4814 QTfrontend/ui/widget/teamselhelper.cpp --- a/QTfrontend/ui/widget/teamselhelper.cpp Tue May 01 00:22:10 2012 +0200 +++ b/QTfrontend/ui/widget/teamselhelper.cpp Tue May 01 11:39:11 2012 +0200 @@ -32,10 +32,11 @@ emit teamActivated(text()); } -TeamShowWidget::TeamShowWidget(HWTeam team, bool isPlaying, QWidget * parent) : +TeamShowWidget::TeamShowWidget(HWTeam team, bool isPlaying, FrameTeams * parent) : QWidget(parent), mainLayout(this), m_team(team), m_isPlaying(isPlaying), phhoger(0), colorButt(0) { + m_parentFrameTeams = parent; QPalette newPalette = palette(); newPalette.setColor(QPalette::Window, QColor(0x00, 0x00, 0x00)); setPalette(newPalette); @@ -129,43 +130,31 @@ void TeamShowWidget::incrementTeamColor() { - FrameTeams* pOurFrameTeams=dynamic_cast(parentWidget()); - QColor color; - if(++pOurFrameTeams->currentColor==pOurFrameTeams->availableColors.end()) - pOurFrameTeams->currentColor=pOurFrameTeams->availableColors.begin(); - color=*pOurFrameTeams->currentColor; - - changeTeamColor(color); + changeTeamColor(m_parentFrameTeams->getNextColor()); } void TeamShowWidget::decrementTeamColor() { - FrameTeams* pOurFrameTeams=dynamic_cast(parentWidget()); - QColor color; - if(pOurFrameTeams->currentColor==pOurFrameTeams->availableColors.begin()) - pOurFrameTeams->currentColor=pOurFrameTeams->availableColors.end()-1; - else --pOurFrameTeams->currentColor; - color=*pOurFrameTeams->currentColor; + const QList & availColors = m_parentFrameTeams->availableColors; + int idx = availColors.indexOf(m_parentFrameTeams->currentColor); + + idx--; - changeTeamColor(color); + if (idx < 0) + idx = availColors.size() - 1; + + changeTeamColor(availColors.at(idx)); } void TeamShowWidget::changeTeamColor(QColor color) { - FrameTeams* pOurFrameTeams=dynamic_cast(parentWidget()); - // set according color iterator - pOurFrameTeams->currentColor=std::find(pOurFrameTeams->availableColors.begin(), - pOurFrameTeams->availableColors.end(), color); - if(pOurFrameTeams->currentColor==pOurFrameTeams->availableColors.end()) - { - // error condition - pOurFrameTeams->currentColor=pOurFrameTeams->availableColors.begin(); - } + QColor & curColor = m_parentFrameTeams->currentColor; + curColor = color; colorButt->setStyleSheet(QString("QPushButton{" "background-color: %1;" "border-width: 1px;" "border-radius: 2px;" - "}").arg(pOurFrameTeams->currentColor->name())); + "}").arg(curColor.name())); m_team.setColor(color); emit teamColorChanged(m_team); diff -r 3273a2b983ca -r 59f33a6a4814 QTfrontend/ui/widget/teamselhelper.h --- a/QTfrontend/ui/widget/teamselhelper.h Tue May 01 00:22:10 2012 +0200 +++ b/QTfrontend/ui/widget/teamselhelper.h Tue May 01 11:39:11 2012 +0200 @@ -57,7 +57,7 @@ void activateTeam(); public: - TeamShowWidget(HWTeam team, bool isPlaying, QWidget * parent); + TeamShowWidget(HWTeam team, bool isPlaying, FrameTeams * parent); void setPlaying(bool isPlaying); void setHHNum(unsigned int num); void setInteractivity(bool interactive); @@ -71,6 +71,7 @@ CHedgehogerWidget* phhoger; QPushButton* colorButt; QPushButton* butt; + FrameTeams * m_parentFrameTeams; // QPushButton* bText; signals: