Scroll added to team control widget
authordisplacer
Fri, 24 Feb 2006 16:06:12 +0000
changeset 63 27e2b5bb6d4b
parent 62 c3eda0c68cd6
child 64 9df467527ae5
Scroll added to team control widget
QTfrontend/frameTeam.cpp
QTfrontend/frameTeam.h
QTfrontend/hedgewars.pro
QTfrontend/teamselect.cpp
QTfrontend/teamselect.h
QTfrontend/teamselhelper.cpp
QTfrontend/vertScrollArea.cpp
QTfrontend/vertScrollArea.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/frameTeam.cpp	Fri Feb 24 16:06:12 2006 +0000
@@ -0,0 +1,39 @@
+#include "frameTeam.h"
+#include "teamselhelper.h"
+
+#include <QResizeEvent>
+#include <QCoreApplication>
+
+#include <iostream>
+using namespace std;
+
+FrameTeams::FrameTeams(QWidget* parent) :
+  QWidget(parent), mainLayout(this)
+{
+}
+
+void FrameTeams::addTeam(tmprop team)
+{
+  TeamShowWidget* pTeamShowWidget =new TeamShowWidget(team, this);
+  int hght=teamToWidget.empty() ? 0 : teamToWidget.begin()->second->size().height();
+  teamToWidget.insert(make_pair(team, pTeamShowWidget));
+  mainLayout.addWidget(pTeamShowWidget);
+  QResizeEvent* pevent=new QResizeEvent(parentWidget()->size(), parentWidget()->size());
+  QCoreApplication::postEvent(parentWidget(), pevent);
+}
+
+void FrameTeams::removeTeam(tmprop team)
+{
+  tmapTeamToWidget::iterator it=teamToWidget.find(team);
+  mainLayout.removeWidget(it->second);
+  delete it->second;
+  teamToWidget.erase(team);
+}
+
+QWidget* FrameTeams::getTeamWidget(tmprop team)
+{
+  tmapTeamToWidget::iterator it=teamToWidget.find(team);
+  QWidget* ret = it!=teamToWidget.end() ? it->second : 0;
+  if(!ret) throw; // FIXME: this is debug exception
+  return ret;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/frameTeam.h	Fri Feb 24 16:06:12 2006 +0000
@@ -0,0 +1,27 @@
+#ifndef _FRAME_TEAM_INCLUDED
+#define _FRAME_TEAM_INCLUDED
+
+#include <QWidget>
+
+#include "teamselect.h"
+#include <map>
+
+class FrameTeams : public QWidget
+{
+  Q_OBJECT
+
+ public:
+  FrameTeams(QWidget* parent=0);
+  QWidget* getTeamWidget(tmprop team);
+
+ public slots:
+  void addTeam(tmprop team);
+  void removeTeam(tmprop team);
+
+ private:
+  QVBoxLayout mainLayout;
+  typedef map<tmprop, QWidget*> tmapTeamToWidget;
+  tmapTeamToWidget teamToWidget;
+};
+
+#endif // _FRAME_TAM_INCLUDED
--- a/QTfrontend/hedgewars.pro	Sun Feb 05 18:51:54 2006 +0000
+++ b/QTfrontend/hedgewars.pro	Fri Feb 24 16:06:12 2006 +0000
@@ -19,7 +19,9 @@
            sha1.h \
            netclient.h \
            teamselect.h \
-           teamselhelper.h 
+           teamselhelper.h \
+           frameTeam.h \
+           vertScrollArea.h
            
 FORMS += hwform.ui
 
@@ -31,8 +33,10 @@
            sha1.cpp \
            netclient.cpp \
            teamselect.cpp \
-           teamselhelper.cpp
+           teamselhelper.cpp \
+           frameTeam.cpp \
+           vertScrollArea.cpp
 
 TRANSLATIONS += translations/hedgewars_ru.ts
 
-RESOURCES += hedgewars.qrc
\ No newline at end of file
+RESOURCES += hedgewars.qrc
--- a/QTfrontend/teamselect.cpp	Sun Feb 05 18:51:54 2006 +0000
+++ b/QTfrontend/teamselect.cpp	Fri Feb 24 16:06:12 2006 +0000
@@ -1,26 +1,26 @@
 #include <QLabel>
 #include <QPixmap>
 #include <QPushButton>
+#include <QFrame>
 
 #include <algorithm>
 
+#include <vertScrollArea.h>
 #include "teamselect.h"
 #include "teamselhelper.h"
+#include "frameTeam.h"
 
 void TeamSelWidget::addTeam(tmprop team)
 {
+  frameDontPlaying->addTeam(team);
   curDontPlayingTeams.push_back(team);
-  TeamShowWidget* pTeamShowWidget =new TeamShowWidget(team);
-  dontPlayingLayout->addWidget(pTeamShowWidget);
-
-  teamToWidget.insert(make_pair(team, pTeamShowWidget));
-
-  QObject::connect(pTeamShowWidget, SIGNAL(teamStatusChanged(tmprop)), this, SLOT(changeTeamStatus(tmprop)));
+  QObject::connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(tmprop)), 
+		   this, SLOT(changeTeamStatus(tmprop)));
 }
 
 void TeamSelWidget::removeTeam(tmprop team)
 {
-  curDontPlayingTeams.erase(std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team));
+  //curDontPlayingTeams.erase(std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team));
 }
 
 void TeamSelWidget::changeTeamStatus(tmprop team)
@@ -38,38 +38,32 @@
     curDontPlayingTeams.erase(itDontPlay);
   }
 
