/*************************************************************************** Description : KPuzzle - A KDE Jigsaw Puzzle Game Version : 0.2 Copyright : (C) 2000-2001 by Michael Wand EMail : mwand@gmx.de ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "main.h" #include "kpuzzle.h" #include "kpuzzleview.h" #include "kpuzzlegame.h" #include "prefs.h" #include "highscore.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /*#ifdef DEBUG #include #include #include #endif*/ /* Constructor */ KPuzzle::KPuzzle() : KMainWindow( 0, "KPuzzle" ) { KGlobal::dirs()->addResourceType("pics","share/apps/kpuzzle/data/"); /* This will become the central widget */ _centralView = new KPuzzleView(this); /* Don't accept dnd */ setAcceptDrops(false); /* Tell the KMainWindow that this is indeed the main widget */ setCentralWidget(_centralView); /* Then, setup the GUI */ createGUI(); statusBar()->show(); /* allow the view to change the statusbar and caption */ connect(_centralView,SIGNAL(sigChangeStatusbar(const QString&)), this,SLOT(changeStatusbar(const QString&))); #ifdef DEBUG KCrash::setCrashHandler(NULL); #endif } /* Destructor */ KPuzzle::~KPuzzle() { } /* This function creates all menu and toolbar entries */ void KPuzzle::createGUI() { KAction* temp; /* File menu */ QPopupMenu* fileMenu = new QPopupMenu(menuBar()); temp = KStdAction::openNew(_centralView, SLOT(slotNewGame()),new KActionCollection(this)); temp->plug(fileMenu); temp->plug(toolBar()); temp = KStdAction::open(_centralView, SLOT(slotOpenGame()),new KActionCollection(this)); temp->plug(fileMenu); temp->plug(toolBar()); _centralView->actSave() = KStdAction::save(0,0,new KActionCollection(this)); _centralView->actSave()->plug(fileMenu); _centralView->actSave()->plug(toolBar()); _centralView->actSaveAs() = KStdAction::saveAs(0,0,new KActionCollection(this)); _centralView->actSaveAs()->plug(fileMenu); _centralView->actTerminate() = new KAction(i18n("&Terminate game"),QIconSet(QPixmap(PICFILE("stop.xpm"))),0,0, 0,this); _centralView->actTerminate()->plug(fileMenu); (new KActionSeparator(this))->plug(fileMenu); (new KActionSeparator(this))->plug(toolBar()); KStdAction::preferences(this, SLOT(slotSetOptions()),new KActionCollection(this))->plug(fileMenu); _centralView->actHighscores() = new KAction(i18n("&Highscores"),0,this, SLOT(slotHighscores()),this); _centralView->actHighscores()->plug(fileMenu); KStdAction::quit(kapp, SLOT(quit()),new KActionCollection(this))->plug(fileMenu); menuBar()->insertItem(i18n("&File"),fileMenu); /* Game menu */ QPopupMenu* gameMenu = new QPopupMenu(menuBar()); _centralView->actPause() = new KAction(i18n("&Pause Game"),QIconSet(QPixmap(PICFILE("pause.xpm"))),0,0, 0,this); _centralView->actPause()->plug(gameMenu); _centralView->actPause()->plug(toolBar()); _centralView->actTerminate()->plug(toolBar()); (new KActionSeparator(this))->plug(toolBar()); _centralView->actShowLarge() = new KAction(i18n("&Show large image"),QIconSet(QPixmap(PICFILE("large.xpm"))),0,0, 0,this); _centralView->actShowLarge()->plug(gameMenu); _centralView->actShowLarge()->plug(toolBar()); _centralView->actShowMainPixmap() = new KAction(i18n("&Show full image"),QIconSet(QPixmap(PICFILE("large-main.xpm"))), 0,0,0,this); _centralView->actShowMainPixmap()->plug(gameMenu); _centralView->actShowMainPixmap()->plug(toolBar()); menuBar()->insertItem(i18n("&Game"),gameMenu); KPopupMenu* hMenu = this->helpMenu(i18n("KPuzzle - A KDE jigsaw puzzle game"),false); menuBar()->insertItem(i18n("&Help"),hMenu); _centralView->enableMenuItems(MI_NONE); } /* Display text on the status bar */ void KPuzzle::changeStatusbar(const QString& text) { statusBar()->message(text); } /* Show options dialog */ void KPuzzle::slotSetOptions() { /* First of all, suspend the game timer */ bool gameIsPaused = false; if (_centralView->game()) { gameIsPaused = _centralView->game()->paused(); _centralView->game()->pause(true); } /* Read configuration data from the global KConfig object */ CPrefsDialog dlg(this); KConfig* cfg = KGlobal::config(); dlg._usePieceMask = cfg->readBoolEntry("UsePieceMask",SV_USE_PIECE_MASK); dlg._turnPiecesAround = cfg->readBoolEntry("TurnPiecesAround",SV_TURN_PIECES_AROUND); dlg._rightKeyPansAround = cfg->readBoolEntry("RightKeyPansAround",SV_RIGHT_KEY_PANS_AROUND); dlg._showMainPixmap = cfg->readBoolEntry("ShowMainPixmap",SV_SHOW_MAIN_PIXMAP); dlg._imageLoading = cfg->readNumEntry("ImageLoading",SV_IMAGE_LOADING); dlg._showBackgroundImage = cfg->readBoolEntry("ShowBackgroundImage",SV_SHOW_BACKGROUND_IMAGE); dlg.setValues(); /* Show the dialog */ if (dlg.exec() == QDialog::Accepted) { dlg.retrieveValues(); if (dlg._imageLoading == IL_PRELOAD && cfg->readNumEntry("ImageLoading",-1) != IL_PRELOAD) { _centralView->useGamePixmap(GP_BIGLOGO); _centralView->useGamePixmap(GP_LOGO); _centralView->useGamePixmap(GP_WIN); _centralView->useGamePixmap(GP_LOSE); _centralView->useGamePixmap(GP_PAUSE); } cfg->writeEntry("UsePieceMask",dlg._usePieceMask); cfg->writeEntry("TurnPiecesAround",dlg._turnPiecesAround); cfg->writeEntry("RightKeyPansAround",dlg._rightKeyPansAround); cfg->writeEntry("ShowMainPixmap",dlg._showMainPixmap); cfg->writeEntry("ImageLoading",dlg._imageLoading); cfg->writeEntry("ShowBackgroundImage",dlg._showBackgroundImage); cfg->sync(); } /* Reset background - that is, we call _centralView->showBackground * with the parameter true; that function will take care of determining * whether the background is a picture or not. */ _centralView->showBackground(true); /* Continue game */ if (_centralView->game()) _centralView->game()->pause(gameIsPaused); } /* Show highscores */ void KPuzzle::slotHighscores() { bool gameIsPaused = false; if (_centralView->game()) { gameIsPaused = _centralView->game()->paused(); _centralView->game()->pause(true); } CHighscoreDialog hs(this,0); hs.initializeDialog(); hs.exec(); if (_centralView->game()) _centralView->game()->pause(gameIsPaused); }