Browse Source

initial checkin

tags/1.3
Sven Oliver Moll 6 years ago
parent
commit
7fe0d08cff

+ 2
- 0
.gitignore View File

@@ -0,0 +1,2 @@
build*
*.pro.user

+ 21
- 0
Makefile View File

@@ -0,0 +1,21 @@

QMAKE ?= qmake

all: release

debug release: src/Makefile
+(cd src;make $(MAKEFLAGS) $@)

src/Makefile:
(cd src;$(QMAKE) -r CONFIG+=debug_and_release)

clean:
(cd src;make distclean)
rm -rf build

exe:
(cd packaging/windows ; ./build-cross.sh)

dmg:
(cd packaging/macosx ; ./build-app.sh)


+ 10
- 0
README.md View File

@@ -0,0 +1,10 @@
FridgeGrid
==========

FridgeGrid is a tool intended to help planning cycle exact code for effects on
old school hardware.

Originally developed for creating Atari 2600 VCS demos, it was extended be
usable for other systems as well. Templates include also the VIC-20 and the
C64.


+ 5
- 0
TODO View File

@@ -0,0 +1,5 @@

- export to png
- "new" in file menu
- templates


+ 44
- 0
packaging/macosx/build-app.sh View File

@@ -0,0 +1,44 @@
#!/bin/sh

set -e
cd "$(dirname $0)"

QTDIR=/usr/local/Trolltech/Qt-4.7.0
export PATH=${PATH}:${QTDIR}/bin

PACKAGINGDIR=../../build/package
BUILDAPP=../../build/release/bin/fridgegrid.app
DEPLOYAPP=${PACKAGINGDIR}/fridgegrid.app
PLUGINDIR=Contents/PlugIns

if [ -d "${DEPLOYAPP}" ]; then
rm -rf "${DEPLOYAPP}"
fi

(cd ../..
# rm -rf build
# qmake -r CONFIG+=release
make release)

mkdir -p "$(dirname ${DEPLOYAPP})"
cp -a "${BUILDAPP}" "${DEPLOYAPP}"

mkdir -p "${DEPLOYAPP}/${PLUGINDIR}"
for plugin in ../../build/release/lib/*.dylib; do
if [ -f ${plugin} ]; then
echo "${plugin}"
cp "${plugin}" "${DEPLOYAPP}/${PLUGINDIR}"
for lib in $(otool -L ${plugin}|grep Qt|sed 's/(.*)//g'|tr -d ' \t'); do
echo " ${lib}"
install_name_tool -change ${lib} \
$(echo ${lib}|sed 's,.*/lib/,@executable_path/../Frameworks/,') \
${DEPLOYAPP}/${PLUGINDIR}/${plugin##*/}
done
fi
done

(cd "$(dirname ${DEPLOYAPP})";macdeployqt "$(basename ${DEPLOYAPP})" -verbose=2)
pwd
rm -f ../../../fridgegrid.dmg
hdiutil create ../../../fridgegrid.dmg -volname "FridgeGrid" -fs HFS+ -srcfolder "${DEPLOYAPP}"


+ 11
- 0
packaging/source/build.sh View File

@@ -0,0 +1,11 @@
#!/bin/sh

set -e

cd "$(dirname $0)"
cd ../../..

find fridgegrid/LICENSE.GPL fridgegrid/Makefile fridgegrid/packaging fridgegrid/src -type f |
grep -v -e 'src/.*Makefile' -e '\.pro\.user$' -e '\.gitignore' |
xargs tar zcvf fridgegrid.tar.gz
advdef -z4 fridgegrid.tar.gz || true

+ 37
- 0
packaging/windows/build-cross.sh View File

@@ -0,0 +1,37 @@
#!/bin/sh

MINGW=/opt/mxe
PLATFORM=i686-pc-mingw32

PACKAGINGDIR=../../build/packaging

set -e

export PATH=${PATH}:${MINGW}/usr/bin

cd "$(dirname $0)"
(cd ../..
#rm -rf build
#${PLATFORM}-qmake -r CONFIG+=debug_and_release
MAKEFLAGS=-j4 make release QMAKE=${PLATFORM}-qmake)

mkdir -p ${PACKAGINGDIR}

for i in ../../build/release/bin/* ../../build/release/lib/*.dll; do
if [ -f "${i}" ]; then
INSTALLFILES="${INSTALLFILES} ${i}"
fi
done

QTLIBS="$(${PLATFORM}-objdump -x ${INSTALLFILES} | tr ' ' '\n' | grep ^Qt.*dll$ | sort -u | sed s,^,${MINGW}/usr/${PLATFORM}/bin/,)"

rm -f ${PACKAGINGDIR}/files-install.nsh ${PACKAGINGDIR}/files-delete.nsh
for i in ${INSTALLFILES} ${QTLIBS};do
echo " File \"$(echo ${i}|tr '/' '\\')\"" \
>> ${PACKAGINGDIR}/files-install.nsh
echo " Delete \$INSTDIR\\${i##*/}" \
>> ${PACKAGINGDIR}/files-delete.nsh
done

${PLATFORM}-makensis fridgegrid-cross.nsi


+ 99
- 0
packaging/windows/fridgegrid-cross.nsi View File

@@ -0,0 +1,99 @@
; fridgegrid-cross.nsi
;
; hacked by Sven Oliver Moll using example2.nsi as a template
;
; distributed under the terms of the GNU General Public License (GPL)
; available at http://www.gnu.org/licenses/gpl.html
;
;--------------------------------
; The name of the installer
Name "fridgegrid"
; The file to write
OutFile "..\..\..\fridgegrid-installer.exe"
; The default installation directory
InstallDir $PROGRAMFILES\fridgegrid
; Registry key to check for directory (so if you install again, it will
; overwrite the old one automatically)
InstallDirRegKey HKLM "Software\fridgegrid" "Install_Dir"
; Request application privileges for Windows Vista
RequestExecutionLevel admin
; Set maximum compression
SetCompressor /SOLID lzma
; License to use
LicenseData ..\..\LICENSE.GPL
;--------------------------------
; Pages
Page license
;Page components
Page directory
Page instfiles
UninstPage uninstConfirm
UninstPage instfiles
;--------------------------------
; The stuff to install
Section "fridgegrid (required)"
SectionIn RO
; Set output path to the installation directory.
SetOutPath $INSTDIR
; Put file there
!include ..\..\build\packaging\files-install.nsh
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\fridgegrid "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\fridgegrid" "DisplayName" "fridgegrid"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\fridgegrid" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\fridgegrid" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\fridgegrid" "NoRepair" 1
WriteUninstaller "uninstall.exe"
SectionEnd
; Optional section (can be disabled by the user)
Section "Start Menu Shortcuts"
CreateDirectory "$SMPROGRAMS\fridgegrid"
CreateShortCut "$SMPROGRAMS\fridgegrid\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
CreateShortCut "$SMPROGRAMS\fridgegrid\fridgegrid.lnk" "$INSTDIR\fridgegrid.exe" "" "$INSTDIR\fridgegrid.exe" 0
SectionEnd
;--------------------------------
; Uninstaller
Section "Uninstall"
; Remove registry keys
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\fridgegrid"
DeleteRegKey HKLM SOFTWARE\fridgegrid
; Remove files and uninstaller
!include ..\..\build\packaging\files-delete.nsh
Delete $INSTDIR\uninstall.exe
; Remove shortcuts, if any
Delete "$SMPROGRAMS\fridgegrid\*.*"
; Remove directories used
RMDir "$SMPROGRAMS\fridgegrid"
RMDir "$INSTDIR"
SectionEnd

