2 * This file is part of NeverNote
\r
3 * Copyright 2009 Randy Baumgarte
\r
5 * This file may be licensed under the terms of of the
\r
6 * GNU General Public License Version 2 (the ``GPL'').
\r
8 * Software distributed under the License is distributed
\r
9 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
\r
10 * express or implied. See the GPL for the specific language
\r
11 * governing rights and limitations.
\r
13 * You should have received a copy of the GPL along with this
\r
14 * program. If not, go to http://www.gnu.org/licenses/gpl.html
\r
15 * or write to the Free Software Foundation, Inc.,
\r
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
20 package cx.fbn.nevernote.dialog;
\r
22 import java.util.ArrayList;
\r
23 import java.util.List;
\r
25 import com.evernote.edam.type.Tag;
\r
26 import com.trolltech.qt.gui.QAbstractItemView;
\r
27 import com.trolltech.qt.gui.QDialog;
\r
28 import com.trolltech.qt.gui.QHBoxLayout;
\r
29 import com.trolltech.qt.gui.QLineEdit;
\r
30 import com.trolltech.qt.gui.QListWidget;
\r
31 import com.trolltech.qt.gui.QListWidgetItem;
\r
32 import com.trolltech.qt.gui.QPushButton;
\r
33 import com.trolltech.qt.gui.QVBoxLayout;
\r
35 public class TagAssign extends QDialog {
\r
36 private final QListWidget tagList;
\r
37 private final QPushButton okButton;
\r
38 private final QPushButton cancelButton;
\r
39 private final QLineEdit newTag;
\r
40 private final QPushButton newTagButton;
\r
41 private boolean okClicked;
\r
42 private final List<String> tags;
\r
44 public TagAssign(List<Tag> allTags, List<String> selectedTags) {
\r
46 tags = new ArrayList<String>();
\r
48 tagList = new QListWidget();
\r
49 tagList.setSortingEnabled(true);
\r
50 tagList.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);
\r
52 newTag = new QLineEdit();
\r
53 newTag.textChanged.connect(this, "newTagTextChanged()");
\r
54 newTagButton = new QPushButton("Add");
\r
55 newTagButton.setEnabled(false);
\r
56 newTagButton.clicked.connect(this, "addTag()");
\r
58 QHBoxLayout addLayout = new QHBoxLayout();
\r
59 addLayout.addWidget(newTag);
\r
60 addLayout.setStretch(0, 10);
\r
61 addLayout.addWidget(newTagButton);
\r
63 okButton = new QPushButton();
\r
64 okButton.setText("OK");
\r
65 okButton.pressed.connect(this, "onClicked()");
\r
67 cancelButton = new QPushButton();
\r
68 cancelButton.setText("Cancel");
\r
69 cancelButton.pressed.connect(this, "onCancel()");
\r
71 QHBoxLayout horizontalLayout = new QHBoxLayout();
\r
72 horizontalLayout.addWidget(tagList);
\r
74 QHBoxLayout buttonLayout = new QHBoxLayout();
\r
75 buttonLayout.addStretch(1);
\r
76 buttonLayout.addWidget(okButton);
\r
77 buttonLayout.addWidget(cancelButton);
\r
78 setWindowTitle(tr("Note Tags"));
\r
80 QVBoxLayout mainLayout = new QVBoxLayout();
\r
81 mainLayout.addLayout(horizontalLayout);
\r
82 mainLayout.addLayout(addLayout);
\r
83 //mainLayout.addStretch(1);
\r
84 mainLayout.addSpacing(1);
\r
85 mainLayout.addLayout(buttonLayout);
\r
86 setLayout(mainLayout);
\r
88 if (allTags != null) {
\r
89 for (int i=0; i<allTags.size(); i++) {
\r
90 tags.add(allTags.get(i).getName());
\r
91 // tagList.addItem(allTags.get(i).getName());
\r
92 QListWidgetItem item = new QListWidgetItem(allTags.get(i).getName());
\r
93 tagList.addItem(item);
\r
94 if (selectedTags != null) {
\r
95 for (int j=0; j<selectedTags.size(); j++) {
\r
96 String name = selectedTags.get(j);
\r
97 if (name.equals(item.text())) {
\r
98 item.setSelected(true);
\r
99 j=selectedTags.size()+1;
\r
109 @SuppressWarnings("unused")
\r
110 private void onClicked() {
\r
115 @SuppressWarnings("unused")
\r
116 private void onCancel() {
\r
121 public boolean okClicked() {
\r
125 @SuppressWarnings("unused")
\r
126 private void newTagTextChanged() {
\r
127 if (newTag.text().equals("")) {
\r
128 newTagButton.setEnabled(false);
\r
131 newTagButton.setEnabled(true);
\r
132 for (int i=0; i<tags.size(); i++) {
\r
133 if (tags.get(i).trim().equalsIgnoreCase(newTag.text().trim())) {
\r
134 newTagButton.setEnabled(false);
\r
140 @SuppressWarnings("unused")
\r
141 private void addTag() {
\r
142 String tag = newTag.text().trim();
\r
143 tagList.addItem(tag);
\r
144 newTag.setText("");
\r
145 newTagButton.setEnabled(false);
\r
147 for (int i=0; i<tagList.count(); i++) {
\r
148 QListWidgetItem item = tagList.item(i);
\r
149 if (item.text().equals(tag)) {
\r
150 item.setSelected(true);
\r
157 public QListWidget getTagList() {
\r