1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "ilocatorfilter.h"
36 #include <QtGui/QBoxLayout>
37 #include <QtGui/QCheckBox>
38 #include <QtGui/QDialog>
39 #include <QtGui/QDialogButtonBox>
40 #include <QtGui/QLabel>
41 #include <QtGui/QLineEdit>
43 using namespace Locator;
45 ILocatorFilter::ILocatorFilter(QObject *parent):
47 m_includedByDefault(false),
52 QString ILocatorFilter::shortcutString() const
57 void ILocatorFilter::setShortcutString(const QString &shortcut)
59 m_shortcut = shortcut;
62 QByteArray ILocatorFilter::saveState() const
65 QDataStream out(&value, QIODevice::WriteOnly);
66 out << shortcutString();
67 out << isIncludedByDefault();
71 bool ILocatorFilter::restoreState(const QByteArray &state)
76 QDataStream in(state);
80 setShortcutString(shortcut);
81 setIncludedByDefault(defaultFilter);
85 bool ILocatorFilter::openConfigDialog(QWidget *parent, bool &needsRefresh)
87 Q_UNUSED(needsRefresh)
89 QDialog dialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
90 dialog.setWindowTitle(tr("Filter Configuration"));
92 QVBoxLayout *vlayout = new QVBoxLayout(&dialog);
93 QHBoxLayout *hlayout = new QHBoxLayout;
94 QLineEdit *shortcutEdit = new QLineEdit(shortcutString());
95 QCheckBox *limitCheck = new QCheckBox(tr("Limit to prefix"));
96 limitCheck->setChecked(!isIncludedByDefault());
98 hlayout->addWidget(new QLabel(tr("Prefix:")));
99 hlayout->addWidget(shortcutEdit);
100 hlayout->addWidget(limitCheck);
102 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok |
103 QDialogButtonBox::Cancel);
104 connect(buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));
105 connect(buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));
107 vlayout->addLayout(hlayout);
108 vlayout->addStretch();
109 vlayout->addWidget(buttonBox);
111 if (dialog.exec() == QDialog::Accepted) {
112 setShortcutString(shortcutEdit->text().trimmed());
113 setIncludedByDefault(!limitCheck->isChecked());
120 bool ILocatorFilter::isConfigurable() const
125 bool ILocatorFilter::isIncludedByDefault() const
127 return m_includedByDefault;
130 void ILocatorFilter::setIncludedByDefault(bool includedByDefault)
132 m_includedByDefault = includedByDefault;
135 bool ILocatorFilter::isHidden() const
140 void ILocatorFilter::setHidden(bool hidden)