-
Notifications
You must be signed in to change notification settings - Fork 12
/
MainWindow.cpp
171 lines (147 loc) · 5.91 KB
/
MainWindow.cpp
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* This file is part of SCView, a STEP-Express viewer
Copyright (C) 2012 Laurent Bauer [email protected]
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; version 2
of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "ui_MainWindow.h"
#include "MainWindow.h"
#include "SchemaTreeDockWidget.h"
#include "textView/ExpressViewDockWidget.h"
#include "textView/ExpressTextEdit.h"
#include "SchemaTree.h"
#include "expressg/ExpressGView.h"
#include "NavigateCommand.h"
#include <QUndoStack>
#include <QToolButton>
#include <QLineEdit>
#include <QLabel>
#include <QHBoxLayout>
#include <QCompleter>
#include <QStringListModel>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, m_UndoStack(new QUndoStack(this))
, m_Registry( SchemaInit )
, m_Current(0)
, m_SchemaTree ( new SchemaTree(&m_Registry) )
, m_SchemaTreeDockWidget (new SchemaTreeDockWidget(m_SchemaTree, this) )
, m_ExpressViewDockWidget( new ExpressViewDockWidget(this))
, m_ExpressTextEdit(new ExpressTextEdit(&m_Registry, m_ExpressViewDockWidget))
, m_ExpressGView (new ExpressGView(this))
, m_StringListModel(new QStringListModel())
, m_SearchLineEdit(0)
{
ui->setupUi(this);
m_Registry.ResetSchemas();
const Schema * sc = m_Registry.NextSchema();
QString title = QApplication::applicationName()+ ": " + QString(sc->Name());
setWindowTitle( title );
buildView();
setCentralWidget(m_ExpressGView);
connect(m_ExpressGView, SIGNAL(descriptorDoubleClicked(const TypeDescriptor*))
, this, SLOT(setDescriptorCommand(const TypeDescriptor*)));
connect(m_SchemaTree, SIGNAL(selectedDescriptorChanged(const TypeDescriptor*))
, this, SLOT(setDescriptorCommand(const TypeDescriptor*)));
connect(m_ExpressTextEdit, SIGNAL(descriptorDoubleClicked(const TypeDescriptor*))
, this, SLOT(setDescriptorCommand(const TypeDescriptor*)));
connect(ui->actionFind, SIGNAL(triggered()), this, SLOT (startSearch()));
QAction * undoAction = m_UndoStack->createUndoAction(this);
QAction * redoAction = m_UndoStack->createRedoAction(this);
undoAction->setIcon(QIcon(":Undo"));
redoAction->setIcon(QIcon(":Redo"));
undoAction->setShortcut(QKeySequence(tr("Ctrl+Z")));
redoAction->setShortcut(QKeySequence(tr("Ctrl+Y")));
ui->mainToolBar->addAction(undoAction);
ui->mainToolBar->addAction(redoAction);
ui->menuEdit->insertAction(ui->actionFind,redoAction);
ui->menuEdit->insertAction(redoAction,undoAction);
}
MainWindow::~MainWindow()
{
delete ui;
}
QStringList MainWindow::typeList()
{
QStringList list;
const TypeDescriptor * typeDescriptor;
m_Registry.ResetTypes();
while ( (typeDescriptor= m_Registry.NextType() ) )
list << typeDescriptor->Name();
return list;
}
QStringList MainWindow::entityList()
{
QStringList list;
const EntityDescriptor * entityDescriptor;
m_Registry.ResetEntities();
while ( (entityDescriptor= m_Registry.NextEntity() ) )
list << entityDescriptor->Name();
return list;
}
void MainWindow::setDescriptor(const TypeDescriptor *descriptor)
{
m_SchemaTree->select(descriptor);
m_ExpressGView->setDescriptor(descriptor);
m_ExpressTextEdit->setDescriptor(descriptor);
}
void MainWindow::startSearch()
{
m_SearchLineEdit->setFocus();
m_SearchLineEdit->clear();
}
void MainWindow::selectSearchResult(QString highlighted)
{
QList<QTreeWidgetItem * > results = m_SchemaTree->findItems(highlighted, Qt::MatchFixedString |Qt::MatchCaseSensitive| Qt::MatchRecursive);
if (!results.isEmpty())
{
QTreeWidgetItem * item = results.first();
m_SchemaTree->clearSelection();
item->setSelected(true);
m_SchemaTree->expandItem(item);
m_SchemaTree->scrollToItem(item);
}
}
void MainWindow::setDescriptorCommand(const TypeDescriptor *descriptor)
{
NavigateCommand * navigateCommand = new NavigateCommand(this, m_Current, descriptor);
m_UndoStack->push(navigateCommand);
m_Current = descriptor;
}
void MainWindow::buildView()
{
addDockWidget(Qt::LeftDockWidgetArea, m_SchemaTreeDockWidget);
ui->menuWindows->addAction(m_SchemaTreeDockWidget->toggleViewAction());
m_ExpressViewDockWidget->setWidget(m_ExpressTextEdit);
addDockWidget(Qt::LeftDockWidgetArea, m_ExpressViewDockWidget);
ui->menuWindows->addAction(m_ExpressViewDockWidget->toggleViewAction());
// Search
QWidget * searchWidget = new QWidget(ui->menuBar);
m_SearchLineEdit = new QLineEdit(searchWidget);
QLabel * label = new QLabel(searchWidget);
label->setPixmap(QPixmap(":/Find"));
QHBoxLayout * layout = new QHBoxLayout(searchWidget);
layout->addWidget(label);
layout->addWidget(m_SearchLineEdit);
layout->setContentsMargins(0,0,0,0);
searchWidget->setLayout(layout);
ui->menuBar->setCornerWidget(searchWidget);
m_SchemaTree->fillStringListModel(m_StringListModel);
m_SearchLineEdit->setText("Search");
QCompleter * completer = new QCompleter(m_StringListModel);
completer->setMaxVisibleItems(10);
completer->setCompletionMode(QCompleter::PopupCompletion);
completer->setCaseSensitivity(Qt::CaseInsensitive);
m_SearchLineEdit->setCompleter(completer);
connect(completer, SIGNAL(highlighted(QString)), this, SLOT(selectSearchResult(QString)));
}