Nicht erschrecken, die Klasse ist recht vollgepackt
Wenn jemand will, poste ich gerne noch die Implementation...
Code: Alles auswählen
#ifndef BATTLEFIELD_H
#define BATTLEFIELD_H
#include "army/Model.h"
#include "army/Unit.h"
//#include "battlefield/Dice.h"
#include <cmath>
#include <QtGui>
#include <iostream>
enum battlefield_action
{
bfa_no_action,
bfa_set_arrow,
bfa_move_unit, //!unit soll bewegt werden (reichweite wird angezeigt, etc...
bfa_set_unit, //!nach mouse-release wird unit bewegt!
//bfa_single_dice,
bfa_measure,
bfa_addUnit,
bfa_setZoom
};
class Battlefield : public QWidget
{
Q_OBJECT
public:
Battlefield(QWidget *parent = 0);
int add_unit(Unit *unit);
void deploy_unit(int id, const QPointF &pos);
//QList <short> dice_values;
public slots:
void action_requested(int action);
void cleanup();
void addUnitFrLst(Unit *unit);
signals:
void measure_done(double);
void addingUnit_done();
void arrow_done();
private slots:
void show_context_menu(QPoint pos);
void move_unit();
private:
int UnitFrListId;
QList <Unit *> units;
QList <Model *> models;
//QList <Dice *> dice_list;
QList <int> models_selected;
QSizeF table_size; // Tischgr��e in Zoll
QPointF arrow[2]; // angezeigter Pfeil, Start- und Endpunkt
double zoom_factor; // Verh�ltnis Pixel pro Zoll
float zoom_level; //zoom durch mousewheel
int add_model(int owner);
//int add_dice(short value, QPointF pos);
int current_action;
int unit_selected; // Aktuell ausgew�hlte Einheit
int moving_unit;
double move_dist;
void calc_zoom_factor();
void acquire_wh_relation();
void deselect_all();
void init_context_menu();
void select_unit(int id);
void select_model(int id);
void enable_unit_controls(bool enable=true);
void set_arrow(QPointF from, QPointF to) {arrow[0] = from; arrow[1] = to; arrow_active=true;};
bool mouse_down;
bool arrow_active;
QPointF mouse_down_at;
QPointF mouse_pos;
QList<QPointF> mouse_stack;
QPointF UnitMovVect;
QList <QPointF> moving_unit_model_offsets;
QMenu *context_menu;
QMenu *unit_menu;
QAction *ct_cleanup_field;
QAction *unit_move_unit;
void transformPainter(QPainter &painter);
protected:
void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void mouseDoubleClickEvent(QMouseEvent *event);
void wheelEvent(QWheelEvent *event);
//!27.08.2007
void keyPressEvent(QKeyEvent *event);
void keyReleaseEvent(QKeyEvent *event);
};
#endif
Hier noch der Konstruktor-Impl.:
Code: Alles auswählen
Battlefield::Battlefield(QWidget *parent) : QWidget(parent)
{
//! 24.08.2007
zoom_level = 1;
//!
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
setContextMenuPolicy(Qt::CustomContextMenu);
init_context_menu();
setMinimumWidth (72 * 8);
setMinimumHeight (48 * 8);
mouse_down = false;
arrow_active = false;
moving_unit = -1;
current_action = bfa_no_action;
table_size = QSizeF(72.0, 48.0);
Unit * test = new Unit("test", 100, 6, 10, "");
int id = add_unit(test);
deploy_unit(id, QPoint(30, 30));
enable_unit_controls(false);
}