Newer
Older
#include "outlinefactory.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <QVBoxLayout>
#include <QDebug>
#include <QToolButton>
#include <QLabel>
#include <QStackedWidget>
namespace TextEditor {
namespace Internal {
OutlineWidgetStack::OutlineWidgetStack(OutlineFactory *factory) :
QStackedWidget(),
m_factory(factory),
m_syncWithEditor(true)
{
QLabel *label = new QLabel(tr("No outline available"), this);
label->setAlignment(Qt::AlignCenter);
// set background to be white
label->setAutoFillBackground(true);
label->setBackgroundRole(QPalette::Base);
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
addWidget(label);
m_toggleSync = new QToolButton;
m_toggleSync->setIcon(QIcon(":/core/images/linkicon.png"));
m_toggleSync->setCheckable(true);
m_toggleSync->setChecked(true);
m_toggleSync->setToolTip(tr("Synchronize with Editor"));
connect(m_toggleSync, SIGNAL(clicked(bool)), this, SLOT(toggleCursorSynchronization()));
Core::EditorManager *editorManager = Core::EditorManager::instance();
connect(editorManager, SIGNAL(currentEditorChanged(Core::IEditor*)),
this, SLOT(updateCurrentEditor(Core::IEditor*)));
updateCurrentEditor(editorManager->currentEditor());
}
OutlineWidgetStack::~OutlineWidgetStack()
{
}
QToolButton *OutlineWidgetStack::toggleSyncButton()
{
return m_toggleSync;
}
bool OutlineWidgetStack::isCursorSynchronized() const
{
return m_syncWithEditor;
}
void OutlineWidgetStack::toggleCursorSynchronization()
{
m_syncWithEditor = !m_syncWithEditor;
if (IOutlineWidget *outlineWidget = qobject_cast<IOutlineWidget*>(currentWidget()))
outlineWidget->setCursorSynchronization(m_syncWithEditor);
}
void OutlineWidgetStack::updateCurrentEditor(Core::IEditor *editor)
{
IOutlineWidget *newWidget = 0;
if (editor) {
foreach (IOutlineWidgetFactory *widgetFactory, m_factory->widgetFactories()) {
if (widgetFactory->supportsEditor(editor)) {
newWidget = widgetFactory->createWidget(editor);
break;
}
}
}
if (newWidget != currentWidget()) {
// delete old widget
if (IOutlineWidget *outlineWidget = qobject_cast<IOutlineWidget*>(currentWidget())) {
removeWidget(outlineWidget);
delete outlineWidget;
}
if (newWidget) {
newWidget->setCursorSynchronization(m_syncWithEditor);
addWidget(newWidget);
setCurrentWidget(newWidget);
}
}
}
OutlineFactory::OutlineFactory() :
Core::INavigationWidgetFactory()
{
}
QList<IOutlineWidgetFactory*> OutlineFactory::widgetFactories() const
{
return m_factories;
}
void OutlineFactory::setWidgetFactories(QList<IOutlineWidgetFactory*> factories)
{
m_factories = factories;
}
QString OutlineFactory::displayName() const
{
return tr("Outline");
}
QString OutlineFactory::id() const
{
return QLatin1String("Outline");
}
QKeySequence OutlineFactory::activationSequence() const
{
return QKeySequence();
}
Core::NavigationView OutlineFactory::createWidget()
{
Core::NavigationView n;
OutlineWidgetStack *placeHolder = new OutlineWidgetStack(this);
n.widget = placeHolder;
n.dockToolBarWidgets.append(placeHolder->toggleSyncButton());
return n;
}
} // namespace Internal
} // namespace TextEditor