Commit b1952ef7 authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

Port of blinken to harmattan + libkok

parent 4249efa6
# Define here your path to the root containing libkok
PATHTOLIBKOKROOT = /home/tsdgeos/devel/libkok/
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += . ../src
QT += svg phonon declarative
INCLUDEPATH += $${PATHTOLIBKOKROOT}/usr/include $${PATHTOLIBKOKROOT}/usr/include/KDE
LIBS += -L $${PATHTOLIBKOKROOT}/usr/lib -lkok
KCONFIG_COMPILER_INPUT = ../src/blinken.kcfg
kconfig_compiler.output = settings.o
kconfig_compiler.commands = kconfig_compiler ${QMAKE_FILE_NAME} ../src/settings.kcfgc -d ${OBJECTS_DIR} && $${QMAKE_CXX} $(CXXFLAGS) -O0 $(INCPATH) -c settings.cpp -o ${QMAKE_FILE_OUT}
kconfig_compiler.input = KCONFIG_COMPILER_INPUT
QMAKE_EXTRA_COMPILERS += kconfig_compiler
# Input
HEADERS += blinkenproxywidget.h \
../src/blinken.h \
../src/blinkengame.h \
../src/button.h \
../src/counter.h \
../src/highscoredialog.h \
../src/number.h \
../src/soundsplayer.h
SOURCES += blinkenproxywidget.cpp \
../src/blinken.cpp \
../src/blinkengame.cpp \
../src/button.cpp \
../src/counter.cpp \
../src/highscoredialog.cpp \
../src/main.cpp \
../src/number.cpp \
../src/soundsplayer.cpp \
kfontutils.cpp
DEFINES += HARMATTAN_BUILD
target.path = /opt/blinken/bin
INSTALLS += target
svg.files = ../images/blinken.svg
svg.path = /opt/blinken/images
INSTALLS += svg
sounds.files = ../sounds/1.wav ../sounds/2.wav ../sounds/3.wav ../sounds/4.wav ../sounds/lose.wav
sounds.path = /opt/blinken/sounds
INSTALLS += sounds
qml.files = qml/main.qml
qml.path = /opt/blinken/qml
INSTALLS += qml
font.files = ../fonts/steve.ttf
font.path = /opt/blinken/fonts
INSTALLS += font
desktopfile.files = blinken_harmattan.desktop
desktopfile.path = /usr/share/applications/
INSTALLS += desktopfile
desktopicon.files = blinken80.png
desktopicon.path = /usr/share/icons/hicolor/80x80/apps
INSTALLS += desktopicon
copying.files = ../COPYING
copying.path = /opt/blinken/
INSTALLS += copying
evil_hack_to_fool_lupdate {
SOURCES += qml/main.qml
}
OTHER_FILES += \
qtc_packaging/debian_harmattan/rules \
qtc_packaging/debian_harmattan/README \
qtc_packaging/debian_harmattan/manifest.aegis \
qtc_packaging/debian_harmattan/copyright \
qtc_packaging/debian_harmattan/control \
qtc_packaging/debian_harmattan/compat \
qtc_packaging/debian_harmattan/changelog
[Desktop Entry]
Encoding=UTF-8
Version=1.0.0
Type=Application
Terminal=false
Name=Blinken
Exec=/opt/blinken/bin/blinken
Icon=/usr/share/icons/hicolor/80x80/apps/blinken80.png
X-Window-Icon=
X-HildonDesk-ShowInToolbar=true
X-Osso-Type=application/x-executable
#include "blinkenproxywidget.h"
#ifdef HARMATTAN_BUILD
BlinkenProxyWidget::BlinkenProxyWidget(QGraphicsItem* parent)
: QGraphicsProxyWidget(parent)
{
widget = new blinken();
widget->setAttribute(Qt::WA_NoSystemBackground);
setWidget(widget);
connect(widget, SIGNAL(askForName(QString, int, int)), this, SIGNAL(askForName(QString, int, int)));
connect(widget, SIGNAL(showHighScoreDialog(int)), this, SIGNAL(showHighScoreDialog(int)));
connect(widget, SIGNAL(showAbout()), this, SIGNAL(showAbout()));
}
void BlinkenProxyWidget::setHighScore(const QString &name, int level, int score)
{
widget->setHighScore(name, level, score);
}
#endif
#ifndef BLINKENPROXYWIDGET_H
#define BLINKENPROXYWIDGET_H
#include "blinken.h"
#include <QGraphicsProxyWidget>
#ifdef HARMATTAN_BUILD
class BlinkenProxyWidget : public QGraphicsProxyWidget
{
Q_OBJECT
public:
BlinkenProxyWidget(QGraphicsItem* parent = 0);
Q_INVOKABLE void setHighScore(const QString &name, int level, int score);
signals:
void askForName(const QString &lastName, int level, int score);
void showHighScoreDialog(int level);
void showAbout();
private:
blinken *widget;
};
#endif
#endif // BLINKENPROXYWIDGET_H
/*********************************************************************************
* *
* Copyright (C) 2005, 2009 by Albert Astals Cid <aacid@kde.org> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) version 3, or any *
* later version accepted by the membership of KDE e.V. (or its *
* successor approved by the membership of KDE e.V.), which shall *
* act as a proxy defined in Section 6 of version 3 of the license. *
* *
* This library 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 *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library. If not, see <http://www.gnu.org/licenses/>. *
* *
*********************************************************************************/
#include "kfontutils.h"
#include <qpainter.h>
qreal KFontUtils::adaptFontSize(QPainter &painter, const QString &string, qreal width, qreal height, qreal maxFontSize, qreal minFontSize, AdaptFontSizeOptions flags)
{
qreal size = maxFontSize;
QRectF boundingRect;
bool done = false;
while (!done && size > minFontSize) {
QFont f = painter.font();
f.setPointSizeF(size);
painter.setFont(f);
int qtFlags = Qt::AlignCenter | Qt::TextWordWrap;
if (flags & DoNotAllowWordWrap) {
qtFlags = qtFlags & ~Qt::TextWordWrap;
}
boundingRect = painter.boundingRect(QRectF(0, 0, width, height), qtFlags, string);
if (boundingRect.width() == 0 || boundingRect.height() == 0) {
return -1;
} else if (boundingRect.width() > width || boundingRect.height() > height) {
size = qMin(width * size / boundingRect.width(), height * size / boundingRect.height());
} else {
done = true;
}
}
return size;
}
qreal KFontUtils::adaptFontSize(QPainter &painter, const QString &text, const QSizeF &availableSize, qreal maxFontSize, qreal minFontSize, AdaptFontSizeOptions flags)
{
return adaptFontSize(painter, text, availableSize.width(), availableSize.height(), maxFontSize, minFontSize, flags);
}
/*********************************************************************************
* *
* Copyright (C) 2005, 2009 by Albert Astals Cid <aacid@kde.org> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) version 3, or any *
* later version accepted by the membership of KDE e.V. (or its *
* successor approved by the membership of KDE e.V.), which shall *
* act as a proxy defined in Section 6 of version 3 of the license. *
* *
* This library 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 *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library. If not, see <http://www.gnu.org/licenses/>. *
* *
*********************************************************************************/
#ifndef KFONTMETRICS_H
#define KFONTMETRICS_H
#include "kdeui_export.h"
class QPainter;
class QSizeF;
class QString;
namespace KFontUtils
{
/** Modifiers for the adaptFontSize function */
enum AdaptFontSizeOption {
NoFlags = 0x01 /** No modifier */,
DoNotAllowWordWrap = 0x02 /** Do not use word wrapping */
};
Q_DECLARE_FLAGS(AdaptFontSizeOptions, AdaptFontSizeOption)
/** Helper function that calculates the biggest font size (in points) used
drawing a centered text using word wrapping.
@param painter The painter where the text will be painted. The font set
in the painter is used for the calculation. Note the
painter font size is modified by this call
@param text The text you want to draw
@param width The available width for drawing
@param height The available height for drawing
@param maxFontSize The maximum font size (in points) to consider
@param minFontSize The minimum font size (in points) to consider
@param flags The modifiers for how the text is painted
@return The calculated biggest font size (in points) that draws the text
in the given dimensions. Can return smaller than minFontSize,
that means the text doesn't fit in the given rectangle. Can
return -1 on error
@since KDE 4.7
*/
qreal KDEUI_EXPORT adaptFontSize(QPainter &painter,
const QString &text,
qreal width,
qreal height,
qreal maxFontSize = 28.0,
qreal minFontSize = 1.0,
AdaptFontSizeOptions flags = NoFlags);
/** Convenience function for adaptFontSize that accepts a QSizeF instead two qreals
@since KDE 4.7
*/
qreal KDEUI_EXPORT adaptFontSize(QPainter &painter,
const QString &text,
const QSizeF &availableSize,
qreal maxFontSize = 28.0,
qreal minFontSize = 1.0,
AdaptFontSizeOptions flags = NoFlags);
}
Q_DECLARE_OPERATORS_FOR_FLAGS(KFontUtils::AdaptFontSizeOptions)
#endif
/***************************************************************************
* Copyright (C) 2011 by Albert Astals Cid <aacid@kde.org> *
* *
* 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. *
***************************************************************************/
import QtQuick 1.1
import com.nokia.meego 1.0
import BlinkenLibrary 1.0
PageStackWindow
{
id: appWindow
initialPage: mainPage
HighScoreManager
{
id: hsm
}
QueryDialog
{
id: aboutDialog
message: qsTr("Blinken for Meego Harmattan 1.0.0<br><br>tsdgeos@yahoo.es<br><br>This software is GPLv2+ licensed")
}
Dialog
{
id: highScoreDialog
function scoreText(score)
{
if (score == 0) return ""
else return score
}
function showLevel(level)
{
if (level == 0) levelChooser.checkedButton = level1Button
else if (level == 1) levelChooser.checkedButton = level2Button
else if (level == 2) levelChooser.checkedButton = level3Button
name1.text = hsm.name(level, 0)
score1.text = scoreText(hsm.score(level, 0))
name2.text = hsm.name(level, 1)
score2.text = scoreText(hsm.score(level, 1))
name3.text = hsm.name(level, 2)
score3.text = scoreText(hsm.score(level, 2))
name4.text = hsm.name(level, 3)
score4.text = scoreText(hsm.score(level, 3))
name5.text = hsm.name(level, 4)
score5.text = scoreText(hsm.score(level, 4))
}
content: Column
{
anchors.horizontalCenter: parent.horizontalCenter
spacing: 10
Label
{
font.family: style.titleFontFamily
font.pixelSize: style.titleFontPixelSize + 10
font.bold: style.titleFontBold
font.capitalization: style.titleFontCapitalization
color: style.titleTextColor
horizontalAlignment: Text.AlignHCenter
width: parent.width
text: qsTr("High Scores")
}
Row
{
anchors.horizontalCenter: parent.horizontalCenter
spacing: 20
Column
{
spacing: 10
Label
{
font.family: style.titleFontFamily
font.pixelSize: style.titleFontPixelSize
font.bold: style.titleFontBold
font.capitalization: style.titleFontCapitalization
color: style.titleTextColor
id: name1
}
Label
{
font.family: style.titleFontFamily
font.pixelSize: style.titleFontPixelSize
font.bold: style.titleFontBold
font.capitalization: style.titleFontCapitalization
color: style.titleTextColor
id: name2
}
Label
{
font.family: style.titleFontFamily
font.pixelSize: style.titleFontPixelSize
font.bold: style.titleFontBold
font.capitalization: style.titleFontCapitalization
color: style.titleTextColor
id: name3
}
Label
{
font.family: style.titleFontFamily
font.pixelSize: style.titleFontPixelSize
font.bold: style.titleFontBold
font.capitalization: style.titleFontCapitalization
color: style.titleTextColor
id: name4
}
Label
{
font.family: style.titleFontFamily
font.pixelSize: style.titleFontPixelSize
font.bold: style.titleFontBold
font.capitalization: style.titleFontCapitalization
color: style.titleTextColor
id: name5
}
}
Column
{
spacing: 10
Label
{
font.family: style.titleFontFamily
font.pixelSize: style.titleFontPixelSize
font.bold: style.titleFontBold
font.capitalization: style.titleFontCapitalization
color: style.titleTextColor
horizontalAlignment: Text.AlignRight
id: score1
}
Label
{
font.family: style.titleFontFamily
font.pixelSize: style.titleFontPixelSize
font.bold: style.titleFontBold
font.capitalization: style.titleFontCapitalization
color: style.titleTextColor
horizontalAlignment: Text.AlignRight
width: parent.width
id: score2
}
Label
{
font.family: style.titleFontFamily
font.pixelSize: style.titleFontPixelSize
font.bold: style.titleFontBold
font.capitalization: style.titleFontCapitalization
color: style.titleTextColor
horizontalAlignment: Text.AlignRight
width: parent.width
id: score3
}
Label
{
font.family: style.titleFontFamily
font.pixelSize: style.titleFontPixelSize
font.bold: style.titleFontBold
font.capitalization: style.titleFontCapitalization
color: style.titleTextColor
horizontalAlignment: Text.AlignRight
width: parent.width
id: score4
}
Label
{
font.family: style.titleFontFamily
font.pixelSize: style.titleFontPixelSize
font.bold: style.titleFontBold
font.capitalization: style.titleFontCapitalization
color: style.titleTextColor
horizontalAlignment: Text.AlignRight
width: parent.width
id: score5
}
}
}
ButtonRow
{
id: levelChooser
Button
{
id: level1Button
text: qsTr("Level 1")
onClicked: highScoreDialog.showLevel(0)
}
Button
{
id: level2Button
text: qsTr("Level 2")
onClicked: highScoreDialog.showLevel(1)
}
Button
{
id: level3Button
text: qsTr("Level ?")
onClicked: highScoreDialog.showLevel(2)
}
}
}
buttons: Row
{
}
}
Dialog
{
property alias name: nameText.text
property int score: -1
property int level: -1
QueryDialogStyle
{
id: style
}
id: askForNameDialog
content: Column
{
id: nameColumn
anchors.horizontalCenter: parent.horizontalCenter
height: 110
Label
{
font.family: style.titleFontFamily
font.pixelSize: style.titleFontPixelSize
font.bold: style.titleFontBold
font.capitalization: style.titleFontCapitalization
color: style.titleTextColor
id: text
text: qsTr("Enter Your Name:")
}
TextField
{
id: nameText
inputMethodHints: Qt.ImhNoPredictiveText
width: 400
height: 50
}
}
buttons: Row
{
spacing: style.buttonsColumnSpacing
anchors.horizontalCenter: parent.horizontalCenter
Button
{
__dialogButton: true
platformStyle: ButtonStyle {inverted: true}
text: qsTr("OK");
onClicked:
{
askForNameDialog.accept()
mainPage.setHighScore(nameText.text, askForNameDialog.level, askForNameDialog.score);
}
}
Button
{
__dialogButton: true
platformStyle: ButtonStyle {inverted: true}
text: qsTr("Cancel");
onClicked:
{
askForNameDialog.reject()
}
}
}
}
Page
{
orientationLock: PageOrientation.LockLandscape
id: mainPage
Rectangle
{
anchors.fill: parent
color: "red"
}
BlinkenWidget
{
id: blinken
anchors.fill: parent
onAskForName:
{
askForNameDialog.open()
askForNameDialog.name = lastName
askForNameDialog.level = level
askForNameDialog.score = score
}
onShowHighScoreDialog:
{
highScoreDialog.showLevel(level)
highScoreDialog.open()
}