added ColorCode plugin

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1630 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
defnax 2009-09-10 20:49:54 +00:00
parent 4546be7778
commit a44b3348e2
46 changed files with 3770 additions and 0 deletions

View File

@ -0,0 +1,50 @@
# -------------------------------------------------
# Project created by QtCreator 2009-06-24T21:25:25
# -------------------------------------------------
#=== this part is common (similar) for all plugin projects =====================
TEMPLATE = lib
CONFIG += plugin release
# this is directory, where PluginInterface.h is located
INCLUDEPATH += ../
# and, the result (*.so or *.dll) should appear in this directory
DESTDIR = ../bin
OBJECTS_DIR = temp/obj
RCC_DIR = temp/qrc
UI_DIR = temp/ui
MOC_DIR = temp/moc
# the name of the result file;
TARGET = $$qtLibraryTarget(colorcode_plugin)
HEADERS += ../PluginInterface.h \
ColorCodePlugin.h
SOURCES += ColorCodePlugin.cpp
#===============================================================================
SOURCES += main.cpp \
mainwindow.cpp \
colorpeg.cpp \
rowhint.cpp \
pegrow.cpp \
msg.cpp \
about.cpp
HEADERS += mainwindow.h \
colorpeg.h \
rowhint.h \
pegrow.h \
msg.h \
about.h
RESOURCES += resource.qrc
FORMS += about.ui
OTHER_FILES += docs/GPL.html \
trans_en.ts \
trans_de.ts
TRANSLATIONS = trans_en.ts \
trans_de.ts
CODECFORTR = UTF-8
CODECFORSRC = UTF-8

View File

@ -0,0 +1,28 @@
# -------------------------------------------------
# Project created by QtCreator 2009-06-24T21:25:25
# -------------------------------------------------
TARGET = ColorCode
TEMPLATE = app
SOURCES += main.cpp \
mainwindow.cpp \
colorpeg.cpp \
rowhint.cpp \
pegrow.cpp \
msg.cpp \
about.cpp
HEADERS += mainwindow.h \
colorpeg.h \
rowhint.h \
pegrow.h \
msg.h \
about.h
RESOURCES += resource.qrc
FORMS += about.ui
OTHER_FILES += docs/GPL.html \
trans_en.ts \
trans_de.ts
RC_FILE = ColorCode.rc
TRANSLATIONS = trans_en.ts \
trans_de.ts
CODECFORTR = UTF-8
CODECFORSRC = UTF-8

View File

@ -0,0 +1 @@
IDI_ICON1 ICON DISCARDABLE "cc32.ico"

View File

@ -0,0 +1,53 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2009 RetroShare Team
*
* 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.
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
//#include <QApplication>
//#include <QString>
//#include <QPushButton>
#include "ColorCodePlugin.h"
#include "mainwindow.h"
QString
ColorCodePlugin::pluginDescription() const
{
QString res;
res = "a StegoSaurus plugin" ;
return res;
}
QString
ColorCodePlugin::pluginName() const
{
return "ColorCode" ;
}
QWidget*
ColorCodePlugin::pluginWidget(QWidget * parent )
{
MainWindow* window = new MainWindow();
return window;
}
Q_EXPORT_PLUGIN2(colorcode_plugin, ColorCodePlugin)

View File

@ -0,0 +1,48 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2009 RetroShare Team
*
* 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.
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef _COLORCODE_PLUGIN_H_
#define _COLORCODE_PLUGIN_H_
#include <QObject>
#include <QString>
#include <QWidget>
#include <PluginInterface.h>
#include <QDebug>
class ColorCodePlugin: public QObject, public PluginInterface
{
Q_OBJECT
Q_INTERFACES(PluginInterface)
public slots:
virtual QString pluginDescription() const ;
virtual QString pluginName() const ;
virtual QWidget* pluginWidget(QWidget * parent = 0) ;
};
#endif

View File

@ -0,0 +1,8 @@
ColorCode 0.1
simply run:
qmake-qt4 -project
qmake-qt4
make

View File

@ -0,0 +1,48 @@
#include "about.h"
About::About(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f)
{
setupUi(this);
setWindowIcon(QIcon(QPixmap(":/img/help-about.png")));
mAuthorIcon->setPixmap(QPixmap(":/img/cc32.png"));
mLicenseIcon->setPixmap(QPixmap(":/img/GNU-icon32.png"));
mAuthorText->setText("<b>" + tr("ColorCode") + "</b><br>" +
tr("A needful game to train your brain ;-)") +
"<br><br>Version: 0.2<br>Author: Dirk Laebisch");
QString license_file = ":/docs/GPL.html";
if (QFile::exists(license_file))
{
QFont fixed_font;
fixed_font.setStyleHint(QFont::TypeWriter);
fixed_font.setFamily("Courier");
mLicenseText->setFont(fixed_font);
QFile f(license_file);
if (f.open(QIODevice::ReadOnly))
{
mLicenseText->setText(QString::fromUtf8(f.readAll().constData()));
}
f.close();
}
else
{
mLicenseText->setText(
"<i>" +
tr("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.") + "</i>"
);
}
}
About::~About()
{
}
QSize About::sizeHint () const
{
return QSize(320, 240);
}

View File

@ -0,0 +1,20 @@
#ifndef ABOUT_H
#define ABOUT_H
#include "ui_about.h"
#include <QDialog>
#include <QFile>
class About : public QDialog, public Ui::About
{
Q_OBJECT
public:
About(QWidget* parent = 0, Qt::WindowFlags f = 0);
~About();
virtual QSize sizeHint () const;
};
#endif // ABOUT_H

View File

