OSDN Git Service

Cleanup compiler warning messages and alter backup & restore to handle new database...
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / ConfigFontPage.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.List;\r
23 \r
24 import com.trolltech.qt.gui.QCheckBox;\r
25 import com.trolltech.qt.gui.QComboBox;\r
26 import com.trolltech.qt.gui.QFontDatabase;\r
27 import com.trolltech.qt.gui.QGridLayout;\r
28 import com.trolltech.qt.gui.QGroupBox;\r
29 import com.trolltech.qt.gui.QLabel;\r
30 import com.trolltech.qt.gui.QVBoxLayout;\r
31 import com.trolltech.qt.gui.QWidget;\r
32 \r
33 import cx.fbn.nevernote.Global;\r
34 \r
35 public class ConfigFontPage extends QWidget {\r
36         private final QCheckBox overrideFonts;\r
37         private final QComboBox fontList;\r
38         private final QComboBox fontSizeList;\r
39         private String font;\r
40         private String fontSize;\r
41                 \r
42         public ConfigFontPage(QWidget parent) {\r
43                 \r
44                 font = Global.getDefaultFont();\r
45                 fontSize = Global.getDefaultFontSize();\r
46                 \r
47                 // Group Box\r
48                 QGroupBox fontGroup = new QGroupBox(tr("New Note Defaults"));\r
49                 QGridLayout fontLayout = new QGridLayout();\r
50                 overrideFonts = new QCheckBox(tr("Override Defaults")); \r
51                 overrideFonts.setCheckable(true);\r
52                 overrideFonts.setChecked(Global.overrideDefaultFont());\r
53                 overrideFonts.clicked.connect(this, "toggleFontOverride(Boolean)");\r
54                 fontLayout.addWidget(overrideFonts,1,2);\r
55                 \r
56                 \r
57                 // Fonts\r
58                 fontList = new QComboBox();                             \r
59                 fontList.activated.connect(this, "fontSelected(String)");\r
60                 fontLayout.addWidget(new QLabel(tr("Font")),2,1);\r
61                 fontLayout.addWidget(fontList,2,2);\r
62                 \r
63                 // Font Sizes\r
64                 fontSizeList = new QComboBox();                         \r
65                 fontLayout.addWidget(fontSizeList,3,2);\r
66                 fontSizeList.activated.connect(this, "fontSizeSelected(String)");\r
67                 fontLayout.addWidget(new QLabel(tr("Size")),3,1);\r
68                 fontGroup.setLayout(fontLayout);\r
69                 fontLayout.setColumnStretch(2, 100);\r
70                 toggleFontOverride(Global.overrideDefaultFont());\r
71                 loadFonts();\r
72                 loadSettings();\r
73                 \r
74                 \r
75                 QVBoxLayout mainLayout = new QVBoxLayout();\r
76                 mainLayout.addWidget(fontGroup);\r
77                 mainLayout.addStretch(1);\r
78                 setLayout(mainLayout);\r
79         }\r
80         \r
81         private void toggleFontOverride(Boolean value) {\r
82                 fontList.setEnabled(value);\r
83                 fontSizeList.setEnabled(value);\r
84         }\r
85         \r
86         private void loadFonts() {\r
87                 QFontDatabase fonts = new QFontDatabase();\r
88                 List<String> fontFamilies = fonts.families();\r
89                 for (int i = 0; i < fontFamilies.size(); i++) {\r
90                         if (font.equals(""))\r
91                                 font = fontFamilies.get(i);\r
92                         fontList.addItem(fontFamilies.get(i));\r
93                         if (i == 0) {\r
94                                 loadFontSize(fontFamilies.get(i));\r
95                         }\r
96                 }\r
97 \r
98         }\r
99         \r
100         // Load the font combo box based upon the font selected\r
101         private void loadFontSize(String name) {        \r
102                 QFontDatabase db = new QFontDatabase(); \r
103                 fontSizeList.clear();\r
104                 List<Integer> points = db.pointSizes(name); \r
105                 for (int i=0; i<points.size(); i++) { \r
106                         if (fontSize.equals(""))\r
107                                 fontSize = points.get(i).toString();\r
108                         fontSizeList.addItem(points.get(i).toString()); \r
109                 }\r
110 \r
111         }\r
112         \r
113         @SuppressWarnings("unused")\r
114         private void fontSelected(String font) {\r
115                 this.font = font;\r
116                 loadFontSize(font);\r
117         }\r
118         \r
119         @SuppressWarnings("unused")\r
120         private void fontSizeSelected(String size) {\r
121                 this.fontSize = size;\r
122         }\r
123         \r
124         private void loadSettings() {\r
125                 if (!Global.getDefaultFont().equals("")) {\r
126                         int index = fontList.findText(Global.getDefaultFont());\r
127                         fontList.setCurrentIndex(index);\r
128                 }\r
129                 if (!Global.getDefaultFontSize().equals("")) {\r
130                         int index = fontSizeList.findText(Global.getDefaultFontSize());\r
131                         fontSizeList.setCurrentIndex(index);\r
132                 }\r
133         }\r
134         \r
135         public String getFont() {\r
136                 return font;\r
137         }\r
138         public String getFontSize() {\r
139                 return fontSize;\r
140         }\r
141         public boolean overrideFont() {\r
142                 return overrideFonts.isChecked();\r
143         }\r
144         \r
145 }\r