OSDN Git Service

Correct LaTeX images. Upgrade to 0.99
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / InsertLatexImage.java
1 /*\r
2  * This file is part of NeverNote \r
3  * Copyright 2009 Randy Baumgarte\r
4  * \r
5  * This file may be licensed under the terms of of the\r
6  * GNU General Public License Version 2 (the ``GPL'').\r
7  *\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
12  *\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
17  *\r
18 */\r
19 \r
20 package cx.fbn.nevernote.dialog;\r
21 \r
22 \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
30 \r
31 public class InsertLatexImage extends QDialog {\r
32 \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
38                 \r
39         // Constructor\r
40         public InsertLatexImage() {\r
41                 okPressed = false;\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
47                 setLayout(grid);\r
48                 \r
49                 \r
50                 url = new QTextEdit("");\r
51                 \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
56                         \r
57                 ok = new QPushButton(tr("OK"));\r
58                 ok.clicked.connect(this, "accept()");\r
59                 ok.setEnabled(false);\r
60                 \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
67                 \r
68                 setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose);\r
69         }\r
70         // Set the formula\r
71         public void setFormula(String x) {\r
72                 url.setText(x);\r
73         }\r
74         // Get the formula \r
75         public String getFormula() {\r
76                 return latexText;\r
77         }\r
78         // Set the url\r
79         public void setUrl(String u) {\r
80                 url.setText(u);\r
81         }\r
82         // Check if the OK button was pressed\r
83         public boolean okPressed() {\r
84                 return okPressed;\r
85         }\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
92         }\r
93         \r
94         @Override\r
95         public void accept() {\r
96                 if (ok.isEnabled()) {\r
97                         okPressed = true;\r
98                         latexText = url.toPlainText();\r
99                         super.accept();\r
100                 }\r
101         }\r
102         \r
103         @Override\r
104         public void reject() {\r
105                 okPressed=false;\r
106                 super.reject();\r
107         }\r
108 }\r