@ -0,0 +1,185 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>About</class>
<widget class="QDialog" name="About">
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>320</width>
<height>240</height>
</rect>
</property>
<property name="windowTitle">
<string>About ColorCode</string>
</property>
<layout class="QVBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>9</number>
</property>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="tabShape">
<enum>QTabWidget::Rounded</enum>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="mAuthorTab">
<attribute name="title">
<string>&amp;Author</string>
</attribute>
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>9</number>
</property>
<item>
<layout class="QVBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="mAuthorIcon">
<property name="text">
<string>icon</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>111</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QTextBrowser" name="mAuthorText">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="mLicenseTab">
<attribute name="title">
<string>&amp;License</string>
</attribute>
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>9</number>
</property>
<item>
<layout class="QVBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="mLicenseIcon">
<property name="text">
<string>icon</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>111</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QTextBrowser" name="mLicenseText">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>tabWidget</tabstop>
<tabstop>mAuthorText</tabstop>
<tabstop>buttonBox</tabstop>
<tabstop>mLicenseText</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>About</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -0,0 +1,232 @@
#include <QtGui>
#include "colorpeg.h"
using namespace std;
const QBrush ColorPeg::mShadowBrush = ColorPeg::GetShadowBrush();
const QPen ColorPeg::mPen = ColorPeg::GetOutlinePen();
QBrush ColorPeg::GetShadowBrush()
{
QRadialGradient rgrad(22, 22, 22, 22, 22);
rgrad.setColorAt(0.3, QColor(0, 0, 0, 0xff));
rgrad.setColorAt(1.0, QColor(0, 0, 0, 0));
return QBrush(rgrad);
}
QPen ColorPeg::GetOutlinePen()
{
QRadialGradient rgrad(20, 20, 32, 0, 0);
rgrad.setColorAt(0.0, Qt::black);
rgrad.setColorAt(1.0, Qt::white);
return QPen(QBrush(rgrad), 2);
}
ColorPeg::ColorPeg(QObject*)
{
setFlags(QGraphicsItem::GraphicsItemFlags(0));
mPegType = NULL;
mPegRow = NULL;
SetBtn(true);
mIsDragged = false;
mId = -1;
}
ColorPeg::~ColorPeg()
{
}
void ColorPeg::SetPegType(PegType *pt)
{
mPegType = pt;
setFlags(ItemIsMovable | ItemIsSelectable);
}
void ColorPeg::SetPegRow(PegRow *pr)
{
mPegRow = pr;
}
PegType* ColorPeg::GetPegType()
{
return mPegType;
}
void ColorPeg::SetId(int id)
{
mId = id;
}
bool ColorPeg::IsBtn() const
{
return mIsBtn;
}
void ColorPeg::SetBtn(bool b)
{
mIsBtn = b;
SetCursorShape();
}
int ColorPeg::GetType() const
{
return mType;
}
void ColorPeg::SetType(const int t)
{
mType = t;
}
void ColorPeg::Reset()
{
SetIsDragged(false);
setSelected(false);
if (mPegRow != NULL)
{
mPegRow->RemovePeg(this);
mPegRow = NULL;
}
}
void ColorPeg::SetIsDragged(bool b)
{
if (false == b)
{
update(boundingRect());
}
mIsDragged = b;
}
void ColorPeg::SetEnabled(const bool b)
{
setEnabled(b);
//setFlags(QGraphicsItem::GraphicsItemFlags(0));
SetCursorShape();
}
void ColorPeg::SetCursorShape(Qt::CursorShape shape, const bool force)
{
if (!force)
{
if (mIsDragged)
{
shape = Qt::ClosedHandCursor;
}
else if (isEnabled())
{
shape = Qt::OpenHandCursor;
}
}
if (cursor().shape() != shape)
{
setCursor(QCursor(shape));
}
}
QVariant ColorPeg::itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == ItemPositionHasChanged)
{
}
else if (change == ItemPositionChange)
{
}
else if (change == ItemFlagsChange)
{
}
else if (change == ItemSelectedHasChanged)
{
scene()->update(scene()->sceneRect());
}
return QGraphicsItem::itemChange(change, value);
}
void ColorPeg::mousePressEvent(QGraphicsSceneMouseEvent *e)
{
if (mPegType != NULL)
{
if (e->button() == Qt::LeftButton)
{
Reset();
SetIsDragged(true);
emit PegPressSignal(this);
SetCursorShape();
}
}
QGraphicsItem::mousePressEvent(e);
}
void ColorPeg::mouseReleaseEvent (QGraphicsSceneMouseEvent *e)
{
if (mPegType != NULL)
{
if (e->button() == Qt::LeftButton)
{
SetIsDragged(false);
emit PegReleasedSignal(this);
SetCursorShape();
}
}
QGraphicsItem::mouseReleaseEvent(e);
}
QPainterPath ColorPeg::shape() const
{
QPainterPath path;
path.addEllipse(boundingRect());
return path;
}
QRectF ColorPeg::boundingRect() const
{
int margin;
if (mIsDragged)
{
margin = 8;
}
else
{
margin = 1;
}
return outlineRect().adjusted(-margin, -margin, +margin, +margin);
}
QRectF ColorPeg::outlineRect() const
{
QRectF rect(0.0, 0.0, 36.0, 36.0);
return rect;
}
void ColorPeg::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget* /* widget */)
{
/*
QPen pen(Qt::red);
pen.setWidth(2);
if (option->state & QStyle::State_Selected)
{
pen.setStyle(Qt::DotLine);
}
*/
if (mIsDragged)
{
painter->setPen(Qt::NoPen);
painter->translate(QPointF(-2, -2));
painter->setBrush(ColorPeg::mShadowBrush);
painter->drawEllipse(QRectF(0, 0, 44, 44));
painter->translate(QPointF(2, 2));
}
else
{
painter->setPen(ColorPeg::mPen);
}
painter->setBrush(QBrush(mPegType->grad));
painter->drawEllipse(outlineRect());
}

