-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdialog_manager.cpp
More file actions
69 lines (63 loc) · 2.1 KB
/
dialog_manager.cpp
File metadata and controls
69 lines (63 loc) · 2.1 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
#include "dialog_manager.h"
#include "dialogs/find_replace_dialog.h"
#include "dialogs/goto_dialog.h"
#include "dialogs/select_range_dialog.h"
#include "dialogs/expand_rom_dialog.h"
#include "dialogs/metadata_editor_dialog.h"
#include "dialogs/map_editor_dialog.h"
#include "dialogs/settings_dialog.h"
#include "dialogs/how_to_use_dialog.h"
#include "hex_editor.h"
dialog_manager::dialog_manager(QWidget *parent) :
QObject(parent)
{
dialog_map[GOTO] = new goto_dialog(parent);
dialog_map[SELECT_RANGE] = new select_range_dialog(parent);
dialog_map[EXPAND] = new expand_ROM_dialog(parent);
dialog_map[METADATA_EDITOR] = new metadata_editor_dialog(parent);
dialog_map[FIND_REPLACE] = new find_replace_dialog(parent);
dialog_map[MAP_EDITOR] = new map_editor_dialog(parent);
dialog_map[SETTINGS] = new settings_dialog(parent);
dialog_map[HOW_TO_USE] = new how_to_use_dialog(parent);
}
void dialog_manager::connect_to_editor(hex_editor *editor)
{
#define CONNECT(D,E,S,T) connect((D *)find_dialog(E), &D::S, editor, &hex_editor::T);
CONNECT(goto_dialog, GOTO, triggered, goto_offset);
CONNECT(select_range_dialog, SELECT_RANGE, triggered, select_range);
CONNECT(find_replace_dialog, FIND_REPLACE, count, count);
CONNECT(find_replace_dialog, FIND_REPLACE, search, search);
CONNECT(find_replace_dialog, FIND_REPLACE, replace, replace);
CONNECT(find_replace_dialog, FIND_REPLACE, replace_all, replace_all);
#undef CONNECT
}
void dialog_manager::set_active_editor(hex_editor *editor)
{
for(auto &dialog : dialog_map){
dialog->set_active_editor(editor);
dialog->refresh();
}
}
void dialog_manager::raise_dialog(dialog_events id)
{
abstract_dialog *dialog = find_dialog(id);
dialog->show();
dialog->raise();
dialog->activateWindow();
}
bool dialog_manager::event(QEvent *event)
{
if(event->type() != (QEvent::Type)DIALOG_EVENT){
return QObject::event(event);
}
raise_dialog(((dialog_event *)event)->sub_type());
return true;
}
abstract_dialog *dialog_manager::find_dialog(dialog_events id)
{
if(dialog_map.contains(id)){
return dialog_map[id];
}
qDebug() << "Error: Dialog " << id << " not found";
return 0;
}