File: ConfigFnBtn.cpp

package info (click to toggle)
bsc 2.27-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,640 kB
  • ctags: 2,610
  • sloc: cpp: 14,100; perl: 114; makefile: 46
file content (191 lines) | stat: -rw-r--r-- 7,649 bytes parent folder | download | duplicates (2)
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
188
189
190
191
/********************************************************************
 * Copyright (C) 2005 Piotr Pszczolkowski
 *-------------------------------------------------------------------
 * This file is part of BSCommander (Beesoft Commander).
 *
 * BsC is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * BsC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with BSCommander; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *******************************************************************/
 
/*------- include files:
-------------------------------------------------------------------*/
#include "ConfigFnBtn.h"
#include "Shared.h"
#include "Config.h"
#include "Settings.h"
#include <qlayout.h>
#include <qbuttongroup.h>
#include <qradiobutton.h>
#include <qpushbutton.h>
#include <qlabel.h>
#include <qfontdialog.h>

/*------- local constants:
-------------------------------------------------------------------*/
const QString ConfigFnBtn::DescriptionDispMode = QT_TR_NOOP( "Description display mode" );
const QString ConfigFnBtn::OnlyFunctionKey     = QT_TR_NOOP( "&Only function key" );
const QString ConfigFnBtn::F11                 = QT_TR_NOOP( "F11" );
const QString ConfigFnBtn::OnlyDescription     = QT_TR_NOOP( "Only &description" );
const QString ConfigFnBtn::Description         = QT_TR_NOOP( "description" );
const QString ConfigFnBtn::FullDescription     = QT_TR_NOOP( "&Full description" );
const QString ConfigFnBtn::F11Description      = QT_TR_NOOP( "F11 description" );
const QString ConfigFnBtn::TwoLinesDescription = QT_TR_NOOP( "&Two line description" );
const QString ConfigFnBtn::F11NlDescription    = QT_TR_NOOP( "F11\ndescription" );
const QString ConfigFnBtn::ButtonPreview       = QT_TR_NOOP( "Button preview" );
const QString ConfigFnBtn::Font                = QT_TR_NOOP( "Font" );


//*******************************************************************
// ConfigFnBtn                                           CONSTRUCTOR
//*******************************************************************
ConfigFnBtn::ConfigFnBtn( QWidget* const in_parent )
: QFrame( in_parent )
, d_main_layout( new QHBoxLayout( this ))
, d_lft_layout( new QVBoxLayout )
, d_rgt_layout( new QVBoxLayout )
, d_radio_grp( new QButtonGroup( 2, Qt::Horizontal, tr( DescriptionDispMode ), this ))
, d_only_fn_lbl( new QLabel( tr( F11 ), d_radio_grp ))
, d_only_fn_rb( new QRadioButton( tr( OnlyFunctionKey ), d_radio_grp ))
, d_only_text_lbl( new QLabel( tr( Description ), d_radio_grp ))
, d_only_text_rb( new QRadioButton( tr( OnlyDescription ), d_radio_grp ))
, d_fn_text_lbl( new QLabel( tr( F11Description ), d_radio_grp ))
, d_fn_text_rb( new QRadioButton( tr( FullDescription ), d_radio_grp ))
, d_fn_nl_text_lbl( new QLabel( tr( F11NlDescription ), d_radio_grp ))
, d_fn_nl_text_rb( new QRadioButton( tr( TwoLinesDescription ), d_radio_grp ))
, d_example_gb( new QGroupBox( 1, Qt::Horizontal, tr( ButtonPreview ), this ))
, d_example_btn( new QPushButton( d_example_gb ))
, d_font_btn( new QPushButton( tr( Font ), this ))
, d_apply_btn( new QPushButton( tr(Shared::ApplyBtnLabel), this ))
{
	Shared::add_icon( d_font_btn, "fonts.png" );
	Shared::add_icon( d_apply_btn, Shared::ApplyIcon );
	
	d_lft_layout->addWidget( d_radio_grp );
	d_rgt_layout->addWidget( d_example_gb );
	d_rgt_layout->addStretch( Shared::OverStretch );
	d_rgt_layout->addWidget( d_font_btn );
	d_rgt_layout->addWidget( d_apply_btn );

	d_main_layout->setSpacing( Shared::LayoutSpacing );
	d_main_layout->setMargin( Shared::LayoutMargin );
	d_main_layout->addLayout( d_lft_layout );
	d_main_layout->addLayout( d_rgt_layout );
	
	connect( d_font_btn , SIGNAL( clicked()      ), this, SLOT( font_selection() ));
	connect( d_apply_btn, SIGNAL( clicked()      ), this, SLOT( apply() ));
	connect( d_radio_grp, SIGNAL( clicked( int ) ), this, SLOT( clicked( int )   ));
	connect( this       , SIGNAL( looks_refresh()), in_parent, SIGNAL( looks_refresh() ));
}

//*******************************************************************
// show                                            PRIVATE inherited
//*******************************************************************
void ConfigFnBtn::show()
{
	QFrame::show();
	read_config();
}
// end of show

//*******************************************************************
// read config                                               PRIVATE
//*******************************************************************
void ConfigFnBtn::read_config()
{
	Config::instance()->refresh();

	d_font = Config::instance()->fn_font();
	d_fn_disp_mode = Config::instance()->fn_disp_mode();
	d_radio_grp->setButton( d_fn_disp_mode );

	update_view();
}
// end of read_config

//*******************************************************************
// save config                                               PRIVATE
//*******************************************************************
void ConfigFnBtn::save_config()
{
	Settings::save( Config::AppConfigGroup, Config::FnDispModeKey, d_fn_disp_mode );
	Settings::save( Config::AppConfigGroup, Config::FnFontKey, d_font.toString() );
}
// end of save_config

//*******************************************************************
// update_view                                               PRIVATE
//*******************************************************************
void ConfigFnBtn::update_view()
{
	QString button_label;
	switch( d_fn_disp_mode ) {
		case Config::ONLY_FN:
			button_label = F11;
			break;
		case Config::ONLY_TEXT:
			button_label = Description;
			break;
		case Config::FULL_DESC:
			button_label = F11Description;
			break;
		case Config::TWO_LINES:
			button_label = F11NlDescription;
			break;
	}
	d_example_btn->setFont( d_font );
	d_example_btn->setText( tr( button_label ) );
}
// end of update_view

//*******************************************************************
// font_selection                                       PRIVATE slot
//-------------------------------------------------------------------
// Uzytkownik nacisnal przycisk zmiany fontu.
//*******************************************************************
void ConfigFnBtn::font_selection()
{
	bool ok;
	const QFont new_font = QFontDialog::getFont( &ok, d_font, this );
	if ( ok ) {
		if( new_font != d_font ) {
			d_font = new_font;
			update_view();
		}
	}
}
// end of font_selection

//*******************************************************************
// apply                                                PRIVATE slot
//*******************************************************************
void ConfigFnBtn::apply()
{
	d_fn_disp_mode = d_radio_grp->selectedId();
	save_config();
	Config::instance()->refresh();
	emit looks_refresh();
}
// end of apply

//*******************************************************************
// clicked                                              PRIVATE slot
//-------------------------------------------------------------------
// Uzytkownik wybral 'radio button'.
//*******************************************************************
void ConfigFnBtn::clicked( const int in_idx )
{
	d_fn_disp_mode = in_idx;
	update_view();
}
// end of clicked