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
23 import com.trolltech.qt.core.Qt;
\r
24 import com.trolltech.qt.gui.QDialog;
\r
25 import com.trolltech.qt.gui.QGridLayout;
\r
26 import com.trolltech.qt.gui.QIcon;
\r
27 import com.trolltech.qt.gui.QLabel;
\r
28 import com.trolltech.qt.gui.QPushButton;
\r
29 import com.trolltech.qt.gui.QTextEdit;
\r
31 public class InsertLatexImage extends QDialog {
\r
33 private boolean okPressed;
\r
34 private final QTextEdit url;
\r
35 private final QPushButton ok;
\r
36 private String latexText;
\r
37 private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
\r
40 public InsertLatexImage() {
\r
42 setWindowTitle(tr("Insert LaTeX Formula"));
\r
43 setWindowIcon(new QIcon(iconPath+"link.png"));
\r
44 QGridLayout grid = new QGridLayout();
\r
45 QGridLayout input = new QGridLayout();
\r
46 QGridLayout button = new QGridLayout();
\r
50 url = new QTextEdit("");
\r
52 input.addWidget(new QLabel(tr("Formula")), 1,1);
\r
53 input.addWidget(url, 2, 1);
\r
54 input.setContentsMargins(10, 10, -10, -10);
\r
55 grid.addLayout(input, 1,1);
\r
57 ok = new QPushButton(tr("OK"));
\r
58 ok.clicked.connect(this, "accept()");
\r
59 ok.setEnabled(false);
\r
61 QPushButton cancel = new QPushButton(tr("Cancel"));
\r
62 cancel.clicked.connect(this, "reject()");
\r
63 button.addWidget(ok, 1, 1);
\r
64 button.addWidget(cancel, 1,2);
\r
65 grid.addLayout(button, 3, 1);
\r
66 url.textChanged.connect(this, "validateInput()");
\r
68 setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose);
\r
71 public void setFormula(String x) {
\r
75 public String getFormula() {
\r
79 public void setUrl(String u) {
\r
82 // Check if the OK button was pressed
\r
83 public boolean okPressed() {
\r
86 // Check that we have a valid URL
\r
87 @SuppressWarnings("unused")
\r
88 private void validateInput() {
\r
89 ok.setEnabled(true);
\r
90 if (url.toPlainText().trim().equals(""))
\r
91 ok.setEnabled(false);
\r
95 public void accept() {
\r
96 if (ok.isEnabled()) {
\r
98 latexText = url.toPlainText();
\r
104 public void reject() {
\r