+ 138
- 0
src/Makefile View File

@@ -0,0 +1,138 @@
#############################################################################
# Makefile for building: src
# Generated by qmake (2.01a) (Qt 4.8.1) on: Fri Apr 5 18:57:12 2013
# Project: src.pro
# Template: subdirs
# Command: /opt/mxe/usr/bin/i686-pc-mingw32-qmake CONFIG+=debug_and_release -o Makefile src.pro
#############################################################################

first: make_default
MAKEFILE = Makefile
QMAKE = /opt/mxe/usr/bin/i686-pc-mingw32-qmake
DEL_FILE = rm -f
CHK_DIR_EXISTS= test -d
MKDIR = mkdir -p
COPY = cp
COPY_FILE = $(COPY)
COPY_DIR = cp -R
INSTALL_FILE = $(COPY_FILE)
INSTALL_PROGRAM = $(COPY_FILE)
INSTALL_DIR = $(COPY_DIR)
DEL_FILE = rm -f
SYMLINK = ln -s
DEL_DIR = rmdir
MOVE = mv
CHK_DIR_EXISTS= test -d
MKDIR = mkdir -p
SUBTARGETS = \
sub-fridgegrid

fridgegrid/$(MAKEFILE):
@$(CHK_DIR_EXISTS) fridgegrid/ || $(MKDIR) fridgegrid/
cd fridgegrid/ && $(QMAKE) /home/svolli/src/fridgegrid/src/fridgegrid/fridgegrid.pro CONFIG+=debug_and_release -o $(MAKEFILE)
sub-fridgegrid-qmake_all: FORCE
@$(CHK_DIR_EXISTS) fridgegrid/ || $(MKDIR) fridgegrid/
cd fridgegrid/ && $(QMAKE) /home/svolli/src/fridgegrid/src/fridgegrid/fridgegrid.pro CONFIG+=debug_and_release -o $(MAKEFILE)
sub-fridgegrid: fridgegrid/$(MAKEFILE) FORCE
cd fridgegrid/ && $(MAKE) -f $(MAKEFILE)
sub-fridgegrid-make_default: fridgegrid/$(MAKEFILE) FORCE
cd fridgegrid/ && $(MAKE) -f $(MAKEFILE)
sub-fridgegrid-make_first: fridgegrid/$(MAKEFILE) FORCE
cd fridgegrid/ && $(MAKE) -f $(MAKEFILE) first
sub-fridgegrid-all: fridgegrid/$(MAKEFILE) FORCE
cd fridgegrid/ && $(MAKE) -f $(MAKEFILE) all
sub-fridgegrid-clean: fridgegrid/$(MAKEFILE) FORCE
cd fridgegrid/ && $(MAKE) -f $(MAKEFILE) clean
sub-fridgegrid-distclean: fridgegrid/$(MAKEFILE) FORCE
cd fridgegrid/ && $(MAKE) -f $(MAKEFILE) distclean
sub-fridgegrid-install_subtargets: fridgegrid/$(MAKEFILE) FORCE
cd fridgegrid/ && $(MAKE) -f $(MAKEFILE) install
sub-fridgegrid-uninstall_subtargets: fridgegrid/$(MAKEFILE) FORCE
cd fridgegrid/ && $(MAKE) -f $(MAKEFILE) uninstall

Makefile: src.pro /opt/mxe/usr/i686-pc-mingw32/mkspecs/unsupported/win32-g++-4.6-cross/qmake.conf /opt/mxe/usr/i686-pc-mingw32/mkspecs/qconfig.pri \
/opt/mxe/usr/i686-pc-mingw32/mkspecs/modules/qt_webkit_version.pri \
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/qt_functions.prf \
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/qt_config.prf \
/opt/mxe/usr/i686-pc-mingw32/mkspecs/unsupported/win32-g++-cross/qmake.conf \
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/exclusive_builds.prf \
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/default_pre.prf \
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/win32/default_pre.prf \
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/release.prf \
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/debug_and_release.prf \
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/default_post.prf \
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/win32/default_post.prf \
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/win32/stl.prf \
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/win32/rtti.prf \
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/win32/exceptions.prf \
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/warn_on.prf \
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/qt.prf \
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/win32/thread.prf \
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/moc.prf \
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/win32/windows.prf \
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/resources.prf \
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/uic.prf \
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/yacc.prf \
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/lex.prf \
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/include_source_dir.prf
$(QMAKE) CONFIG+=debug_and_release -o Makefile src.pro
/opt/mxe/usr/i686-pc-mingw32/mkspecs/qconfig.pri:
/opt/mxe/usr/i686-pc-mingw32/mkspecs/modules/qt_webkit_version.pri:
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/qt_functions.prf:
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/qt_config.prf:
/opt/mxe/usr/i686-pc-mingw32/mkspecs/unsupported/win32-g++-cross/qmake.conf:
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/exclusive_builds.prf:
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/default_pre.prf:
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/win32/default_pre.prf:
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/release.prf:
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/debug_and_release.prf:
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/default_post.prf:
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/win32/default_post.prf:
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/win32/stl.prf:
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/win32/rtti.prf:
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/win32/exceptions.prf:
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/warn_on.prf:
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/qt.prf:
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/win32/thread.prf:
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/moc.prf:
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/win32/windows.prf:
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/resources.prf:
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/uic.prf:
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/yacc.prf:
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/lex.prf:
/opt/mxe/usr/i686-pc-mingw32/mkspecs/features/include_source_dir.prf:
qmake: qmake_all FORCE
@$(QMAKE) CONFIG+=debug_and_release -o Makefile src.pro

qmake_all: sub-fridgegrid-qmake_all FORCE

make_default: sub-fridgegrid-make_default FORCE
make_first: sub-fridgegrid-make_first FORCE
all: sub-fridgegrid-all FORCE
clean: sub-fridgegrid-clean FORCE
distclean: sub-fridgegrid-distclean FORCE
-$(DEL_FILE) Makefile
install_subtargets: sub-fridgegrid-install_subtargets FORCE
uninstall_subtargets: sub-fridgegrid-uninstall_subtargets FORCE

sub-fridgegrid-sub_Debug: fridgegrid/$(MAKEFILE)
cd fridgegrid/ && $(MAKE) -f $(MAKEFILE) debug
debug: sub-fridgegrid-sub_Debug

sub-fridgegrid-sub_Release: fridgegrid/$(MAKEFILE)
cd fridgegrid/ && $(MAKE) -f $(MAKEFILE) release
release: sub-fridgegrid-sub_Release

sub-fridgegrid-check: fridgegrid/$(MAKEFILE)
cd fridgegrid/ && $(MAKE) -f $(MAKEFILE) check
check: sub-fridgegrid-check

mocclean: compiler_moc_header_clean compiler_moc_source_clean

mocables: compiler_moc_header_make_all compiler_moc_source_make_all
install: install_subtargets FORCE

uninstall: uninstall_subtargets FORCE

FORCE:


+ 57
- 0
src/buildconfig.pri View File

@@ -0,0 +1,57 @@
#############################################################################
# src/buildconfig.pri
# hand hacked by SvOlli
# released as public domain
#############################################################################

