Commit 6f346928 authored by Gaël de Chalendar's avatar Gaël de Chalendar
Browse files

Solved the toolbars problems and reactivated playing of sounds

svn path=/trunk/playground/games/ksirk/; revision=646198
parent 65680e8b
......@@ -28,18 +28,18 @@
KsirkChatDelegate::KsirkChatDelegate(QObject *parent) :
KChatBaseItemDelegate(parent)
{
kDebug() << "KsirkChatDelegate::KsirkChatDelegate" << endl;
// kDebug() << "KsirkChatDelegate::KsirkChatDelegate" << endl;
}
void KsirkChatDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
kDebug() << "KsirkChatDelegate::paint" << endl;
// kDebug() << "KsirkChatDelegate::paint" << endl;
KsirkChatItem m = index.model()->data(index, Qt::DisplayRole).value<KsirkChatItem>();
if (!m.first.isEmpty())
{
kDebug() << " " <<m.first << " / " << m.second << endl;
// kDebug() << " " <<m.first << " / " << m.second << endl;
KChatBaseItemDelegate::paint(painter, option, index, m.first, m.second);
}
else
......@@ -51,14 +51,14 @@ void KsirkChatDelegate::paint(QPainter *painter,
QSize KsirkChatDelegate::sizeHint(const QStyleOptionViewItem & option ,
const QModelIndex & index ) const
{
kDebug() << "KsirkChatDelegate::sizeHint" << endl;
// kDebug() << "KsirkChatDelegate::sizeHint" << endl;
KsirkChatItem m = index.model()->data(index, Qt::DisplayRole).value<KsirkChatItem>();
if (!m.first.isEmpty())
{
return KChatBaseItemDelegate::sizeHint(option, index, m.first, m.second);
}
QSize result = m.sizeHint(option);
kDebug() << "KsirkChatDelegate::sizeHint: " << result << endl;
// kDebug() << "KsirkChatDelegate::sizeHint: " << result << endl;
return result;
}
......
......@@ -51,7 +51,7 @@ KsirkChatItem::KsirkChatItem(const KsirkChatItem& item) : KChatBaseMessage(item)
void KsirkChatItem::paint(QPainter* p,
const QStyleOptionViewItem &option, int row)
{
std::cerr << "KsirkChatItem::paint" << std::endl;
// std::cerr << "KsirkChatItem::paint" << std::endl;
QTextDocument fake; // used to allow to compute lines height
fake.setHtml("gpl");
......@@ -75,14 +75,14 @@ void KsirkChatItem::paint(QPainter* p,
switch (m_order[i])
{
case Text:
kDebug() << " paint string '" << m_strings[i] << "' at " << x << ", " << row*h << endl;
// kDebug() << " paint string '" << m_strings[i] << "' at " << x << ", " << row*h << endl;
p->drawPixmap(option.rect.x()+x,option.rect.y(),px);
x += px.width();
break;
case Pixmap:
if (! m_pixmaps[i].isNull())
{
kDebug() << " paint pixmap at " << x << ", " << row*h << endl;
// kDebug() << " paint pixmap at " << x << ", " << row*h << endl;
QPixmap scaled = m_pixmaps[i].scaledToHeight(h);
p->drawPixmap(option.rect.x()+x,option.rect.y(),scaled);
x+= scaled.width();
......@@ -125,7 +125,7 @@ QSize KsirkChatItem::sizeHint(const QStyleOptionViewItem &option)
default: ;
}
}
kDebug() << "KsirkChatItem::sizeHint: " << QSize(w,h) << endl;
// kDebug() << "KsirkChatItem::sizeHint: " << QSize(w,h) << endl;
return QSize(w,h);
}
......
......@@ -42,7 +42,7 @@ KsirkChatModel::KsirkChatModel(QObject *parent)
int KsirkChatModel::rowCount(const QModelIndex &parent) const
{
kDebug() << "KsirkChatModel::rowCount" << endl;
// kDebug() << "KsirkChatModel::rowCount" << endl;
if (parent.isValid())
return 0;
else
......@@ -51,7 +51,7 @@ int KsirkChatModel::rowCount(const QModelIndex &parent) const
QVariant KsirkChatModel::data(const QModelIndex &index, int role) const
{
kDebug() << "KsirkChatModel::data " << index.row() << " ; m_messages size=" << m_messages.size() << endl;
// kDebug() << "KsirkChatModel::data " << index.row() << " ; m_messages size=" << m_messages.size() << endl;
if (!index.isValid())
return QVariant();
......@@ -65,7 +65,7 @@ QVariant KsirkChatModel::data(const QModelIndex &index, int role) const
void KsirkChatModel::addMessage(const KsirkChatItem& message)
{
kDebug() << "KsirkChatModel::addMessage" << endl;
// kDebug() << "KsirkChatModel::addMessage" << endl;
int row;
row = m_messages.size();
beginInsertRows(QModelIndex(), row, row);
......
......@@ -134,7 +134,7 @@ void KGameWindow::initCombatMovement(Country *paysAttaquant, Country *paysDefens
{
// kDebug() << "KGameWindow::initCombatMovement" << endl;
toolBar("gameActionsToolBar")-> hide();
gameActionsToolBar-> hide();
m_animFighters->clear();
m_animFighters->changeTarget(this,SLOT(slotMovingFightersArrived(AnimSpritesGroup*)));
......@@ -214,7 +214,7 @@ void KGameWindow::initCombatMovement(Country *paysAttaquant, Country *paysDefens
QMessageBox::critical(0, i18n("Error !"), i18n("Sound roule not found - Verify your installation\nProgram cannot continue"));
exit(2);
}
// m_audioPlayer->play(sndRoulePath);
m_audioPlayer->play(sndRoulePath);
CannonSprite* defenderSprite = new CannonSprite( Sprites::SkinSpritesData::single().strData("cannon-file"), m_backGnd, Sprites::SkinSpritesData::single().intData("cannon-frames"), Sprites::SkinSpritesData::single().intData("cannon-versions"), 200);
defenderSprite-> setDefendant();
......@@ -228,7 +228,7 @@ void KGameWindow::initCombatMovement(Country *paysAttaquant, Country *paysDefens
QMessageBox::critical(0, i18n("Error !"), i18n("Sound roule not found - Verify your installation\nProgram cannot continue"));
exit(2);
}
// m_audioPlayer->play(sndRoulePath);
m_audioPlayer->play(sndRoulePath);
}
void KGameWindow::animCombat()
......@@ -261,7 +261,7 @@ void KGameWindow::animCombat()
}
if (KsirkSettings::soundEnabled())
{
// m_audioPlayer->play(sndCanonPath);
m_audioPlayer->play(sndCanonPath);
}
}
}
......@@ -332,7 +332,7 @@ void KGameWindow::animExplosion(int who)
}
if (KsirkSettings::soundEnabled())
{
// m_audioPlayer->play(sndCrashPath);
m_audioPlayer->play(sndCrashPath);
}
kDebug() << "KGameWindow::animExplosion finished" << endl;
// m_frame-> initTimer();
......@@ -383,7 +383,7 @@ void KGameWindow::initCombatBringBack(Country *paysAttaquant, Country *paysDefen
QMessageBox::critical(0, i18n("Error !"), i18n("Sound roule not found - Verify your installation\nProgram cannot continue"));
exit(2);
}
// m_audioPlayer->play(sndRoulePath);
m_audioPlayer->play(sndRoulePath);
}
else if (who == 1) //Defenseur detruit, ramene Attaquant
{
......@@ -409,7 +409,7 @@ void KGameWindow::initCombatBringBack(Country *paysAttaquant, Country *paysDefen
QMessageBox::critical(0, i18n("Error !"), i18n("Sound roule not found - Verify your installation\nProgram cannot continue"));
exit(2);
}
// m_audioPlayer->play(sndRoulePath);
m_audioPlayer->play(sndRoulePath);
}
else if (who == 2)
{
......
......@@ -103,10 +103,13 @@ KGameWindow::KGameWindow(QWidget* parent) :
// m_accels(this),
// m_chat(0),
m_chatDlg(0),
m_audioPlayer(0),//new Phonon::AudioPlayer( Phonon::NotificationCategory )),
m_timer(this)
m_audioPlayer(new Phonon::AudioPlayer( Phonon::NotificationCategory )),
m_timer(this),
mainToolBar(0),
gameActionsToolBar(0)
{
kDebug() << "KGameWindow constructor begin" << endl;
statusBar()->addWidget(m_barFlagButton);
m_config=KGlobal::config();
......@@ -144,6 +147,8 @@ KGameWindow::KGameWindow(QWidget* parent) :
kDebug() << "Setting skin" << endl;
GameLogic::GameAutomaton::changeable().skin(m_config->readEntry("skin", "skins/default"));
// kDebug() << "Before initActions" << endl;
// initActions();
// kDebug() << "Before initStatusBar" << endl;
......@@ -176,14 +181,14 @@ KGameWindow::~KGameWindow()
void KGameWindow::initActions()
{
kDebug() << "Adding exit toolBar button" << endl;
addAButton(CM_EXITGAME, SLOT(close()), i18n("Exit"), KShortcut(Qt::ALT+Qt::Key_F4), false, "mainToolBar");
addAButton(CM_EXITGAME, SLOT(close()), i18n("Exit"), KShortcut(Qt::ALT+Qt::Key_F4), false, "globalToolBar");
kDebug() << "Adding new game toolBar button" << endl;
addAButton(CM_NEWGAME, SLOT(slotNewGame()), i18n("New game"), KShortcut(Qt::CTRL+Qt::Key_N), false, "mainToolBar");
addAButton(CM_NEWGAME, SLOT(slotNewGame()), i18n("New game"), KShortcut(Qt::CTRL+Qt::Key_N), false, "globalToolBar");
kDebug() << "Adding new net game toolBar button" << endl;
addAButton(CM_NEWNETGAME, SLOT(slotJoinNetworkGame()), i18n("Join network game"), KShortcut(Qt::CTRL+Qt::Key_J), false, "mainToolBar");
addAButton(CM_NEWNETGAME, SLOT(slotJoinNetworkGame()), i18n("Join network game"), KShortcut(Qt::CTRL+Qt::Key_J), false, "globalToolBar");
kDebug() << "Adding info toolBar button" << endl;
addAButton(CM_PREFERENCES, SLOT(optionsConfigure()), i18n("Preferences"), KShortcut(), false, "mainToolBar");
addAButton(CM_INFO, SLOT(slotShowAboutApplication()), i18n("About"), KShortcut(), false, "mainToolBar");
addAButton(CM_PREFERENCES, SLOT(optionsConfigure()), i18n("Preferences"), KShortcut(), false, "globalToolBar");
addAButton(CM_INFO, SLOT(slotShowAboutApplication()), i18n("About"), KShortcut(), false, "globalToolBar");
}
void KGameWindow::initStatusBar()
......@@ -274,11 +279,11 @@ void KGameWindow::newSkin(const QString& onuFileName)
loadDices();
m_frame = new DecoratedGameFrame(this, m_theWorld->width(), m_theWorld->height());
setCentralWidget(m_frame);
m_frame->setMaximumWidth(m_theWorld->width());
m_frame->setMaximumHeight(m_theWorld->height());
m_frame->setCacheMode( QGraphicsView::CacheBackground );
setCentralWidget(m_frame);
kDebug() << "ONU backgnd file name: " << m_theWorld->mapFileName() << endl;
if (m_scene != 0)
......@@ -302,13 +307,22 @@ void KGameWindow::newSkin(const QString& onuFileName)
// initTimer();
kDebug() <<"End new skin" << endl;
mainToolBar = new KToolBar("globalToolBar",this, Qt::BottomToolBarArea);
mainToolBar-> setToolButtonStyle(Qt::ToolButtonIconOnly);
mainToolBar-> setAllowedAreas(Qt::BottomToolBarArea);
mainToolBar-> setIconSize(QSize(32,32));
mainToolBar->show();
gameActionsToolBar = new KToolBar("gameActionsToolBar", this, Qt::BottomToolBarArea);
gameActionsToolBar-> setToolButtonStyle(Qt::ToolButtonIconOnly);
gameActionsToolBar-> setAllowedAreas(Qt::BottomToolBarArea);
gameActionsToolBar-> setIconSize(QSize(32,32));
gameActionsToolBar->show();
initActions();
toolBar("mainToolBar")-> hide();
toolBar("gameActionsToolBar")-> hide();
toolBar("mainToolBar")-> show();
toolBar("gameActionsToolBar")-> show();
// toolBar("mainToolBar")-> setBarPos(KToolBar::Bottom);
// toolBar("gameActionsToolBar")-> setBarPos(KToolBar::Bottom);
mainToolBar-> hide();
gameActionsToolBar-> hide();
mainToolBar-> show();
gameActionsToolBar-> show();
m_frame->setFocus();
}
......@@ -788,7 +802,7 @@ void KGameWindow::clearGameActionsToolbar(bool send)
GameLogic::GameAutomaton::changeable().sendMessage(buffer,ClearGameActionsToolbar);
}
(*toolBar("gameActionsToolBar")).clear();
gameActionsToolBar->clear();
std::set< QString >::const_iterator it, it_end;
it = m_temporaryAccelerators.begin(); it_end = m_temporaryAccelerators.end();
for (; it != it_end; it++)
......@@ -815,8 +829,20 @@ void KGameWindow::addAButton(
QMessageBox::critical(0, i18n("Error !"), i18n("Cannot load button image\nProgram cannot continue"));
exit(2);
}
(*toolBar(toolBarName.c_str())).addAction(QPixmap(imageFileName),
txt, this, slot);
KToolBar* toolBar;
if (toolBarName == "globalToolBar")
{
toolBar = mainToolBar;
}
else if (toolBarName == "gameActionsToolBar")
{
toolBar = gameActionsToolBar;
}
else
{
kError() << "Unknown toolbar name" << endl;
}
toolBar->addAction(QPixmap(imageFileName), txt, this, slot);
// kDebug() << "Button added " << txt << endl;
if (shortcut != KShortcut())
{
......@@ -1502,7 +1528,7 @@ int KGameWindow::setCurrentPlayerToNext(bool restartRunningAIs)
bool KGameWindow::terminateAttackSequence()
{
m_animFighters->hideAndRemoveAll();
toolBar("gameActionsToolBar")-> show();
gameActionsToolBar-> show();
return attackEnd();
}
......
......@@ -45,6 +45,7 @@
class KPushButton;
class KTextEdit;
class KGameChat;
class KToolBar;
class QEvent;
class QDockWidget;
......@@ -733,6 +734,9 @@ private:
QList<AnimSpritesGroup*> m_animSpritesGroups;
KToolBar* mainToolBar;
KToolBar* gameActionsToolBar;
private: // Private methods
void attack(GameLogic::Country& attacker, GameLogic::Country& defender, unsigned int nb);
void moveArmies(GameLogic::Country& src, GameLogic::Country& dest, unsigned int nb);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment