2 * This file is part of NixNote/NeighborNote
\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 //**********************************************
\r
23 //**********************************************
\r
24 //* This is the dialog box that pops up when
\r
25 //* a user tries to insert a LaTeX image.
\r
26 //**********************************************
\r
27 //**********************************************
\r
29 import com.trolltech.qt.core.Qt;
\r
30 import com.trolltech.qt.gui.QDialog;
\r
31 import com.trolltech.qt.gui.QGridLayout;
\r
32 import com.trolltech.qt.gui.QIcon;
\r
33 import com.trolltech.qt.gui.QLabel;
\r
34 import com.trolltech.qt.gui.QPushButton;
\r
35 import com.trolltech.qt.gui.QTextEdit;
\r
37 public class InsertLatexImage extends QDialog {
\r
39 private boolean okPressed;
\r
40 private final QTextEdit url;
\r
41 private final QPushButton ok;
\r
42 private String latexText;
\r
43 private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
\r
46 public InsertLatexImage() {
\r
48 setWindowTitle(tr("Insert LaTeX Formula"));
\r
49 setWindowIcon(new QIcon(iconPath+"link.png"));
\r
50 QGridLayout grid = new QGridLayout();
\r
51 QGridLayout input = new QGridLayout();
\r
52 QGridLayout button = new QGridLayout();
\r
56 url = new QTextEdit("");
\r
58 input.addWidget(new QLabel(tr("Formula")), 1,1);
\r
59 input.addWidget(url, 2, 1);
\r
60 input.setContentsMargins(10, 10, -10, -10);
\r
61 grid.addLayout(input, 1,1);
\r
63 ok = new QPushButton(tr("OK"));
\r
64 ok.clicked.connect(this, "accept()");
\r
65 ok.setEnabled(false);
\r
67 QPushButton cancel = new QPushButton(tr("Cancel"));
\r
68 cancel.clicked.connect(this, "reject()");
\r
69 button.addWidget(ok, 1, 1);
\r
70 button.addWidget(cancel, 1,2);
\r
71 grid.addLayout(button, 3, 1);
\r
72 url.textChanged.connect(this, "validateInput()");
\r
74 setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose);
\r
77 public void setFormula(String x) {
\r
81 public String getFormula() {
\r
85 public void setUrl(String u) {
\r
88 // Check if the OK button was pressed
\r
89 public boolean okPressed() {
\r
92 // Check that we have a valid URL
\r
93 @SuppressWarnings("unused")
\r
94 private void validateInput() {
\r
95 ok.setEnabled(true);
\r
96 if (url.toPlainText().trim().equals(""))
\r
97 ok.setEnabled(false);
\r
101 public void accept() {
\r
102 if (ok.isEnabled()) {
\r
104 latexText = url.toPlainText();
\r
110 public void reject() {
\r