contains(QT_VERSION, ^4\\.[0-3]\\..*) {
message("Cannot build this software with Qt version $${QT_VERSION}.")
error("Use at least Qt 4.4.")
}

count( TOPSRC, 0 ) {
TOPSRC = ".."
}
BUILDDIR = $${TOPSRC}/..

count( TARGET, 0 ) {
error(TARGET not set $$TARGET)
}

build_pass:CONFIG(release, debug|release) {
TARGETARCH = "release"
} else {
TARGETARCH = "debug"
}

contains(TEMPLATE,app) {
is_test = $$find( OUT_PWD, "/tests/" )
count( is_test, 1 ) {
DESTDIR = $${BUILDDIR}/build/$${TARGETARCH}/test
} else {
DESTDIR = $${BUILDDIR}/build/$${TARGETARCH}/bin
}
} else {
contains( CONFIG, plugin ) {
DESTDIR = $${BUILDDIR}/build/$${TARGETARCH}/lib
} else {
DESTDIR = $${BUILDDIR}/build/$${TARGETARCH}/tmp/lib
}
}
LIBS += -L$${BUILDDIR}/build/$${TARGETARCH}/tmp/lib

DLLDESTDIR = $${BUILDDIR}/build/$${TARGETARCH}/lib
MOC_DIR = $${BUILDDIR}/build/$${TARGETARCH}/tmp/$${TARGET}/moc
OBJECTS_DIR = $${BUILDDIR}/build/$${TARGETARCH}/tmp/$${TARGET}/objs
RCC_DIR = $${BUILDDIR}/build/$${TARGETARCH}/tmp/$${TARGET}/rcc
UI_DIR = $${BUILDDIR}/build/$${TARGETARCH}/tmp/$${TARGET}/ui
UI_HEADERS_DIR = $${BUILDDIR}/build/$${TARGETARCH}/tmp/$${TARGET}/ui_headers
UI_SOURCES_DIR = $${BUILDDIR}/build/$${TARGETARCH}/tmp/$${TARGET}/ui_sources

contains( QMAKE_CXX, g++ ) {
QMAKE_CXXFLAGS_DEBUG += -pedantic -Wno-long-long
QMAKE_CXXFLAGS += -ffunction-sections -fdata-sections
!macx {
QMAKE_LFLAGS += -Wl,--gc-sections -rdynamic
}
}

+ 277
- 0
src/fridgegrid/DragLabel.cpp View File

@@ -0,0 +1,277 @@
/*
* tools/src/fridgemagnets/MainWindow.cpp
* written by Sven Oliver Moll
*
* distributed under the terms of the GNU General Public License (GPL)
* available at http://www.gnu.org/licenses/gpl.html
*/

/* class declaration */
#include "DragLabel.hpp"

/* system headers */

/* Qt headers */
#include <QContextMenuEvent>
#include <QMenu>
#include <QPainter>

/* local library headers */

/* local headers */
#include "DragWidget.hpp"
#include "DragLabelPropertiesDialog.hpp"



DragLabel::DragLabel( DragWidget *parent )
: QLabel(parent)
, mpParent( parent )
, mSize( 4, 1 )
, mText()
, mColor( 192, 192, 255 )
{
draw();
connect( this, SIGNAL(requestCopy(QByteArray,QPoint)),
parent, SLOT(newElement(QByteArray,QPoint)) );
}


DragLabel::DragLabel( const QSize &size, const QString &text,
DragWidget *parent, const QColor &color )
: QLabel(parent)
, mpParent( parent )
, mSize( size )
, mText( text )
, mColor( color )
{
draw();
connect( this, SIGNAL(requestCopy(QByteArray,QPoint)),
parent, SLOT(newElement(QByteArray,QPoint)) );
}


DragLabel::DragLabel( const QByteArray &d, DragWidget *parent )
: QLabel( parent )
, mpParent( parent )
, mSize()
, mText()
, mColor()
{
setFromByteArray( d );
connect( this, SIGNAL(requestCopy(QByteArray,QPoint)),
parent, SLOT(newElement(QByteArray,QPoint)) );
}


QPoint DragLabel::setFromByteArray( const QByteArray &d )
{
QPoint point;
QByteArray dataCopy( d );
QDataStream dataStream( &dataCopy, QIODevice::ReadOnly );
dataStream >> mText >> mColor >> mSize >> point;
draw();
move( point );
return point;
}


QByteArray DragLabel::toByteArray() const
{
QByteArray data;
QDataStream dataStream( &data, QIODevice::WriteOnly );
dataStream << mText << mColor << mSize << pos();
return data;
}


QString DragLabel::labelText() const
{
return mText;
}


QColor DragLabel::color() const
{
return mColor;
}


void DragLabel::setLabelText( const QString &text )
{
mText = text;
draw();
}


void DragLabel::setGridSizeWidth( int width )
{
mSize.setWidth( width );
draw();
}


void DragLabel::setGridSizeHeight( int height )
{
mSize.setHeight( height );
draw();
}


void DragLabel::setColor(const QColor &color)
{
mColor = color;
draw();
}


void DragLabel::parameterMenu( const QPoint &position )
{
DragLabelPropertiesDialog dialog( this );
dialog.move( position - QPoint( 30, 30 ) );
dialog.exec();
}


void DragLabel::contextMenuEvent( QContextMenuEvent *event )
{
QMenu menu( this );

QAction *setParams = new QAction( tr("Set Parameters"), this );
QAction *duplicate = new QAction( tr("Duplicate"), this );
QAction *destroy = new QAction( tr("Delete"), this );
menu.addAction( setParams );
menu.addAction( duplicate );
menu.addAction( destroy );
QAction *selected = menu.exec( event->globalPos() );
if( selected == setParams )
{
parameterMenu( event->globalPos() );
}
else if( selected == duplicate )
{
emit requestCopy( toByteArray(), pos() );
}
else if( selected == destroy )
{
deleteLater();
}
}


QSize DragLabel::gridSize() const
{
return mSize;
}


void DragLabel::setGridSize( const QSize &size )
{
mSize = size;
draw();
}


void DragLabel::draw()
{
if( mSize.width() <= 0 )
{
mSize.setWidth( 1 );
}
if( mSize.height() <= 0 )
{
mSize.setHeight( 1 );
}
QFontMetrics metric(font());
QSize size = metric.size(Qt::TextSingleLine, mText);

int imgWidth = 0;
int imgHeight = 0;
bool rotate = false;
QSize grid( mpParent->gridSize() );

if( (mSize.width() * grid.width() - 4) >= (mSize.height() * grid.height() - 4) )
{
imgWidth = (mSize.width() * grid.width() - 4);
imgHeight = (mSize.height() * grid.height() - 4);
rotate = false;
}
else
{
imgHeight = (mSize.width() * grid.width() - 4);
imgWidth = (mSize.height() * grid.height() - 4);
rotate = true;
}
QImage image( imgWidth, imgHeight, QImage::Format_ARGB32_Premultiplied );
setSizeIncrement( grid );
image.fill(qRgba(0, 0, 0, 0));

QFont font;
font.setStyleStrategy( QFont::ForceOutline );

QPainter painter;
painter.begin( &image );
painter.setRenderHint( QPainter::Antialiasing );
painter.setBrush( mColor );
painter.drawRect( QRectF(0.5, 0.5, image.width()-1, image.height()-1) );

painter.setFont( font );
if( (mColor.red() < 96) &&
(mColor.green() < 96) &&
(mColor.blue() < 96) )
{
painter.setPen( QColor(255,255,255) );
}
else
{
painter.setPen( QColor(0,0,0) );
}
painter.drawText( QRect(QPoint(2, 0), size), Qt::AlignCenter, mText );
painter.end();

if( rotate )
{
QTransform rot;
rot.rotate( 90 );
image = image.transformed( rot );
}
setPixmap( QPixmap::fromImage(image) );
resize( image.width(), image.height() );
}


