1
0
mirror of https://github.com/fwbuilder/fwbuilder synced 2026-03-25 20:57:29 +01:00

Removed 'clear' button next to filter combobox.

Changed filter combobox into a lineedit that has an embedded 'clear' button.
This commit is contained in:
Theron Tock 2011-06-16 18:28:10 -07:00
parent d57e13002b
commit 4fe02aa328
9 changed files with 95 additions and 158 deletions

View File

@ -1,55 +0,0 @@
/*
Firewall Builder
Copyright (C) 2009 NetCitadel, LLC
Author: a2k@codeminders.com
$Id$
This program is free software which we release under the GNU General Public
License. You may redistribute and/or modify this program under the terms
of that license as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
To get a copy of the GNU General Public License, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "AutocompletedComboBox.h"
AutocompletedComboBox::AutocompletedComboBox(QWidget* parent)
{
this->setParent(parent);
model.setStringList(words);
completer = new QCompleter(&model, this);
this->setCompleter(this->completer);
connect(this, SIGNAL(editTextChanged(QString)),
this, SLOT(filterUpdate(QString)));
this->setModel(&model);
timer.setSingleShot(true);
connect(&timer, SIGNAL(timeout ()), this, SLOT(addWord()));
}
void AutocompletedComboBox::filterUpdate(QString /*UNUSED text */)
{
timer.stop();
timer.start(1000);
}
void AutocompletedComboBox::addWord()
{
if (this->currentText().length() < 2) return;
if (words.contains(this->currentText())) return;
QString text = this->currentText();
words << text;
this->model.setStringList(this->words);
this->setEditText(text);
}

View File

@ -1,50 +0,0 @@
/*
Firewall Builder
Copyright (C) 2009 NetCitadel, LLC
Author: a2k@codeminders.com
$Id$
This program is free software which we release under the GNU General Public
License. You may redistribute and/or modify this program under the terms
of that license as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
To get a copy of the GNU General Public License, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef AUTOCOMPLETEDCOMBOBOX_H
#define AUTOCOMPLETEDCOMBOBOX_H
#include <QTimer>
#include <QComboBox>
#include <QCompleter>
#include <QStringListModel>
class AutocompletedComboBox : public QComboBox
{
Q_OBJECT
private:
QCompleter *completer;
QStringList words;
QStringListModel model;
QTimer timer;
public:
AutocompletedComboBox(QWidget* parent = 0);
public slots:
void filterUpdate(QString);
void addWord();
};
#endif // AUTOCOMPLETEDCOMBOBOX_H

View File

@ -0,0 +1,50 @@
/****************************************************************************
**
** Copyright (c) 2007 Trolltech ASA <info@trolltech.com>
**
** Use, modification and distribution is allowed without limitation,
** warranty, liability or support of any kind.
**
****************************************************************************/
#include "FilterLineEdit.h"
#include <QToolButton>
#include <QStyle>
FilterLineEdit::FilterLineEdit(QWidget *parent)
: QLineEdit(parent)
{
clearButton = new QToolButton(this);
QPixmap pixmap(":/Icons/neg2");
clearButton->setIcon(QIcon(pixmap));
clearButton->setIconSize(pixmap.size());
clearButton->setCursor(Qt::ArrowCursor);
clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
clearButton->hide();
connect(clearButton, SIGNAL(clicked()), this, SLOT(clear()));
connect(this, SIGNAL(textChanged(const QString&)),
this, SLOT(updateCloseButton(const QString&)));
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
setStyleSheet(QString("QLineEdit { padding-right: %1px; } ").arg(clearButton->sizeHint().width() + frameWidth + 1));
QSize msz = minimumSizeHint();
setMinimumSize(qMax(msz.width(),
clearButton->sizeHint().height() + frameWidth * 2 + 2),
qMax(msz.height(),
clearButton->sizeHint().height() + frameWidth * 2 + 2));
}
void FilterLineEdit::resizeEvent(QResizeEvent *)
{
QSize sz = clearButton->sizeHint();
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
clearButton->move(rect().right() - frameWidth - sz.width(),
(rect().bottom() + 1 - sz.height())/2);
}
void FilterLineEdit::updateCloseButton(const QString& text)
{
clearButton->setVisible(!text.isEmpty());
}

View File

