libyui-qt
2.43.5
|
00001 /* 00002 Copyright (C) 2000-2012 Novell, Inc 00003 This library is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU Lesser General Public License as 00005 published by the Free Software Foundation; either version 2.1 of the 00006 License, or (at your option) version 3.0 of the License. This library 00007 is distributed in the hope that it will be useful, but WITHOUT ANY 00008 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00009 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00010 License for more details. You should have received a copy of the GNU 00011 Lesser General Public License along with this library; if not, write 00012 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth 00013 Floor, Boston, MA 02110-1301 USA 00014 */ 00015 00016 00017 /*-/ 00018 00019 File: QY2StyleEditor.cc 00020 00021 Author: Thomas Goettlicher <tgoettlicher@suse.de> 00022 00023 Textdomain "qt" 00024 00025 /-*/ 00026 00027 #include "QY2StyleEditor.h" 00028 #include "QY2Styler.h" 00029 #include "ui_QStyleEditor.h" 00030 #include <QDebug> 00031 #include <QFile> 00032 #include <QFileDialog> 00033 #include <QMessageBox> 00034 #include <QTextObject> 00035 #include "YQi18n.h" 00036 00037 00038 QY2StyleEditor::QY2StyleEditor( QWidget *parent ) 00039 : QDialog( parent ) 00040 { 00041 ui.setupUi(this); 00042 00043 ui.textEdit->setPlainText( "/* enter style sheet here */" ); 00044 ui.closeButton->setAutoDefault(false); 00045 setWindowTitle( _( "Stylesheet Editor" ) ); 00046 00047 connect( ui.applyButton, SIGNAL( clicked() ), 00048 this, SLOT( slotApplyStyle() )); 00049 00050 connect( ui.closeButton, SIGNAL( clicked() ), 00051 this, SLOT( close() )); 00052 00053 connect( ui.loadButton, SIGNAL( clicked() ), 00054 this, SLOT( slotLoadFile() )); 00055 00056 connect( ui.textEdit, SIGNAL( textChanged() ), 00057 this, SLOT( slotTextChanged() )); 00058 00059 connect( ui.autoApply, SIGNAL( stateChanged(int) ), 00060 this, SLOT( slotTextChanged() )); 00061 } 00062 00063 00064 QY2StyleEditor::~QY2StyleEditor() 00065 { 00066 } 00067 00068 void QY2StyleEditor::slotTextChanged() 00069 { 00070 if ( ui.autoApply->isChecked() ) 00071 slotApplyStyle(); 00072 } 00073 00074 void QY2StyleEditor::slotApplyStyle() 00075 { 00076 QY2Styler::styler()->setStyleSheet( ui.textEdit->toPlainText() ); 00077 } 00078 00079 00080 void QY2StyleEditor::slotLoadFile() 00081 { 00082 00083 QString fileName = QFileDialog::getOpenFileName( this, // parent 00084 QString( "Load stylesheet ..." ), // caption 00085 QY2Styler::styler()->themeDir(), // dir 00086 QString( "*.qss"), 0, // filter 00087 QFileDialog::DontUseNativeDialog ); 00088 00089 if ( fileName.isEmpty() ) 00090 return; // user clicked cancel 00091 00092 00093 QFile file( fileName); 00094 00095 if ( file.open( QFile::ReadOnly ) ) 00096 ui.textEdit->setPlainText( file.readAll() ); 00097 else 00098 { 00099 QMessageBox::warning( this, // parent 00100 QString("Error") , // caption 00101 QString( "Couldn't load file\n%1" ).arg( fileName ), 00102 QMessageBox::Ok | QMessageBox::Default, // button0 00103 Qt::NoButton, // button1 00104 Qt::NoButton ); // button2 00105 } 00106 00107 } 00108 00109 00110 00111 #include "QY2StyleEditor.moc"