1 | /**********************************************************************
|
---|
2 | ** Copyright (C) 2000-2007 Trolltech ASA. All rights reserved.
|
---|
3 | **
|
---|
4 | ** This file is part of Qt Designer.
|
---|
5 | **
|
---|
6 | ** This file may be distributed and/or modified under the terms of the
|
---|
7 | ** GNU General Public License version 2 as published by the Free Software
|
---|
8 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
9 | ** packaging of this file.
|
---|
10 | **
|
---|
11 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
---|
12 | ** licenses may use this file in accordance with the Qt Commercial License
|
---|
13 | ** Agreement provided with the Software.
|
---|
14 | **
|
---|
15 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
16 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
17 | **
|
---|
18 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
19 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
20 | ** information about Qt Commercial License Agreements.
|
---|
21 | **
|
---|
22 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
23 | ** not clear to you.
|
---|
24 | **
|
---|
25 | **********************************************************************/
|
---|
26 |
|
---|
27 | void PreferencesBase::init()
|
---|
28 | {
|
---|
29 | QFontDatabase fdb;
|
---|
30 | comboFamily->insertStringList( fdb.families() );
|
---|
31 | listElements->setCurrentItem( listElements->firstItem() );
|
---|
32 | currentElement = "";
|
---|
33 | }
|
---|
34 |
|
---|
35 | void PreferencesBase::destroy()
|
---|
36 | {
|
---|
37 |
|
---|
38 | }
|
---|
39 |
|
---|
40 | void PreferencesBase::colorClicked()
|
---|
41 | {
|
---|
42 | QColor c = QColorDialog::getColor( currentStyle.color, this, "editor_getcolor_dlg" );
|
---|
43 | if ( c.isValid() ) {
|
---|
44 | currentStyle.color = c;
|
---|
45 | setColorPixmap( c );
|
---|
46 | }
|
---|
47 | }
|
---|
48 |
|
---|
49 | void PreferencesBase::reInit()
|
---|
50 | {
|
---|
51 | styles = Config::readStyles( path );
|
---|
52 | currentElement = "";
|
---|
53 | elementChanged( "Comment" );
|
---|
54 | for ( int i = 0; i < comboFamily->count(); ++i ) {
|
---|
55 | if ( listElements->text( i ) == "Comment" ) {
|
---|
56 | listElements->setCurrentItem( i );
|
---|
57 | break;
|
---|
58 | }
|
---|
59 | }
|
---|
60 | checkWordWrap->setChecked( Config::wordWrap( path ) );
|
---|
61 | checkCompletion->setChecked( Config::completion( path ) );
|
---|
62 | checkParenMatching->setChecked( Config::parenMatching( path ) );
|
---|
63 | spinTabSize->setValue( Config::indentTabSize( path ) );
|
---|
64 | spinIndentSize->setValue( Config::indentIndentSize( path ) );
|
---|
65 | checkKeepTabs->setChecked( Config::indentKeepTabs( path ) );
|
---|
66 | checkAutoIndent->setChecked( Config::indentAutoIndent( path ) );
|
---|
67 | }
|
---|
68 |
|
---|
69 | void PreferencesBase::save()
|
---|
70 | {
|
---|
71 | if ( !currentElement.isEmpty() ) {
|
---|
72 | styles.remove( currentElement );
|
---|
73 | styles.insert( currentElement, currentStyle );
|
---|
74 | currentElement = "";
|
---|
75 | }
|
---|
76 |
|
---|
77 | QSettings settings;
|
---|
78 | Config::saveStyles( styles, path );
|
---|
79 | Config::setWordWrap( checkWordWrap->isChecked(), path );
|
---|
80 | Config::setCompletion( checkCompletion->isChecked(), path );
|
---|
81 | Config::setParenMatching( checkParenMatching->isChecked(), path );
|
---|
82 | Config::setIndentTabSize( spinTabSize->value(), path );
|
---|
83 | Config::setIndentIndentSize( spinIndentSize->value(), path );
|
---|
84 | Config::setIndentKeepTabs( checkKeepTabs->isChecked(), path );
|
---|
85 | Config::setIndentAutoIndent( checkAutoIndent->isChecked(), path );
|
---|
86 | }
|
---|
87 |
|
---|
88 | void PreferencesBase::updatePreview()
|
---|
89 | {
|
---|
90 | editPreview->setFont( currentStyle.font );
|
---|
91 | QPalette pal = editPreview->palette();
|
---|
92 | pal.setColor( QPalette::Active, QColorGroup::Text, currentStyle.color );
|
---|
93 | pal.setColor( QPalette::Active, QColorGroup::Foreground, currentStyle.color );
|
---|
94 | editPreview->setPalette( pal );
|
---|
95 | }
|
---|
96 |
|
---|
97 | void PreferencesBase::boldChanged( bool b )
|
---|
98 | {
|
---|
99 | currentStyle.font.setBold( b );
|
---|
100 | updatePreview();
|
---|
101 | }
|
---|
102 |
|
---|
103 | void PreferencesBase::elementChanged( const QString &element )
|
---|
104 | {
|
---|
105 | if ( !currentElement.isEmpty() ) {
|
---|
106 | styles.remove( currentElement );
|
---|
107 | styles.insert( currentElement, currentStyle );
|
---|
108 | currentElement = "";
|
---|
109 | }
|
---|
110 | QMap<QString, ConfigStyle>::Iterator it = styles.find( element );
|
---|
111 | if ( it == styles.end() )
|
---|
112 | return;
|
---|
113 | ConfigStyle s = *it;
|
---|
114 | currentStyle = s;
|
---|
115 | comboFamily->lineEdit()->setText( s.font.family() );
|
---|
116 | spinSize->setValue( s.font.pointSize() );
|
---|
117 | checkBold->setChecked( s.font.bold() );
|
---|
118 | checkItalic->setChecked( s.font.italic() );
|
---|
119 | checkUnderline->setChecked( s.font.underline() );
|
---|
120 | setColorPixmap( s.color );
|
---|
121 | currentElement = element;
|
---|
122 | updatePreview();
|
---|
123 | }
|
---|
124 |
|
---|
125 | void PreferencesBase::familyChanged( const QString &f )
|
---|
126 | {
|
---|
127 | QString oldFamily = currentStyle.font.family();
|
---|
128 | currentStyle.font.setFamily( f );
|
---|
129 | if ( currentElement == "Standard" ) {
|
---|
130 | for ( QMap<QString, ConfigStyle>::Iterator it = styles.begin(); it != styles.end(); ++it ) {
|
---|
131 | if ( (*it).font.family() == oldFamily )
|
---|
132 | (*it).font.setFamily( f );
|
---|
133 | }
|
---|
134 | }
|
---|
135 | updatePreview();
|
---|
136 | }
|
---|
137 |
|
---|
138 | void PreferencesBase::italicChanged( bool b )
|
---|
139 | {
|
---|
140 | currentStyle.font.setItalic( b );
|
---|
141 | updatePreview();
|
---|
142 | }
|
---|
143 |
|
---|
144 | void PreferencesBase::setColorPixmap( const QColor &c )
|
---|
145 | {
|
---|
146 | QPixmap pm( 20, 20 );
|
---|
147 | pm.fill( c );
|
---|
148 | buttonColor->setPixmap( pm );
|
---|
149 | updatePreview();
|
---|
150 | }
|
---|
151 |
|
---|
152 | void PreferencesBase::setPath( const QString &p )
|
---|
153 | {
|
---|
154 | path = p;
|
---|
155 | }
|
---|
156 |
|
---|
157 | void PreferencesBase::sizeChanged( int s )
|
---|
158 | {
|
---|
159 | int oldSize = currentStyle.font.pointSize();
|
---|
160 | currentStyle.font.setPointSize( s );
|
---|
161 | if ( currentElement == "Standard" ) {
|
---|
162 | for ( QMap<QString, ConfigStyle>::Iterator it = styles.begin(); it != styles.end(); ++it ) {
|
---|
163 | if ( (*it).font.pointSize() == oldSize )
|
---|
164 | (*it).font.setPointSize( s );
|
---|
165 | }
|
---|
166 | }
|
---|
167 | updatePreview();
|
---|
168 | }
|
---|
169 |
|
---|
170 | void PreferencesBase::underlineChanged( bool b )
|
---|
171 | {
|
---|
172 | currentStyle.font.setUnderline( b );
|
---|
173 | updatePreview();
|
---|
174 | }
|
---|