libyui-qt  2.43.5
 All Classes Functions Variables
QY2StyleEditor.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: QY2StyleEditor.cc
20 
21  Author: Thomas Goettlicher <tgoettlicher@suse.de>
22 
23  Textdomain "qt"
24 
25 /-*/
26 
27 #include "QY2StyleEditor.h"
28 #include "QY2Styler.h"
29 #include "ui_QStyleEditor.h"
30 #include <QDebug>
31 #include <QFile>
32 #include <QFileDialog>
33 #include <QMessageBox>
34 #include <QTextObject>
35 #include "YQi18n.h"
36 
37 
39  : QDialog( parent )
40 {
41  ui.setupUi(this);
42 
43  ui.textEdit->setPlainText( "/* enter style sheet here */" );
44  ui.closeButton->setAutoDefault(false);
45  setWindowTitle( _( "Stylesheet Editor" ) );
46 
47  connect( ui.applyButton, SIGNAL( clicked() ),
48  this, SLOT( slotApplyStyle() ));
49 
50  connect( ui.closeButton, SIGNAL( clicked() ),
51  this, SLOT( close() ));
52 
53  connect( ui.loadButton, SIGNAL( clicked() ),
54  this, SLOT( slotLoadFile() ));
55 
56  connect( ui.textEdit, SIGNAL( textChanged() ),
57  this, SLOT( slotTextChanged() ));
58 
59  connect( ui.autoApply, SIGNAL( stateChanged(int) ),
60  this, SLOT( slotTextChanged() ));
61 }
62 
63 
65 {
66 }
67 
68 void QY2StyleEditor::slotTextChanged()
69 {
70  if ( ui.autoApply->isChecked() )
71  slotApplyStyle();
72 }
73 
74 void QY2StyleEditor::slotApplyStyle()
75 {
76  QY2Styler::styler()->setStyleSheet( ui.textEdit->toPlainText() );
77 }
78 
79 
80 void QY2StyleEditor::slotLoadFile()
81 {
82 
83  QString fileName = QFileDialog::getOpenFileName( this, // parent
84  QString( "Load stylesheet ..." ), // caption
85  QY2Styler::styler()->themeDir(), // dir
86  QString( "*.qss"), 0, // filter
87  QFileDialog::DontUseNativeDialog );
88 
89  if ( fileName.isEmpty() )
90  return; // user clicked cancel
91 
92 
93  QFile file( fileName);
94 
95  if ( file.open( QFile::ReadOnly ) )
96  ui.textEdit->setPlainText( file.readAll() );
97  else
98  {
99  QMessageBox::warning( this, // parent
100  QString("Error") , // caption
101  QString( "Couldn't load file\n%1" ).arg( fileName ),
102  QMessageBox::Ok | QMessageBox::Default, // button0
103  Qt::NoButton, // button1
104  Qt::NoButton ); // button2
105  }
106 
107 }
108 
109 
110 
111 #include "QY2StyleEditor.moc"