Commit fe09def4 authored by Àlex Fiestas's avatar Àlex Fiestas
Browse files

Added a combo to "fast switch" between playgrounds.

svn path=/trunk/KDE/kdegames/ktuberling/; revision=1125457
parent df440f31
......@@ -13,7 +13,8 @@ set(ktuberling_SRCS
toplevel.cpp
playground.cpp
todraw.cpp
soundfactory.cpp )
soundfactory.cpp
playgrounddelegate.cpp )
kde4_add_app_icon(ktuberling_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/hi*-app-ktuberling.png")
kde4_add_executable(ktuberling ${ktuberling_SRCS})
......
......@@ -29,4 +29,7 @@
<Action name="edit_undo"/>
<Action name="edit_redo"/>
</ToolBar>
<ToolBar name="gameOptions"><text>Game Options</text>
<Action name="playgroundSelection"/>
</ToolBar>
</gui>
......@@ -281,12 +281,21 @@ void PlayGround::registerPlayGrounds()
KConfig c(KStandardDirs::locate("appdata", "pics/" + desktop));
KConfigGroup cg = c.group("KTuberlingTheme");
QString gameboard = layoutDocument.documentElement().attribute("gameboard");
m_topLevel->registerGameboard(cg.readEntry("Name"), theme);
QPixmap pixmap(200,100);
playGroundPixmap(gameboard,pixmap);
m_topLevel->registerGameboard(cg.readEntry("Name"), theme, pixmap);
}
}
}
}
void PlayGround::playGroundPixmap(const QString &playgroundName, QPixmap &pixmap)
{
m_SvgRenderer.load(KStandardDirs::locate("appdata", "pics/" + playgroundName));
QPainter painter(&pixmap);
m_SvgRenderer.render(&painter,"background");
}
// Load background and draggable objects masks
bool PlayGround::loadPlayGround(const QString &gameboardFile)
{
......
......@@ -66,6 +66,7 @@ private:
bool insideBackground(const QSizeF &size, const QPointF &pos) const;
void placeDraggedItem(const QPoint &pos);
void placeNewItem(const QPoint &pos);
void playGroundPixmap(const QString &playgroundName, QPixmap &pixmap);
void recenterView();
......
/*
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "playgrounddelegate.h"
#include <QPainter>
PlaygroundDelegate::PlaygroundDelegate(QObject *parent): QAbstractItemDelegate(parent)
{ }
QSize PlaygroundDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
Q_UNUSED(option);
Q_UNUSED(index);
return QSize(200,100);
}
void PlaygroundDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QString title = index.model()->data(index, Qt::DisplayRole).toString();
QPixmap pixmap = index.model()->data(index,Qt::UserRole).value<QPixmap>();
//Paint background with highlight
painter->save();
if (option.state & QStyle::State_Selected) {
painter->setBrush(option.palette.color(QPalette::Highlight));
} else {
painter->setBrush(Qt::gray);
}
painter->drawRect(option.rect);
painter->restore();
//Any way of do this more beatifuly?
painter->drawPixmap(option.rect.x()+4,option.rect.y()+4,option.rect.width()-8,option.rect.height()-8,pixmap);
QFont font = painter->font();
font.setWeight(QFont::Bold);
painter->setFont(font);
painter->drawText(option.rect, Qt::AlignCenter | Qt::TextWordWrap, title);
painter->save();
painter->restore();
}
\ No newline at end of file
/*
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PLAYGROUNDDELEGATE_H
#define PLAYGROUNDDELEGATE_H
#include <QtGui/QAbstractItemDelegate>
#include <QAbstractItemView>
class PlaygroundDelegate : public QAbstractItemDelegate
{
public:
PlaygroundDelegate(QObject *parent = 0);
private:
virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
};
#endif // PLAYGROUNDDELEGATE_H
......@@ -28,6 +28,7 @@
#include <kconfiggroup.h>
#include <ktemporaryfile.h>
#include <kdeprintdialog.h>
#include <kcombobox.h>
#include <QClipboard>
#include <QPrintDialog>
......@@ -36,6 +37,7 @@
#include "toplevel.moc"
#include "playground.h"
#include "soundfactory.h"
#include "playgrounddelegate.h"
// Constructor
TopLevel::TopLevel()
......@@ -73,7 +75,7 @@ TopLevel::~TopLevel()
}
// Register an available gameboard
void TopLevel::registerGameboard(const QString &menuText, const QString &board)
void TopLevel::registerGameboard(const QString &menuText, const QString &board, const QPixmap &pixmap)
{
QList<QAction*> actionList;
KToggleAction *t = new KToggleAction(menuText, this);
......@@ -83,6 +85,9 @@ void TopLevel::registerGameboard(const QString &menuText, const QString &board)
actionList << t;
playgroundsGroup->addAction(t);
plugActionList( "playgroundList", actionList );
playgroundCombo->addItem(menuText,QVariant(pixmap));
playgroundCombo->setItemData(playgroundCombo->count()-1,QVariant(board),BOARD_THEME);
}
// Register an available language
......@@ -101,6 +106,12 @@ void TopLevel::registerLanguage(const QString &code, const QString &soundFile, b
}
// Switch to another gameboard
void TopLevel::changeGameboardFromCombo(int index)
{
QString newBoard = playgroundCombo->itemData(index,BOARD_THEME).toString();
changeGameboard(newBoard);
}
void TopLevel::changeGameboard()
{
QAction *action = qobject_cast<QAction*>(sender());
......@@ -115,6 +126,8 @@ void TopLevel::changeGameboard()
void TopLevel::changeGameboard(const QString &newGameBoard)
{
if (newGameBoard == playGround->currentGameboard()) return;
int index = playgroundCombo->findData(newGameBoard,BOARD_THEME);
playgroundCombo->setCurrentIndex(index);
QString fileToLoad;
QFileInfo fi(newGameBoard);
......@@ -263,6 +276,21 @@ void TopLevel::setupKAction()
actionCollection()->addAction("lock_aspect_ratio", t);
connect(t, SIGNAL(triggered(bool)), this, SLOT(lockAspectRatio(bool)));
playgroundCombo = new KComboBox(this);
playgroundCombo->setMinimumWidth(200);
playgroundCombo->view()->setMinimumHeight(100);
playgroundCombo->view()->setMinimumWidth(200);
playgroundCombo->view()->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
PlaygroundDelegate *playgroundDelegate = new PlaygroundDelegate(playgroundCombo->view());
playgroundCombo->setItemDelegate(playgroundDelegate);
connect(playgroundCombo, SIGNAL(currentIndexChanged(int)),this,SLOT(changeGameboardFromCombo(int)));
QWidgetAction *widgetAction = new QWidgetAction(this);
widgetAction->setDefaultWidget(playgroundCombo);
actionCollection()->addAction("playgroundSelection",widgetAction);
setupGUI(ToolBar | Keys | Save | Create);
}
......
......@@ -13,6 +13,7 @@
#include <kxmlguiwindow.h>
#include <kurl.h>
#include <kcombobox.h>
class QActionGroup;
class PlayGround;
......@@ -28,7 +29,7 @@ public:
~TopLevel();
void open(const KUrl &url);
void registerGameboard(const QString &menuText, const QString &boardFile);
void registerGameboard(const QString& menuText, const QString& boardFile, const QPixmap& pixmap);
void registerLanguage(const QString &code, const QString &soundFile, bool enabled);
void changeLanguage(const QString &langCode);
void playSound(const QString &ref) const;
......@@ -54,6 +55,7 @@ private slots:
void filePrint();
void editCopy();
void soundOff();
void changeGameboardFromCombo(int index);
void changeGameboard();
void changeLanguage();
void toggleFullScreen();
......@@ -68,9 +70,11 @@ private:
ID_NEW, ID_OPEN, ID_SAVE, ID_PRINT,
ID_UNDO, ID_REDO,
ID_HELP };
enum { BOARD_THEME = Qt::UserRole + 1};
QActionGroup *playgroundsGroup, *languagesGroup;
KComboBox *playgroundCombo;
PlayGround *playGround; // Play ground central widget
SoundFactory *soundFactory; // Speech organ
......
Supports Markdown
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