display haxx0red teams colors correctly.
authorsheepluva
Tue, 01 May 2012 11:39:11 +0200
changeset 6970 59f33a6a4814
parent 6969 3273a2b983ca
child 6971 b7b38e051b5f
display haxx0red teams colors correctly. also got rid of some casts and std:: iteration stuff
QTfrontend/ui/widget/frameTeam.cpp
QTfrontend/ui/widget/frameTeam.h
QTfrontend/ui/widget/teamselhelper.cpp
QTfrontend/ui/widget/teamselhelper.h
--- 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<QColor>::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)
--- 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<QColor> availableColors;
-        QList<QColor>::Iterator currentColor;
+        QColor currentColor;
 
         void emitTeamColorChanged(const HWTeam& team);
 
--- 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<FrameTeams*>(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<FrameTeams*>(parentWidget());
-    QColor color;
-    if(pOurFrameTeams->currentColor==pOurFrameTeams->availableColors.begin())
-        pOurFrameTeams->currentColor=pOurFrameTeams->availableColors.end()-1;
-    else --pOurFrameTeams->currentColor;
-    color=*pOurFrameTeams->currentColor;
+    const QList<QColor> & 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<FrameTeams*>(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);
--- 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: