OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / locator / ilocatorfilter.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "ilocatorfilter.h"
35
36 #include <QtGui/QBoxLayout>
37 #include <QtGui/QCheckBox>
38 #include <QtGui/QDialog>
39 #include <QtGui/QDialogButtonBox>
40 #include <QtGui/QLabel>
41 #include <QtGui/QLineEdit>
42
43 using namespace Locator;
44
45 ILocatorFilter::ILocatorFilter(QObject *parent):
46     QObject(parent),
47     m_includedByDefault(false),
48     m_hidden(false)
49 {
50 }
51
52 QString ILocatorFilter::shortcutString() const
53 {
54     return m_shortcut;
55 }
56
57 void ILocatorFilter::setShortcutString(const QString &shortcut)
58 {
59     m_shortcut = shortcut;
60 }
61
62 QByteArray ILocatorFilter::saveState() const
63 {
64     QByteArray value;
65     QDataStream out(&value, QIODevice::WriteOnly);
66     out << shortcutString();
67     out << isIncludedByDefault();
68     return value;
69 }
70
71 bool ILocatorFilter::restoreState(const QByteArray &state)
72 {
73     QString shortcut;
74     bool defaultFilter;
75
76     QDataStream in(state);
77     in >> shortcut;
78     in >> defaultFilter;
79
80     setShortcutString(shortcut);
81     setIncludedByDefault(defaultFilter);
82     return true;
83 }
84
85 bool ILocatorFilter::openConfigDialog(QWidget *parent, bool &needsRefresh)
86 {
87     Q_UNUSED(needsRefresh)
88
89     QDialog dialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
90     dialog.setWindowTitle(tr("Filter Configuration"));
91
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());
97
98     hlayout->addWidget(new QLabel(tr("Prefix:")));
99     hlayout->addWidget(shortcutEdit);
100     hlayout->addWidget(limitCheck);
101
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()));
106
107     vlayout->addLayout(hlayout);
108     vlayout->addStretch();
109     vlayout->addWidget(buttonBox);
110
111     if (dialog.exec() == QDialog::Accepted) {
112         setShortcutString(shortcutEdit->text().trimmed());
113         setIncludedByDefault(!limitCheck->isChecked());
114         return true;
115     }
116
117     return false;
118 }
119
120 bool ILocatorFilter::isConfigurable() const
121 {
122     return true;
123 }
124
125 bool ILocatorFilter::isIncludedByDefault() const
126 {
127     return m_includedByDefault;
128 }
129
130 void ILocatorFilter::setIncludedByDefault(bool includedByDefault)
131 {
132     m_includedByDefault = includedByDefault;
133 }
134
135 bool ILocatorFilter::isHidden() const
136 {
137     return m_hidden;
138 }
139
140 void ILocatorFilter::setHidden(bool hidden)
141 {
142     m_hidden = hidden;
143 }