2 * This file is part of NeverNote
\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
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
32 public class TableDialog extends QDialog {
\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
45 public TableDialog() {
\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
54 unit = new QComboBox(this);
\r
55 unit.addItem(tr("Percent"),new Boolean(true));
\r
56 unit.addItem(tr("Pixels"),new Boolean(false));
\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
67 cols.setMaximum(30);
\r
70 unit.activated.connect(this, "unitChanged()");
\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
83 error = new QLabel();
\r
84 msgGrid.addWidget(error, 1, 1);
\r
85 grid.addLayout(msgGrid, 2, 1);
\r
87 ok = new QPushButton(tr("OK"));
\r
88 ok.clicked.connect(this, "okButtonPressed()");
\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
96 // width.textChanged.connect(this, "validateInput()");
\r
100 // The OK button was pressed
\r
101 @SuppressWarnings("unused")
\r
102 private void okButtonPressed() {
\r
106 // The CANCEL button was pressed
\r
107 @SuppressWarnings("unused")
\r
108 private void cancelButtonPressed() {
\r
112 // Check if the OK button was pressed
\r
113 public boolean okPressed() {
\r
116 // Check if proper input was input
\r
117 @SuppressWarnings("unused")
\r
118 private void validateInput() {
\r
119 ok.setEnabled(false);
\r
121 ok.setEnabled(true);
\r
124 @SuppressWarnings("unused")
\r
125 private void validateWidth() {
\r
126 if (width.text().trim().length() == 0) {
\r
127 ok.setEnabled(false);
\r
129 ok.setEnabled(true);
\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
138 width.setText("80");
\r
139 widthValidator.setTop(100);
\r
141 widthValidator.setTop(32767);
\r
145 public int getRows() {
\r
146 return new Integer(rows.text());
\r
148 public int getCols() {
\r
149 return new Integer(cols.text());
\r
151 public int getWidth() {
\r
152 return new Integer(width.text());
\r
154 public boolean isPercent() {
\r
155 int i = unit.currentIndex();
\r
156 return ((Boolean)unit.itemData(i)).booleanValue();
\r