+ Use of style sheets

This commit is contained in:
wmayer
2013-10-14 12:57:00 +02:00
parent 434400f8a0
commit 6f4fe2b9e2
9 changed files with 121 additions and 271 deletions

View File

@@ -26,6 +26,7 @@
# include <QApplication>
# include <QLocale>
# include <QStyleFactory>
# include <QTextStream>
#endif
#include "DlgGeneralImp.h"
@@ -127,7 +128,7 @@ void DlgGeneralImp::saveSettings()
SplashScreen->onSave();
// set new user defined style
(void)QApplication::setStyle(WindowStyle->currentText());
//(void)QApplication::setStyle(WindowStyle->currentText());
setRecentFileSize();
ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("General");
@@ -144,6 +145,40 @@ void DlgGeneralImp::saveSettings()
int pixel = size.toInt();
hGrp->SetInt("ToolbarIconSize", pixel);
getMainWindow()->setIconSize(QSize(pixel,pixel));
hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow");
hGrp->SetBool("TiledBackground", this->tiledBackground->isChecked());
QMdiArea* mdi = getMainWindow()->findChild<QMdiArea*>();
mdi->setProperty("showImage", this->tiledBackground->isChecked());
QVariant sheet = this->StyleSheets->itemData(this->StyleSheets->currentIndex());
if (this->selectedStyleSheet != sheet.toString()) {
this->selectedStyleSheet = sheet.toString();
hGrp->SetASCII("StyleSheet", (const char*)sheet.toByteArray());
if (!sheet.toString().isEmpty()) {
QFile f(sheet.toString());
if (f.open(QFile::ReadOnly)) {
mdi->setBackground(QBrush(Qt::NoBrush));
QTextStream str(&f);
qApp->setStyleSheet(str.readAll());
}
}
}
if (sheet.toString().isEmpty()) {
if (this->tiledBackground->isChecked()) {
qApp->setStyleSheet(QString());
mdi->setBackground(QPixmap(QLatin1String(":/icons/background.png")));
}
else {
qApp->setStyleSheet(QString());
mdi->setBackground(QBrush(QColor(160,160,160)));
}
}
if (mdi->style())
mdi->style()->unpolish(qApp);
}
void DlgGeneralImp::loadSettings()
@@ -204,6 +239,29 @@ void DlgGeneralImp::loadSettings()
this->toolbarIconSize->addItem(tr("Extra large (%1 x %1)").arg(48), QVariant((int)48));
index = this->toolbarIconSize->findData(QVariant(current));
if (index > -1) this->toolbarIconSize->setCurrentIndex(index);
hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow");
this->tiledBackground->setChecked(hGrp->GetBool("TiledBackground", false));
// List all .css files
QDir dir(QLatin1String(":/stylesheets"));
QString filter = QString::fromAscii("*.css");
QFileInfoList fileNames = dir.entryInfoList(QStringList(filter), QDir::Files, QDir::Name);
this->StyleSheets->addItem(tr("No style sheet"), QString::fromAscii(""));
for (QFileInfoList::iterator it = fileNames.begin(); it != fileNames.end(); ++it) {
this->StyleSheets->addItem(it->baseName(), it->absoluteFilePath());
}
// read also from resource directory
dir.setPath(QString::fromUtf8((App::Application::getResourceDir() + "Gui/Stylesheets/").c_str()));
fileNames = dir.entryInfoList(QStringList(filter), QDir::Files, QDir::Name);
for (QFileInfoList::iterator it = fileNames.begin(); it != fileNames.end(); ++it) {
this->StyleSheets->addItem(it->baseName(), it->absoluteFilePath());
}
this->selectedStyleSheet = QString::fromAscii(hGrp->GetASCII("StyleSheet").c_str());
index = this->StyleSheets->findData(this->selectedStyleSheet);
if (index > -1) this->StyleSheets->setCurrentIndex(index);
}
void DlgGeneralImp::changeEvent(QEvent *e)