void DragLabel::writeDomAttributes( QDomElement *domElement ) const
{
domElement->setAttribute( "text", mText );
domElement->setAttribute( "x", pos().x() / mpParent->gridSize().width() );
domElement->setAttribute( "y", pos().y() / mpParent->gridSize().height() );
domElement->setAttribute( "width", mSize.width() );
domElement->setAttribute( "height", mSize.height() );
domElement->setAttribute( "color", mColor.name() );
}


QPoint DragLabel::readDomAttributes( const QDomElement *domElement )
{
bool ok = true;
int x = mpParent->gridSize().width() * domElement->attribute( "x" ).toInt( &ok );
if( !ok ) return QPoint();
int y = mpParent->gridSize().height() * domElement->attribute( "y" ).toInt( &ok );
if( !ok ) return QPoint();
int width = domElement->attribute( "width" ).toInt( &ok );
if( !ok ) return QPoint();
int height = domElement->attribute( "height" ).toInt( &ok );
if( !ok ) return QPoint();
QString text = domElement->attribute( "text");
if( text.isNull() ) return QPoint();
mText = text;
mSize.setHeight( height );
mSize.setWidth( width );
QColor color( domElement->attribute( "color" ) );
if( color.isValid() )
{
mColor = color;
}
draw();
return QPoint( x, y );
}

+ 177
- 0
src/fridgegrid/DragLabel.hpp View File

@@ -0,0 +1,177 @@
/*
* tools/src/fridgemagnets/DragLabel.hpp
* written by Sven Oliver Moll
*
* distributed under the terms of the GNU General Public License (GPL)
* available at http://www.gnu.org/licenses/gpl.html
*/

#ifndef DRAGLABEL_HPP
#define DRAGLABEL_HPP DRAGLABEL_HPP


/* base class */
#include <QLabel>

/* system headers */

/* Qt headers */
#include <QDomElement>

/* local library headers */

/* local headers */

/* forward declaration of Qt classes */
class QDragEnterEvent;
class QDragMoveEvent;
class QFrame;

/* forward declaration of local classes */
class DragWidget;



/*!
\brief \todo

*/
class DragLabel : public QLabel
{
Q_OBJECT

public:
/*!
\brief \todo

\param parent
*/
DragLabel( DragWidget *parent );
/*!
\brief \todo

\param size
\param text
\param parent
\param color
*/
DragLabel( const QSize &size, const QString &text, DragWidget *parent, const QColor &color = QColor(192,192,255) );
/*!
\brief \todo

\param d
\param parent
*/
DragLabel( const QByteArray &d, DragWidget *parent );
/*!
\brief \todo

\return QString
*/
QString labelText() const;
/*!
\brief \todo

\return QColor
*/
QColor color() const;
/*!
\brief \todo

\return QSize
*/
QSize gridSize() const;
/*!
\brief \todo

\param d
\return
*/
QPoint setFromByteArray( const QByteArray &d );
/*!
\brief \todo

\return QByteArray
*/
QByteArray toByteArray() const;
/*!
\brief \todo

\param size
*/
void setGridSize( const QSize &size );
/*!
\brief \todo

\param domElement
*/
void writeDomAttributes( QDomElement *domElement ) const;
/*!
\brief \todo

\param domElement
\return QPoint
*/
QPoint readDomAttributes( const QDomElement *domElement );

public slots:
/*!
\brief \todo

*/
void parameterMenu( const QPoint &position );
/*!
\brief \todo

\param text
*/
void setLabelText( const QString &text );
/*!
\brief \todo

\param width
*/
void setGridSizeWidth( int width );
/*!
\brief \todo

\param height
*/
void setGridSizeHeight( int height );
/*!
\brief \todo

\param color
*/
void setColor( const QColor &color );
/*!
\brief \todo

*/
void draw();

signals:
/*!
\brief \todo

\param d
\param p
*/
void requestCopy( const QByteArray &d, const QPoint &p );

protected:
/*!
\brief \todo

\param event
*/
void contextMenuEvent( QContextMenuEvent *event );

private:

DragWidget *mpParent; /*!< \brief \todo TODO */
QSize mSize; /*!< \brief \todo TODO */
QString mText; /*!< \brief \todo TODO */
QColor mColor; /*!< \brief \todo TODO */
};
#endif

+ 123
- 0
src/fridgegrid/DragLabelPropertiesDialog.cpp View File

@@ -0,0 +1,123 @@
/*
* tools/src/fridgemagnets/MainWindow.cpp
* written by Sven Oliver Moll
*
* distributed under the terms of the GNU General Public License (GPL)
* available at http://www.gnu.org/licenses/gpl.html
*/

/* class declaration */
#include "DragLabelPropertiesDialog.hpp"

/* system headers */

/* Qt headers */
#include <QColorDialog>
#include <QGridLayout>
#include <QLineEdit>
#include <QPushButton>
#include <QSpinBox>

/* local library headers */

/* local headers */
#include "DragLabel.hpp"



DragLabelPropertiesDialog::DragLabelPropertiesDialog( DragLabel *parent )
: QDialog( parent )
, mpParent( parent )
, mpTextEdit( new QLineEdit( this ) )
, mpWidthEdit( new QSpinBox( this ) )
, mpHeightEdit( new QSpinBox( this ) )
, mpColorEdit( new QLineEdit( this ) )
, mOld( parent->toByteArray() )
{
QLabel *textLabel = new QLabel( tr("Text"), this );
QLabel *widthLabel = new QLabel( tr("Width"), this );
QLabel *heightLabel = new QLabel( tr("Height"), this );
QPushButton *ok = new QPushButton( tr("Ok"), this );
QPushButton *cancel = new QPushButton( tr("Cancel"), this );
QPushButton *colorLabel = new QPushButton( tr("Color"), this );
QGridLayout *layout = new QGridLayout( this );
mpTextEdit->setText( mpParent->labelText() );
mpWidthEdit->setValue( mpParent->gridSize().width() );
mpHeightEdit->setValue( mpParent->gridSize().height() );
mpWidthEdit->setRange( 1, 76 );
mpHeightEdit->setRange( 1, 30 );
mpColorEdit->setMaxLength( 6 );
mpColorEdit->setText( mpParent->color().name().mid(1) );

layout->addWidget( textLabel, 0, 0, 1, 2 );
layout->addWidget( widthLabel, 1, 0, 1, 2 );
layout->addWidget( heightLabel, 2, 0, 1, 2 );
layout->addWidget( colorLabel, 3, 0, 1, 2 );
layout->addWidget( mpTextEdit, 0, 2, 1, 2 );
layout->addWidget( mpWidthEdit, 1, 2, 1, 2 );
layout->addWidget( mpHeightEdit, 2, 2, 1, 2 );
layout->addWidget( mpColorEdit, 3, 2, 1, 2 );
layout->addWidget( ok, 4, 0 );
layout->addWidget( cancel, 4, 3 );

//ok->setShortcut( QKeySequence(Qt::Key_Enter) );
connect( cancel, SIGNAL(clicked()),
this, SLOT(reject()) );
connect( ok, SIGNAL(clicked()),
this, SLOT(accept()) );
connect( colorLabel, SIGNAL(clicked()),
this, SLOT(colorDialog()) );

connect( mpTextEdit, SIGNAL(textChanged(QString)),
parent, SLOT(setLabelText(QString)) );
connect( mpWidthEdit, SIGNAL(valueChanged(int)),
parent, SLOT(setGridSizeWidth(int)) );
connect( mpHeightEdit, SIGNAL(valueChanged(int)),
parent, SLOT(setGridSizeHeight(int)) );
connect( mpColorEdit, SIGNAL(textChanged(QString)),
this, SLOT(setColorValue(QString)) );

connect( this, SIGNAL(rejected()),
this, SLOT(revert()) );
}