-  QGridLayout* pRemoveGrid;
-  QGridLayout* pAddGrid;
-  QWidget* newParent;
+  FrameTeams* pRemoveTeams;
+  FrameTeams* pAddTeams;
   if(itDontPlay==curDontPlayingTeams.end()) {
-    pRemoveGrid=playingLayout;
-    pAddGrid=dontPlayingLayout;
-    newParent=dontPlayingColorFrame;
+    pRemoveTeams=framePlaying;
+    pAddTeams=frameDontPlaying;
   } else {
-    pRemoveGrid=dontPlayingLayout;
-    pAddGrid=playingLayout;
-    newParent=playingColorFrame;
+    pRemoveTeams=frameDontPlaying;
+    pAddTeams=framePlaying;
   }
 
-  pRemoveGrid->removeWidget(teamToWidget[team]);
-  teamToWidget[team]->setParent(newParent);
-  pAddGrid->addWidget(teamToWidget[team]);
+  pAddTeams->addTeam(team);
+  pRemoveTeams->removeTeam(team);
+}
+
+void TeamSelWidget::addScrArea(FrameTeams* pfteams, QColor color)
+{
+  VertScrArea* area=new VertScrArea(color);
+  area->setWidget(pfteams);
+  mainLayout.addWidget(area, 50);
 }
 
 TeamSelWidget::TeamSelWidget(QWidget* parent) :
   QWidget(parent), mainLayout(this)
 {
-  playingColorFrame = new QFrame;
-  QPalette newPalette = palette();
-  newPalette.setColor(QPalette::Background, QColor("DarkTurquoise"));
-  playingColorFrame->setPalette(newPalette);
-  mainLayout.addWidget(playingColorFrame);
-
-  dontPlayingColorFrame = new QFrame;
-  newPalette.setColor(QPalette::Background, QColor("LightGoldenrodYellow")); //BlanchedAlmond MistyRose honeydew PeachPuff LightCoral
-  dontPlayingColorFrame->setPalette(newPalette);
-  mainLayout.addWidget(dontPlayingColorFrame);
-  
-  playingLayout = new QGridLayout(playingColorFrame);
-  dontPlayingLayout = new QGridLayout(dontPlayingColorFrame);
+  framePlaying=new FrameTeams();
+  frameDontPlaying=new FrameTeams();
+  addScrArea(framePlaying, QColor("DarkTurquoise"));
+  addScrArea(frameDontPlaying, QColor("LightGoldenrodYellow"));
 }
--- a/QTfrontend/teamselect.h	Sun Feb 05 18:51:54 2006 +0000
+++ b/QTfrontend/teamselect.h	Fri Feb 24 16:06:12 2006 +0000
@@ -3,16 +3,19 @@
 
 #include <QWidget>
 #include <QVBoxLayout>
-#include <QFrame>
+class QFrame;
 
 #include <list>
 #include <map>
 
+class TeamSelWidget;
+class FrameTeams;
+
 using namespace std;
 
 struct tmprop
 {
-  tmprop(QString nm) : teamName(nm){};
+  tmprop(QString nm) : teamName(nm) {};
   QString teamName;
   QString pixmapFileName;
   bool operator==(const tmprop& t1) const {
@@ -36,16 +39,14 @@
   void changeTeamStatus(tmprop team);
 
  private:
-  QVBoxLayout mainLayout;
+  void addScrArea(FrameTeams* pfteams, QColor color);
+  FrameTeams* frameDontPlaying;
+  FrameTeams* framePlaying;
 
-  QFrame* playingColorFrame;
-  QFrame* dontPlayingColorFrame;
-  QGridLayout* playingLayout;
-  QGridLayout* dontPlayingLayout;
+  QVBoxLayout mainLayout;
 
   list<tmprop> curPlayingTeams;
   list<tmprop> curDontPlayingTeams;
-  map<tmprop, QWidget*> teamToWidget;
 };
 
 #endif // _TEAM_SELECT_INCLUDED
--- a/QTfrontend/teamselhelper.cpp	Sun Feb 05 18:51:54 2006 +0000
+++ b/QTfrontend/teamselhelper.cpp	Fri Feb 24 16:06:12 2006 +0000
@@ -3,6 +3,8 @@
 #include <QPixmap>
 #include <QPushButton>
 
+#include <iostream>
+
 void TeamLabel::teamButtonClicked()
 {
   emit teamActivated(text());
@@ -14,7 +16,7 @@
   QLabel* pixlbl=new QLabel();
   pixlbl->setPixmap(QPixmap("./Data/Graphics/thinking.png"));
   mainLayout.addWidget(pixlbl);
-  
+
   TeamLabel* lbl=new TeamLabel(team.teamName);
   mainLayout.addWidget(lbl);
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/vertScrollArea.cpp	Fri Feb 24 16:06:12 2006 +0000
@@ -0,0 +1,16 @@
+#include "vertScrollArea.h"
+
+#include <QResizeEvent>
+
+VertScrArea::VertScrArea(QColor frameColor, QWidget * parent) :
+  QScrollArea(parent)
+{
+  QPalette newPalette = palette();
+  newPalette.setColor(QPalette::Background, frameColor);
+  setPalette(newPalette);
+}
+
+void VertScrArea::resizeEvent(QResizeEvent * event)
+{
+  widget()->resize(event->size().width(), widget()->sizeHint().height());
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/vertScrollArea.h	Fri Feb 24 16:06:12 2006 +0000
@@ -0,0 +1,17 @@
+#ifndef _VERT_SCROLL_AREA_INCLUDED
+#define _VERT_SCROLL_AREA_INCLUDED
+
+#include <QScrollArea>
+
+class VertScrArea : public QScrollArea
+{
+  Q_OBJECT
+
+ public:
+  VertScrArea(QColor frameColor, QWidget * parent = 0);
+
+ protected:
+  virtual void resizeEvent(QResizeEvent * event);
+};
+
+#endif // _VERT_SCROLL_AREA_INCLUDED