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
|
/***************************************************************************
* Copyright (C) 2007 by Lukasz Fibinger <lucke@o2.pl> *
* *
* 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. *
* *
* 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. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "filterbar.h"
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqcheckbox.h>
#include <kdialog.h>
#include <klocale.h>
#include <kpushbutton.h>
#include <ktoolbarbutton.h>
#include <klineedit.h>
#include <kiconloader.h>
#include <kconfig.h>
#include <interfaces/torrentinterface.h>
FilterBar::FilterBar(TQWidget *parent, const char *name) :
TQWidget(parent, name)
{
const int gap = 3;
TQVBoxLayout* foo = new TQVBoxLayout(this);
foo->addSpacing(gap);
TQHBoxLayout* tqlayout = new TQHBoxLayout(foo);
tqlayout->addSpacing(gap);
m_close = new KToolBarButton("fileclose",0,this);
connect(m_close,TQT_SIGNAL(clicked()),this,TQT_SLOT(hide()));
tqlayout->addWidget(m_close);
m_filter = new TQLabel(i18n("Find:"), this);
tqlayout->addWidget(m_filter);
tqlayout->addSpacing(KDialog::spacingHint());
m_filterInput = new KLineEdit(this);
tqlayout->addWidget(m_filterInput);
m_clear = new KPushButton(this);
m_clear->setIconSet(SmallIcon("clear_left"));
m_clear->setFlat(true);
tqlayout->addWidget(m_clear);
tqlayout->addSpacing(gap);
m_case_sensitive = new TQCheckBox(i18n("Case sensitive"),this);
m_case_sensitive->setChecked(true);
tqlayout->addWidget(m_case_sensitive);
tqlayout->addItem(new TQSpacerItem(10,10,TQSizePolicy::Expanding));
connect(m_filterInput, TQT_SIGNAL(textChanged(const TQString&)),
this, TQT_SLOT(slotChangeFilter(const TQString&)));
connect(m_clear, TQT_SIGNAL(clicked()), m_filterInput, TQT_SLOT(clear()));
}
FilterBar::~FilterBar()
{
}
void FilterBar::saveSettings(KConfig* cfg)
{
cfg->writeEntry("filter_bar_hidden",isHidden());
cfg->writeEntry("filter_bar_text",m_name_filter);
cfg->writeEntry("filter_bar_case_sensitive",m_case_sensitive->isChecked());
}
void FilterBar::loadSettings(KConfig* cfg)
{
setHidden(cfg->readBoolEntry("filter_bar_hidden",true));
m_case_sensitive->setChecked(cfg->readBoolEntry("filter_bar_case_sensitive",true));
m_name_filter = cfg->readEntry("filter_bar_text",TQString());
m_filterInput->setText(m_name_filter);
}
bool FilterBar::matchesFilter(kt::TorrentInterface* tc)
{
bool cs = m_case_sensitive->isChecked();
if (m_name_filter.length() == 0)
return true;
else
return tc->getStats().torrent_name.contains(m_name_filter,cs);
}
void FilterBar::slotChangeFilter(const TQString& nameFilter)
{
m_name_filter = nameFilter;
}
void FilterBar::keyPressEvent(TQKeyEvent* event)
{
if ((event->key() == TQt::Key_Escape))
{
m_filterInput->clear();
m_name_filter = TQString();
//hide();
}
else
TQWidget::keyPressEvent(event);
}
void FilterBar::hideEvent(TQHideEvent* event)
{
m_filterInput->releaseKeyboard();
TQWidget::hideEvent(event);
}
#include "filterbar.moc"
|