DragLabelPropertiesDialog::~DragLabelPropertiesDialog()
{
}


void DragLabelPropertiesDialog::colorDialog()
{
QColor old( mpParent->color() );
QColorDialog colorDialog( this );
colorDialog.setCurrentColor( old );
connect( &colorDialog, SIGNAL(colorSelected(QColor)),
mpParent, SLOT(setColor(QColor)) );
connect( &colorDialog, SIGNAL(currentColorChanged(QColor)),
this, SLOT(setColorValue(QColor)) );
if( colorDialog.exec() == QDialog::Rejected )
{
mpParent->setColor( old );
mpColorEdit->setText( old.name().mid(1) );
}
}


void DragLabelPropertiesDialog::revert()
{
mpParent->setFromByteArray( mOld );
}


void DragLabelPropertiesDialog::setColorValue( const QString &color )
{
mpParent->setColor( QColor( QString("#%1").arg(color) ) );
}


void DragLabelPropertiesDialog::setColorValue( const QColor &color )
{
mpParent->setColor( color );
mpColorEdit->setText( color.name().mid(1) );
}

+ 86
- 0
src/fridgegrid/DragLabelPropertiesDialog.hpp View File

@@ -0,0 +1,86 @@
/*
* tools/src/fridgemagnets/MainWindow.hpp
* written by Sven Oliver Moll
*
* distributed under the terms of the GNU General Public License (GPL)
* available at http://www.gnu.org/licenses/gpl.html
*/

#ifndef DRAGLABELPROPERTIESDIALOG_HPP
#define DRAGLABELPROPERTIESDIALOG_HPP DRAGLABELPROPERTIESDIALOG_HPP

/* base class */
#include <QDialog>

/* system headers */

/* Qt headers */

/* local library headers */

/* local headers */

/* forward declaration of Qt classes */
class QLineEdit;
class QSpinBox;

/* forward declaration of local classes */
class DragLabel;


/*!
\brief \todo

*/
class DragLabelPropertiesDialog : public QDialog
{
Q_OBJECT
public:
/*!
\brief \todo

\param parent
*/
explicit DragLabelPropertiesDialog( DragLabel *parent = 0 );
/*!
\brief \todo

*/
virtual ~DragLabelPropertiesDialog();

signals:
public slots:
/*!
\brief \todo

*/
void colorDialog();
/*!
\brief \todo

\param color
*/
void setColorValue( const QString &color );
/*!
\brief \todo

\param color
*/
void setColorValue( const QColor &color );
/*!
\brief \todo

*/
void revert();

private:
DragLabel *mpParent; /*!< \brief \todo TODO */
QLineEdit *mpTextEdit; /*!< \brief \todo TODO */
QSpinBox *mpWidthEdit; /*!< \brief \todo TODO */
QSpinBox *mpHeightEdit; /*!< \brief \todo TODO */
QLineEdit *mpColorEdit; /*!< \brief \todo TODO */
QByteArray mOld; /*!< \brief \todo TODO */
};

#endif

+ 488
- 0
src/fridgegrid/DragWidget.cpp View File

@@ -0,0 +1,488 @@
/*
* tools/src/fridgemagnets/MainWindow.cpp
* written by Sven Oliver Moll
*
* distributed under the terms of the GNU General Public License (GPL)
* available at http://www.gnu.org/licenses/gpl.html
*/

/* class declaration */
#include "DragWidget.hpp"

/* system headers */

/* Qt headers */
#include <QApplication>
#include <QDomDocument>
#include <QDragEnterEvent>
#include <QDragMoveEvent>
#include <QDropEvent>
#include <QFileDialog>
#include <QFileInfo>
#include <QMessageBox>
#include <QPainter>
#include <QSettings>
#include <QTextStream>
#include <QTextEdit>

//#include <QSize>

/* local library headers */

/* local headers */
#include "DragLabel.hpp"


const int DragWidget::cGridX = 19;
const int DragWidget::cGridY = 19;


DragWidget::DragWidget( QWidget *parent )
: QWidget( parent )
, mpTextEdit( 0 )
, mGridSize( cGridX, cGridY )
{
setMinimumSize( 400, 200 );
setAcceptDrops(true);
}


DragWidget::~DragWidget()
{
}


QSize DragWidget::gridSize()
{
return mGridSize;
}


void DragWidget::setTextEdit( QTextEdit *textEdit )
{
mpTextEdit = textEdit;
}


void DragWidget::updateLabelPos( const QSize &newSize )
{
QMap<DragLabel*,QPoint> sizemap;
QList<DragLabel*> labels( findChildren<DragLabel*>() );
foreach( DragLabel *label, labels )
{
QPoint gridPos( label->pos().x() / mGridSize.width(),
label->pos().y() / mGridSize.height() );
sizemap.insert( label, gridPos );
}
mGridSize = newSize;
foreach( DragLabel *label, labels )
{
place( label, sizemap.value(label).x() * mGridSize.width(),
sizemap.value(label).y() * mGridSize.height() );
label->draw();
}
update();
}


void DragWidget::setGridX( int x )
{
updateLabelPos( QSize( x, mGridSize.height() ) );
}


void DragWidget::setGridY( int y )
{
updateLabelPos( QSize( mGridSize.width(), y ) );
}


void DragWidget::dragEnterEvent( QDragEnterEvent *event )
{
if( event->mimeData()->hasFormat("application/x-fridgemagnet") )
{
if( children().contains( event->source() ) )
{
event->setDropAction( Qt::MoveAction );
event->accept();
}
else
{
event->acceptProposedAction();
}
}
else if( event->mimeData()->hasText() )
{
event->acceptProposedAction();
}
else
{
event->ignore();
}
}


void DragWidget::dragMoveEvent( QDragMoveEvent *event )
{
if( event->mimeData()->hasFormat("application/x-fridgemagnet") )
{
if( children().contains(event->source()) )
{
event->setDropAction(Qt::MoveAction);
event->accept();
}
else
{
event->acceptProposedAction();
}
}
else if( event->mimeData()->hasText() )
{
event->acceptProposedAction();
}
else
{
event->ignore();
}
}


