File indexing completed on 2024-04-21 04:02:36
0001 /* 0002 SPDX-FileCopyrightText: 1997 Mathias Mueller <in5y158@public.uni-hamburg.de> 0003 SPDX-FileCopyrightText: 2006 Mauricio Piacentini <mauricio@tabuleiro.com> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef EDITOR_H 0009 #define EDITOR_H 0010 0011 // Qt 0012 #include <QDialog> 0013 0014 // KF 0015 #include <KToolBar> 0016 0017 // LibKMahjongg 0018 #include <KMahjonggTileset> 0019 0020 // KMahjongg 0021 #include "boardlayout.h" 0022 #include "frameimage.h" 0023 #include "kmtypes.h" 0024 0025 class FrameImage; 0026 class QLabel; 0027 class KActionCollection; 0028 0029 /** 0030 * @author Mauricio Piacentini <mauricio@tabuleiro.com> 0031 */ 0032 class Editor : public QDialog 0033 { 0034 Q_OBJECT 0035 0036 public: 0037 explicit Editor(QWidget * parent = nullptr); 0038 ~Editor() override; 0039 0040 public Q_SLOTS: 0041 /** 0042 * Load the settings from prefs. */ 0043 void setTilesetFromSettings(); 0044 0045 protected Q_SLOTS: 0046 void drawFrameMousePressEvent(QMouseEvent *); 0047 void drawFrameMouseMovedEvent(QMouseEvent *); 0048 void loadBoard(); 0049 bool saveBoard(); 0050 void newBoard(); 0051 void slotShiftLeft(); 0052 void slotShiftRight(); 0053 void slotShiftUp(); 0054 void slotShiftDown(); 0055 void slotModeChanged(QAction *); 0056 0057 protected: 0058 void resizeEvent(QResizeEvent * event) override; 0059 void paintEvent(QPaintEvent * pa) override; 0060 void setupToolbar(); 0061 void drawBackground(QPixmap * to) const; 0062 0063 /** 0064 * @param to destination QPixmap to draw to */ 0065 void drawTiles(QPixmap * to); 0066 0067 bool testSave(); 0068 void transformPointToPosition(const QPoint &, POSITION &, bool align) const; 0069 void drawCursor(POSITION & p, bool visible); 0070 bool canInsert(POSITION & p) const; 0071 void statusChanged() const; 0072 QString statusText() const; 0073 0074 /** 0075 * Override the closeEvent(...) method of qdialog. */ 0076 void closeEvent(QCloseEvent * e) override; 0077 0078 /** 0079 * Update the tile size. */ 0080 void updateTileSize(const QSize size); 0081 0082 private: 0083 enum class EditMode { 0084 remove = 98, 0085 insert = 99, 0086 move = 100 0087 }; 0088 EditMode m_mode; 0089 0090 QString m_tileset; 0091 0092 int m_borderLeft; 0093 int m_borderTop; 0094 int m_numTiles; 0095 bool m_clean; 0096 0097 FrameImage * m_drawFrame; 0098 KMahjonggTileset m_tiles; 0099 BoardLayout m_theBoard; 0100 POSITION m_curPos; 0101 0102 QLabel * m_theLabel; 0103 0104 KToolBar * m_topToolbar; 0105 KActionCollection * m_actionCollection; 0106 }; 0107 0108 #endif