-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspecdockwidget.cpp
148 lines (133 loc) · 4.26 KB
/
specdockwidget.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
#include "specdockwidget.h"
#include <QEvent>
#include <QFileInfo>
#include <QMainWindow>
#include <QToolBar>
#include "specactionlibrary.h"
#include "specsplitter.h"
#include "specview.h"
#include "specitemaction.h"
#define APPLYTOSUBDOCKS foreach(specDockWidget* sub, subDocks)
specDockWidget::specDockWidget(QString type, QWidget* parent, bool floating) :
QDockWidget(parent),
widgetTypeName(type),
Plot(0),
changingTitle(false)
{
setFloating(floating);
setVisible(false) ;
}
void specDockWidget::setupWindow(specActionLibrary* actions)
{
// prepare main widget
QMainWindow* widget = new QMainWindow(this) ;
widget->setWindowFlags(Qt::Widget);
setWidget(widget) ;
// // get brushes
// QPalette pal = palette() ;
// QBrush activeWindow = pal.brush(QPalette::Active, QPalette::Window),
// inactiveWindow = pal.brush(QPalette::Inactive, QPalette::Window) ;
// if (activeWindow == inactiveWindow)
// inactiveWindow.setColor(inactiveWindow.color().darker()) ;
//
// pal.setBrush(QPalette::Inactive, QPalette::Window, inactiveWindow) ;
// setPalette(pal) ;
// add inner widgets
QList<QWidget*> innerWidgets = mainWidgets() ;
if(innerWidgets.size() == 1)
widget->setCentralWidget(innerWidgets.first()) ;
else
{
specSplitter* splitter = new specSplitter(Qt::Vertical, this) ;
foreach(QWidget * innerWidget, innerWidgets)
splitter->insertWidget(0, innerWidget);
widget->setCentralWidget(splitter);
}
// add toolbars
if(!actions)
return ;
QList<QWidget*> allWidgets ;
allWidgets << this << innerWidgets ;
foreach(QWidget * w, allWidgets)
{
specView* view = dynamic_cast<specView*>(w);
specPlot* plot = dynamic_cast<specPlot*>(w) ;
if(view && view->model())
{
view->setActionLibrary(actions) ;
actions->addDragDropPartner(view->model());
connect(view->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
this, SLOT(selectionChanged(QItemSelection, QItemSelection))) ;
// connect(view->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
// this, SLOT(currentChanged(QModelIndex,QModelIndex))) ;
}
if(plot)
{
Plot = plot ;
actions->addPlot(plot) ;
}
QToolBar* toolbar = actions->toolBar(w) ;
if(toolbar->actions().isEmpty())
delete toolbar ;
else
widget->addToolBar(toolbar);
// w->setPalette(pal);
}
specView* view = findChild<specView*>() ;
if(!view) return ;
selectionChanged(view->selectionModel()->selection(), QItemSelection());
}
void specDockWidget::changeEvent(QEvent* event)
{
if(changingTitle) return ;
if(event->type() == QEvent::WindowTitleChange)
{
changingTitle = true ;
setWindowTitle(QFileInfo(windowFilePath()).fileName()
+ QLatin1String("[*]")
+ QLatin1Char(' ') + QChar(0x2014) + QLatin1Char(' ')
+ widgetTypeName) ;
changingTitle = false ;
event->accept();
}
QDockWidget::changeEvent(event) ;
toggleViewAction()->setText(tr("Show \"") + widgetTypeName + tr("\" window"));
}
void specDockWidget::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
{
if (Plot) Plot->haltPlotting(true);
foreach(QModelIndex index, deselected.indexes())
{
if(!index.isValid()) continue ;
if(index.column()) continue ;
specModelItem* pointer = (specModelItem*) index.internalPointer() ;
pointer->detach();
-- selectedTypes[pointer->typeId()] ;
}
foreach(QModelIndex index, selected.indexes())
{
if(!index.isValid()) continue ;
if(index.column()) continue ;
specModelItem* pointer = (specModelItem*) index.internalPointer() ;
pointer->attach(Plot);
++ selectedTypes[pointer->typeId()] ;
}
if(Plot) Plot->haltPlotting(false) ;
foreach(specItemAction * action, findChildren<specItemAction*>())
{
QList<specStreamable::type> ts = action->requiredTypes() ;
bool enable = ts.isEmpty();
foreach(specStreamable::type t, ts)
enable = enable || selectedTypes[t] ;
action->setEnabled(enable && action->requirements()) ;
action->setChecked(action->checkRequirements());
}
}
//void specDockWidget::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) // TODO why does this not work?
//{
// foreach (specItemAction* action, findChildren<specItemAction*>())
// {
// action->setEnabled(action->isEnabled() && action->requirements());
// action->setCheckable(action->checkRequirements());
// }
//}