void DragWidget::dropEvent( QDropEvent *event )
{
if( event->mimeData()->hasFormat("application/x-fridgemagnet") )
{
const QMimeData *mime = event->mimeData();

QByteArray itemData( mime->data("application/x-fridgemagnet") );
QDataStream dataStream( &itemData, QIODevice::ReadOnly );

QPoint offset;
QByteArray data;
dataStream >> offset >> data;
DragLabel *newLabel = new DragLabel( data, this );

place( newLabel, event->pos() - offset );
newLabel->show();
newLabel->setAttribute( Qt::WA_DeleteOnClose );

if( event->source() == this )
{
event->setDropAction( Qt::MoveAction );
event->accept();
}
else
{
event->acceptProposedAction();
}
}
else if( event->mimeData()->hasText() )
{
QStringList pieces = event->mimeData()->text().split( '\n', QString::SkipEmptyParts );
QPoint position = event->pos();

foreach( const QString &piece, pieces )
{
DragLabel *newLabel = new DragLabel( this );
newLabel->setText( piece );
if( event->mimeData()->hasColor() )
{
QColor color = qvariant_cast<QColor>( event->mimeData()->colorData() );
newLabel->setColor( color );
}
place( newLabel, position );
newLabel->show();
newLabel->setAttribute( Qt::WA_DeleteOnClose );

position += QPoint( newLabel->width(), 0 );
}

event->acceptProposedAction();
}
else
{
event->ignore();
}
}


void DragWidget::mousePressEvent( QMouseEvent *event )
{
if( event->button() != Qt::LeftButton )
{
return;
}
DragLabel *child = static_cast<DragLabel*>( childAt(event->pos()) );
if( !child )
{
return;
}

QPoint hotSpot = event->pos() - child->pos();

QByteArray itemData;
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
dataStream << hotSpot << child->toByteArray();

QMimeData *mimeData = new QMimeData;
mimeData->setData( "application/x-fridgemagnet", itemData );
mimeData->setText( child->labelText() );
mimeData->setColorData( child->color() );

QDrag *drag = new QDrag( this );
drag->setMimeData( mimeData );
drag->setPixmap( *(child->pixmap()) );
drag->setHotSpot( hotSpot );

child->hide();

if( drag->exec( Qt::MoveAction | Qt::CopyAction, Qt::CopyAction ) == Qt::MoveAction )
{
child->close();
}
else
{
child->show();
}
}


void DragWidget::mouseDoubleClickEvent( QMouseEvent *event )
{
if( event->button() != Qt::LeftButton )
{
return;
}
DragLabel *child = static_cast<DragLabel*>( childAt(event->pos()) );
if( !child )
{
return;
}

child->parameterMenu( event->globalPos() );
}


void DragWidget::paintEvent( QPaintEvent *event )
{
Q_UNUSED( event );
QPainter painter( this );
painter.setRenderHint( QPainter::Antialiasing );
painter.setBrush( Qt::black );
for( int i = mGridSize.width() - 1; i < size().width() ; i += mGridSize.width() )
{
painter.drawLine( i, 0, i, size().height() - 1 );
}
for( int i = mGridSize.height() - 1; i < size().height() ; i += mGridSize.height() )
{
painter.drawLine( 0, i, size().width() - 1, i );
}
painter.end();
}


void DragWidget::place( QWidget *w, int x, int y )
{
if( (x % mGridSize.width()) > (mGridSize.width() / 2) )
{
x += mGridSize.width();
}
if( (y % mGridSize.height()) > (mGridSize.height() / 2) )
{
y += mGridSize.height();
}
x -= (x % mGridSize.width());
y -= (y % mGridSize.height());
w->move( x + 1, y + 1 );
}


void DragWidget::place(QWidget *w, const QPoint &p)
{
place( w, p.x(), p.y() );
}


void DragWidget::save()
{
QSettings settings;
QFileInfo lastFilename( settings.value( "Filename" ).toString() );
QString fileName = QFileDialog::getSaveFileName( this, QCoreApplication::applicationName(),
lastFilename.absoluteFilePath(), "*.xml" );
if( fileName.isEmpty() )
{
return;
}
settings.setValue( "Filename", fileName );

QDomDocument domDoc;
QDomElement domRoot = domDoc.createElement( "FridgeGrid" );
domDoc.appendChild(domRoot);
QDomElement comment = domDoc.createElement( "comment" );
if( mpTextEdit )
{
comment.setAttribute( "text", mpTextEdit->toPlainText() );
}
domRoot.appendChild( comment );
QDomElement elements = domDoc.createElement( "elements" );
domRoot.appendChild( elements );

QList<DragLabel*> labels( findChildren<DragLabel*>() );
foreach( DragLabel *label, labels )
{
QDomElement domElement = domDoc.createElement("element");
label->writeDomAttributes( &domElement );
elements.appendChild(domElement);
}

QFile file( fileName );
const int indentSize = 2;
file.open( QIODevice::WriteOnly );
QTextStream out( &file );
domDoc.save( out, indentSize );
file.close();
}


void DragWidget::load()
{
QSettings settings;
QFileInfo lastFilename( settings.value("Filename").toString() );
QString fileName = QFileDialog::getOpenFileName( this, QCoreApplication::applicationName(),
lastFilename.absolutePath(), "*.xml" );
if( fileName.isEmpty() )
{
return;
}
settings.setValue( "Filename", fileName );

QFile file( fileName );
file.open( QIODevice::ReadOnly );

QString errorStr;
int errorLine;
int errorColumn;
QDomDocument domDoc;

if( !domDoc.setContent( &file, true, &errorStr, &errorLine, &errorColumn ) )
{
QMessageBox::information( window(), QApplication::applicationName(),
tr("Parse error at line %1, column %2:\n%3")
.arg(errorLine)
.arg(errorColumn)
.arg(errorStr) );
//return false;
}

QDomElement domRoot = domDoc.documentElement();
if( domRoot.tagName() != "FridgeGrid" )
{
QMessageBox::information( window(), QApplication::applicationName(),
tr("The file is not a FridgeGrid file.") );
//return false;
}
#if 0
else if (root.hasAttribute("version")
&& root.attribute("version") != "1.0")
{
QMessageBox::information( window(), QApplication::applicationName(),
tr("The file is not a FridgeGrid version 1.0 "
"file.") );
return false;
}
#endif

QList<DragLabel*> labels( findChildren<DragLabel*>() );
foreach( DragLabel *label, labels )
{
label->deleteLater();
}

QDomElement comment = domRoot.firstChildElement( "comment" );
if( mpTextEdit )
{
mpTextEdit->setPlainText( comment.attribute("text") );
}
QDomElement elements = domRoot.firstChildElement( "elements" );
QDomNodeList elementList = elements.elementsByTagName( "element" );
for( int i = 0; i < elementList.size(); ++i )
{
const QDomElement &domElement = elementList.at(i).toElement();
DragLabel *newLabel = new DragLabel( this );
QPoint pos( newLabel->readDomAttributes( &domElement ) );
if( pos.isNull() )
{
delete newLabel;
}
else
{
place( newLabel, pos );
newLabel->show();
newLabel->setAttribute(Qt::WA_DeleteOnClose);
}
}

//return true;
}


void DragWidget::newElement( const QByteArray &d, const QPoint &p )
{
DragLabel *wordLabel = 0;
if( d.isNull() )
{
wordLabel = new DragLabel( this );
}
else
{
wordLabel = new DragLabel( d, this );
}
place( wordLabel, p.x(), p.y() );
wordLabel->show();
wordLabel->setAttribute( Qt::WA_DeleteOnClose );
}


QVariant DragWidget::getData()
{
QVariantList list;
QList<DragLabel*> labels( findChildren<DragLabel*>() );
foreach( DragLabel *label, labels )
{
QVariantMap map;
map.insert( "pos", label->pos() );
map.insert( "data", label->toByteArray() );
list.append( map );
}
return list;
}


