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 public class SetIcon extends QDialog {
33 private boolean okPressed;
35 QPushButton iconButton;
38 boolean startUseDefault;
39 private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
42 public SetIcon(QIcon i) {
44 setWindowTitle(tr("Set Icon"));
45 QGridLayout grid = new QGridLayout();
46 setWindowIcon(new QIcon(iconPath+"nevernote.png"));
49 QGridLayout textGrid = new QGridLayout();
50 textGrid.setContentsMargins(10, 10,-10, -10);
51 useDefault = new QCheckBox();
52 iconButton = new QPushButton();
53 iconButton.setSizePolicy(Policy.Fixed, Policy.Fixed);
54 iconButton.clicked.connect(this, "iconButtonPressed()");
55 useDefault.setText(tr("Use Default"));
56 iconButton.setIcon(i);
58 textGrid.addWidget(iconButton,1,1);
59 textGrid.addWidget(useDefault,2,1);
60 useDefault.clicked.connect(this, "useDefaultIconChecked(Boolean)");
61 grid.addLayout(textGrid,1,1);
63 QGridLayout buttonGrid = new QGridLayout();
64 ok = new QPushButton(tr("OK"));
65 ok.clicked.connect(this, "okButtonPressed()");
67 QPushButton cancel = new QPushButton(tr("Cancel"));
68 cancel.clicked.connect(this, "cancelButtonPressed()");
69 buttonGrid.addWidget(ok, 3, 1);
70 buttonGrid.addWidget(cancel, 3,2);
71 grid.addLayout(buttonGrid,2,1);
74 // The OK button was pressed
75 @SuppressWarnings("unused")
76 private void okButtonPressed() {
81 // The CANCEL button was pressed
82 @SuppressWarnings("unused")
83 private void cancelButtonPressed() {
88 // Check if the OK button was pressed
89 public boolean okPressed() {
93 // Icon Button pressed
94 @SuppressWarnings("unused")
95 private void iconButtonPressed() {
96 QFileDialog fd = new QFileDialog(this);
97 fd.setFileMode(FileMode.ExistingFile);
98 fd.setConfirmOverwrite(true);
99 fd.setWindowTitle(tr("Icon"));
100 fd.setFilter(tr("PNG (*.png);;All Files (*.*)"));
101 fd.setAcceptMode(AcceptMode.AcceptOpen);
102 fd.setDirectory(System.getProperty("user.home"));
103 if (fd.exec() == 0 || fd.selectedFiles().size() == 0) {
108 String path = fd.selectedFiles().get(0);
109 iconButton.setIcon(new QIcon(path));
110 iconButton.setSizePolicy(Policy.Fixed, Policy.Fixed);
113 public void setUseDefaultIcon(boolean val) {
114 useDefault.setChecked(val);
115 iconButton.setEnabled(!val);
116 startUseDefault = val;
119 public QIcon getIcon() {
120 if (useDefault.isChecked())
122 return iconButton.icon();
125 public void useDefaultIconChecked(Boolean value) {
126 iconButton.setEnabled(!value);
128 if (value != startUseDefault)
131 ok.setEnabled(false);
134 public String getFileType() {