Debian Codegraph @

HercStudio/FontPreferences.cpp

raw symbols SCIP
1 /*
2 * File: Fonts.cpp
3 *
4 * Author: Jacob Dekel
5 * Created on: Nov 9, 2009
6 *
7 * Copyright (c) 2009-2013 Jacob Dekel
8 * $Id$
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 *
23 */
24
25 #include "FontPreferences.h"
26 #include "Preferences.h"
27 #include "StringTokenizer.h"
28 #include "ConfigurationEditor.h"
29 #include "HerculesStudio.h"
30
31 #include <QFile>
32 #include <sstream>
33
34 FontPreferences::FontPreferences(std::string line) :
35 mLine(line), mName("(System Default)"), mSize(9), mBold(false), mItalic(false)
36 {
37 setPrefLine(line);
38 }
39
40 FontPreferences::~FontPreferences()
41 {
42
43 }
44
45 void FontPreferences::setFontName( const std::string& fontName)
46 {
47 mName = fontName;
48 }
49
50 std::string& FontPreferences::fontName()
51 {
52 return mName;
53 }
54
55 void FontPreferences::setFontSize( int fontSize )
56 {
57 mSize = fontSize;
58 hOutDebug(2, "FontPreferences set size" << mSize);
59 }
60
61 int FontPreferences::fontSize()
62 {
63 hOutDebug(2, "FontPreferences return size " << mSize);
64 return mSize;
65 }
66
67 void FontPreferences::setFontBoldness( bool isBold )
68 {
69 mBold = isBold;
70 }
71
72 void FontPreferences::setFontItalic( bool isItalic )
73 {
74 mItalic = isItalic;
75 }
76
77 bool FontPreferences::fontIsBold()
78 {
79 return mBold;
80 }
81
82 bool FontPreferences::fontIsItalic()
83 {
84 return mItalic;
85 }
86
87 int FontPreferences::fontVariation()
88 {
89 return (mBold ? Bold : 0) + (mItalic ? Italic : 0);
90 }
91
92 void FontPreferences::setPrefLine(std::string line)
93 {
94 hOutDebug(2, "FontPreferences Line='" << line << "'");
95 if (line.length() == 0) return;
96 Tokenizer::handle pos=0, lastPos=0;
97 std::string word = StringTokenizer::getFirstWord(line, pos, lastPos, ",");
98 if (word == "") return;
99 mName = word;
100 word = StringTokenizer::getNextWord(line, pos, lastPos, ",");
101 mSize = ConfigurationEditor::parseNum(word,10);
102 mBold = ("true" == StringTokenizer::getNextWord(line, pos, lastPos, ","));
103 mItalic = ("true" == StringTokenizer::getNextWord(line, pos, lastPos, ", \n\t"));
104 return;
105 }
106
107 std::string FontPreferences::prefLine()
108 {
109 std::stringstream ss;
110 ss << mName << "," << mSize << "," << (mBold ? "true" : "false" ) << "," << (mItalic ? "true" : "false");
111 return ss.str();
112 }