2 * This file is part of NeverNote
3 * Copyright 2009 Randy Baumgarte
5 * This file may be licensed under the terms of of the
6 * GNU General Public License Version 2 (the ``GPL'').
8 * Software distributed under the License is distributed
9 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
10 * express or implied. See the GPL for the specific language
11 * governing rights and limitations.
13 * You should have received a copy of the GPL along with this
14 * program. If not, go to http://www.gnu.org/licenses/gpl.html
15 * or write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package cx.fbn.nevernote.dialog;
22 import com.trolltech.qt.gui.QCheckBox;
23 import com.trolltech.qt.gui.QDialog;
24 import com.trolltech.qt.gui.QFileDialog;
25 import com.trolltech.qt.gui.QFileDialog.AcceptMode;
26 import com.trolltech.qt.gui.QFileDialog.FileMode;
27 import com.trolltech.qt.gui.QGridLayout;
28 import com.trolltech.qt.gui.QIcon;
29 import com.trolltech.qt.gui.QPushButton;
30 import com.trolltech.qt.gui.QSizePolicy.Policy;
32 import cx.fbn.nevernote.Global;
34 public class SetIcon extends QDialog {
35 private boolean okPressed;
37 QPushButton iconButton;
40 boolean startUseDefault;
43 private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
46 public SetIcon(QIcon i, String path) {
49 setWindowTitle(tr("Set Icon"));
50 QGridLayout grid = new QGridLayout();
51 setWindowIcon(new QIcon(iconPath+"nevernote.png"));
54 QGridLayout textGrid = new QGridLayout();
55 textGrid.setContentsMargins(10, 10,-10, -10);
56 useDefault = new QCheckBox();
57 iconButton = new QPushButton();
58 iconButton.setSizePolicy(Policy.Fixed, Policy.Fixed);
59 iconButton.clicked.connect(this, "iconButtonPressed()");
60 useDefault.setText(tr("Use Default"));
61 iconButton.setIcon(i);
63 textGrid.addWidget(iconButton,1,1);
64 textGrid.addWidget(useDefault,2,1);
65 useDefault.clicked.connect(this, "useDefaultIconChecked(Boolean)");
66 grid.addLayout(textGrid,1,1);
68 QGridLayout buttonGrid = new QGridLayout();
69 ok = new QPushButton(tr("OK"));
70 ok.clicked.connect(this, "okButtonPressed()");
72 QPushButton cancel = new QPushButton(tr("Cancel"));
73 cancel.clicked.connect(this, "cancelButtonPressed()");
74 buttonGrid.addWidget(ok, 3, 1);
75 buttonGrid.addWidget(cancel, 3,2);
76 grid.addLayout(buttonGrid,2,1);
79 // The OK button was pressed
80 @SuppressWarnings("unused")
81 private void okButtonPressed() {
86 // The CANCEL button was pressed
87 @SuppressWarnings("unused")
88 private void cancelButtonPressed() {
93 // Check if the OK button was pressed
94 public boolean okPressed() {
98 // Icon Button pressed
99 @SuppressWarnings("unused")
100 private void iconButtonPressed() {
101 QFileDialog fd = new QFileDialog(this);
102 fd.setFileMode(FileMode.ExistingFile);
103 fd.setConfirmOverwrite(true);
104 fd.setWindowTitle(tr("Icon"));
105 fd.setFilter(tr("PNG (*.png);;All Files (*.*)"));
106 fd.setAcceptMode(AcceptMode.AcceptOpen);
107 if (path == null || path.equals(""))
108 fd.setDirectory(Global.getFileManager().getImageDirPath(""));
110 fd.setDirectory(path);
111 if (fd.exec() == 0 || fd.selectedFiles().size() == 0) {
115 this.path = fd.selectedFiles().get(0);
116 this.path = path.substring(0,path.lastIndexOf("/"));
118 String path = fd.selectedFiles().get(0);
119 iconButton.setIcon(new QIcon(path));
120 iconButton.setSizePolicy(Policy.Fixed, Policy.Fixed);
123 public void setUseDefaultIcon(boolean val) {
124 useDefault.setChecked(val);
125 iconButton.setEnabled(!val);
126 startUseDefault = val;
129 public QIcon getIcon() {
130 if (useDefault.isChecked())
132 return iconButton.icon();
135 public void useDefaultIconChecked(Boolean value) {
136 iconButton.setEnabled(!value);
138 if (value != startUseDefault)
141 ok.setEnabled(false);
144 public String getFileType() {
148 public String getPath() {