2 * This file is part of NixNote/NeighborNote
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 //**********************************************
23 //**********************************************
24 //* Show the "set icon" dialog box for notebooks, tags, etc...
25 //**********************************************
26 //**********************************************
29 import com.trolltech.qt.gui.QCheckBox;
30 import com.trolltech.qt.gui.QDialog;
31 import com.trolltech.qt.gui.QFileDialog;
32 import com.trolltech.qt.gui.QFileDialog.AcceptMode;
33 import com.trolltech.qt.gui.QFileDialog.FileMode;
34 import com.trolltech.qt.gui.QGridLayout;
35 import com.trolltech.qt.gui.QIcon;
36 import com.trolltech.qt.gui.QPushButton;
37 import com.trolltech.qt.gui.QSizePolicy.Policy;
39 import cx.fbn.nevernote.Global;
41 public class SetIcon extends QDialog {
42 private boolean okPressed;
44 QPushButton iconButton;
47 boolean startUseDefault;
50 private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
53 public SetIcon(QIcon i, String path) {
56 setWindowTitle(tr("Set Icon"));
57 QGridLayout grid = new QGridLayout();
58 setWindowIcon(new QIcon(iconPath+"nevernote.png"));
61 QGridLayout textGrid = new QGridLayout();
62 textGrid.setContentsMargins(10, 10,-10, -10);
63 useDefault = new QCheckBox();
64 iconButton = new QPushButton();
65 iconButton.setSizePolicy(Policy.Fixed, Policy.Fixed);
66 iconButton.clicked.connect(this, "iconButtonPressed()");
67 useDefault.setText(tr("Use Default"));
68 iconButton.setIcon(i);
70 textGrid.addWidget(iconButton,1,1);
71 textGrid.addWidget(useDefault,2,1);
72 useDefault.clicked.connect(this, "useDefaultIconChecked(Boolean)");
73 grid.addLayout(textGrid,1,1);
75 QGridLayout buttonGrid = new QGridLayout();
76 ok = new QPushButton(tr("OK"));
77 ok.clicked.connect(this, "okButtonPressed()");
79 QPushButton cancel = new QPushButton(tr("Cancel"));
80 cancel.clicked.connect(this, "cancelButtonPressed()");
81 buttonGrid.addWidget(ok, 3, 1);
82 buttonGrid.addWidget(cancel, 3,2);
83 grid.addLayout(buttonGrid,2,1);
86 // The OK button was pressed
87 @SuppressWarnings("unused")
88 private void okButtonPressed() {
93 // The CANCEL button was pressed
94 @SuppressWarnings("unused")
95 private void cancelButtonPressed() {
100 // Check if the OK button was pressed
101 public boolean okPressed() {
105 // Icon Button pressed
106 @SuppressWarnings("unused")
107 private void iconButtonPressed() {
108 QFileDialog fd = new QFileDialog(this);
109 fd.setFileMode(FileMode.ExistingFile);
110 fd.setConfirmOverwrite(true);
111 fd.setWindowTitle(tr("Icon"));
112 fd.setFilter(tr("PNG (*.png);;All Files (*.*)"));
113 fd.setAcceptMode(AcceptMode.AcceptOpen);
114 if (path == null || path.equals(""))
115 fd.setDirectory(Global.getFileManager().getImageDirPath(""));
117 fd.setDirectory(path);
118 if (fd.exec() == 0 || fd.selectedFiles().size() == 0) {
122 this.path = fd.selectedFiles().get(0);
123 this.path = path.substring(0,path.lastIndexOf("/"));
125 String path = fd.selectedFiles().get(0);
126 iconButton.setIcon(new QIcon(path));
127 iconButton.setSizePolicy(Policy.Fixed, Policy.Fixed);
130 public void setUseDefaultIcon(boolean val) {
131 useDefault.setChecked(val);
132 iconButton.setEnabled(!val);
133 startUseDefault = val;
136 public QIcon getIcon() {
137 if (useDefault.isChecked())
139 return iconButton.icon();
142 public void useDefaultIconChecked(Boolean value) {
143 iconButton.setEnabled(!value);
145 if (value != startUseDefault)
148 ok.setEnabled(false);
151 public String getFileType() {
155 public String getPath() {