-
Notifications
You must be signed in to change notification settings - Fork 0
/
sm3_font.cpp
188 lines (137 loc) · 6.06 KB
/
sm3_font.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//! \file sm_font.cpp
#include "sysmon3.h"
#include "sm3_font.h"
SM_Font::SM_Font( sysmon3* parent )
{
server = parent->server;
settings = &parent->settings;
QString familyKey = server + "-fontFamily";
QString family = settings->value( familyKey, "DejaVu Sans" ).toString();
QString sizeKey = server + "-fontSize";
int fontSize = settings->value( sizeKey, 12 ).toInt();
QFont oldfont = QFont( family, fontSize );
widgets = new SM_Widgets( oldfont );
bool checked = settings->value( server + "-fontBold", false ).toBool();
// Frame layout
setWindowTitle( "Font Selection Dialog" );
setAttribute( Qt::WA_DeleteOnClose );
QBoxLayout* topbox = new QVBoxLayout( this );
topbox->setSpacing( 2 );
// Body
pb_font = widgets->sm_pushbutton( tr( "Select Base Font" ) );
topbox->addWidget( pb_font );
connect( pb_font, SIGNAL( clicked() ), SLOT( selectFont() ) );
lbl_family = widgets->sm_label( tr( "Current Family:" ), -1 );
lbl_family->setFixedHeight( BUTTON_H );
QGridLayout* lineGrid = new QGridLayout();
QFontDatabase fontLib;;
cb_family = widgets->sm_comboBox();
cb_family->addItems( fontLib.families() );
cb_family->setCurrentText( family );
connect( cb_family, SIGNAL( currentIndexChanged( int ) ),
this, SLOT ( update ( int ) ) );
int row = 0;
lineGrid->addWidget( lbl_family, row , 0 );
lineGrid->addWidget( cb_family , row++, 1 );
lbl_size = widgets->sm_label( tr( "Point Size:" ), -1 );
lbl_size->setFixedHeight( BUTTON_H );
sb_size = widgets->sm_spinBox();
sb_size->setRange( 9, 24 );
sb_size->setValue( fontSize );
connect( sb_size, SIGNAL( valueChanged ( int ) ),
this, SLOT ( update ( int ) ) );
ckbox_grid = widgets->sm_checkbox( "Bold", ckbox_bold, checked );
stats_row = new QHBoxLayout();
stats_row->addWidget( lbl_size );
stats_row->addWidget( sb_size );
stats_row->addLayout( ckbox_grid );
lineGrid->addLayout( stats_row, row++, 0 );
samples = widgets->sm_banner( tr( "Selected Font Samples:" ) );
lineGrid->addWidget( samples, row++, 0, 1, 2 );
small = widgets->sm_label( tr( "Small Font Sample" ), -1 );
lineGrid->addWidget( small, row++, 0, 1, 2 );
regular = widgets->sm_label( tr( "Regular Font Sample" ) );
lineGrid->addWidget( regular, row++, 0, 1, 2 );
regularBold = widgets->sm_label( tr( "Regular Font Sample, Bold" ), 0, QFont::Bold );
lineGrid->addWidget( regularBold, row++, 0, 1, 2 );
large = widgets->sm_label( tr( "Large Font Sample" ), +1 );
lineGrid->addWidget( large, row++, 0, 1, 2 );
largeBold = widgets->sm_label( tr( "Large Font Sample, Bold" ), +1, QFont::Bold );
lineGrid->addWidget( largeBold, row++, 0, 1, 2 );
title = widgets->sm_label( tr( "Title Font Sample" ), +2, QFont::Bold );
lineGrid->addWidget( title, row++, 0, 1, 2 );
topbox->addLayout( lineGrid );
pb_default = widgets->sm_pushbutton( tr( "Select Default" ) );
connect( pb_default, SIGNAL( clicked() ), SLOT( setDefault() ) );
topbox->addWidget( pb_default );
pb_apply = widgets->sm_pushbutton( tr( "Apply" ) );
connect( pb_apply, SIGNAL( clicked() ), SLOT( apply() ) );
//pb_help = sm_pushbutton( tr( "Help" ) );
//connect( pb_help, SIGNAL( clicked() ), SLOT( help() ) );
pb_exit = widgets->sm_pushbutton( tr( "Exit" ) );
connect( pb_exit, SIGNAL( clicked() ), SLOT( close() ) );
QBoxLayout* buttons = new QHBoxLayout();
buttons->addWidget( pb_apply );
//buttons->addWidget( pb_help );
buttons->addWidget( pb_exit );
topbox->addLayout( buttons );
redraw(); // Set fonts fot all local widgets
}
void SM_Font::setDefault( void )
{
cb_family->setCurrentText( "DejaVu Sans" );
sb_size ->setValue ( 12 );
}
void SM_Font::update( int index )
{
index++; // So the comiler does not complain about unused parameter
redraw();
}
void SM_Font::apply()
{
// Set font vales in settings
settings->setValue( server + "-fontFamily", cb_family->currentText() );
settings->setValue( server + "-fontSize" , sb_size->value() );
settings->setValue( server + "-fontBold" , ckbox_bold->isChecked() );
settings->sync();
emit updateFonts();
}
//void SM_Font::help()
//{
// SM_Help* help = new SM_Help();
// help->show_help( "manual/smfont.html" );
//}
void SM_Font::selectFont()
{
bool ok = false;
QString family = cb_family->currentText();
int pointSize = sb_size->value();
QFont oldFont = QFont( family, pointSize );
QFont newFont = QFontDialog::getFont( &ok, oldFont, this );
if ( ! ok ) return;
cb_family ->setCurrentText ( newFont.family() );
sb_size ->setValue ( newFont.pointSize() );
}
void SM_Font::redraw( void )
{
QString family = cb_family->currentText();
int pointSize = sb_size->value();
lbl_family ->setFont( QFont( family, pointSize ) );
cb_family ->setFont( QFont( family, pointSize ) );
lbl_size ->setFont( QFont( family, pointSize ) );
sb_size ->setFont( QFont( family, pointSize ) );
ckbox_bold ->setFont( QFont( family, pointSize ) );
samples ->setFont( QFont( family, pointSize ) );
small ->setFont( QFont( family, pointSize - 1 ) );
regular ->setFont( QFont( family, pointSize ) );
regularBold ->setFont( QFont( family, pointSize, QFont::Bold ) );
large ->setFont( QFont( family, pointSize + 1 ) );
largeBold ->setFont( QFont( family, pointSize + 1, QFont::Bold ) );
title ->setFont( QFont( family, pointSize + 2, QFont::Bold ) );
pb_default ->setFont( QFont( family, pointSize + 1 ) );
pb_apply ->setFont( QFont( family, pointSize + 1 ) );
pb_font ->setFont( QFont( family, pointSize + 1 ) );
//pb_help ->setFont( QFont( family, pointSize + 1 ) );
pb_exit ->setFont( QFont( family, pointSize + 1 ) );
this->repaint();
}