forked from netpipe/cannachat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadtheme.h
120 lines (98 loc) · 3.48 KB
/
loadtheme.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#ifndef LOADTHEME_H
#define LOADTHEME_H
//#include <QWidget>
#include <mainwindow.h>
#include "ui_mainwindow.h"
//#include <QCoreApplication>
#include "qstylesheetmanager.h"
#include <QFileDialog>
#include <QDebug>
#include <QMessageBox>
#include <QFile>
#include <QDebug>
#include <QDirIterator>
void MainWindow::themeInit(){
QFile MyFile("themes.txt");
MyFile.open(QIODevice::ReadWrite);
QTextStream in (&MyFile);
QString line;
QStringList list;
// QList<QString> nums;
QStringList nums;
QRegExp rx("[:]");
line = in.readLine();
if (line.contains(":")) {
list = line.split(rx);
qDebug() << "theme" << list.at(1).toLatin1();
QStyleSheetManager::loadStyleSheet( list.at(1).toLatin1());
}
QDirIterator it("./Resource/themes/", QStringList() << "*.qss", QDir::Files, QDirIterator::Subdirectories);
while (it.hasNext()){
// QFileInfo fileInfo(f.fileName());
ui->cmbTheme->addItem(it.next().toLatin1());
}
loaded=true;
// do {
// } while (!line.isNull());
// ui->cmbTheme->itemText(ui->cmbTheme->count());
// if (ui->cmbTheme->currentText().toLatin1() != ""){
// //QStyleSheetManager::loadStyleSheet( ui->cmbTheme->currentText().toLatin1());
// QStyleSheetManager::loadStyleSheet( ui->cmbTheme->itemText(ui->cmbTheme->count()-1));
// } else {}
}
void MainWindow::on_cmbTheme_currentIndexChanged(const QString &arg1)
{
if (loaded==true)
{
fileName=ui->cmbTheme->currentText();
QFile file(fileName);
QStyleSheetManager::loadStyleSheet(ui->cmbTheme->currentText());
QFile file2("themes.txt");
if(file2.open(QIODevice::ReadWrite | QIODevice::Text))// QIODevice::Append |
{
QTextStream stream(&file2);
file2.seek(0);
stream << "theme:" << ui->cmbTheme->currentText().toLatin1()<< endl;
for (int i = 0; i < ui->cmbTheme->count(); i++)
{
stream << "theme:" << ui->cmbTheme->itemText(i) << endl;
}
// file.write("\n");
file2.close();
}
if (ui->cmbTheme->currentText().toLatin1() != ""){
// ui->cmbTheme->currentText().toLatin1();
}
}
}
void MainWindow::on_scantheme_clicked()
{
ui->cmbTheme->clear();
QDirIterator it("./Resource/themes/", QStringList() << "*.qss", QDir::Files, QDirIterator::Subdirectories);
while (it.hasNext()){
// QFileInfo fileInfo(f.fileName());
ui->cmbTheme->addItem(it.next().toLatin1());
}
on_themeApply_clicked(); //save files
}
void MainWindow::on_themeApply_clicked() //theme
{
QFile file("themes.txt");
if(file.open(QIODevice::ReadWrite | QIODevice::Text))// QIODevice::Append |
{
QTextStream stream(&file);
file.seek(0);
stream << "theme:" << ui->cmbTheme->currentText().toLatin1()<< endl;
for (int i = 0; i < ui->cmbTheme->count(); i++)
{
stream << "theme:" << ui->cmbTheme->itemText(i) << endl;
}
// file.write("\n");
file.close();
}
if (ui->cmbTheme->currentText().toLatin1() != ""){
QStyleSheetManager::loadStyleSheet( ui->cmbTheme->currentText().toLatin1());
}
writesettings();
}
#endif // LOADTHEME_H