2 * This file is part of NixNote
\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
22 //**********************************************
\r
23 //**********************************************
\r
24 //* Used to create a table in a note
\r
25 //**********************************************
\r
26 //**********************************************
\r
29 import com.trolltech.qt.gui.QComboBox;
\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.QIntValidator;
\r
34 import com.trolltech.qt.gui.QLabel;
\r
35 import com.trolltech.qt.gui.QLineEdit;
\r
36 import com.trolltech.qt.gui.QPushButton;
\r
37 import com.trolltech.qt.gui.QSpinBox;
\r
39 public class TableDialog extends QDialog {
\r
41 private boolean okPressed;
\r
42 private final QSpinBox rows;
\r
43 private final QSpinBox cols;
\r
44 private final QLineEdit width;
\r
45 private final QPushButton ok;
\r
46 private final QLabel error;
\r
47 private final QIntValidator widthValidator;
\r
48 private final QComboBox unit;
\r
49 private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
\r
52 public TableDialog() {
\r
54 setWindowTitle(tr("Insert Table"));
\r
55 setWindowIcon(new QIcon(iconPath+"table.png"));
\r
56 QGridLayout grid = new QGridLayout();
\r
57 QGridLayout input = new QGridLayout();
\r
58 QGridLayout msgGrid = new QGridLayout();
\r
59 QGridLayout button = new QGridLayout();
\r
62 unit = new QComboBox(this);
\r
63 unit.addItem(tr("Percent"),new Boolean(true));
\r
64 unit.addItem(tr("Pixels"),new Boolean(false));
\r
67 width = new QLineEdit("80");
\r
68 widthValidator = new QIntValidator(0,100, this);
\r
69 width.setValidator(widthValidator);
\r
70 width.textChanged.connect(this, "validateWidth()");
\r
71 rows = new QSpinBox();
\r
72 cols = new QSpinBox();
\r
73 rows.setMaximum(30);
\r
75 cols.setMaximum(30);
\r
78 unit.activated.connect(this, "unitChanged()");
\r
80 input.addWidget(new QLabel(tr("Rows")), 1,1);
\r
81 input.addWidget(rows, 1, 2);
\r
82 input.addWidget(new QLabel(tr("Columns")), 2,1);
\r
83 input.addWidget(cols, 2, 2);
\r
84 input.addWidget(new QLabel(tr("Width")), 3,1);
\r
85 input.addWidget(width, 3, 2);
\r
86 input.addWidget(new QLabel(tr("Unit")),4,1);
\r
87 input.addWidget(unit,4,2);
\r
88 input.setContentsMargins(10, 10, -10, -10);
\r
89 grid.addLayout(input, 1,1);
\r
91 error = new QLabel();
\r
92 msgGrid.addWidget(error, 1, 1);
\r
93 grid.addLayout(msgGrid, 2, 1);
\r
95 ok = new QPushButton(tr("OK"));
\r
96 ok.clicked.connect(this, "okButtonPressed()");
\r
98 QPushButton cancel = new QPushButton(tr("Cancel"));
\r
99 cancel.clicked.connect(this, "cancelButtonPressed()");
\r
100 button.addWidget(ok, 1, 1);
\r
101 button.addWidget(cancel, 1,2);
\r
102 grid.addLayout(button, 3, 1);
\r
104 // width.textChanged.connect(this, "validateInput()");
\r
108 // The OK button was pressed
\r
109 @SuppressWarnings("unused")
\r
110 private void okButtonPressed() {
\r
114 // The CANCEL button was pressed
\r
115 @SuppressWarnings("unused")
\r
116 private void cancelButtonPressed() {
\r
120 // Check if the OK button was pressed
\r
121 public boolean okPressed() {
\r
124 // Check if proper input was input
\r
125 @SuppressWarnings("unused")
\r
126 private void validateInput() {
\r
127 ok.setEnabled(false);
\r
129 ok.setEnabled(true);
\r
132 @SuppressWarnings("unused")
\r
133 private void validateWidth() {
\r
134 if (width.text().trim().length() == 0) {
\r
135 ok.setEnabled(false);
\r
137 ok.setEnabled(true);
\r
140 @SuppressWarnings("unused")
\r
141 private void unitChanged() {
\r
142 int i = unit.currentIndex();
\r
143 if ((Boolean)unit.itemData(i)) { // if 'percent'
\r
144 Integer w = new Integer(width.text());
\r
146 width.setText("80");
\r
147 widthValidator.setTop(100);
\r
149 widthValidator.setTop(32767);
\r
153 public int getRows() {
\r
154 return new Integer(rows.text());
\r
156 public int getCols() {
\r
157 return new Integer(cols.text());
\r
159 public int getWidth() {
\r
160 return new Integer(width.text());
\r
162 public boolean isPercent() {
\r
163 int i = unit.currentIndex();
\r
164 return ((Boolean)unit.itemData(i)).booleanValue();
\r