View File

@ -0,0 +1,77 @@
#ifndef COLORPEG_H
#define COLORPEG_H
#include <QColor>
#include <QPen>
#include <QRadialGradient>
#include <QGraphicsItem>
#include <iostream>
#include <vector>
#include "mainwindow.h"
#include "pegrow.h"
#include "rowhint.h"
class ColorPeg : public QObject, public QGraphicsItem
{
Q_OBJECT
//Q_DECLARE_TR_FUNCTIONS(ColorPeg)
public:
ColorPeg(QObject* parent = 0);
~ColorPeg();
int mId;
void SetId(int id);
void SetPegType(PegType* pt);
void SetPegRow(PegRow* pr);
QRectF boundingRect() const;
QPainterPath shape() const;
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
void SetType(const int t);
void SetEnabled(const bool b);
void SetCursorShape( Qt::CursorShape shape = Qt::ArrowCursor, const bool force = false);
PegType* GetPegType();
int GetType() const;
QColor GetPenColor() const;
QColor GetBrushColor() const;
bool IsBtn() const;
void SetBtn(bool b);
void Reset();
signals:
void PegReleasedSignal(ColorPeg* cp);
void PegPressSignal(ColorPeg* cp);
protected:
PegType* mPegType;
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
void mousePressEvent(QGraphicsSceneMouseEvent* e);
void mouseReleaseEvent(QGraphicsSceneMouseEvent* e);
private:
static const QBrush mShadowBrush;
static QBrush GetShadowBrush();
static const QPen mPen;
static QPen GetOutlinePen();
QRectF outlineRect() const;
void SetIsDragged(bool b);
PegRow* mPegRow;
const QBrush mBrush;
int mType;
bool mIsBtn;
bool mIsDragged;
};
#endif // COLORPEG_H

View File

