OSDN Git Service

Change the editor button bar from a QHBoxLayout to a QToolBar. This will allow the...
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / InsertLinkDialog.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.QLabel;\r
27 import com.trolltech.qt.gui.QLineEdit;\r
28 import com.trolltech.qt.gui.QPushButton;\r
29 \r
30 public class InsertLinkDialog extends QDialog {\r
31 \r
32         private boolean         okPressed;\r
33         private final QLineEdit url;\r
34         private final QPushButton ok;\r
35         private String          urlText;\r
36         \r
37         \r
38         // Constructor\r
39         public InsertLinkDialog() {\r
40                 okPressed = false;\r
41                 setWindowTitle(tr("Insert Link"));\r
42                 QGridLayout grid = new QGridLayout();\r
43                 QGridLayout input = new QGridLayout();\r
44                 QGridLayout button = new QGridLayout();\r
45                 setLayout(grid);\r
46                 \r
47                 \r
48                 url = new QLineEdit("");\r
49                 \r
50                 input.addWidget(new QLabel(tr("Url")), 1,1);\r
51                 input.addWidget(url, 1, 2);\r
52                 input.setContentsMargins(10, 10,  -10, -10);\r
53                 grid.addLayout(input, 1,1);\r
54                         \r
55                 ok = new QPushButton(tr("OK"));\r
56                 ok.clicked.connect(this, "accept()");\r
57                 ok.setEnabled(false);\r
58                 \r
59                 QPushButton cancel = new QPushButton(tr("Cancel"));\r
60                 cancel.clicked.connect(this, "reject()");\r
61                 button.addWidget(ok, 1, 1);\r
62                 button.addWidget(cancel, 1,2);\r
63                 grid.addLayout(button, 3, 1);\r
64                 url.textChanged.connect(this, "validateInput()");\r
65                 \r
66                 setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose);\r
67         }\r
68         \r
69         // Get the password \r
70         public String getUrl() {\r
71                 return urlText;\r
72         }\r
73         // Set the url\r
74         public void setUrl(String u) {\r
75                 url.setText(u);\r
76         }\r
77         // Check if the OK button was pressed\r
78         public boolean okPressed() {\r
79                 return okPressed;\r
80         }\r
81         // Check that we have a valid URL\r
82         @SuppressWarnings("unused")\r
83         private void validateInput() {\r
84                 ok.setEnabled(true);\r
85                 if (url.text().trim().equals("")) \r
86                         ok.setEnabled(false);\r
87         }\r
88         \r
89         @Override\r
90         public void accept() {\r
91                 if (ok.isEnabled()) {\r
92                         okPressed = true;\r
93                         urlText = url.text();\r
94                         super.accept();\r
95                 }\r
96         }\r
97         \r
98         @Override\r
99         public void reject() {\r
100                 okPressed=false;\r
101                 super.reject();\r
102         }\r
103 }\r