//[-------------------------------------------------------] //[ Public functions ] //[-------------------------------------------------------] ClassListWidget::ClassListWidget(ClassListType listType,QWidget *parent, Qt::WindowFlags f): QWidget(parent, f) , m_bFirstLevelAlwaysExpanded(listType == HierachicalView) { QBoxLayout *boxLayout = new QVBoxLayout; setLayout(boxLayout); FilterWidget *filterWidget = new FilterWidget(this, FilterWidget::LayoutAlignNone); filterWidget->setRefuseFocus(true); connect(filterWidget, SIGNAL(filterChanged(QString)),this, SLOT(filterChanged(QString))); boxLayout->addWidget(filterWidget); m_pClassListModel = new ClassListModel(listType == HierachicalView, this); // Setup the sort and filter proxy model // The filtering is case insensitive m_pSortAndFilterProxyModel = new TreeSortAndFilterProxyModel(this); m_pSortAndFilterProxyModel->setSourceModel(m_pClassListModel); m_pSortAndFilterProxyModel->setDynamicSortFilter(true); m_pSortAndFilterProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); m_pSortAndFilterProxyModel->sort(0); m_pView = new QTreeView(this); m_pView->setModel(m_pSortAndFilterProxyModel); layout()->addWidget(m_pView); // Connect signal of QAbstractItemView directly to own signal, with this the class don't need to implement a slot to deliver the signal to the outside world. connect(m_pView, SIGNAL(activated(QModelIndex)), this, SIGNAL(activated(QModelIndex))); if(m_bFirstLevelAlwaysExpanded) m_pView->expandToDepth(0); }
WidgetBox::WidgetBox(QDesignerFormEditorInterface *core, QWidget *parent, Qt::WindowFlags flags) : QDesignerWidgetBox(parent, flags), m_core(core), m_view(new WidgetBoxTreeWidget(m_core)) { QVBoxLayout *l = new QVBoxLayout(this); l->setMargin(0); l->setSpacing(0); // Prevent the filter from grabbing focus since Our view has Qt::NoFocus FilterWidget *filterWidget = new FilterWidget(0, FilterWidget::LayoutAlignNone); filterWidget->setRefuseFocus(true); connect(filterWidget, SIGNAL(filterChanged(QString)), m_view, SLOT(filter(QString))); QToolBar *toolBar = new QToolBar(this); toolBar->addWidget(filterWidget); l->addWidget(toolBar); // View connect(m_view, SIGNAL(pressed(QString,QString,QPoint)), this, SLOT(handleMousePress(QString,QString,QPoint))); l->addWidget(m_view); setAcceptDrops (true); }