void DragWidget::setData( const QVariant &data )
{
QVariantList list( data.toList() );
QVariant element;

QList<DragLabel*> labels( findChildren<DragLabel*>() );
foreach( DragLabel *label, labels )
{
label->deleteLater();
}

foreach( element, list )
{
QVariantMap map( element.toMap() );
DragLabel *newLabel = new DragLabel( this );
QPoint pos = map.value( "pos" ).toPoint();
newLabel->setFromByteArray( map.value( "data" ).toByteArray() );
if( pos.isNull() )
{
delete newLabel;
}
else
{
place( newLabel, pos );
newLabel->show();
newLabel->setAttribute( Qt::WA_DeleteOnClose );
}
}
}

+ 170
- 0
src/fridgegrid/DragWidget.hpp View File

@@ -0,0 +1,170 @@
/*
* tools/src/fridgemagnets/DragWidget.hpp
* written by Sven Oliver Moll
*
* distributed under the terms of the GNU General Public License (GPL)
* available at http://www.gnu.org/licenses/gpl.html
*/

#ifndef DRAGWIDGET_HPP
#define DRAGWIDGET_HPP DRAGWIDGET_HPP

/* base class */
#include <QLabel>

/* system headers */

/* Qt headers */

/* local library headers */

/* local headers */

/* forward declaration of Qt classes */
class QDomDocument;
class QDomElement;
class QDragEnterEvent;
class QDropEvent;
class QPaintEvent;
class QTextEdit;

/* forward declaration of local classes */


/*!
\brief \todo

*/
class DragWidget : public QWidget
{
Q_OBJECT

public:
/*!
\brief \todo

\param parent
*/
explicit DragWidget( QWidget *parent = 0 );
/*!
\brief \todo

*/
virtual ~DragWidget();
/*!
\brief \todo

\return QSize
*/
QSize gridSize();

static const int cGridX; /*!< \brief \todo TODO */
static const int cGridY; /*!< \brief \todo TODO */

QVariant getData();
void setData( const QVariant &data );

/*!
\brief \todo

\param textEdit
*/
void setTextEdit(QTextEdit *textEdit);

public slots:
/*!
\brief \todo

\param x
*/
void setGridX( int x );
/*!
\brief \todo

\param y
*/
void setGridY( int y );
/*!
\brief \todo

*/
void save();
/*!
\brief \todo

*/
void load();
/*!
\brief \todo

\param d
\param p
*/
void newElement( const QByteArray &d = QByteArray(), const QPoint &p = QPoint() );

protected:
/*!
\brief \todo

\param event
*/
void dragEnterEvent( QDragEnterEvent *event );
/*!
\brief \todo

\param event
*/
void dragMoveEvent( QDragMoveEvent *event );
/*!
\brief \todo

\param event
*/
void dropEvent( QDropEvent *event );
/*!
\brief \todo

\param event
*/
void mousePressEvent( QMouseEvent *event);
/*!
\brief \todo

\param event
*/
void mouseDoubleClickEvent( QMouseEvent *event );
/*!
\brief \todo

\param event
*/
void paintEvent( QPaintEvent *event );

private:
/*!
\brief \todo

\param w
\param x
\param y
*/
void place( QWidget *w, int x, int y );
/*!
\brief \todo

\param w
\param p
*/
void place( QWidget *w, const QPoint &p );
/*!
\brief \todo

\param newSize
*/
void updateLabelPos( const QSize &newSize );

QTextEdit *mpTextEdit; /*!< \brief \todo TODO */
QSize mGridSize; /*!< \brief \todo TODO */
};

#endif

+ 215
- 0
src/fridgegrid/MainWidget.cpp View File

@@ -0,0 +1,215 @@
/*
* tools/src/fridgemagnets/MainWindow.cpp
* written by Sven Oliver Moll
*
* distributed under the terms of the GNU General Public License (GPL)
* available at http://www.gnu.org/licenses/gpl.html
*/

/* class declaration */
#include "MainWidget.hpp"

/* system headers */

/* Qt headers */
#include <QApplication>
#include <QDomDocument>
#include <QDragEnterEvent>
#include <QDragMoveEvent>
#include <QDropEvent>
#include <QFileDialog>
#include <QFileInfo>
#include <QMessageBox>
#include <QPainter>
#include <QSettings>
#include <QSplitter>
#include <QTextEdit>
#include <QTimer>
#include <QTextStream>
#include <QVBoxLayout>

//#include <QSize>

/* local library headers */

/* local headers */
#include "DragWidget.hpp"


MainWidget::MainWidget( QWidget *parent )
: QWidget( parent )
, mpParent( parent )
, mpSplitter( new QSplitter( Qt::Vertical, this ) )
, mpTextEdit( new QTextEdit( this ) )
, mpDragWidget( new DragWidget( this ) )
{
QBoxLayout *layout = new QVBoxLayout( this );
mpSplitter->addWidget( mpTextEdit );
mpSplitter->addWidget( mpDragWidget );
mpSplitter->restoreState( QSettings().value("MainWidgetSplitter").toByteArray() );

//mpTextEdit->setCurrentFont( QFont("Courier") );
mpTextEdit->setFontFamily( "Courier" );
QTimer *updateDelay = new QTimer( this );
updateDelay->setInterval( 500 );
updateDelay->setSingleShot( true );
connect( mpTextEdit, SIGNAL(textChanged()),
updateDelay, SLOT(start()) );
connect( updateDelay, SIGNAL(timeout()),
this, SLOT(commentChange()) );
layout->setContentsMargins( 0, 0, 0, 0 );
layout->addWidget( mpSplitter );
setLayout( layout );

commentChange();
}


MainWidget::~MainWidget()
{
QSettings settings;
settings.setValue( "MainWidgetSplitter", mpSplitter->saveState() );
settings.setValue( "Comment", mpTextEdit->toPlainText() );
settings.setValue( "MainField", mpDragWidget->getData() );
}


void MainWidget::commentChange()
{
if( mpParent )
{
const QStringList &comment( mpTextEdit->toPlainText().split('\n', QString::SkipEmptyParts) );
if( comment.size() > 0 )
{
mpParent->setWindowTitle( QString( "%1 (%2)").arg( comment.at(0),
QCoreApplication::applicationName() ) );
}
else
{
mpParent->setWindowTitle( QCoreApplication::applicationName() );
}
}
}


QSize MainWidget::gridSize()
{
return mpDragWidget->gridSize();
}


void MainWidget::setGridX( int x )
{
mpDragWidget->setGridX( x );
}


void MainWidget::setGridY( int y )
{
mpDragWidget->setGridY( y );
}


void MainWidget::save()
{
QSettings settings;
QFileInfo lastFilename( settings.value( "Filename" ).toString() );
QString fileName = QFileDialog::getSaveFileName( this, QCoreApplication::applicationName(),
lastFilename.absoluteFilePath(), "*.xml" );
if( fileName.isEmpty() )
{
return;
}
if( !fileName.endsWith(".xml",Qt::CaseInsensitive ) )
{
fileName.append( ".xml" );
}
QDomDocument domDoc;
QDomElement domRoot = domDoc.createElement( "FridgeGrid" );
domDoc.appendChild( domRoot );
QDomElement elements = domDoc.createElement( "elements" );
domRoot.appendChild( elements );

QDomElement comment = domDoc.createElement( "comment" );
comment.setAttribute( "text", mpTextEdit->toPlainText() );
domRoot.appendChild( comment );

mpDragWidget->save( &domDoc, &domRoot, &elements );

QFile file( fileName );
const int indentSize = 2;
file.open( QIODevice::WriteOnly );
QTextStream out( &file );
domDoc.save( out, indentSize );
file.close();
}


