OSDN Git Service

Add option to start minimized.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / ConfigAppearancePage.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 import java.util.ArrayList;\r
23 import java.util.List;\r
24 \r
25 import com.trolltech.qt.gui.QApplication;\r
26 import com.trolltech.qt.gui.QCheckBox;\r
27 import com.trolltech.qt.gui.QComboBox;\r
28 import com.trolltech.qt.gui.QFormLayout;\r
29 import com.trolltech.qt.gui.QGroupBox;\r
30 import com.trolltech.qt.gui.QHBoxLayout;\r
31 import com.trolltech.qt.gui.QLabel;\r
32 import com.trolltech.qt.gui.QSpinBox;\r
33 import com.trolltech.qt.gui.QStyleFactory;\r
34 import com.trolltech.qt.gui.QVBoxLayout;\r
35 import com.trolltech.qt.gui.QWidget;\r
36 \r
37 import cx.fbn.nevernote.Global;\r
38 \r
39 public class ConfigAppearancePage extends QWidget {\r
40         private final QComboBox dateFormat;\r
41         private final QComboBox timeFormat;\r
42         private final QComboBox styleFormat;\r
43         private final QComboBox tagBehavior;\r
44         private final QCheckBox standardPalette;\r
45         private final QCheckBox showSplashScreen;\r
46         private final QCheckBox showTrayIcon;\r
47         private final QCheckBox verifyDelete;\r
48         private final QCheckBox pdfPreview;\r
49         private final QCheckBox newNoteWithTags;\r
50         private final QCheckBox mimicEvernote;\r
51         private final QCheckBox startMinimized;\r
52         private final QSpinBox autoSaveInterval;\r
53         \r
54         private final List<String> tformats;\r
55         private final List<String> dformats;\r
56         \r
57         public ConfigAppearancePage(QWidget parent) {\r
58 //              super(parent);\r
59                 \r
60                 dformats = new ArrayList<String>();\r
61                 tformats = new ArrayList<String>();\r
62                 \r
63                 dformats.add("MM/dd/yy - 12/31/09");\r
64                 dformats.add("MM/dd/yyyy - 12/31/2009");\r
65                 dformats.add("dd/MM/yy - 31/12/09");\r
66                 dformats.add("dd/MM/yyyy - 31/12/2009");\r
67                 dformats.add("yyyy/MM/dd - 2009/12/31");\r
68                 dformats.add("yy/MM/dd - 9/12/31");\r
69                 \r
70                 tformats.add("HH:mm:ss - 2:13:01");\r
71                 tformats.add("HH:mm:ss a - 2:13:01 am");\r
72                 tformats.add("HH:mm - 2:13");\r
73                 tformats.add("HH:mm a - 2:13 am");\r
74 \r
75                 \r
76                 // Style sheet formats\r
77                 List<String> styles = QStyleFactory.keys();\r
78                 QGroupBox styleGroup = new QGroupBox(tr("GUI Style"));\r
79                 styleFormat = new QComboBox();                          \r
80                 styleFormat.addItems(styles);\r
81                 styleFormat.activated.connect(this, "styleSelected(String)");\r
82                 \r
83                 standardPalette = new QCheckBox();\r
84                 standardPalette.setText(tr("Use standard palette"));\r
85                 standardPalette.clicked.connect(this, "standardPaletteChanged()");\r
86 \r
87                 QFormLayout styleLayout = new QFormLayout();\r
88                 styleLayout.addWidget(styleFormat);\r
89                 styleLayout.addWidget(standardPalette);\r
90                 \r
91                 styleGroup.setLayout(styleLayout);\r
92 \r
93                 QGroupBox tagBehaviorGroup = new QGroupBox(tr("Tag Behavior"));\r
94                 tagBehavior = new QComboBox();\r
95                 tagBehavior.addItem(tr("Do nothing"),"DoNothing");\r
96                 tagBehavior.addItem(tr("Count tags & do not hide inactive"),"NoHideInactiveCount");\r
97                 tagBehavior.addItem(tr("Count tags & hide inactive"),"HideInactiveCount");\r
98                 tagBehavior.addItem(tr("Color active tags"),"ColorActive");\r
99                 \r
100                 QFormLayout tagLayout = new QFormLayout();\r
101                 tagLayout.addWidget(tagBehavior);\r
102                 tagBehaviorGroup.setLayout(tagLayout);\r
103                 \r
104                 \r
105                 \r
106                 // Date/Time settings\r
107                 QGroupBox datetimeGroup = new QGroupBox(tr("Date/Time Format"));\r
108                 dateFormat = new QComboBox();                           \r
109                 for (int i=0; i<dformats.size(); i++) {\r
110                         dateFormat.addItem(tr(dformats.get(i)));\r
111                 }\r
112                 \r
113                 timeFormat = new QComboBox();           \r
114                 for (int i=0; i<tformats.size(); i++) {\r
115                         timeFormat.addItem(tr(tformats.get(i)));\r
116                 }\r
117 \r
118                 QFormLayout formatLayout = new QFormLayout();\r
119                 formatLayout.addWidget(dateFormat);\r
120                 formatLayout.addWidget(timeFormat);\r
121                 datetimeGroup.setLayout(formatLayout);\r
122                 \r
123                 mimicEvernote = new QCheckBox(tr("Mimic Evernote Selection Behavior (Requires Restart)"));\r
124                 showSplashScreen = new QCheckBox(tr("Show Splash Screen on Startup"));\r
125                 showTrayIcon = new QCheckBox(tr("Show Tray Icon"));\r
126                 verifyDelete = new QCheckBox(tr("Verify Deletes"));\r
127                 startMinimized = new QCheckBox(tr("Start Minimized"));\r
128                 pdfPreview = new QCheckBox(tr("Display PDF Documents Inline"));\r
129                 newNoteWithTags = new QCheckBox(tr("Create New Notes With Selected Tags"));\r
130                 \r
131                 QHBoxLayout autoSaveLayout = new QHBoxLayout();\r
132                 autoSaveLayout.addWidget(new QLabel(tr("Automatic Save Interval (in Minutes)")));\r
133                 autoSaveInterval = new QSpinBox();\r
134                 autoSaveLayout.addWidget(autoSaveInterval);\r
135                 autoSaveInterval.setMaximum(1440);\r
136                 autoSaveInterval.setMinimum(0);\r
137                 \r
138                 QVBoxLayout mainLayout = new QVBoxLayout();\r
139                 mainLayout.addWidget(styleGroup);\r
140                 mainLayout.addWidget(datetimeGroup);\r
141                 mainLayout.addLayout(autoSaveLayout);\r
142                 mainLayout.addWidget(tagBehaviorGroup);\r
143                 mainLayout.addWidget(mimicEvernote); \r
144                 mainLayout.addWidget(showTrayIcon);\r
145                 mainLayout.addWidget(startMinimized);\r
146                 mainLayout.addWidget(showSplashScreen);\r
147                 mainLayout.addWidget(verifyDelete);\r
148                 mainLayout.addWidget(pdfPreview);\r
149                 mainLayout.addWidget(newNoteWithTags);\r
150                 mainLayout.addStretch(1);\r
151                 setLayout(mainLayout);\r
152 \r
153 \r
154         }\r
155 \r
156         \r
157         //*****************************************\r
158         //* date format get/set methods \r
159         //*****************************************\r
160         public void setDateFormat(String id) {\r
161                 for (int i=0; i<dformats.size(); i++) {\r
162                         String d = dformats.get(i);\r
163                         if (d.substring(0,id.length()).equals(id))\r
164                                 dateFormat.setCurrentIndex(i);\r
165                 }\r
166         }\r
167         public String getDateFormat() {\r
168                 int i = dateFormat.currentIndex();\r
169                 return dateFormat.itemText(i);  \r
170         }\r
171         \r
172 \r
173         \r
174         //*****************************************\r
175         //* time format get/set methods \r
176         //*****************************************\r
177         public void setTimeFormat(String id) {\r
178                 for (int i=0; i<tformats.size(); i++) {\r
179                         String d = tformats.get(i);\r
180                         int dash = d.indexOf("-");\r
181                         d = d.substring(0,dash-1);\r
182                         if (d.equals(id)) {\r
183                                 timeFormat.setCurrentIndex(i);\r
184                                 return;\r
185                         }\r
186                 }\r
187         }\r
188         public String getTimeFormat() {\r
189                 int i = timeFormat.currentIndex();\r
190                 return timeFormat.itemText(i);  \r
191         }\r
192 \r
193         \r
194         //*****************************************\r
195         //* gui style format get/set methods \r
196         //*****************************************\r
197         public void setStyle(String id) {\r
198                 for (int i=0; i<styleFormat.count(); i++) {\r
199                         String d = styleFormat.itemText(i);\r
200                         if (d.equals(id))\r
201                                 styleFormat.setCurrentIndex(i);\r
202                 }\r
203         }\r
204         public String getStyle() {\r
205                 int i = styleFormat.currentIndex();\r
206                 return styleFormat.itemText(i); \r
207         }\r
208         \r
209         //*****************************************\r
210         //* palette style get/set methods \r
211         //*****************************************\r
212         public void setStandardPalette(boolean value) {\r
213                 standardPalette.setChecked(value);\r
214         }\r
215         public boolean getStandardPalette() {\r
216                 return standardPalette.isChecked();     \r
217         }\r
218         \r
219         //*******************************************\r
220         //* Show/Hide tray icon get/set\r
221         //*******************************************\r
222         public void setShowTrayIcon(boolean val) {\r
223                 showTrayIcon.setChecked(val);   \r
224         }\r
225         public boolean getShowTrayIcon() {\r
226                 return showTrayIcon.isChecked();\r
227         }\r
228         \r
229         \r
230         //*****************************************\r
231         //* Show the splash screen on startup\r
232         //*****************************************\r
233         public void setShowSplashScreen(boolean val) {\r
234                 showSplashScreen.setChecked(val);\r
235         }\r
236         public boolean getShowSplashScreen() {\r
237                 return showSplashScreen.isChecked();\r
238         }\r
239         \r
240         //*******************************************\r
241         //* verify deletes get/set\r
242         //*******************************************\r
243         public void setVerifyDelete(boolean val) {\r
244                 verifyDelete.setChecked(val);   \r
245         }\r
246         public boolean getVerifyDelete() {\r
247                 return verifyDelete.isChecked();\r
248         }\r
249         \r
250         \r
251         //*******************************************\r
252         //* Show/Hide tray icon get/set\r
253         //*******************************************\r
254         public void setPdfPreview(boolean val) {\r
255                 pdfPreview.setChecked(val);     \r
256         }\r
257         public boolean getPdfPreview() {\r
258                 return pdfPreview.isChecked();\r
259         }\r
260 \r
261         \r
262         //********************************************\r
263         //* Listeners for palette & style changes\r
264         //********************************************\r
265         \r
266         public void styleSelected(String style) {\r
267                 QApplication.setStyle(style);\r
268                 QApplication.setPalette(QApplication.style().standardPalette());\r
269         }\r
270         \r
271         public void standardPaletteChanged() {\r
272                 if (standardPalette.isChecked())\r
273                         QApplication.setPalette(QApplication.style().standardPalette());\r
274                 else\r
275                         QApplication.setPalette(Global.originalPalette);\r
276                         \r
277         }\r
278 \r
279         \r
280         //*****************************************\r
281         //* automatic save timer\r
282         //*****************************************\r
283         public void setAutoSaveInterval(int len) {\r
284                 autoSaveInterval.setValue(len);\r
285         }\r
286         public int getAutoSaveInterval() {\r
287                 return autoSaveInterval.value();        \r
288         }\r
289 \r
290         \r
291         //*****************************************\r
292         //* Get/Set tag behavior combo box\r
293         //*****************************************\r
294         public void setTagBehavior(String value) {\r
295                 for (int i=0; i<tagBehavior.count(); i++) {\r
296                         String d = tagBehavior.itemData(i).toString();\r
297                         if (value.equalsIgnoreCase(d)) {\r
298                                 tagBehavior.setCurrentIndex(i);\r
299                                 return;\r
300                         }\r
301                 }\r
302         }\r
303         public String getTagBehavior() {\r
304                 int i = tagBehavior.currentIndex();\r
305                 return tagBehavior.itemData(i).toString();\r
306         }\r
307 \r
308         //*****************************************\r
309         //* Mimic Evernote Selection\r
310         //*****************************************\r
311         public boolean getMimicEvernote() {\r
312                 return mimicEvernote.isChecked();\r
313         }\r
314         public void setMimicEvernote(boolean val) {\r
315                 mimicEvernote.setChecked(val);\r
316         }\r
317 \r
318         \r
319         //*****************************************\r
320         //* Mimic Evernote Selection\r
321         //*****************************************\r
322         public boolean getStartMinimized() {\r
323                 return startMinimized.isChecked();\r
324         }\r
325         public void setStartMinimized(boolean val) {\r
326                 startMinimized.setChecked(val);\r
327         }\r
328 \r
329 \r
330         //*****************************************\r
331         //* Create Note With Selected Tags\r
332         //*****************************************\r
333         public boolean getNewNoteWithTags() {\r
334                 return newNoteWithTags.isChecked();\r
335         }\r
336         public void setNewNoteWithTags(boolean val) {\r
337                 newNoteWithTags.setChecked(val);\r
338         }\r
339 \r
340 }\r