summaryrefslogtreecommitdiffstats
path: root/noatun-plugins/nexscope/gui.cpp
blob: db0fcb383be1163773258e1aa499a4513ae6c372 (plain)
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#include <klocale.h>
#include <tqheader.h>
#include <layout.h>
#include <tqdragobject.h>
#include <kfiledialog.h>
#include <kstdaction.h>
#include <kaction.h>

#include "gui.h"
#include "renderers.h"
#include "nex.h"

class CreatorItem : public TQListViewItem
{
public:
	CreatorItem(TQListView *parent, const TQString &title)
		: TQListViewItem(parent, title)
		{}
};

class TreeItem : public TQListViewItem
{
public:
	TreeItem(TreeItem *parent, TreeItem *after, CreatorItem *creator)
		: TQListViewItem(parent, after, creator->text(0))
	{
		RendererList *list;
		if (parent)
			list=static_cast<RendererList*>(parent->mRenderer);
		else
			list=nex->rendererList();
		
		Renderer *afterRenderer=0;
		if (after)
			afterRenderer=after->mRenderer;
		
		list->lock();
		int pos=list->renderers().findRef(afterRenderer);
		if (pos==-1) pos=list->renderers().count();
		
		list->renderers().insert((uint)pos, mRenderer=nex->renderer(creator->text(0)));
		list->unlock();
	}
	
	TreeItem(TQListView *parent, TreeItem *after, const TQString &title)
		: TQListViewItem(parent, after, title)
	{
		mRenderer=nex->rendererList();
		setExpandable(true);
	}
	
	~TreeItem()
	{
		RendererList *list;
		if (parent())
			list=static_cast<RendererList*>(static_cast<TreeItem*>(parent())->mRenderer);
		else
			return;
		
		list->lock();
		list->renderers().removeRef(mRenderer);
		list->unlock();
		delete mRenderer;
	}

	Renderer *renderer() { return mRenderer; }
private:
	Renderer *mRenderer;
};

Control::Control() : mConfigurator(0)
{
	{
		KToolBar *tools=toolBar();
		KStdAction::save(this, TQT_SLOT(save()), actionCollection())->plug(tools);
		KStdAction::saveAs(this, TQT_SLOT(saveAs()), actionCollection())->plug(tools);
		KStdAction::open(this, TQT_SLOT(open()), actionCollection())->plug(tools);
	
	}
	
	setCaption(i18n("Nex Configuration"));
	TQSplitter *mainSplitter=new TQSplitter(this);
	setCentralWidget(mainSplitter);
	TQSplitter *left=new TQSplitter(Qt::Vertical, mainSplitter);
	{
		mTree=new RendererListView(left);
		mTree->setItemsMovable(true);
		mTree->setSorting(-1);
		mTree->setRootIsDecorated(true);
		
		connect(mTree, TQT_SIGNAL(dropped(TQDropEvent*, TQListViewItem*, TQListViewItem*)),
		        TQT_SLOT(dropEvent(TQDropEvent*, TQListViewItem*, TQListViewItem*)));
		
		connect(mTree, TQT_SIGNAL(currentChanged(TQListViewItem*)),
		        TQT_SLOT(currentChanged(TQListViewItem*)));
		
		mCreatorsList=new RendererListView(left);
		mCreatorsList->addColumn(i18n("Name"));
		mCreatorsList->header()->hide();
		mCreatorsList->setDropVisualizer(false);
	}
		
	mRight=new TQWidget(mainSplitter);
	(new TQHBoxLayout(mRight))->setAutoAdd(true);
	
	TQStringList list=nex->renderers();
	for (TQStringList::Iterator i=list.begin(); i!=list.end(); ++i)
		addCreator(*i);
		
	new TreeItem(mTree, 0, i18n("Main"));
}

void Control::save(const KURL &file)
{
// TODO
}

void Control::save()
{
	if (mCurrentURL.isEmpty())
		saveAs();
	else
		save(mCurrentURL);
}

void Control::saveAs()
{
	KURL url;
	url=KFileDialog::getSaveURL(0, "application/x-nexscope", this);
	if (!url.isEmpty())
		save(mCurrentURL=url);
}

void Control::open()
{
	KURL url=KFileDialog::getOpenURL(0, "application/x-nexscope");
	if (!url.isEmpty())
		open(mCurrentURL=url);
}

void Control::open(const KURL &file)
{
// TODO
}


void Control::addCreator(const TQString &title)
{
	new CreatorItem(mCreatorsList, title);
}

void Control::dropEvent(TQDropEvent *e, TQListViewItem *parent, TQListViewItem *pafter)
{
//	if ((e->source() == mCreatorsList) && parent)
	{
		CreatorItem *i=static_cast<CreatorItem*>(mCreatorsList->currentItem());
		if (!i)
		{
			std::cerr << "no creatoritem" << std::endl;

		}
		new TreeItem(static_cast<TreeItem*>(parent), static_cast<TreeItem*>(pafter), i);
	}
}

void Control::currentChanged(TQListViewItem *item)
{
	TreeItem *treeItem=static_cast<TreeItem*>(item);
	delete mConfigurator;
	mConfigurator=treeItem->renderer()->configure(mRight);
	if (mConfigurator)
		mConfigurator->show();
}


RendererListView::RendererListView(TQWidget *p) : KListView(p)
{
	addColumn(i18n("Name"));
	header()->hide();
	setDragEnabled(true);
	setAcceptDrops(true);
	setSelectionMode(TQListView::Single);
}
	
bool RendererListView::acceptDrag(TQDropEvent *event) const
{
	return true; //TQCString(event->format()) == "application/x-nex-rendererdrag";
}

TQDragObject *RendererListView::dragObject() const
{
	if (!currentItem()) return 0;
	return new TQStoredDrag("application/x-nex-rendererdrag", (TQWidget*)this);
}


#include "gui.moc"