-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsm3_widgets.cpp
146 lines (109 loc) · 3.7 KB
/
sm3_widgets.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
//! \file us_widgets.cpp
#include "sm3_widgets.h"
SM_Widgets::SM_Widgets( QFont f ) : font( f )
{
}
// label
QLabel* SM_Widgets::sm_label( const QString& labelString, int fontAdjust, QFont::Weight weight )
{
QLabel* newLabel = new QLabel( labelString );
newLabel->setFrameStyle( QFrame::StyledPanel | QFrame::Raised );
newLabel->setAlignment ( Qt::AlignVCenter | Qt::AlignLeft );
newLabel->setMargin ( 2 );
newLabel->setAutoFillBackground( true );
QFont thisFont = font;
thisFont.setPointSize( font.pointSize() + fontAdjust );
thisFont.setWeight ( weight );
newLabel->setFont( thisFont );
return newLabel;
}
// textlabel ( fontAdjust defaults to smaller font (-1) if not specified )
QLabel* SM_Widgets::sm_textlabel( const QString& labelString, int fontAdjust, QFont::Weight weight )
{
return sm_label( labelString, fontAdjust, weight );
}
// banner ( defaults to Bold if weight not specified )
QLabel* SM_Widgets::sm_banner( const QString& labelString, int fontAdjust, QFont::Weight weight )
{
QLabel* newLabel = sm_label( labelString, fontAdjust, weight );
newLabel->setAlignment ( Qt::AlignCenter );
newLabel->setFrameStyle( QFrame::WinPanel | QFrame::Raised );
newLabel->setMidLineWidth( 2 );
newLabel->setFont( font );
return newLabel;
}
// pushbutton
QPushButton* SM_Widgets::sm_pushbutton( const QString& labelString, bool enabled,
int fontAdjust )
{
QPushButton* button = new QPushButton( labelString.toLatin1() );
QFont thisFont = font;
thisFont.setPointSize( font.pointSize() + fontAdjust );
button->setFont( thisFont );
//QString style = "border: 4px outset gray; border-radius: 10px;"
QString style = "QPushButton {"
"border: 4px outset gray;"
"border-radius: 10px;"
"}"
"QPushButton:hover {"
"background-color:#aaa;"
"}";
button->setStyleSheet( style );
button->setAutoDefault( false );
button->setEnabled( enabled );
return button;
}
// SpinBox
QSpinBox* SM_Widgets::sm_spinBox( const int fontAdjust )
{
QSpinBox* sbox = new QSpinBox();
QFont thisFont = font;
thisFont.setPointSize( font.weight() + fontAdjust );
sbox->setAutoFillBackground( true );
sbox->setFont( thisFont );
return sbox;
}
// Combo Box
QComboBox* SM_Widgets::sm_comboBox( void )
{
QComboBox* cb = new QComboBox();
cb->setAutoFillBackground( true );
cb->setFont( font );
return cb;
}
// checkbox
QGridLayout* SM_Widgets::sm_checkbox(
const QString& text, QCheckBox*& cb, bool state )
{
QFont thisFont = font;
thisFont.setWeight( QFont::Bold );
QFontMetrics fm( font );
QLabel* lb_spacer = new QLabel;
// Space as wide as a 'w'
lb_spacer->setFixedWidth ( fm.horizontalAdvance( "w" ) );
lb_spacer->setAutoFillBackground( true );
cb = new QCheckBox( text.toLatin1() );
cb->setFont ( thisFont );
cb->setChecked ( state );
cb->setAutoFillBackground( true );
QGridLayout* layout = new QGridLayout;
layout->setContentsMargins( 0, 0, 0, 0 );
layout->setSpacing ( 0 );
layout->addWidget( lb_spacer, 0, 0 );
layout->addWidget( cb , 0, 1 );
return layout;
}
// lineedit
QLineEdit* SM_Widgets::sm_lineedit( const QString& text, int fontAdjust,
bool readonly )
{
QLineEdit* le = new QLineEdit();
if ( readonly ) fontAdjust++;
QFont thisFont = font;
thisFont.setPointSize( font.pointSize() + fontAdjust );
le->setFont ( thisFont );
le->insert ( text );
le->setAutoFillBackground( true );
le->show();
return le;
}