OSDN Git Service

Moved the show/hide of the note index column from the Edit/Preferences menu to a...
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / TableDialog.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.gui.QComboBox;\r
24 import com.trolltech.qt.gui.QDialog;\r
25 import com.trolltech.qt.gui.QGridLayout;\r
26 import com.trolltech.qt.gui.QIntValidator;\r
27 import com.trolltech.qt.gui.QLabel;\r
28 import com.trolltech.qt.gui.QLineEdit;\r
29 import com.trolltech.qt.gui.QPushButton;\r
30 import com.trolltech.qt.gui.QSpinBox;\r
31 \r
32 public class TableDialog extends QDialog {\r
33 \r
34         private boolean                         okPressed;\r
35         private final QSpinBox          rows;\r
36         private final QSpinBox          cols;\r
37         private final QLineEdit         width;\r
38         private final QPushButton       ok;\r
39         private final QLabel            error;\r
40         private final QIntValidator     widthValidator;\r
41         private final QComboBox          unit;\r
42         \r
43         \r
44         // Constructor\r
45         public TableDialog() {\r
46                 okPressed = false;\r
47                 setWindowTitle(tr("Insert Table"));\r
48                 QGridLayout grid = new QGridLayout();\r
49                 QGridLayout input = new QGridLayout();\r
50                 QGridLayout msgGrid = new QGridLayout();\r
51                 QGridLayout button = new QGridLayout();\r
52                 setLayout(grid);\r
53                 \r
54                 unit = new QComboBox(this);\r
55                 unit.addItem(tr("Percent"),new Boolean(true));\r
56                 unit.addItem(tr("Pixels"),new Boolean(false));\r
57                 \r
58                 \r
59                 width = new QLineEdit("80");\r
60                 widthValidator = new QIntValidator(0,100, this);\r
61                 width.setValidator(widthValidator);\r
62                 width.textChanged.connect(this, "validateWidth()");\r
63                 rows = new QSpinBox();\r
64                 cols = new QSpinBox();\r
65                 rows.setMaximum(30);\r
66                 rows.setMinimum(1);\r
67                 cols.setMaximum(30);\r
68                 cols.setMinimum(1);\r
69                 \r
70                 unit.activated.connect(this, "unitChanged()");\r
71                 \r
72                 input.addWidget(new QLabel(tr("Rows")), 1,1);\r
73                 input.addWidget(rows, 1, 2);\r
74                 input.addWidget(new QLabel(tr("Columns")), 2,1);\r
75                 input.addWidget(cols, 2, 2);\r
76                 input.addWidget(new QLabel(tr("Width")), 3,1);\r
77                 input.addWidget(width, 3, 2);\r
78                 input.addWidget(new QLabel(tr("Unit")),4,1);\r
79                 input.addWidget(unit,4,2);\r
80                 input.setContentsMargins(10, 10,  -10, -10);\r
81                 grid.addLayout(input, 1,1);\r
82                 \r
83                 error = new QLabel();\r
84                 msgGrid.addWidget(error, 1, 1);\r
85                 grid.addLayout(msgGrid, 2, 1);\r
86                 \r
87                 ok = new QPushButton(tr("OK"));\r
88                 ok.clicked.connect(this, "okButtonPressed()");\r
89                 \r
90                 QPushButton cancel = new QPushButton(tr("Cancel"));\r
91                 cancel.clicked.connect(this, "cancelButtonPressed()");\r
92                 button.addWidget(ok, 1, 1);\r
93                 button.addWidget(cancel, 1,2);\r
94                 grid.addLayout(button, 3, 1);\r
95                 \r
96 //              width.textChanged.connect(this, "validateInput()");\r
97                 \r
98         }\r
99         \r
100         // The OK button was pressed\r
101         @SuppressWarnings("unused")\r
102         private void okButtonPressed() {\r
103                 okPressed = true;\r
104                 close();\r
105         }\r
106         // The CANCEL button was pressed\r
107         @SuppressWarnings("unused")\r
108         private void cancelButtonPressed() {\r
109                 okPressed = false;\r
110                 close();\r
111         }\r
112         // Check if the OK button was pressed\r
113         public boolean okPressed() {\r
114                 return okPressed;\r
115         }\r
116         // Check if proper input was input\r
117         @SuppressWarnings("unused")\r
118         private void validateInput() {\r
119                 ok.setEnabled(false);\r
120                 \r
121                 ok.setEnabled(true);\r
122         }\r
123         \r
124         @SuppressWarnings("unused")\r
125         private void validateWidth() {\r
126                 if (width.text().trim().length() == 0) {\r
127                         ok.setEnabled(false);\r
128                 } else\r
129                         ok.setEnabled(true);\r
130         }\r
131         \r
132         @SuppressWarnings("unused")\r
133         private void unitChanged() {\r
134                 int i = unit.currentIndex();\r
135                 if ((Boolean)unit.itemData(i)) { // if 'percent'\r
136                         Integer w = new Integer(width.text());\r
137                         if (w > 100)\r
138                                 width.setText("80");\r
139                         widthValidator.setTop(100);\r
140                 } else {\r
141                         widthValidator.setTop(32767);\r
142                 }\r
143         }\r
144         \r
145         public int getRows() {\r
146                 return new Integer(rows.text());\r
147         }\r
148         public int getCols() {\r
149                 return new Integer(cols.text());\r
150         }\r
151         public int getWidth() {\r
152                 return new Integer(width.text());\r
153         }\r
154         public boolean isPercent() {\r
155                 int i = unit.currentIndex();\r
156                 return ((Boolean)unit.itemData(i)).booleanValue();\r
157         }\r
158 \r
159 }\r