Commit 62abd343 authored by roangel's avatar roangel
Browse files

Added grid, added checkboxes to hide/show elements in the scene

parent bca51c27
......@@ -987,7 +987,11 @@ void MainGUIWindow::on_radioButton_table_mode_toggled(bool checked)
case myGraphicsScene::mode_crazyfly_zones:
{
scene->setMode(myGraphicsScene::mode_table);
ui->radioButton_crazyfly_zones_mode->setChecked(false);
break;
}
case myGraphicsScene::mode_locked:
{
scene->setMode(myGraphicsScene::mode_table);
break;
}
}
......@@ -1002,7 +1006,6 @@ void MainGUIWindow::on_radioButton_crazyfly_zones_mode_toggled(bool checked)
case myGraphicsScene::mode_table:
{
scene->setMode(myGraphicsScene::mode_crazyfly_zones);
ui->radioButton_table_mode->setChecked(false);
break;
}
case myGraphicsScene::mode_crazyfly_zones:
......@@ -1010,6 +1013,11 @@ void MainGUIWindow::on_radioButton_crazyfly_zones_mode_toggled(bool checked)
// already in the mode we want, do nothing
break;
}
case myGraphicsScene::mode_locked:
{
scene->setMode(myGraphicsScene::mode_crazyfly_zones);
break;
}
}
}
......@@ -1026,3 +1034,53 @@ void MainGUIWindow::handleTablePiecesNumChanged(int newNum)
// ui->radioButton_crazyfly_zones_mode->setEnabled(true);
// }
}
void MainGUIWindow::on_radioButton_lock_mode_toggled(bool checked)
{
switch(scene->getMode())
{
case myGraphicsScene::mode_table:
{
scene->setMode(myGraphicsScene::mode_locked);
break;
}
case myGraphicsScene::mode_crazyfly_zones:
{
scene->setMode(myGraphicsScene::mode_locked);
break;
}
case myGraphicsScene::mode_locked:
{
break;
}
}
}
void MainGUIWindow::on_checkBox_grid_toggled(bool checked)
{
scene->setGrid(checked);
}
void MainGUIWindow::on_checkBox_table_toggled(bool checked)
{
if(checked)
{
scene->showTable();
}
else
{
scene->hideTable();
}
}
void MainGUIWindow::on_checkBox_crazyfly_zones_toggled(bool checked)
{
if(checked)
{
scene->showCrazyFlyZones();
}
else
{
scene->hideCrazyFlyZones();
}
}
......@@ -138,6 +138,14 @@ private slots:
void on_radioButton_crazyfly_zones_mode_toggled(bool checked);
void handleTablePiecesNumChanged(int newNum);
void on_radioButton_lock_mode_toggled(bool checked);
void on_checkBox_grid_toggled(bool checked);
void on_checkBox_table_toggled(bool checked);
void on_checkBox_crazyfly_zones_toggled(bool checked);
private:
Ui::MainGUIWindow *ui;
......
......@@ -96,7 +96,7 @@
<x>790</x>
<y>30</y>
<width>121</width>
<height>80</height>
<height>121</height>
</rect>
</property>
<property name="title">
......@@ -144,14 +144,35 @@
<bool>true</bool>
</property>
</widget>
<widget class="QRadioButton" name="radioButton_lock_mode">
<property name="geometry">
<rect>
<x>10</x>
<y>80</y>
<width>91</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>7</pointsize>
</font>
</property>
<property name="text">
<string>Lock</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_2">
<property name="geometry">
<rect>
<x>790</x>
<y>130</y>
<y>230</y>
<width>120</width>
<height>241</height>
<height>141</height>
</rect>
</property>
<property name="title">
......@@ -174,6 +195,9 @@
<property name="text">
<string>Show CF Zones</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<widget class="QCheckBox" name="checkBox_vicon_markers">
<property name="geometry">
......@@ -193,6 +217,48 @@
<string>Show Markers</string>
</property>
</widget>
<widget class="QCheckBox" name="checkBox_grid">
<property name="geometry">
<rect>
<x>10</x>
<y>60</y>
<width>101</width>
<height>20</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>7</pointsize>
</font>
</property>
<property name="text">
<string>Show Grid</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<widget class="QCheckBox" name="checkBox_table">
<property name="geometry">
<rect>
<x>10</x>
<y>80</y>
<width>101</width>
<height>20</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>7</pointsize>
</font>
</property>
<property name="text">
<string>Show Table</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</widget>
</widget>
<widget class="QFrame" name="frame_3">
......
......@@ -19,8 +19,8 @@
QT_BEGIN_MOC_NAMESPACE
struct qt_meta_stringdata_MainGUIWindow_t {
QByteArrayData data[12];
char stringdata0[191];
QByteArrayData data[16];
char stringdata0[310];
};
#define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
......@@ -40,14 +40,22 @@ QT_MOC_LITERAL(7, 71, 33), // "on_radioButton_table_mode_tog..."
QT_MOC_LITERAL(8, 105, 7), // "checked"
QT_MOC_LITERAL(9, 113, 42), // "on_radioButton_crazyfly_zones..."
QT_MOC_LITERAL(10, 156, 27), // "handleTablePiecesNumChanged"
QT_MOC_LITERAL(11, 184, 6) // "newNum"
QT_MOC_LITERAL(11, 184, 6), // "newNum"
QT_MOC_LITERAL(12, 191, 32), // "on_radioButton_lock_mode_toggled"
QT_MOC_LITERAL(13, 224, 24), // "on_checkBox_grid_toggled"
QT_MOC_LITERAL(14, 249, 25), // "on_checkBox_table_toggled"
QT_MOC_LITERAL(15, 275, 34) // "on_checkBox_crazyfly_zones_to..."
},
"MainGUIWindow\0set_tabs\0\0n\0transitionToMode\0"
"mode\0on_removeTable_clicked\0"
"on_radioButton_table_mode_toggled\0"
"checked\0on_radioButton_crazyfly_zones_mode_toggled\0"
"handleTablePiecesNumChanged\0newNum"
"handleTablePiecesNumChanged\0newNum\0"
"on_radioButton_lock_mode_toggled\0"
"on_checkBox_grid_toggled\0"
"on_checkBox_table_toggled\0"
"on_checkBox_crazyfly_zones_toggled"
};
#undef QT_MOC_LITERAL
......@@ -57,7 +65,7 @@ static const uint qt_meta_data_MainGUIWindow[] = {
7, // revision
0, // classname
0, 0, // classinfo
6, 14, // methods
10, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
......@@ -65,12 +73,16 @@ static const uint qt_meta_data_MainGUIWindow[] = {
0, // signalCount
// slots: name, argc, parameters, tag, flags
1, 1, 44, 2, 0x08 /* Private */,
4, 1, 47, 2, 0x08 /* Private */,
6, 0, 50, 2, 0x08 /* Private */,
7, 1, 51, 2, 0x08 /* Private */,
9, 1, 54, 2, 0x08 /* Private */,
10, 1, 57, 2, 0x08 /* Private */,
1, 1, 64, 2, 0x08 /* Private */,
4, 1, 67, 2, 0x08 /* Private */,
6, 0, 70, 2, 0x08 /* Private */,
7, 1, 71, 2, 0x08 /* Private */,
9, 1, 74, 2, 0x08 /* Private */,
10, 1, 77, 2, 0x08 /* Private */,
12, 1, 80, 2, 0x08 /* Private */,
13, 1, 83, 2, 0x08 /* Private */,
14, 1, 86, 2, 0x08 /* Private */,
15, 1, 89, 2, 0x08 /* Private */,
// slots: parameters
QMetaType::Void, QMetaType::Int, 3,
......@@ -79,6 +91,10 @@ static const uint qt_meta_data_MainGUIWindow[] = {
QMetaType::Void, QMetaType::Bool, 8,
QMetaType::Void, QMetaType::Bool, 8,
QMetaType::Void, QMetaType::Int, 11,
QMetaType::Void, QMetaType::Bool, 8,
QMetaType::Void, QMetaType::Bool, 8,
QMetaType::Void, QMetaType::Bool, 8,
QMetaType::Void, QMetaType::Bool, 8,
0 // eod
};
......@@ -95,6 +111,10 @@ void MainGUIWindow::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _i
case 3: _t->on_radioButton_table_mode_toggled((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 4: _t->on_radioButton_crazyfly_zones_mode_toggled((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 5: _t->handleTablePiecesNumChanged((*reinterpret_cast< int(*)>(_a[1]))); break;
case 6: _t->on_radioButton_lock_mode_toggled((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 7: _t->on_checkBox_grid_toggled((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 8: _t->on_checkBox_table_toggled((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 9: _t->on_checkBox_crazyfly_zones_toggled((*reinterpret_cast< bool(*)>(_a[1]))); break;
default: ;
}
}
......@@ -125,13 +145,13 @@ int MainGUIWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 6)
if (_id < 10)
qt_static_metacall(this, _c, _id, _a);
_id -= 6;
_id -= 10;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 6)
if (_id < 10)
*reinterpret_cast<int*>(_a[0]) = -1;
_id -= 6;
_id -= 10;
}
return _id;
}
......
......@@ -13,6 +13,7 @@ myGraphicsScene::myGraphicsScene(QObject *parent)
setMode(mode_table);
tmp_rect = 0;
startedRect = false;
setGrid(true);
}
......@@ -53,6 +54,13 @@ void myGraphicsScene::keyPressEvent(QKeyEvent * keyEvent)
}
break;
}
case mode_locked:
{
// nothing so far
break;
}
default:
break;
}
QGraphicsScene::keyPressEvent(keyEvent);
......@@ -89,14 +97,12 @@ void myGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
return;
if(Qt::ControlModifier == QApplication::keyboardModifiers())
{
// TODO: implement table creation mode
// Drag and drop approach
startedRect = true;
p1 = new QPointF(mouseEvent->scenePos());
switch(mode)
{
case mode_table:
{
startedRect = true;
p1 = new QPointF(mouseEvent->scenePos());
tmp_rect = new QRectF(*p1, *p1);
tmp_table_piece_item = new tablePiece(*tmp_rect);
addItem(tmp_table_piece_item);
......@@ -104,13 +110,22 @@ void myGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
}
case mode_crazyfly_zones:
{
startedRect = true;
p1 = new QPointF(mouseEvent->scenePos());
tmp_rect = new QRectF(*p1, *p1);
int index = crazyfly_zones.size();
tmp_crazyfly_zone_item = new crazyFlyZone(*tmp_rect, index);
addItem(tmp_crazyfly_zone_item);
break;
}
case mode_locked:
{
// do nothing so far
startedRect = false;
break;
}
default:
break;
}
}
else
......@@ -227,11 +242,56 @@ void myGraphicsScene::setMode(int new_mode)
unlockCrazyFlyZones();
break;
}
case mode_locked:
{
// TODO: define locked mode. Do not allow to create anything, change some color of something to state that we are in that mode
lockTablePieces();
lockCrazyFlyZones();
break;
}
}
mode = new_mode;
emit modeChanged(new_mode);
}
void myGraphicsScene::setGrid(bool enable)
{
grid_enable = enable;
update();
}
void myGraphicsScene::hideTable()
{
for(int i = 0; i < table_pieces.size(); i++)
{
this->removeItem(table_pieces[i]);
}
}
void myGraphicsScene::showTable()
{
for(int i = 0; i < table_pieces.size(); i++)
{
this->addItem(table_pieces[i]);
}
}
void myGraphicsScene::hideCrazyFlyZones()
{
for(int i = 0; i < crazyfly_zones.size(); i++)
{
this->removeItem(crazyfly_zones[i]);
}
}
void myGraphicsScene::showCrazyFlyZones()
{
for(int i = 0; i < crazyfly_zones.size(); i++)
{
this->addItem(crazyfly_zones[i]);
}
}
void myGraphicsScene::removeCrazyFlyZone(int index)
{
this->removeItem(crazyfly_zones[index]);
......@@ -251,6 +311,30 @@ void myGraphicsScene::removeTable()
emit numTablePiecesChanged(table_pieces.size());
}
void myGraphicsScene::drawBackground(QPainter *painter, const QRectF &rect)
{
if(grid_enable)
{
const int gridSize = 25;
qreal left = int(rect.left()) - (int(rect.left()) % gridSize);
qreal top = int(rect.top()) - (int(rect.top()) % gridSize);
QVarLengthArray<QLineF, 100> lines;
for (qreal x = left; x < rect.right(); x += gridSize)
lines.append(QLineF(x, rect.top(), x, rect.bottom()));
for (qreal y = top; y < rect.bottom(); y += gridSize)
lines.append(QLineF(rect.left(), y, rect.right(), y));
// qDebug() << lines.size();
painter->setPen(QPen(QColor(0, 0, 0, 0x40), 0));
painter->drawLines(lines.data(), lines.size());
}
}
void myGraphicsScene::removeTablePiece(int index)
{
this->removeItem(table_pieces[index]);
......@@ -296,6 +380,13 @@ void myGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
}
break;
}
case mode_locked:
{
// Do nothing so far..
break;
}
default:
break;
}
......
......@@ -25,7 +25,15 @@ public:
int getMode();
void setMode(int new_mode);
enum {mode_table, mode_crazyfly_zones};
void setGrid(bool enable);
void hideTable();
void showTable();
void hideCrazyFlyZones();
void showCrazyFlyZones();
enum {mode_table, mode_crazyfly_zones, mode_locked};
void removeTable();
......@@ -46,6 +54,7 @@ protected:
void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
void keyPressEvent(QKeyEvent * keyEvent) override;
void drawBackground(QPainter *painter, const QRectF &rect);
private:
void lockTablePieces(void);
......@@ -69,6 +78,7 @@ private:
bool startedRect;
int mode;
bool grid_enable;
};
#endif
......@@ -41,9 +41,12 @@ public:
QGroupBox *groupBox;
QRadioButton *radioButton_table_mode;
QRadioButton *radioButton_crazyfly_zones_mode;
QRadioButton *radioButton_lock_mode;
QGroupBox *groupBox_2;
QCheckBox *checkBox_crazyfly_zones;
QCheckBox *checkBox_vicon_markers;
QCheckBox *checkBox_grid;
QCheckBox *checkBox_table;
QFrame *frame_3;
QMenuBar *menuBar;
QToolBar *mainToolBar;
......@@ -80,7 +83,7 @@ public:
removeTable->setGeometry(QRect(340, 430, 91, 21));
groupBox = new QGroupBox(frame_drawing);
groupBox->setObjectName(QStringLiteral("groupBox"));
groupBox->setGeometry(QRect(790, 30, 121, 80));
groupBox->setGeometry(QRect(790, 30, 121, 121));
radioButton_table_mode = new QRadioButton(groupBox);
radioButton_table_mode->setObjectName(QStringLiteral("radioButton_table_mode"));
radioButton_table_mode->setGeometry(QRect(10, 20, 61, 20));
......@@ -93,17 +96,33 @@ public:
radioButton_crazyfly_zones_mode->setGeometry(QRect(10, 50, 91, 16));
radioButton_crazyfly_zones_mode->setFont(font);
radioButton_crazyfly_zones_mode->setCheckable(true);
radioButton_lock_mode = new QRadioButton(groupBox);
radioButton_lock_mode->setObjectName(QStringLiteral("radioButton_lock_mode"));
radioButton_lock_mode->setGeometry(QRect(10, 80, 91, 16));
radioButton_lock_mode->setFont(font);
radioButton_lock_mode->setCheckable(true);
groupBox_2 = new QGroupBox(frame_drawing);
groupBox_2->setObjectName(QStringLiteral("groupBox_2"));
groupBox_2->setGeometry(QRect(790, 130, 120, 241));
groupBox_2->setGeometry(QRect(790, 230, 120, 141));
checkBox_crazyfly_zones = new QCheckBox(groupBox_2);
checkBox_crazyfly_zones->setObjectName(QStringLiteral("checkBox_crazyfly_zones"));
checkBox_crazyfly_zones->setGeometry(QRect(10, 20, 101, 20));
checkBox_crazyfly_zones->setFont(font);
checkBox_crazyfly_zones->setChecked(true);
checkBox_vicon_markers = new QCheckBox(groupBox_2);
checkBox_vicon_markers->setObjectName(QStringLiteral("checkBox_vicon_markers"));
checkBox_vicon_markers->setGeometry(QRect(10, 40, 101, 20));
checkBox_vicon_markers->setFont(font);
checkBox_grid = new QCheckBox(groupBox_2);
checkBox_grid->setObjectName(QStringLiteral("checkBox_grid"));
checkBox_grid->setGeometry(QRect(10, 60, 101, 20));
checkBox_grid->setFont(font);
checkBox_grid->setChecked(true);
checkBox_table = new QCheckBox(groupBox_2);
checkBox_table->setObjectName(QStringLiteral("checkBox_table"));
checkBox_table->setGeometry(QRect(10, 80, 101, 20));
checkBox_table->setFont(font);
checkBox_table->setChecked(true);
frame_3 = new QFrame(centralWidget);
frame_3->setObjectName(QStringLiteral("frame_3"));
frame_3->setGeometry(QRect(990, 20, 481, 469));
......@@ -136,9 +155,12 @@ public:
groupBox->setTitle(QApplication::translate("MainGUIWindow", "Creation Modes", 0));
radioButton_table_mode->setText(QApplication::translate("MainGUIWindow", "Tables", 0));
radioButton_crazyfly_zones_mode->setText(QApplication::translate("MainGUIWindow", "CrazyFly Zones", 0));
radioButton_lock_mode->setText(QApplication::translate("MainGUIWindow", "Lock", 0));
groupBox_2->setTitle(QApplication::translate("MainGUIWindow", "What to show", 0));
checkBox_crazyfly_zones->setText(QApplication::translate("MainGUIWindow", "Show CF Zones", 0));
checkBox_vicon_markers->setText(QApplication::translate("MainGUIWindow", "Show Markers", 0));
checkBox_grid->setText(QApplication::translate("MainGUIWindow", "Show Grid", 0));
checkBox_table->setText(QApplication::translate("MainGUIWindow", "Show Table", 0));
} // retranslateUi
};
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>