00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef EASY_SOK_MAP_WIDGET_INC_GUARD_H
00022 #define EASY_SOK_MAP_WIDGET_INC_GUARD_H
00023
00024
00025 #include <vector>
00026
00027 #include <qcanvas.h>
00028 #include <qpixmap.h>
00029 #include <qpoint.h>
00030
00031 #include "atomic_move.h"
00032 #include "move.h"
00033 #include "theme.h"
00034
00035
00036 class Map;
00037 class PixmapProvider;
00038 class QTimer;
00039 class Theme;
00040
00041
00042
00043
00051 class MapWidget : public QCanvasView
00052 {
00053 Q_OBJECT
00054
00055 public:
00056
00070 MapWidget(Map const * map, PixmapProvider * pixmap_provider, Theme const * theme,
00071 bool disable_auto_hide, QWidget * parent = 0, char const * name = 0);
00072
00073
00078 virtual ~MapWidget();
00079
00080
00091 void setMap(Map const * map);
00092
00093
00103 void setPixmapProvider(PixmapProvider * pixmap_provider, Theme const * theme);
00104
00105
00110 AtomicMove::AtomicMoveType keeperDirection();
00111
00112
00117 QPoint const & virtualKeeper() const;
00118
00119
00120 public slots:
00121
00122
00129 void setKeeperDirection(AtomicMove::AtomicMoveType direction);
00130
00131
00140 void setArrows(std::vector<Move> const & arrows);
00141
00142
00147 void updateDisplay();
00148
00149
00158 void setVirtualKeeper(const QPoint & position);
00159
00160
00165 void configChanged();
00166
00167
00172 void switchToBetterScaling();
00173
00174
00179 void mouseRepeat();
00180
00181
00188 void cursorVisible(bool stop_autohide);
00189
00190
00195 void cursorHidden();
00196
00197
00198 signals:
00199
00206 void fieldClicked(QPoint point);
00207
00208
00216 void gemMoved(QPoint from, QPoint to);
00217
00218
00226 void keeperMoved(QPoint from, QPoint to);
00227
00228
00233 void undo();
00234
00235
00240 void redo();
00241
00242
00243 protected:
00244
00249 virtual void resizeEvent(QResizeEvent * event);
00250
00251
00256 virtual void contentsMousePressEvent(QMouseEvent * event);
00257
00258
00263 virtual void contentsMouseMoveEvent(QMouseEvent * event);
00264
00265
00270 virtual void contentsMouseReleaseEvent(QMouseEvent * event);
00271
00272
00273 private:
00274
00281 void deleteItems(std::vector<QCanvasSprite *> & items) const;
00282
00283
00298 void createItems(std::vector<QCanvasSprite *> & items, int type,
00299 QPoint const & position, int x, int y, int z) const;
00300
00301
00306 void createItems(std::vector<QCanvasSprite *> & items, QPoint const & position, int x, int y, int z) const;
00307
00308
00313 void createItems(std::vector<QCanvasSprite *> & items, std::vector<int> image_indices,
00314 int x, int y, int z) const;
00315
00316
00327 void placeItems(std::vector<QCanvasSprite *> & items, int x, int y, int z);
00328
00329
00334 void updateGeometry();
00335
00336
00341 void deletePixmaps();
00342
00343
00348 void deleteArrows();
00349
00350
00358 void addArrow(QPoint from, QPoint to);
00359
00360
00365 void deleteItems();
00366
00367
00372 void newItems();
00373
00374
00381 bool isValidPosition(QPoint position) const;
00382
00383
00390 QPoint getFieldFromPosition(QPoint position) const;
00391
00392
00399 void moveMovingItemPosition(QPoint const & offset);
00400
00401
00408 QCanvasPixmapArray * createPixmapArray(QPixmap const & pixmap) const;
00409
00410
00415 mutable QCanvas m_canvas;
00416
00417
00422 PixmapProvider * m_pixmap_provider;
00423
00424
00429 Theme const * m_theme;
00430
00431
00436 Map const * m_map;
00437
00438
00443 std::vector<int> m_pieces;
00444
00445
00450 int m_x_offset;
00451
00452
00457 int m_y_offset;
00458
00459
00464 int m_square_size;
00465
00466
00471 int m_map_width;
00472
00473
00478 int m_map_height;
00479
00480
00485 int m_size;
00486
00487
00492 bool m_force_update;
00493
00494
00499 bool m_valid_click;
00500
00501
00506 bool m_in_drag;
00507
00508
00513 bool m_is_keeper_drag;
00514
00515
00520 AtomicMove::AtomicMoveType m_keeper_direction;
00521
00522
00527 QPoint m_click_position;
00528
00529
00534 QPoint m_click_field;
00535
00536
00541 QPoint m_click_offset;
00542
00543
00548 QPoint m_last_mouse_position;
00549
00550
00555 QPoint m_virtual_keeper_pos;
00556
00557
00562 std::vector<QCanvasSprite *> m_virtual_keeper_item;
00563
00564
00569 std::vector<QCanvasSprite *> m_moving_item;
00570
00571
00576 std::vector<std::vector<QCanvasSprite *> > m_arrow_items;
00577
00578
00583 std::vector<std::vector<QCanvasSprite *> > m_items;
00584
00585
00590 mutable std::vector<QCanvasPixmapArray *> m_pixmaps;
00591
00596 std::vector<Move> m_arrows;
00597
00598
00603 QTimer * m_timer;
00604
00605
00610 QTimer * m_repeat_timer;
00611
00612
00617 int m_mouse_repeat_state;
00618
00619
00624 int m_mouse_repeat_delay;
00625
00626
00631 int m_mouse_repeat_rate;
00632
00633
00638 int m_scaling_mode;
00639
00640
00645 int m_switch_time;
00646
00647
00652 int m_min_square_size;
00653
00654
00659 bool m_has_scrollbars;
00660
00661
00666 bool m_cursor_hidden;
00667
00668
00673 bool m_auto_hide_cursor;
00674
00675
00680 bool m_disable_auto_hide;
00681
00682
00687 int m_cursor_hide_delay;
00688
00689
00694 QTimer * m_cursor_timer;
00695
00696
00701 int m_virtual_keeper_direction;
00702 };
00703
00704
00705 #endif