File indexing completed on 2024-05-12 04:05:53

0001 /***************************************************************************
0002  *   Copyright 2007      Francesco Rossi <redsh@email.it>                  *
0003  *   Copyright 2006-2007 Mick Kappenburg <ksudoku@kappendburg.net>         *
0004  *   Copyright 2006-2008 Johannes Bergmeier <johannes.bergmeier@gmx.net>   *
0005  *   Copyright 2012      Ian Wadham <iandw.au@gmail.com>                   *
0006  *                                                                         *
0007  *   This program is free software; you can redistribute it and/or modify  *
0008  *   it under the terms of the GNU General Public License as published by  *
0009  *   the Free Software Foundation; either version 2 of the License, or     *
0010  *   (at your option) any later version.                                   *
0011  *                                                                         *
0012  *   This program is distributed in the hope that it will be useful,       *
0013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0015  *   GNU General Public License for more details.                          *
0016  *                                                                         *
0017  *   You should have received a copy of the GNU General Public License     *
0018  *   along with this program; if not, write to the                         *
0019  *   Free Software Foundation, Inc.,                                       *
0020  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
0021  ***************************************************************************/
0022 
0023 #ifndef _KSVIEW_H_
0024 #define _KSVIEW_H_
0025 
0026 #include "ksudokugame.h"
0027 
0028 
0029 class QWidget;
0030 
0031 namespace ksudoku {
0032     
0033 enum ViewFlag {
0034     ShowErrors        = 0x01,
0035     ShowObviousErrors = 0x02,
0036     ShowHighlights    = 0x04
0037 };
0038 
0039 using ViewFlags = QFlags<ViewFlag>;
0040     
0041 class Game;
0042 struct SymbolTable;
0043 class ValueListWidget;
0044 class GameActions;
0045 
0046 /**
0047  * Every implementation of ViewInterface needs following signals:
0048  *   void valueSelected(int value);
0049  */
0050 class ViewInterface {
0051 public:
0052     virtual ~ViewInterface() {}
0053 public:
0054     virtual QWidget* widget() = 0;
0055 public: // SLOTS
0056     virtual void selectValue(int value) = 0;
0057 };
0058 
0059 /**
0060  * Interface for all views
0061  */
0062 class KsView : public QObject
0063 {
0064     Q_OBJECT
0065 private:
0066     // prevent copy constructor (not implemented)
0067     explicit KsView(KsView const& other);
0068     // prevent assignment (not implemented)
0069     KsView& operator=(KsView const& other);
0070 
0071 public:
0072     KsView(const Game& game, GameActions* gameActions, QObject* parent = nullptr);
0073     ~KsView() override;
0074 
0075     //getters
0076     ///return game used by the view
0077     Game game() const { return m_game; }
0078 
0079     QWidget* widget() const { return m_viewWidget; }
0080     
0081     ValueListWidget* valueListWidget() const { return m_valueListWidget; }
0082     // TODO make this own the valueListWidget
0083     void setValueListWidget(ValueListWidget* widget) {
0084         m_valueListWidget = widget;
0085     }
0086     
0087     SymbolTable* symbolTable() const;
0088     void setSymbolTable(SymbolTable* table);
0089     
0090     ViewFlags flags() const { return m_flags; }
0091     void setFlags(ViewFlags flags) {
0092         m_flags = flags;
0093         Q_EMIT flagsChanged(flags);
0094     }
0095 
0096 public:
0097     void createView();
0098     
0099 public Q_SLOTS:
0100     void selectValue(int value);
0101     
0102     void settingsChanged();
0103     
0104 Q_SIGNALS:
0105     void flagsChanged(ksudoku::ViewFlags flags);
0106     void symbolsChanged(ksudoku::SymbolTable* table);
0107     void valueSelected(int value);
0108     
0109 
0110 private:
0111     void setWidget(QWidget* viewWidget);
0112 
0113 private:
0114     ///pointer to external Game
0115     Game m_game;
0116 
0117     SymbolTable* m_symbolTable;
0118     ViewFlags m_flags;
0119 
0120     GameActions* m_gameActions;
0121     
0122     ViewInterface* m_view;
0123     QWidget* m_viewWidget;
0124     ValueListWidget* m_valueListWidget;
0125     
0126     int m_currentValue;
0127 };
0128 
0129 }
0130 
0131 #endif
0132