nodeeditor_doxy
src/ExampleApp/stylesheeteditor.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the examples of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:BSD$
00010 ** You may use this file under the terms of the BSD license as follows:
00011 **
00012 ** "Redistribution and use in source and binary forms, with or without
00013 ** modification, are permitted provided that the following conditions are
00014 ** met:
00015 **   * Redistributions of source code must retain the above copyright
00016 **     notice, this list of conditions and the following disclaimer.
00017 **   * Redistributions in binary form must reproduce the above copyright
00018 **     notice, this list of conditions and the following disclaimer in
00019 **     the documentation and/or other materials provided with the
00020 **     distribution.
00021 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
00022 **     the names of its contributors may be used to endorse or promote
00023 **     products derived from this software without specific prior written
00024 **     permission.
00025 **
00026 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00027 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00028 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00029 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00030 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00031 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00032 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00033 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00034 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00035 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00036 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
00037 ** $QT_END_LICENSE$
00038 **
00039 ****************************************************************************/
00040 
00041 #include <QtGui>
00042 
00043 #include "stylesheeteditor.h"
00044 
00045 StyleSheetEditor::StyleSheetEditor(QWidget *parent)
00046     : QFrame(parent)
00047 {
00048     ui.setupUi(this);
00049 
00050     QRegExp regExp(".(.*)\\+?Style");
00051     QString defaultStyle = QApplication::style()->metaObject()->className();
00052 
00053     if (regExp.exactMatch(defaultStyle))
00054         defaultStyle = regExp.cap(1);
00055 
00056     ui.styleCombo->addItems(QStyleFactory::keys());
00057     ui.styleCombo->setCurrentIndex(ui.styleCombo->findText(defaultStyle, Qt::MatchContains));
00058     ui.styleSheetCombo->setCurrentIndex(ui.styleSheetCombo->findText("Coffee"));
00059     loadStyleSheet("Coffee");
00060 }
00061 
00062 void StyleSheetEditor::on_styleCombo_activated(const QString &styleName)
00063 {
00064     //qApp->setStyle(styleName);
00065         emit newStyle(styleName);
00066     ui.applyButton->setEnabled(false);
00067         //return 
00068 }
00069 
00070 void StyleSheetEditor::on_styleSheetCombo_activated(const QString &sheetName)
00071 {
00072     loadStyleSheet(sheetName);
00073 }
00074 
00075 void StyleSheetEditor::on_styleTextEdit_textChanged()
00076 {
00077     ui.applyButton->setEnabled(true);
00078 }
00079 
00080 void StyleSheetEditor::on_applyButton_clicked()
00081 {
00082     //qApp->setStyleSheet(ui.styleTextEdit->toPlainText());
00083         emit newStylesheet(ui.styleTextEdit->toPlainText());
00084     ui.applyButton->setEnabled(false);
00085 }
00086 
00087 void StyleSheetEditor::loadStyleSheet(const QString &sheetName)
00088 {
00089     QFile file(":/qss/" + sheetName.toLower() + ".qss");
00090     file.open(QFile::ReadOnly);
00091     QString styleSheet = QLatin1String(file.readAll());
00092 
00093     ui.styleTextEdit->setPlainText(styleSheet);
00094     //qApp->setStyleSheet(styleSheet);
00095         emit newStylesheet(styleSheet);
00096     ui.applyButton->setEnabled(false);
00097 }
00098 
00099