1
0
mirror of https://gitee.com/drabel/LibQQt.git synced 2025-01-04 10:18:44 +08:00

add qqtqssmanager

This commit is contained in:
tianduanrui 2018-07-02 09:33:39 +08:00
parent ab8e0da105
commit 5f5d54dca8
3 changed files with 122 additions and 2 deletions

View File

@ -0,0 +1,64 @@
#include "qqtqssmanager.h"
QQtQSSManager::QQtQSSManager ( QObject* parent )
{
}
QQtQSSManager::~QQtQSSManager()
{
}
QList<QString> QQtQSSManager::styleList()
{
while ( mStyleList.count() > 0 )
mStyleList.removeAt ( 0 );
QDir d ( SKIN_PATH );
foreach ( QFileInfo mfi, d.entryInfoList() )
{
if ( mfi.isFile() )
{
if ( mfi.suffix() != "qss" )
continue;
//不包括default.qss
if ( mfi.baseName() == "default" )
continue;
QString styleName = mfi.completeBaseName();
mStyleList.push_back ( styleName );
}
}
return mStyleList;
}
void QQtQSSManager::setCurrentStyle ( QString styleName )
{
if ( !QDir ( skin ( "default.qss" ) ).exists() )
return;
if ( !QDir ( skin ( QString ( "%1.qss" ).arg ( styleName ) ) ).exists() )
return;
#ifdef __EMBEDDED_LINUX__
QString cmd = QString ( "touch %1" ).arg ( skin ( "current.qss" ) );
system ( cmd.toLocal8Bit().constData() );
#endif
QByteArray bytes;
QFile f1 ( skin ( "default.qss" ) );
f1.open ( QFile::ReadOnly );
bytes = f1.readAll();
f1.close();
QFile f2 ( skin ( QString ( "%1.qss" ).arg ( styleName ) ) );
f2.open ( QFile::ReadOnly );
bytes += f2.readAll();
f2.close();
QFile file ( skin ( "current.qss" ) );
file.open ( QFile::Truncate | QFile::WriteOnly );
file.write ( bytes );
file.close();
qqtApp->setQSSStyle ( skin ( "current.qss" ) );
}

49
src/frame/qqtqssmanager.h Normal file
View File

@ -0,0 +1,49 @@
#ifndef QQTQSSMANAGER_H
#define QQTQSSMANAGER_H
#include <QStyle>
#include <qqtcore.h>
#include <qqt-local.h>
#include <qqtapplication.h>
#include <qqtframe.h>
/**
* @brief QQtQSSManager
* app运行当前目录
* skin目录
*
* default主题
* default.qss是必然加载的QQtApp的皮肤qss配置
* default文件夹里qrc里
*
* blue主题
* blue.qss代表blue主题blue文件夹里blue.qss这个文件决定主题列表里的主题的名字qssManager会提供列表
* [].qss[]
*
*
* qss配置文件current.qss
* current.qss里包含default.qss和用户选定的当前主题的qss
* QQtApplication生效使QQtApplication
*
* qss文件里的url路径是相对于app工作目录的相对路径
* qrc里qss文件必要
* defaultqss才是主题default是主题公共资源
* qrc里或者打包成二进制格式的文件使使QSSManager加载
*/
class QQTSHARED_EXPORT QQtQSSManager : public QObject
{
Q_OBJECT
public:
explicit QQtQSSManager ( QObject* parent = 0 );
virtual ~QQtQSSManager();
//主题列表
QList<QString> styleList();
//主题名 "blue"
void setCurrentStyle ( QString styleName );
private:
QList<QString> mStyleList;
};
#endif // QQTQSSMANAGER_H

View File

@ -36,15 +36,18 @@ contains (QSYS_PRIVATE, Win32|Windows|Win64 || MSVC32|MSVC|MSVC64) {
#core
SOURCES += \
$$PWD/core/qqtcore.cpp \
$$PWD/core/qqtevent.cpp \
$$PWD/core/qqtdictionary.cpp \
$$PWD/core/qqtobjectmanager.cpp
HEADERS += \
$$PWD/core/qqtcore.h \
$$PWD/core/qqtevent.h \
$$PWD/core/qqtdictionary.h \
$$PWD/core/qqtobjectmanager.h
SOURCES += \
$$PWD/core/qqtevent.cpp
HEADERS += \
$$PWD/core/qqtevent.h
#后台进程支持这个只有ios不支持这个支持在源文件pri里处理。
DEFINES += __PROCESSMODULE__
#ios has no backend process
@ -187,6 +190,10 @@ FORMS += \
$$PWD/frame/qqtinput.ui \
$$PWD/frame/qqtmsgbox.ui
SOURCES += \
$$PWD/frame/qqtqssmanager.cpp
HEADERS += \
$$PWD/frame/qqtqssmanager.h
#multimedia
#support Qt5, if Qt4 want to use, you need compile QtMultiMedia for Qt4.