OSDN Git Service

Merge branch 'japaneseSearch' into develop
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / InsertLatexImage.java
1 /*\r
2  * This file is part of NixNote/NeighborNote \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 //**********************************************\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
28 \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
36 \r
37 public class InsertLatexImage extends QDialog {\r
38 \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
44                 \r
45         // Constructor\r
46         public InsertLatexImage() {\r
47                 okPressed = false;\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
53                 setLayout(grid);\r
54                 \r
55                 \r
56                 url = new QTextEdit("");\r
57                 \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
62                         \r
63                 ok = new QPushButton(tr("OK"));\r
64                 ok.clicked.connect(this, "accept()");\r
65                 ok.setEnabled(false);\r
66                 \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
73                 \r
74                 setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose);\r
75         }\r
76         // Set the formula\r
77         public void setFormula(String x) {\r
78                 url.setText(x);\r
79         }\r
80         // Get the formula \r
81         public String getFormula() {\r
82                 return latexText;\r
83         }\r
84         // Set the url\r
85         public void setUrl(String u) {\r
86                 url.setText(u);\r
87         }\r
88         // Check if the OK button was pressed\r
89         public boolean okPressed() {\r
90                 return okPressed;\r
91         }\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
98         }\r
99         \r
100         @Override\r
101         public void accept() {\r
102                 if (ok.isEnabled()) {\r
103                         okPressed = true;\r
104                         latexText = url.toPlainText();\r
105                         super.accept();\r
106                 }\r
107         }\r
108         \r
109         @Override\r
110         public void reject() {\r
111                 okPressed=false;\r
112                 super.reject();\r
113         }\r
114 }\r