File indexing completed on 2024-04-28 05:43:23
0001 /*************************************************************************** 0002 * Copyright (C) 2006 David Saxton <david@bluehaze.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify * 0005 * it under the terms of the GNU General Public License as published by * 0006 * the Free Software Foundation; either version 2 of the License, or * 0007 * (at your option) any later version. * 0008 ***************************************************************************/ 0009 0010 #include "componentmodelwidget.h" 0011 #include "component.h" 0012 #include "componentmodellibrary.h" 0013 0014 #include <KLineEdit> 0015 #include <KLocalizedString> 0016 #include <KToolBar> 0017 //#include <ktoolbarbutton.h> // converted to QToolButton 0018 0019 #include <QDebug> 0020 #include <QLabel> 0021 #include <QListWidget> 0022 #include <QVBoxLayout> 0023 // #include <q3header.h> // needed? 0024 #include <QPainter> 0025 #include <QPalette> 0026 #include <QToolButton> 0027 0028 // BEGIN class ComponentModelWidget 0029 ComponentModelWidget::ComponentModelWidget(QWidget *parent) 0030 : QWidget(parent) 0031 { 0032 QVBoxLayout *vlayout = new QVBoxLayout(this /*, 0, 6 - 2018.12.07 */); 0033 vlayout->setMargin(0); 0034 vlayout->setSpacing(6); 0035 0036 // parts of the following code are stolen from amarok/src/playlistwindow.cpp :) 0037 // BEGIN Filter lineedit 0038 QHBoxLayout *h1Layout = new QHBoxLayout; 0039 h1Layout->setMargin(0); 0040 KToolBar *bar = new KToolBar(QStringLiteral("ComponentModelSearch"), this); 0041 bar->setIconSize(QSize(22, 22) /*, false ?? */); // looks more sensible 0042 // bar->setFlat( true ); //removes the ugly frame 0043 bar->setMovable(false); // removes the ugly frame 0044 // bar->setMovingEnabled( false ); //removes the ugly frame // removed, apparently 0045 0046 // QWidget * button = new QToolButton( "locationbar_erase", 1, bar ); 0047 QWidget *button = new QToolButton(bar); 0048 button->setObjectName("locationbar_erase"); // TODO what is: "locationbar_erase", 1, 0049 // button: locationbar_erase is the name of the icon to be displayed on it 0050 m_pSearchEdit = new KLineEdit(bar); 0051 m_pSearchEdit->setPlaceholderText(i18n("Filter here...")); 0052 0053 // bar->setStretchableWidget( m_pSearchEdit ); // TODO removed, investigate 0054 m_pSearchEdit->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)); 0055 m_pSearchEdit->setFrame(true /* 2019.01.19: was QFrame::Sunken */); 0056 connect(m_pSearchEdit, &QLineEdit::textChanged, this, &ComponentModelWidget::setFilter); 0057 0058 // TODO Because plain QWidget* type doesn't have a clicked signal to connect, we cast 0059 connect(qobject_cast<QToolButton *>(button), &QToolButton::clicked, m_pSearchEdit, &QLineEdit::clear); 0060 0061 button->setToolTip(i18n("Clear filter")); 0062 QString filtertip = i18n("Enter space-separated terms to filter the component library."); 0063 0064 m_pSearchEdit->setToolTip(filtertip); 0065 0066 h1Layout->addWidget(m_pSearchEdit); 0067 h1Layout->addWidget(button); 0068 // END Filter lineedit 0069 0070 m_pList = new QListWidget(this); 0071 // m_pList->setItemMargin( 3 ); 0072 // m_pList->addColumn( "model" ); // 2018.06.02 - should not be needed 0073 // m_pList->setFullWidth( true ); // 2018.06.02 - is it fixed? 0074 m_pList->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); 0075 // m_pList->header()->hide(); 0076 m_pList->setToolTip(i18n("Select a predefined component configuration from this list.")); 0077 0078 vlayout->addWidget(bar); 0079 // vlayout->addWidget( m_pSearchEdit ); 0080 vlayout->addLayout(h1Layout); 0081 vlayout->addWidget(m_pList); 0082 } 0083 0084 ComponentModelWidget::~ComponentModelWidget() 0085 { 0086 } 0087 0088 void ComponentModelWidget::reset() 0089 { 0090 m_pList->clear(); 0091 m_pSearchEdit->clear(); 0092 } 0093 0094 void ComponentModelWidget::init(Component *component) 0095 { 0096 // for testing purposes 0097 reset(); 0098 if (!component) 0099 return; 0100 0101 QStringList types; 0102 if (component->type() == "ec/npnbjt") { 0103 // types = ComponentModelLibrary::self()->modelIDs( ComponentModelLibrary::NPN ); 0104 } else if (component->type() == "ec/pnpbjt") { 0105 // types = ComponentModelLibrary::self()->modelIDs( ComponentModelLibrary::PNP ); 0106 } else 0107 return; 0108 0109 QStringList::iterator end = types.end(); 0110 for (QStringList::iterator it = types.begin(); it != end; ++it) { 0111 QListWidgetItem *newItem = new QListWidgetItem(m_pList); 0112 newItem->setText(*it); 0113 } 0114 } 0115 0116 void ComponentModelWidget::setFilter(const QString &filter) 0117 { 0118 QString lower = filter.toLower(); 0119 0120 for (int itemNr = 0; itemNr < m_pList->count(); ++itemNr) { 0121 QListWidgetItem *item = m_pList->item(itemNr); 0122 bool hasText = item->text().toLower().contains(lower); 0123 item->setHidden(!hasText); 0124 } 0125 } 0126 // END class ComponentModelWidget 0127 0128 #include "moc_componentmodelwidget.cpp"