void MainWidget::load( const QString &fileName )
{
QFile file;
if( fileName.isEmpty() )
{
QSettings settings;
QFileInfo lastFilename( settings.value("Filename").toString() );
QString selectedFileName = QFileDialog::getOpenFileName( this, QCoreApplication::applicationName(),
lastFilename.absolutePath(), "*.xml" );
if( selectedFileName.isEmpty() )
{
return;
}
settings.setValue( "Filename", selectedFileName );
file.setFileName( selectedFileName );
}
else
{
file.setFileName( fileName );
}
file.open( QIODevice::ReadOnly );

QString errorStr;
int errorLine;
int errorColumn;
QDomDocument domDoc;

if( !domDoc.setContent( &file, true, &errorStr, &errorLine, &errorColumn ) )
{
QMessageBox::information( window(), QApplication::applicationName(),
tr("Parse error at line %1, column %2:\n%3")
.arg(errorLine)
.arg(errorColumn)
.arg(errorStr) );
//return false;
}

QDomElement domRoot = domDoc.documentElement();
if( domRoot.tagName() != "FridgeGrid" )
{
QMessageBox::information( window(), QApplication::applicationName(),
tr("The file is not a FridgeGrid file.") );
//return false;
}
#if 0
else if (root.hasAttribute("version")
&& root.attribute("version") != "1.0")
{
QMessageBox::information( window(), QApplication::applicationName(),
tr("The file is not a FridgeGrid version 1.0 "
"file.") );
return false;
}
#endif

QDomElement comment = domRoot.firstChildElement( "comment" );
mpTextEdit->setPlainText( comment.attribute("text") );
QDomElement elements = domRoot.firstChildElement( "elements" );
mpDragWidget->load( &elements );

file.close();
}


void MainWidget::newElement( const QByteArray &d, const QPoint &p )
{
mpDragWidget->newElement( d, p );
}

+ 101
- 0
src/fridgegrid/MainWidget.hpp View File

@@ -0,0 +1,101 @@
/*
* tools/src/fridgemagnets/MainWidget.hpp
* written by Sven Oliver Moll
*
* distributed under the terms of the GNU General Public License (GPL)
* available at http://www.gnu.org/licenses/gpl.html
*/

#ifndef MAINWIDGET_HPP
#define MAINWIDGET_HPP MAINWIDGET_HPP

/* base class */
#include <QLabel>

/* system headers */

/* Qt headers */

/* local library headers */

/* local headers */

/* forward declaration of Qt classes */
class QSplitter;
class QTextEdit;

/* forward declaration of local classes */
class DragWidget;


/*!
\brief \todo

*/
class MainWidget : public QWidget
{
Q_OBJECT

public:
/*!
\brief constructor

\param parent
*/
explicit MainWidget( QWidget *parent = 0 );
/*!
\brief destructor

*/
virtual ~MainWidget();
/*!
\brief \todo

\return QSize
*/
QSize gridSize();

public slots:
/*!
\brief \todo

\param x
*/
void setGridX( int x );
/*!
\brief \todo

\param y
*/
void setGridY( int y );
/*!
\brief save current setup to XML file

*/
void save();
/*!
\brief load current setup to XML file

*/
void load( const QString &fileName = QString() );
/*!
\brief \todo

\param d
\param p
*/
void newElement( const QByteArray &d = QByteArray(), const QPoint &p = QPoint() );
/*!
\brief \todo

*/
void commentChange();

private:
QWidget *mpParent;
QSplitter *mpSplitter;
QTextEdit *mpTextEdit;
DragWidget *mpDragWidget;
};

#endif

+ 133
- 0
src/fridgegrid/MainWindow.cpp View File

@@ -0,0 +1,133 @@
/*
* tools/src/fridgemagnets/MainWindow.cpp
* written by Sven Oliver Moll
*
* distributed under the terms of the GNU General Public License (GPL)
* available at http://www.gnu.org/licenses/gpl.html
*/

/* class declaration */
#include "MainWindow.hpp"

/* system headers */

/* Qt headers */
#include <QtGui>

/* local library headers */

/* local headers */
#include "DragWidget.hpp"


MainWindow::MainWindow( QWidget *parent, Qt::WindowFlags flags )
: QMainWindow( parent, flags )
, mpSplitter( new QSplitter( Qt::Vertical, this ) )
, mpTextEdit( new QTextEdit( mpSplitter ) )
, mpDragWidget( new DragWidget( mpSplitter ) )
{
QCommonStyle style;
QSettings settings;

mpSplitter->setObjectName( "CentralSplitter" );
mpSplitter->addWidget( mpTextEdit );
mpSplitter->addWidget( mpDragWidget );
mpSplitter->restoreState( settings.value( "Splitter").toByteArray() );
setCentralWidget( mpSplitter );

mpTextEdit->setObjectName( "CommentEditor" );
mpTextEdit->setAcceptRichText( false );
mpTextEdit->setText( settings.value( "Comment" ).toString() );
commentChange();

mpDragWidget->setObjectName( "MainArea" );
mpDragWidget->setTextEdit( mpTextEdit );
mpDragWidget->resize( 400, 50 );
mpDragWidget->setData( settings.value( "Saved" ) );

QToolBar *toolBar = 0;
QAction *action = 0;
QSpinBox *spinBox = 0;

toolBar = addToolBar( tr("File") );
toolBar->setObjectName( "FileToolBar" );
toolBar->setContextMenuPolicy( Qt::PreventContextMenu );

action = new QAction( style.standardIcon( QStyle::SP_DialogOpenButton ), "Open", this );
action->setShortcuts( QKeySequence::New );
connect( action, SIGNAL(triggered()),
mpDragWidget, SLOT(load()) );
toolBar->addAction( action );

action = new QAction( style.standardIcon( QStyle::SP_DialogSaveButton ), "Save", this );
action->setShortcuts( QKeySequence::Open );
connect( action, SIGNAL(triggered()),
mpDragWidget, SLOT(save()) );
toolBar->addAction( action );

toolBar = addToolBar( tr("Element") );
toolBar->setObjectName( "ElementsToolBar" );
toolBar->setContextMenuPolicy( Qt::PreventContextMenu );

action = new QAction( style.standardIcon( QStyle::SP_FileIcon ), "New", this );
action->setShortcuts( QKeySequence::New );
connect( action, SIGNAL(triggered()),
mpDragWidget, SLOT(newElement()) );
toolBar->addAction( action );

spinBox = new QSpinBox( this );
spinBox->setRange( 7, 25 );
spinBox->setValue( mpDragWidget->gridSize().width() );
connect( spinBox, SIGNAL(valueChanged(int)),
mpDragWidget, SLOT(setGridX(int)) );
toolBar->addWidget( spinBox );

spinBox = new QSpinBox( this );
spinBox->setRange( 7, 25 );
spinBox->setValue( mpDragWidget->gridSize().height() );
connect( spinBox, SIGNAL(valueChanged(int)),
mpDragWidget, SLOT(setGridY(int)) );
toolBar->addWidget( spinBox );

restoreGeometry( settings.value( "Geometry" ).toByteArray() );
restoreState( settings.value( "State" ).toByteArray() );