ksview.cpp 3.75 KB
Newer Older
1 2 3
/***************************************************************************
 *   Copyright 2007      Francesco Rossi <redsh@email.it>                  *
 *   Copyright 2006-2007 Mick Kappenburg <ksudoku@kappendburg.net>         *
4
 *   Copyright 2006-2008 Johannes Bergmeier <johannes.bergmeier@gmx.net>   *
5
 *   Copyright 2012      Ian Wadham <iandw.au@gmail.com>                   *
6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *                                                                         *
 *   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.,                                       *
Johannes Bergmeier's avatar
Johannes Bergmeier committed
20
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
21
 ***************************************************************************/
22 23 24 25

#include "ksview.h"

#include "ksudokugame.h"
26
#include "settings.h"
27

28 29
#include <QPainter>
#include <QPixmap>
30

Johannes Bergmeier's avatar
Johannes Bergmeier committed
31 32 33

#include "puzzle.h"

34
#ifdef OPENGL_SUPPORT
35
#include "roxdokuview.h"
36 37
#endif

38
#include "view2d.h"
39

40 41
namespace ksudoku{

42 43
KsView::KsView(const Game& game, GameActions* gameActions, QObject* parent)
	: QObject(parent), m_game(game), m_gameActions(gameActions), m_viewWidget(0)
44
{
45
	m_symbolTable = 0;
Johannes Bergmeier's avatar
Johannes Bergmeier committed
46
	m_currentValue = 1;
47
	m_valueListWidget = 0;
48 49 50 51
}

KsView::~KsView()
{
52
	delete m_viewWidget;
53 54
}

55 56 57
void KsView::createView() {
	GameType type = m_game.puzzle()->gameType();
	switch(type) {
58
		case TypeSudoku: {
59
			setWidget(new View2D(0, m_game, m_gameActions));
60 61
			break;
		}
62
		case TypeCustom: {
63 64
#ifdef OPENGL_SUPPORT
			if(m_game.puzzle()->graph()->sizeZ() > 1) {
65 66
			    // TODO - IDW - Add a parent widget. Memory leak?
			    setWidget(new RoxdokuView(m_game, m_gameActions, 0));
67 68 69 70 71
			}
			else {
			    setWidget(new View2D(0, m_game, m_gameActions));
			}
#else
72
			setWidget(new View2D(0, m_game, m_gameActions));
73
#endif
74 75
			break;
		}
76
#ifdef OPENGL_SUPPORT
77
		case TypeRoxdoku: {
78 79
			// TODO - IDW - Add a parent widget. Memory leak?
			setWidget(new RoxdokuView(m_game, m_gameActions, 0));
80 81
			break;
		}
82
#endif
83 84 85 86 87 88 89 90 91
		default:
			// TODO this will not work
			break;
	}
	
	QObject* view = m_view->widget();
	connect(view, SIGNAL(valueSelected(int)), SLOT(selectValue(int)));
	
	connect(this, SIGNAL(valueSelected(int)), view, SLOT(selectValue(int)));
92 93

	connect(parent(), SIGNAL(settingsChanged()), view, SLOT(settingsChanged()));
94 95
	
	settingsChanged();
96 97
}

Johannes Bergmeier's avatar
Johannes Bergmeier committed
98
void KsView::selectValue(int value) {
99
	if(value == m_currentValue) return;
Johannes Bergmeier's avatar
Johannes Bergmeier committed
100 101
	m_currentValue = value;
	emit valueSelected(value);
Johannes Bergmeier's avatar
Johannes Bergmeier committed
102 103
}

104 105 106 107 108 109
SymbolTable* KsView::symbolTable() const {
	return m_symbolTable;
}

void KsView::setSymbolTable(SymbolTable* table) {
	m_symbolTable = table;
Johannes Bergmeier's avatar
Johannes Bergmeier committed
110
	emit symbolsChanged(table);
111 112
}

Johannes Bergmeier's avatar
Johannes Bergmeier committed
113 114 115 116
void KsView::setWidget(QWidget* widget) {
	m_viewWidget = widget;
	emit flagsChanged(m_flags);
	emit symbolsChanged(m_symbolTable);
117 118 119 120 121 122 123 124 125
	
	m_view = dynamic_cast<ViewInterface*>(widget);
}

void KsView::settingsChanged() {
	ViewFlags flags;
	if(Settings::showErrors()) flags |= ShowErrors;
	if(Settings::showHighlights()) flags |= ShowHighlights;
	setFlags(flags);
126
}
127

128
}