mirror of
https://gitee.com/drabel/LibQQt.git
synced 2025-01-04 10:18:44 +08:00
add qqtqssmanager
This commit is contained in:
parent
ab8e0da105
commit
5f5d54dca8
64
src/frame/qqtqssmanager.cpp
Normal file
64
src/frame/qqtqssmanager.cpp
Normal 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
49
src/frame/qqtqssmanager.h
Normal 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文件必要。
|
||||
* 注意:主题列表不包括default,其他的主题qss才是主题,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
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user