-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSimWindow.cpp
More file actions
143 lines (127 loc) · 3.82 KB
/
SimWindow.cpp
File metadata and controls
143 lines (127 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include "SimWindow.h"
#include "global_data_holder.h"
#include "svgpp\SvgManager.h"
#include "svgpp\SvgPolyPath.h"
#include "SimulationManager.h"
SimWindow::SimWindow(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
new QShortcut(QKeySequence(Qt::Key_F11), this, SLOT(showFullScreen()));
new QShortcut(QKeySequence(Qt::Key_Escape), this, SLOT(showNormal()));
setAcceptDrops(true);
initLeftDockActions();
startTimer(200);
}
SimWindow::~SimWindow()
{
}
SimViewer* SimWindow::getViewer()
{
return ui.widget;
}
const SimViewer* SimWindow::getViewer()const
{
return ui.widget;
}
void SimWindow::updateParamUI()
{
}
void SimWindow::on_actionSave_triggered()
{
try
{
QString name = QFileDialog::getSaveFileName(this, "save mesh", "", "*.obj");
if (name.isEmpty())
return;
if (!name.toLower().endsWith(".obj"))
name.append(".obj");
g_dataholder.m_simManager->saveCurrentCloth(name.toStdString());
} catch (std::exception e)
{
std::cout << e.what() << std::endl;
} catch (...)
{
std::cout << "unknown error" << std::endl;
}
}
void SimWindow::timerEvent(QTimerEvent* ev)
{
float fps = ui.widget->getFps();
setWindowTitle(QString().sprintf("fps = %.1f", fps));
}
void SimWindow::dragEnterEvent(QDragEnterEvent* event)
{
//if (event->mimeData()->hasUrls())
//{
// QList<QUrl> urls = event->mimeData()->urls();
// if (urls[0].fileName().endsWith(".svg"))
// event->acceptProposedAction();
//}
}
void SimWindow::dropEvent(QDropEvent* event)
{
//QUrl url = event->mimeData()->urls()[0];
//QString name = url.toLocalFile();
//try
//{
// if (ui.widget->getSvgManager() == nullptr)
// throw std::exception("svgManger: nullptr");
// ui.widget->getSvgManager()->load(name.toStdString().c_str());
// pushHistory("load svg");
// ui.widget->updateGL();
//}
//catch (std::exception e)
//{
// std::cout << e.what() << std::endl;
//}
//catch (...)
//{
// std::cout << "unknown error" << std::endl;
//}
//event->acceptProposedAction();
}
void SimWindow::initLeftDockActions()
{
m_ldbSignalMapper.reset(new QSignalMapper(this));
connect(m_ldbSignalMapper.data(), SIGNAL(mapped(int)), this, SLOT(leftDocButtonsClicked(int)));
ui.dockWidgetLeftContents->setLayout(new QGridLayout(ui.dockWidgetLeftContents));
ui.dockWidgetLeftContents->layout()->setAlignment(Qt::AlignTop);
// add buttons
for (size_t i = (size_t)AbstractSimEventHandle::ProcessorTypeGeneral+1;
i < (size_t)AbstractSimEventHandle::ProcessorTypeEnd; i++)
{
auto type = AbstractSimEventHandle::ProcessorType(i);
addLeftDockWidgetButton(type);
}
// do connections
for (auto it : m_leftDockButtons.toStdMap())
{
m_ldbSignalMapper->setMapping(it.second.data(), it.first);
connect(it.second.data(), SIGNAL(clicked()), m_ldbSignalMapper.data(), SLOT(map()));
}
}
void SimWindow::addLeftDockWidgetButton(AbstractSimEventHandle::ProcessorType type)
{
auto handle = ui.widget->getEventHandle(type);
auto colorStr = QString("background-color: rgb(73, 73, 73)");
QIcon icon;
icon.addFile(handle->iconFile(), QSize(), QIcon::Active);
icon.addFile(handle->iconFile(), QSize(), QIcon::Selected);
icon.addFile(handle->inactiveIconFile(), QSize(), QIcon::Normal);
QSharedPointer<QPushButton> btn(new QPushButton(ui.dockWidgetLeft));
btn->setIconSize(QSize(80, 80));
btn->setIcon(icon);
btn->setCheckable(true);
btn->setStyleSheet(colorStr);
btn->setAutoExclusive(true);
btn->setToolTip(handle->toolTips());
m_leftDockButtons.insert(type, btn);
ui.dockWidgetLeftContents->layout()->addWidget(btn.data());
}
void SimWindow::leftDocButtonsClicked(int i)
{
AbstractSimEventHandle::ProcessorType type = (AbstractSimEventHandle::ProcessorType)i;
ui.widget->setEventHandleType(type);
m_leftDockButtons[type]->setChecked(true);
}