1 /***************************************************************************
2                           kdialogsetupjoueur.cpp  -  description
3                              -------------------
4     begin                : Thu Jul 19 2001
5     copyright            : (C) 2001 by Gaël de Chalendar
6     email                : Gael.de.Chalendar@free.fr
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either either version 2
14    of the License, or (at your option) any later version.of the License, or     *
15  *   (at your option) any later version.                                   *
16  *                                                                         *
17  *   You should have received a copy of the GNU General Public License
18  *   along with this program; if not, write to the Free Software
19  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  *   02110-1301, USA
21  ***************************************************************************/
22 #define KDE_NO_COMPAT
23 #include "kwaitedplayersetupdialog.h"
24 #include "GameLogic/gameautomaton.h"
25 #include "kgamewin.h"
26 #include "GameLogic/onu.h"
27 #include "Sprites/skinSpritesData.h"
28 
29 #include <QString>
30 #include <QLabel>
31 #include <QLineEdit>
32 #include <QCheckBox>
33 #include <QComboBox>
34 #include <QPixmap>
35 
36 #include <KLocalizedString>
37 #include "ksirk_debug.h"
38 
39 #define _XOPEN_SOURCE_
40 #include <unistd.h>
41 
42 namespace Ksirk
43 {
44 using namespace GameLogic;
45 
KWaitedPlayerSetupDialog(GameLogic::GameAutomaton * automaton,QString & password,int & result,QWidget * parent)46 KWaitedPlayerSetupDialog::KWaitedPlayerSetupDialog(
47                           GameLogic::GameAutomaton* automaton,
48                           QString& password,
49                           int& result,
50                           QWidget *parent) :
51   QDialog(parent), QWaitedPlayerSetupDialog(),
52   m_automaton(automaton),
53   m_password(password), m_result(result)
54 {
55   setupUi(this);
56   qCDebug(KSIRK_LOG) << "KWaitedPlayerSetupDialog constructor";
57   fillWaitedPlayersCombo();
58 
59   QObject::connect((const QObject *)PushButton1, SIGNAL(clicked()), this, SLOT(slotOK()) );
60 
61 }
62 
~KWaitedPlayerSetupDialog()63 KWaitedPlayerSetupDialog::~KWaitedPlayerSetupDialog(){
64 }
65 
slotOK()66 void KWaitedPlayerSetupDialog::slotOK()
67 {
68   qCDebug(KSIRK_LOG) << "slotOk";
69   // toport
70 //   m_password = QString(crypt(passwordEdit->password(),"T6"));
71   m_result = waitedPlayersCombo->currentIndex();
72   close();
73 }
74 
fillWaitedPlayersCombo()75 void KWaitedPlayerSetupDialog::fillWaitedPlayersCombo()
76 {
77   qCDebug(KSIRK_LOG) << "Filling nations combo";
78 
79   QList<PlayerMatrix>::iterator it, it_end;
80   it = m_automaton->game()->waitedPlayers().begin();
81   it_end = m_automaton->game()->waitedPlayers().end();
82   for (; it != it_end; it++)
83   {
84     qCDebug(KSIRK_LOG) << "Adding waited player " << (*it).name ;
85     QString imgName = m_automaton->game()->theWorld()->nationNamed((*it).nation)->flagFileName();
86 //     load image
87     QPixmap flag;
88     QSize size(flag.width()/Sprites::SkinSpritesData::single().intData("flag-frames"),flag.height());
89     QImage image(size, QImage::Format_ARGB32_Premultiplied);
90     image.fill(0);
91     QPainter p(&image);
92     QSvgRenderer renderer;
93     renderer.load(imgName);
94     renderer.render(&p/*, svgid*/);
95     QPixmap allpm = QPixmap::fromImage(image);
96     flag = allpm.copy(0, 0, size.width(), size.height());
97 
98 //     get name
99     QString name = (*it).name;
100     name += QString(" (");
101     name += (i18n((*it).nation.toUtf8().data()));
102     name += QString(")");
103 //     fill a combo entry
104     waitedPlayersCombo->addItem(QIcon(flag),name);
105   }
106 
107 }
108 
109 }
110 
111 
112