libyui-qt  2.49.2
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 "YQUI.h"
28 #include "QY2StyleEditor.h"
29 #include "QY2Styler.h"
30 #include "ui_QStyleEditor.h"
31 #include <QDebug>
32 #include <QFile>
33 #include <QFileDialog>
34 #include <QMessageBox>
35 #include <QTextObject>
36 #include "YQi18n.h"
37 
38 
40  : QDialog( parent )
41 {
42  ui.setupUi(this);
43 
44  ui.textEdit->setPlainText( "/* enter style sheet here */" );
45  ui.closeButton->setAutoDefault(false);
46  setWindowTitle( _( "Stylesheet Editor" ) );
47 
48  connect( ui.applyButton, &pclass(ui.applyButton)::clicked,
49  this, &pclass(this)::slotApplyStyle);
50 
51  connect( ui.closeButton, &pclass(ui.closeButton)::clicked,
52  this, &pclass(this)::close);
53 
54  connect( ui.loadButton, &pclass(ui.loadButton)::clicked,
55  this, &pclass(this)::slotLoadFile);
56 
57  connect( ui.textEdit, &pclass(ui.textEdit)::textChanged,
58  this, &pclass(this)::slotTextChanged);
59 
60  connect( ui.autoApply, &pclass(ui.autoApply)::stateChanged,
61  this, &pclass(this)::slotTextChanged);
62 }
63 
64 
66 {
67 }
68 
69 void QY2StyleEditor::slotTextChanged()
70 {
71  if ( ui.autoApply->isChecked() )
72  slotApplyStyle();
73 }
74 
75 void QY2StyleEditor::slotApplyStyle()
76 {
77  QY2Styler::styler()->setStyleSheet( ui.textEdit->toPlainText() );
78 }
79 
80 
81 void QY2StyleEditor::slotLoadFile()
82 {
83 
84  QString fileName = QFileDialog::getOpenFileName( this, // parent
85  QString( "Load stylesheet ..." ), // caption
86  QY2Styler::styler()->themeDir(), // dir
87  QString( "*.qss"), 0, // filter
88  QFileDialog::DontUseNativeDialog );
89 
90  if ( fileName.isEmpty() )
91  return; // user clicked cancel
92 
93 
94  QFile file( fileName);
95 
96  if ( file.open( QFile::ReadOnly ) )
97  ui.textEdit->setPlainText( file.readAll() );
98  else
99  {
100  QMessageBox::warning( this, // parent
101  QString("Error") , // caption
102  QString( "Couldn't load file\n%1" ).arg( fileName ),
103  QMessageBox::Ok | QMessageBox::Default, // button0
104  Qt::NoButton, // button1
105  Qt::NoButton ); // button2
106  }
107 
108 }
109 
110 
111 
112 #include "QY2StyleEditor.moc"
void setStyleSheet(const QString &text)
Applies a style sheet from a string.
Definition: QY2Styler.cc:177
QY2StyleEditor(QWidget *parent)
Constructor.
~QY2StyleEditor()
Destructor.