@ -0,0 +1,34 @@
/****************************************************************************
**
** Copyright (c) 2007 Trolltech ASA <info@trolltech.com>
**
** Use, modification and distribution is allowed without limitation,
** warranty, liability or support of any kind.
**
****************************************************************************/
#ifndef FilterLineEdit_h
#define FilterLineEdit_h
#include <QLineEdit>
class QToolButton;
class FilterLineEdit : public QLineEdit
{
Q_OBJECT
public:
FilterLineEdit(QWidget *parent = 0);
protected:
void resizeEvent(QResizeEvent *);
private slots:
void updateCloseButton(const QString &text);
private:
QToolButton *clearButton;
};
#endif /* FilterLineEdit_h */

BIN
src/libgui/Icons/neg2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 543 B

View File

@ -257,6 +257,7 @@
<file alias="Icons/UserService/icon-tree" >Icons/user_16.png</file>
<file alias="Icons/lock" >Icons/lock.png</file>
<file alias="Icons/neg" >Icons/neg.png</file>
<file alias="Icons/neg2" >Icons/neg2.png</file>
<file alias="Icons/physAddress/icon" >Icons/physaddress_25.png</file>
<file alias="Icons/physAddress/icon-big" >Icons/physaddress_64.png</file>
<file alias="Icons/physAddress/icon-neg" >Icons/physaddress-neg_25.png</file>

View File

@ -269,7 +269,7 @@ void ObjectManipulator::insertSubtree(FWObject *parent, FWObject *obj)
void ObjectManipulator::insertSubtree(ObjectTreeViewItem *itm, FWObject *obj)
{
this->m_objectManipulator->filter->clearEditText();
this->m_objectManipulator->filter->clear();
ObjectTreeViewItem *nitm = insertObject(itm, obj);
if (nitm==NULL) return;
@ -641,7 +641,7 @@ void ObjectManipulator::addLib(FWObject *lib)
objTreeView->header()->resizeSections(QHeaderView::ResizeToContents);
m_objectManipulator->filter->connect(m_objectManipulator->filter,
SIGNAL(editTextChanged(QString)),
SIGNAL(textChanged(QString)),
objTreeView, SLOT(setFilter(QString)));
}

View File

@ -170,7 +170,6 @@ HEADERS += ../../config.h \
pfsyncOptionsDialog.h \
check_update_url.h \
startup_tip_url.h \
AutocompletedComboBox.h \
InterfaceEditorWidget.h \
FWCmdBasic.h \
FWCmdChange.h \
@ -194,6 +193,7 @@ HEADERS += ../../config.h \
KeywordsDialog.h \
CommentKeywords.h \
DynamicGroupDialog.h \
FilterLineEdit.h \
\
ObjectDescriptor.h \
QThreadLogger.h \
@ -388,7 +388,6 @@ SOURCES += ProjectPanel.cpp \
pfsyncOptionsDialog.cpp \
heartbeatOptionsDialog.cpp \
openaisOptionsDialog.cpp \
AutocompletedComboBox.cpp \
InterfaceEditorWidget.cpp \
FWCmdBasic.cpp \
FWCmdChange.cpp \
@ -412,6 +411,7 @@ SOURCES += ProjectPanel.cpp \
KeywordsDialog.cpp \
CommentKeywords.cpp \
DynamicGroupDialog.cpp \
FilterLineEdit.cpp \
\
ObjectDescriptor.cpp \
QThreadLogger.cpp \

View File

@ -35,36 +35,6 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="AutocompletedComboBox" name="filter">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Object name pattern</string>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QToolButton" name="clearFilter">
<property name="toolTip">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Lucida Grande'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Clear filter&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
@ -98,6 +68,9 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="FilterLineEdit" name="filter"/>
</item>
</layout>
</item>
<item row="1" column="0">
@ -148,9 +121,9 @@ p, li { white-space: pre-wrap; }
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>AutocompletedComboBox</class>
<extends>QComboBox</extends>
<header>AutocompletedComboBox.h</header>
<class>FilterLineEdit</class>
<extends>QLineEdit</extends>
<header>FilterLineEdit.h</header>
</customwidget>
</customwidgets>
<resources>
@ -173,22 +146,6 @@ p, li { white-space: pre-wrap; }
</hint>
</hints>
</connection>
<connection>
<sender>clearFilter</sender>
<signal>clicked()</signal>
<receiver>filter</receiver>
<slot>clearEditText()</slot>
<hints>
<hint type="sourcelabel">
<x>25</x>
<y>51</y>
</hint>
<hint type="destinationlabel">
<x>69</x>
<y>59</y>
</hint>
</hints>
</connection>
<connection>
<sender>libs</sender>
<signal>activated(int)</signal>