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
|
/***************************************************************************
choosewidgetimpl.cpp - dialog to choose widget
-------------------
begin : Thu 13 Apr 2004
copyright : (C) 2000 Michal Rudolf <mrudolf@kdewebdev.org>
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/** KDE INCLUDES */
#include <klistview.h>
#include <klocale.h>
/** QT INCLUDES */
#include <tqptrstack.h>
#include <tqobject.h>
#include <tqobjectlist.h>
#include <tqlineedit.h>
#include "tqmetaobject.h"
/** OTHER INCLUDES */
#include "choosewidgetimpl.h"
#include "choosewidgetimpl.moc"
ChooseWidget::ChooseWidget(TQWidget* a_parent, const char* a_name, bool a_modal)
: ChooseWidgetBase(a_parent, a_name, a_modal)
{
connect( nameEdit, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(textChanged(const TQString&)) );
connect( widgetView, TQT_SIGNAL(executed(TQListViewItem*)), TQT_SLOT(selectedItem(TQListViewItem*)));
widgetView->setFullWidth(true);
widgetView->addColumn(i18n("Widgets"));
widgetView->setRootIsDecorated(true);
nameEdit->setFocus();
}
ChooseWidget::~ChooseWidget()
{
}
void ChooseWidget::setWidget(TQWidget* w)
{
widgetView->clear();
if (!w)
return;
TQListViewItem* item;
TQPtrStack<TQWidget> p_widgets;
TQPtrStack<TQListViewItem> p_items;
item = new TQListViewItem(widgetView, TQString("%1 (%2)").tqarg(w->name()).tqarg(w->className()));
item->setOpen(true);
p_widgets.push(w);
p_items.push(item);
while (!p_widgets.isEmpty()) {
w = p_widgets.pop();
item = p_items.pop();
TQObjectList *objectList = w->queryList(0, 0, true, false);
for (TQObjectListIt it(*objectList); it.current(); ++it) {
TQListViewItem* newItem = item;
if (isKommanderWidget(*it))
newItem = new TQListViewItem(item, TQString("%1 (%2)").tqarg((*it)->name()).tqarg((*it)->className()));
if (!(*it)->childrenListObject().isEmpty()) {
p_widgets.push((TQWidget*)(*it));
p_items.push(newItem);
}
}
delete objectList;
}
if (widgetView->childCount()) {
widgetView->setCurrentItem(widgetView->firstChild());
widgetView->firstChild()->setSelected(true);
}
}
TQString ChooseWidget::selection()
{
if (widgetView->currentItem())
return widgetView->currentItem()->text(0);
else
return TQString();
}
void ChooseWidget::textChanged(const TQString& text)
{
TQListViewItem* item = widgetView->tqfindItem(text, 0, TQt::BeginsWith);
if (item) {
widgetView->setCurrentItem(item);
widgetView->ensureItemVisible(item);
}
}
bool ChooseWidget::isKommanderWidget(TQObject* w)
{
bool pExists = false;
TQMetaObject *metaObj = w->tqmetaObject();
if (metaObj)
{
int id = metaObj->tqfindProperty("KommanderWidget", true);
const TQMetaProperty *metaProp = metaObj->property(id, true);
if (metaProp && metaProp->isValid())
pExists = true;
}
if (pExists)
{
TQVariant flag = (w)->property("KommanderWidget");
if(flag.isValid() && !(TQString(w->name()).startsWith("qt_")))
return true;
}
return false;
}
void ChooseWidget::selectedItem(TQListViewItem* item)
{
if (item)
accept();
}
|