@ -0,0 +1,492 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:webmasters@gnu.org" />
<link rel="icon" type="image/png" href="/graphics/gnu-head-mini.png" />
<meta name="ICBM" content="42.256233,-71.006581" />
<meta name="DC.title" content="gnu.org" />
<title>GNU General Public License v2.0 - GNU Project - Free Software Foundation (FSF)</title>
</head>
<body>
<h3>GNU GENERAL PUBLIC LICENSE</h3>
<p>
Version 2, June 1991
</p>
<pre>
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
</pre>
<h3>Preamble</h3>
<p>
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
</p>
<p>
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
</p>
<p>
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
</p>
<p>
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
</p>
<p>
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
</p>
<p>
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
</p>
<p>
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
</p>
<p>
The precise terms and conditions for copying, distribution and
modification follow.
</p>
<h3>TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION</h3>
<p>
<strong>0.</strong>
This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
</p>
<p>
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
</p>
<p>
<strong>1.</strong>
You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
</p>
<p>
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
</p>
<p>
<strong>2.</strong>
You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
</p>
<dl>
<dt></dt>
<dd>
<strong>a)</strong>
You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
</dd>
<dt></dt>
<dd>
<strong>b)</strong>
You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
</dd>
<dt></dt>
<dd>
<strong>c)</strong>
If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
</dd>
</dl>
<p>
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
</p>
<p>
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
</p>
<p>
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
</p>
<p>
<strong>3.</strong>
You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
</p>
<!-- we use this doubled UL to get the sub-sections indented, -->
<!-- while making the bullets as unobvious as possible. -->
<dl>
<dt></dt>
<dd>
<strong>a)</strong>
Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
</dd>
<dt></dt>
<dd>
<strong>b)</strong>
Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
</dd>
<dt></dt>
<dd>
<strong>c)</strong>
Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
</dd>
</dl>
<p>
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
</p>
<p>
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
</p>
<p>
<strong>4.</strong>
You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
</p>
<p>
<strong>5.</strong>
You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
</p>
<p>
<strong>6.</strong>
Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
</p>
<p>
<strong>7.</strong>
If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
</p>
<p>
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
</p>
<p>
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
</p>
<p>
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
</p>
<p>
<strong>8.</strong>
If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
</p>
<p>
<strong>9.</strong>
The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
</p>
<p>
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
</p>
<p>
<strong>10.</strong>
If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
</p>
<p><strong>NO WARRANTY</strong></p>
<p>
<strong>11.</strong>
BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
</p>
<p>
<strong>12.</strong>
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
</p>
<h3>END OF TERMS AND CONDITIONS</h3>
<h3>How to Apply These Terms to Your New Programs</h3>
<p>
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
</p>
<p>
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
</p>
<pre>
<var>one line to give the program's name and an idea of what it does.</var>
Copyright (C) <var>yyyy</var> <var>name of author</var>
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.
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
</pre>
<p>
Also add information on how to contact you by electronic and paper mail.
</p>
<p>
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
</p>
<pre>
Gnomovision version 69, Copyright (C) <var>year</var> <var>name of author</var>
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
type `show w'. This is free software, and you are welcome
to redistribute it under certain conditions; type `show c'
for details.
</pre>
<p>
The hypothetical commands <samp>`show w'</samp> and <samp>`show c'</samp> should show
the appropriate parts of the General Public License. Of course, the
commands you use may be called something other than <samp>`show w'</samp> and
<samp>`show c'</samp>; they could even be mouse-clicks or menu items--whatever
suits your program.
</p>
<p>
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
</p>
<pre>
Yoyodyne, Inc., hereby disclaims all copyright
interest in the program `Gnomovision'
(which makes passes at compilers) written
by James Hacker.
<var>signature of Ty Coon</var>, 1 April 1989
Ty Coon, President of Vice
</pre>
<p>
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the
<a href="http://www.gnu.org/licenses/lgpl.html">GNU Lesser General Public License</a>
instead of this License.
</p>
</body>
</html>

View File

@ -0,0 +1,4 @@
#ifndef GAMEBOARD_H
#define GAMEBOARD_H
#endif // GAMEBOARD_H

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 826 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 842 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 360 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 802 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 485 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 734 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 514 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 764 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 761 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 931 B

View File

@ -0,0 +1,71 @@
#include <iostream>
#include <QtGui/QApplication>
#include <QLibraryInfo>
#include <QLocale>
#include <QTranslator>
#include "mainwindow.h"
int main(int argc, char* argv[])
{
using namespace std;
string lang("");
if (argc > 1)
{
string str;
for (int i = 1; i < argc; ++i)
{
str = argv[i];
if (str == "-h" || str == "--help")
{
cout << "usage: ColorCode [options]" << endl;
cout << " options:" << endl;
cout << " -l cc, --lang=cc use country code cc instead of system locale, accepted values for cc: en|de" << endl;
cout << " -h, --help prints this message ;-)" << endl;
return 0;
}
else if (str == "-l" && i < argc - 1)
{
if (std::string(argv[i + 1]) == "de" || std::string(argv[i + 1]) == "en")
{
std::string test(argv[i]);
lang = argv[i + 1];
}
}
else if ( str.size() == 9
&& str.find("--lang=") != string::npos
&& (str.substr(7) == "en" || str.substr(7) == "de") )
{
lang = str.substr(7);
}
}
}
QApplication app(argc, argv);
QTranslator qtTranslator;
if (lang == "")
{
qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
}
else
{
qtTranslator.load("qt_" + QString::fromStdString(lang), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
}
app.installTranslator(&qtTranslator);
QTranslator appTranslator;
if (lang == "")
{
appTranslator.load("trans_" + QLocale::system().name());
}
else
{
appTranslator.load(":/trans_" + QString::fromStdString(lang));
}
app.installTranslator(&appTranslator);
MainWindow w;
w.show();
return app.exec();
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,169 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <iostream>
#include <QMainWindow>
struct PegType
{
int ix;
QRadialGradient grad;
QColor pencolor;
};
//typedef std::vector<PegType> TypesMap;
class QAction;
class QActionGroup;
class QComboBox;
class QGraphicsItem;
class QGraphicsTextItem;
class QGraphicsScene;
class QGraphicsView;
class ColorPeg;
class PegRow;
class RowHint;
class Msg;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
static const int STATE_RUNNING;
static const int STATE_WON;
static const int STATE_LOST;
static const int STATE_GAVE_UP;
static const int MAX_COLOR_CNT;
static const int LEVEL_COLOR_CNTS[3];
int ROW_CNT;
int POS_CNT;
public slots:
void PegPressSlot(ColorPeg *cp);
void PegReleasedSlot(ColorPeg *cp);
void RowSolutionSlot(int ix);
void HintPressedSlot(int ix);
void ShowMsgSlot(QString msg);
void RemovePegSlot(ColorPeg* cp);
protected :
void resizeEvent(QResizeEvent* e);
void contextMenuEvent(QContextMenuEvent* e);
private slots:
void InitRows();
void InitPegBtns();
void NewGameSlot();
void RestartGameSlot();
void GiveInSlot();
void ResetRows();
void AboutSlot();
void AboutQtSlot();
void ShowToolbarSlot();
void ShowMenubarSlot();
void ShowStatusbarSlot();
void SameColorSlot();
void AutoCloseSlot();
void ForceLevelSlot();
void RandRowSlot();
void PrevRowSlot();
void ClearRowSlot();
void LevelChangedSlot();
void UpdateRowMenuSlot();
void TestSlot();
private:
enum Level { LEVEL_EASY,
LEVEL_MEDIUM,
LEVEL_HARD };
static Level mLevel;
static int mColorCnt;
static int mMaxZ;
int mGameState;
std::vector<int> mSolution;
QGraphicsScene* scene;
QGraphicsView* view;
QSize* mOrigSize;
Msg* mMsg;
PegRow* mCurRow;
std::vector<ColorPeg *> mPegBuff;
PegRow* mSolRow;
PegRow* mPegRows[10];
RowHint* mHintBtns[10];
PegType* mTypesMap[10];
ColorPeg* mPegBtns[10];
ColorPeg* mSolPegs[4];
QPoint mBtnPos[10];
void FillTypesMap();
void InitSolution();
void InitActions();
void InitMenus();
void InitToolBars();
void SetLevel();
void SetState(const int s);
void NewGame();
void SetSolution();
void ShowSolution();
void NextRow();
void ResolveRow();
void ResolveGame();
void Scale();
ColorPeg* CreatePeg(int ix);
void RemovePeg(ColorPeg* cp);
QMenu* GameMenu;
QMenu* RowMenu;
QMenu* SettingsMenu;
QMenu* LevelMenu;
QMenu* HelpMenu;
QMenu* RowContextMenu;
QToolBar* mGameToolbar;
QToolBar* mLevelToolbar;
QComboBox* mLevelCmb;
QActionGroup* mLevelActions;
QAction* NewGameAction;
QAction* RestartGameAction;
QAction* GiveInAction;
QAction* ShowToolbarAction;
QAction* ShowMenubarAction;
QAction* ShowStatusbarAction;
QAction* SameColorAction;
QAction* AutoCloseAction;
QAction* AboutAction;
QAction* AboutQtAction;
QAction* ExitAction;
QAction* mActLevelEasy;
QAction* mActLevelMedium;
QAction* mActLevelHard;
QAction* RandRowAction;
QAction* PrevRowAction;
QAction* ClearRowAction;
};
#endif // MAINWINDOW_H

View File

@ -0,0 +1,83 @@
#include <QtGui>
#include "msg.h"
using namespace std;
Msg::Msg()
{
/*
setFont(QFont("Arial", 14, QFont::Bold, false));
setDefaultTextColor(QColor("#cccccc"));
setTextWidth(300);
mTd = new QTextDocument();
mTd->setDefaultFont(QFont("Arial", 14, QFont::Bold, false));
mTd->setTextWidth(300);
//QAbstractTextDocumentLayout* lay = mTd->documentLayout();
setDocument(mTd);
*/
mFont = QFont("Arial", 14, QFont::Bold, false);
mFont.setStyleHint(QFont::SansSerif);
mLay = new QTextLayout();
mLay->setFont(mFont);
mLay->setTextOption(QTextOption(Qt::AlignHCenter));
mUpdateRect = QRectF(0, 0, 10, 10);
}
Msg::~Msg()
{
}
void Msg::ShowMsg(const QString str)
{
//setPlainText(str);
//mTd->clear();
//mTd->setPlainText(str);
mUpdateRect = boundingRect();
mLay->setText(str);
int leading = -3;//fontMetrics.leading();
qreal h = 10;
qreal maxw = 0;
qreal maxh = 0;
mLay->beginLayout();
while (1)
{
QTextLine line = mLay->createLine();
if (!line.isValid())
{
break;
}
line.setLineWidth(280);
h += leading;
line.setPosition(QPointF(0, h));
h += line.height();
maxw = qMax(maxw, line.naturalTextWidth());
}
mLay->endLayout();
maxw = qMax(mUpdateRect.width(), mLay->boundingRect().width());
maxh = qMax(mUpdateRect.height(), mLay->boundingRect().height() + 8);
mUpdateRect = QRectF(0, 0, maxw, maxh);
update(boundingRect());
}
QRectF Msg::boundingRect() const
{
return mUpdateRect;
}
void Msg::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /* widget */)
{
//painter->setBrush(Qt::NoBrush);
painter->setPen(QPen(QColor("#f0f0f0")));
mLay->draw(painter, QPoint(0, 0));
}

View File

@ -0,0 +1,31 @@
#ifndef MSG_H
#define MSG_H
#include <QGraphicsTextItem>
#include <QFont>
#include <QTextDocument>
#include <QTextBlock>
#include <QAbstractTextDocumentLayout>
#include <iostream>
class Msg : public QGraphicsTextItem
{
public:
Msg();
~Msg();
void ShowMsg(const QString str);
QRectF boundingRect() const;
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
private:
/*
QTextDocument* mTd;
QTextBlock mTb;
*/
QTextLayout* mLay;
QFont mFont;
QRectF mUpdateRect;
};
#endif // MSG_H

View File

@ -0,0 +1,238 @@
#include <QtGui>
#include "colorpeg.h"
#include "pegrow.h"
#include "rowhint.h"
using namespace std;
PegRow::PegRow(QObject*)
{
mIx = -1;
//setFlags(QGraphicsItem::GraphicsItemFlags(0));
mPen = QPen(QColor("#808080"));
for (int i = 0; i < 4; ++i)
{
mColorPegs[i] = NULL;
}
Reset();
}
PegRow::~PegRow()
{
}
void PegRow::Reset()
{
ClearRow();
SetActive(false);
}
void PegRow::ClearRow()
{
for (int i = 0; i < 4; ++i)
{
if (mColorPegs[i] != NULL)
{
emit(RemovePegSignal(mColorPegs[i]));
}
}
}
int PegRow::GetIx() const
{
return mIx;
}
void PegRow::SetIx(const int ix)
{
mIx = ix;
}
int PegRow::GetPegCnt()
{
int cnt = 0;
int i = 0;
for (i = 0; i < 4; ++i)
{
if (mColorPegs[i] != NULL)
{
++cnt;
}
}
return cnt;
}
ColorPeg** PegRow::GetPegs()
{
return mColorPegs;
}
void PegRow::SetActive(const bool b)
{
mIsActive = b;
if (b)
{
setOpacity(1.0);
}
else
{
setOpacity(0.5);
}
update(boundingRect());
}
bool PegRow::SnapCP(ColorPeg *cp)
{
bool snapped = false;
if (mIsActive)
{
QPointF p = mapFromParent(cp->pos());
p.rx() += 18;
p.ry() += 18;
int ix = -1;
int i;
if (p.y() >= 0 && p.y() <= 40)
{
for (i = 0; i < 4; ++i)
{
if (p.x() >= i * 40 && p.x() < (i + 1) * 40)
{
if (mColorPegs[i] != NULL)
{
emit RemovePegSignal(mColorPegs[i]);
mColorPegs[i] = NULL;
}
mColorPegs[i] = cp;
cp->SetPegRow(this);
ix = i;
cp->setPos(mapToParent(i * 40 + 2, 2));
break;
}
}
}
snapped = ix > -1;
CheckSolution();
}
return snapped;
}
void PegRow::ForceSnap(ColorPeg* cp, int posix)
{
if (mIsActive)
{
if (mColorPegs[posix] != NULL)
{
emit RemovePegSignal(mColorPegs[posix]);
mColorPegs[posix] = NULL;
}
mColorPegs[posix] = cp;
cp->SetPegRow(this);
cp->setPos(mapToParent(posix * 40 + 2, 2));
CheckSolution();
}
}
void PegRow::CloseRow()
{
for (int i = 0; i < 4; ++i)
{
if (mColorPegs[i] != NULL)
{
mColorPegs[i]->SetEnabled(false);
}
}
SetActive(false);
}
void PegRow::CheckSolution()
{
mSolution.clear();
for (int i = 0; i < 4; ++i)
{
if (mColorPegs[i] != NULL)
{
//mColorPegs[i]->setEnabled(false);
//mColorPegs[i]->setFlags(QGraphicsItem::GraphicsItemFlags(0));
mSolution.push_back(mColorPegs[i]->GetPegType()->ix);
}
}
emit RowSolutionSignal(mIx);
}
std::vector<int> PegRow::GetSolution() const
{
return mSolution;
}
void PegRow::RemovePeg(ColorPeg *cp)
{
for (int i = 0; i < 4; ++i)
{
if (mColorPegs[i] == cp)
{
mColorPegs[i] = NULL;
if (mIsActive)
{
CheckSolution();
}
}
}
}
QVariant PegRow::itemChange(GraphicsItemChange change, const QVariant &value)
{
return QGraphicsItem::itemChange(change, value);
}
QPainterPath PegRow::shape() const
{
QPainterPath path;
path.addRect(boundingRect());
return path;
}
QRectF PegRow::boundingRect() const
{
const int Margin = 1;
return outlineRect().adjusted(-Margin, -Margin, +Margin, +Margin);
}
QRectF PegRow::outlineRect() const
{
return QRectF(0.0, 0.0, 160.0, 40.0);
}
void PegRow::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* /* widget */)
{
mPen.setWidth(2);
if (option->state & QStyle::State_Selected)
{
mPen.setStyle(Qt::DotLine);
}
painter->setPen(mPen);
int i;
for (i = 0; i < 4; i++)
{
QRadialGradient grad(QPointF(i * 40 + 10, 10), 100);
grad.setColorAt(0, QColor("#cccccc"));
grad.setColorAt(1, QColor("#ffffff"));
painter->setBrush(QBrush(grad));
painter->drawRect(QRectF(i * 40, 0.0, 40.0, 40.0));
}
}

View File

@ -0,0 +1,70 @@
#ifndef PEGROW_H
#define PEGROW_H
#include <QObject>
#include <QColor>
#include <QPen>
#include <QRadialGradient>
#include <QGraphicsItem>
#include <iostream>
#include <vector>
#include "mainwindow.h"
#include "pegrow.h"
#include "colorpeg.h"
class PegRow : public QObject, public QGraphicsItem
{
Q_OBJECT
public:
PegRow(QObject* parent = 0);
~PegRow();
int GetIx() const;
int GetPegCnt();
ColorPeg** GetPegs();
std::vector<int> GetSolution() const;
void SetIx(const int ix);
void SetActive(const bool b);
bool SnapCP(ColorPeg* cp);
void ForceSnap(ColorPeg* cp, int posix);
void RemovePeg(ColorPeg* cp);
void CloseRow();
void ClearRow();
void Reset();
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
QRectF boundingRect() const;
QPainterPath shape() const;
signals:
void RowSolutionSignal(int ix);
void RemovePegSignal(ColorPeg* cp);
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
//void contextMenuEvent(QGraphicsSceneContextMenuEvent* e);
private slots:
//void FillRandSlot();
private:
std::vector<int> mSolution;
QPen mPen;
bool mIsActive;
int mIx;
void CheckSolution();
ColorPeg* mColorPegs[4];
QRectF outlineRect() const;
/*
void InitActions();
void InitMenus();
QAction* FillRandAct;
QAction* ClearRowAct;
QMenu* ContextMenu;
*/
};
#endif // PEGROW_H

View File

@ -0,0 +1,25 @@
<RCC>
<qresource prefix="/" >
<file>docs/GPL.html</file>
<file>img/application-exit.png</file>
<file>img/document-new.png</file>
<file>img/GNU-icon16.png</file>
<file>img/GNU-icon32.png</file>
<file>img/GNU-icon64.png</file>
<file>img/GNU-icon.png</file>
<file>img/help-about.png</file>
<file>img/qt.png</file>
<file>img/story-editor.png</file>
<file>img/view-refresh.png</file>
<file>img/bm03.png</file>
<file>trans_de.qm</file>
<file>img/face-sad.png</file>
<file>img/edit-clear.png</file>
<file>img/edit-copy.png</file>
<file>img/system-switch-user.png</file>
<file>img/cc16.png</file>
<file>img/cc32.png</file>
<file>img/cc64.png</file>
<file>cc32.ico</file>
</qresource>
</RCC>

View File

@ -0,0 +1,154 @@
#include <QtGui>
#include "rowhint.h"
using namespace std;
RowHint::RowHint(QObject*)
{
//setFlags(QGraphicsItem::GraphicsItemFlags(0));
mIx = -1;
mPen = QPen(QColor("#808080"));
mPen.setWidth(2);
QRadialGradient grad(QPointF(10, 10), 100);
grad.setColorAt(0, QColor("#d8d8d8"));
grad.setColorAt(1, QColor("#ffffff"));
mBrush1 = QBrush(grad);
grad.setColorAt(0, QColor(216, 216, 216, 51));
grad.setColorAt(1, QColor(255, 255, 255, 51));
mBrush0 = QBrush(grad);
Reset();
}
RowHint::~RowHint()
{
scene()->removeItem(this);
}
void RowHint::Reset()
{
mActive = true;
mHints.clear();
mSolved = false;
SetActive(false);
}
int RowHint::GetIx() const
{
return mIx;
}
void RowHint::SetIx(const int ix)
{
mIx = ix;
}
void RowHint::SetActive(bool b)
{
if (b == mActive)
{
return;
}
mActive = b;
setAcceptHoverEvents(b);
setEnabled(b);
if (b)
{
setCursor(Qt::PointingHandCursor);
//setOpacity(1);
setToolTip(tr("Commit Your solution"));
}
else
{
setCursor(Qt::ArrowCursor);
//setOpacity(0.2);
setToolTip(QString(""));
}
//scene()->update(mapRectToScene(boundingRect()));
update(boundingRect());
}
void RowHint::DrawHints(std::vector<int> res)
{
mHints = res;
mSolved = true;
for (unsigned i = 0; i < mHints.size(); ++i)
{
}
update(boundingRect());
}
void RowHint::mousePressEvent(QGraphicsSceneMouseEvent *e)
{
if (mActive && !mSolved)
{
if (e->button() == Qt::LeftButton)
{
SetActive(false);
emit HintPressedSignal(mIx);
}
}
QGraphicsItem::mousePressEvent(e);
}
QPainterPath RowHint::shape() const
{
QPainterPath path;
path.addRect(boundingRect());
return path;
}
QRectF RowHint::boundingRect() const
{
const int Margin = 1;
return outlineRect().adjusted(-Margin, -Margin, +Margin, +Margin);
}
QRectF RowHint::outlineRect() const
{
return QRectF(0.0, 0.0, 40.0, 40.0);
}
void RowHint::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /* widget */)
{
painter->setPen(mPen);
if (mActive)
{
painter->setBrush(mBrush1);
}
else
{
painter->setBrush(mBrush0);
}
QPainterPath path;
path.addRect(QRectF(0.0, 0.0, 40.0, 40.0));
for (int i = 0; i < 4; i++)
{
//painter->drawEllipse(QRect((i % 2) * 16 + 6, floor(i / 2) * 16 + 6, 12, 12));
path.addEllipse(QRectF((i % 2) * 16 + 6, floor(i / 2) * 16 + 6, 12, 12));
}
//painter->drawRect(QRectF(0.0, 0.0, 40.0, 40.0));
painter->drawPath(path);
if (mSolved)
{
for (unsigned i = 0; i < mHints.size(); i++)
{
if (mHints.at(i) == 2)
{
painter->setBrush(QBrush(Qt::black));
}
else
{
painter->setBrush(QBrush(Qt::white));
}
painter->drawEllipse(QRectF((i % 2) * 16 + 6, floor(i / 2) * 16 + 6, 12, 12));
}
}
}

View File

@ -0,0 +1,49 @@
#ifndef ROWHINT_H
#define ROWHINT_H
#include <QGraphicsItem>
#include <QColor>
#include <QPen>
#include <QRadialGradient>
#include <iostream>
#include <vector>
#include "mainwindow.h"
class RowHint : public QObject, public QGraphicsItem
{
Q_OBJECT
public:
RowHint(QObject* parent = 0);
~RowHint();
int mIx;
bool mActive;
bool mSolved;
std::vector<int> mHints;
int GetIx() const;
void SetIx(const int ix);
void SetActive(bool b);
void DrawHints(std::vector<int> res);
void Reset();
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
QRectF boundingRect() const;
QPainterPath shape() const;
signals:
void HintPressedSignal(int ix);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent* e);
private:
QPen mPen;
QBrush mBrush0;
QBrush mBrush1;
QRectF outlineRect() const;
};
#endif // ROWHINT_H

View File

@ -0,0 +1,250 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="de_DE">
<defaultcodec>UTF-8</defaultcodec>
<context>
<name>About</name>
<message>
<source>&amp;Author</source>
<translation>&amp;Autor</translation>
</message>
<message>
<source>icon</source>
<translation></translation>
</message>
<message>
<source>&amp;License</source>
<translation>&amp;Lizenz</translation>
</message>
<message>
<source>A needful game to train your brain ;-)</source>
<translation>Ein Spiel, um den Verstand&lt;br&gt;wachzuhalten ;-)</translation>
</message>
<message>
<source>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.</source>
<translation> Dieses Programm ist freie Software. Sie können es unter den Bedingungen der GNU General Public License, wie von der Free Software Foundation veröffentlicht, weitergeben und/oder modifizieren, entweder gemäß Version 2 der Lizenz oder (nach Ihrer Option) jeder späteren Version.</translation>
</message>
<message>
<source>ColorCode</source>
<translation>ColorCode</translation>
</message>
<message>
<source>About ColorCode</source>
<translation>Info ColorCode</translation>
</message>
</context>
<context>
<name>MainWindow</name>
<message>
<source>New Game</source>
<translation>Neues Spiel</translation>
</message>
<message>
<source>Do you want to give in
and start a new Game?</source>
<translation>Wollen Sie aufgeben und
ein neues Spiel beginnen?</translation>
</message>
<message>
<source>About Qt</source>
<translation>Info Qt</translation>
</message>
<message>
<source>&amp;New Game</source>
<translation>&amp;Neues Spiel</translation>
</message>
<message>
<source>Ctrl+N</source>
<translation></translation>
</message>
<message>
<source>&amp;Restart Game</source>
<translation>Spiel neu &amp;beginnen</translation>
</message>
<message>
<source>Ctrl+R</source>
<translation></translation>
</message>
<message>
<source>E&amp;xit</source>
<translation>B&amp;eenden</translation>
</message>
<message>
<source>Ctrl+Q</source>
<translation></translation>
</message>
<message>
<source>Ctrl+T</source>
<translation></translation>
</message>
<message>
<source>Ctrl+C</source>
<translation></translation>
</message>
<message>
<source>Ctrl+4</source>
<translation></translation>
</message>
<message>
<source>Ctrl+A</source>
<translation></translation>
</message>
<message>
<source>About &amp;Qt</source>
<translation>Info &amp;Qt</translation>
</message>
<message>
<source>&amp;Game</source>
<translation>&amp;Spiel</translation>
</message>
<message>
<source>&amp;Settings</source>
<translation>&amp;Einstellungen</translation>
</message>
<message>
<source>&amp;Help</source>
<translation>&amp;Hilfe</translation>
</message>
<message>
<source>Game</source>
<translation>Spiel</translation>
</message>
<message>
<source>Message</source>
<translation>Hinweis</translation>
</message>
<message>
<source>The changed settings will only apply to new games!
Do you want to give in the current and start a new Game?</source>
<translation>Die geänderten Einstellungen werden erst in neuen Spielen berücksichtigt!
Möchten Sie das gegenwärtige Spiel aufgeben und ein neues Spiel beginnen?</translation>
</message>
<message>
<source>Press the Hint Field if You&apos;re done.</source>
<translation>Fertig? Dann klicken Sie auf das Hinweis-Feld.</translation>
</message>
<message>
<source>Place Your pegs ...</source>
<translation>Setzen Sie Ihre Steine ...</translation>
</message>
<message>
<source>Congratulation! You have won!</source>
<translation>Glückwunsch! Sie haben gewonnen!</translation>
</message>
<message>
<source>Sorry! You lost!</source>
<translation>Schade, aber Sie haben es nicht vermocht!</translation>
</message>
<message>
<source>Ctrl+I</source>
<translation></translation>
</message>
<message>
<source>Give In</source>
<translation>Aufgeben</translation>
</message>
<message>
<source>Do you really want to give in?</source>
<translation>Wollen Sie wirklich aufgeben?</translation>
</message>
<message>
<source>&amp;Throw In The Towel</source>
<translation>&amp;Handtuch werfen</translation>
</message>
<message>
<source>Ctrl+G</source>
<translation></translation>
</message>
<message>
<source>Sure, You&apos;re too weak for me!</source>
<translation>Klar, Sie sind zu schwach für mich!</translation>
</message>
<message>
<source>Ctrl+Shift+R</source>
<translation></translation>
</message>
<message>
<source>Ctrl+Shift+C</source>
<translation></translation>
</message>
<message>
<source>Fill Row by Random</source>
<translation>Reihe zufällig füllen</translation>
</message>
<message>
<source>Duplicate Previous Row</source>
<translation>Vorherige Reihe duplizieren</translation>
</message>
<message>
<source>Ctrl+D</source>
<translation></translation>
</message>
<message>
<source>Clear Row</source>
<translation>Reihe leeren</translation>
</message>
<message>
<source>&amp;Row</source>
<translation>&amp;Reihe</translation>
</message>
<message>
<source>ColorCode</source>
<translation>ColorCode</translation>
</message>
<message>
<source>About &amp;ColorCode</source>
<translation>Info &amp;ColorCode</translation>
</message>
<message>
<source>Ctrl+M</source>
<translation></translation>
</message>
<message>
<source>Ctrl+S</source>
<translation></translation>
</message>
<message>
<source>Easy - 6 Colors</source>
<translation>Leicht - 6 Farben</translation>
</message>
<message>
<source>Medium - 8 Colors</source>
<translation>Mittel - 8 Farben</translation>
</message>
<message>
<source>Hard - 10 Colors</source>
<translation>Schwer - 10 Farben</translation>
</message>
<message>
<source>Show Toolbar</source>
<translation>Toolbar anzeigen</translation>
</message>
<message>
<source>Show Menubar</source>
<translation>Menüleiste anzeigen</translation>
</message>
<message>
<source>Show Statusbar</source>
<translation>Statusleiste anzeigen</translation>
</message>
<message>
<source>Allow Pegs of the Same Color</source>
<translation>Steine gleicher Farbe erlauben</translation>
</message>
<message>
<source>Close Rows when the 4th Peg is placed</source>
<translation>Reihen nach Setzen des 4. Steins auswerten</translation>
</message>
<message>
<source>Level</source>
<translation>Schwierigkeitsgrad</translation>
</message>
</context>
<context>
<name>RowHint</name>
<message>
<source>Commit Your solution</source>
<translation>Kombination testen</translation>
</message>
</context>
</TS>

View File

@ -0,0 +1,248 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0">
<defaultcodec>UTF-8</defaultcodec>
<context>
<name>About</name>
<message>
<source>&amp;Author</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>icon</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&amp;License</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>A needful game to train your brain ;-)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>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.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>ColorCode</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>About ColorCode</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MainWindow</name>
<message>
<source>New Game</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Do you want to give in
and start a new Game?</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>About Qt</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&amp;New Game</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ctrl+N</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&amp;Restart Game</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ctrl+R</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>E&amp;xit</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ctrl+Q</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ctrl+T</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ctrl+C</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ctrl+4</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ctrl+A</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>About &amp;Qt</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&amp;Game</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&amp;Settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&amp;Help</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Game</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Message</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>The changed settings will only apply to new games!
Do you want to give in the current and start a new Game?</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Press the Hint Field if You&apos;re done.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Place Your pegs ...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Congratulation! You have won!</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Sorry! You lost!</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ctrl+I</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Give In</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Do you really want to give in?</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&amp;Throw In The Towel</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ctrl+G</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Sure, You&apos;re too weak for me!</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ctrl+Shift+R</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ctrl+Shift+C</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Fill Row by Random</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Duplicate Previous Row</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ctrl+D</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Clear Row</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&amp;Row</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>ColorCode</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>About &amp;ColorCode</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ctrl+M</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ctrl+S</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Easy - 6 Colors</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Medium - 8 Colors</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Hard - 10 Colors</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show Toolbar</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show Menubar</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show Statusbar</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Allow Pegs of the Same Color</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Close Rows when the 4th Peg is placed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Level</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RowHint</name>
<message>
<source>Commit Your solution</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>