Create project

This commit is contained in:
Andrey Rodionov 2020-04-12 22:15:57 +03:00
commit a36a44fa0b
7 changed files with 399 additions and 0 deletions

87
.gitignore vendored Normal file
View File

@ -0,0 +1,87 @@
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------
*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
.qmake.stash
.qmake.cache
Thumbs.db
.directory
*.orig
# Version project
version.h
# qtcreator generated files
*.pro.user*
*.txt.user*
*.qbs.user*
*.qmlproject.user*
*.pluginspec
# xemacs temporary files
*.flc
# Vim temporary files
.*.swp
# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
# MinGW generated files
*.Debug
*.Release
# translation related:
share/qtcreator/translations/*_tr.h
share/qtcreator/translations/qtcreator_untranslated.ts
# Directories to ignore
# ---------------------
debug
lib/*
lib64/*
release
.rcc
.pch
doc/doxygen/html
qch/*
# Binaries
# --------
bin
build
target_wrapper.sh

25
CMakeLists.txt Normal file
View File

@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.5)
project(rtptheme LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt5 COMPONENTS Widgets REQUIRED)
add_library(rtptheme SHARED
main.cpp
rtptheme.cpp
rtptheme.h
rtptheme.json
)
target_link_libraries(rtptheme PRIVATE Qt5::Widgets)
target_link_libraries(rtptheme PRIVATE Qt5::GuiPrivate)
target_compile_definitions(rtptheme PRIVATE RTPTHEME_LIBRARY)

26
main.cpp Normal file
View File

@ -0,0 +1,26 @@
#include <qpa/qplatformthemeplugin.h>
#include "rtptheme.h"
QT_BEGIN_NAMESPACE
class RTPThemePlugin : public QPlatformThemePlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID QPlatformThemeFactoryInterface_iid FILE "rtptheme.json")
public:
QPlatformTheme *create(const QString &key, const QStringList &params) override;
};
QPlatformTheme *RTPThemePlugin::create(const QString &key, const QStringList &params)
{
Q_UNUSED(params);
if (!key.compare(QLatin1String("rtptheme"), Qt::CaseInsensitive))
return new RTPTheme;
return nullptr;
}
QT_END_NAMESPACE
#include "main.moc"

189
rtptheme.cpp Normal file
View File

@ -0,0 +1,189 @@
#include "rtptheme.h"
#include <private/qguiapplication_p.h>
#include <qpa/qplatformtheme_p.h>
#include <qpa/qplatformthemefactory_p.h>
#include <qpa/qplatformintegration.h>
#include <QPalette>
#include <QFont>
QT_BEGIN_NAMESPACE
class RTPThemePrivate : public QPlatformThemePrivate
{
public:
RTPThemePrivate()
: QPlatformThemePrivate()
{ }
~RTPThemePrivate()
{
delete baseTheme;
}
QPlatformTheme *baseTheme;
};
RTPTheme::RTPTheme()
: d_ptr(new RTPThemePrivate)
{
Q_D(RTPTheme);
QStringList themeNames;
themeNames += QGuiApplicationPrivate::platform_integration->themeNames();
// 1) Look for a theme plugin.
for (const QString &themeName : qAsConst(themeNames)) {
d->baseTheme = QPlatformThemeFactory::create(themeName, nullptr);
if (d->baseTheme)
break;
}
// 2) If no theme plugin was found ask the platform integration to
// create a theme
if (!d->baseTheme) {
for (const QString &themeName : qAsConst(themeNames)) {
d->baseTheme = QGuiApplicationPrivate::platform_integration->createPlatformTheme(themeName);
if (d->baseTheme)
break;
}
// No error message; not having a theme plugin is allowed.
}
// 3) Fall back on the built-in "null" platform theme.
if (!d->baseTheme)
d->baseTheme = new QPlatformTheme;
}
QPlatformMenuItem* RTPTheme::createPlatformMenuItem() const
{
Q_D(const RTPTheme);
return d->baseTheme->createPlatformMenuItem();
}
QPlatformMenu* RTPTheme::createPlatformMenu() const
{
Q_D(const RTPTheme);
return d->baseTheme->createPlatformMenu();
}
QPlatformMenuBar* RTPTheme::createPlatformMenuBar() const
{
Q_D(const RTPTheme);
return d->baseTheme->createPlatformMenuBar();
}
void RTPTheme::showPlatformMenuBar()
{
Q_D(const RTPTheme);
return d->baseTheme->showPlatformMenuBar();
}
bool RTPTheme::usePlatformNativeDialog(DialogType type) const
{
Q_D(const RTPTheme);
if (type == FileDialog)
return true;
return d->baseTheme->usePlatformNativeDialog(type);
}
QPlatformDialogHelper* RTPTheme::createPlatformDialogHelper(DialogType type) const
{
Q_D(const RTPTheme);
return d->baseTheme->createPlatformDialogHelper(type);
}
#ifndef QT_NO_SYSTEMTRAYICON
QPlatformSystemTrayIcon* RTPTheme::createPlatformSystemTrayIcon() const
{
Q_D(const RTPTheme);
return d->baseTheme->createPlatformSystemTrayIcon();
}
#endif
const QPalette *RTPTheme::palette(Palette type) const
{
Q_D(const RTPTheme);
if (type == SystemPalette) {
QStringList active {
"#000000", "#d3d3d3", "#ffffff", "#e9e9e9", "#696969", "#8d8d8d",
"#000000", "#ffffff", "#000000", "#fdfcfa", "#d3d3d3", "#000000",
"#232323", "#ffffff", "#0000ff", "#644a9b", "#faf6ef", "#000000",
"#ffffdc", "#000000" };
QStringList disabled {
"#808080", "#d3d3d3", "#ffffff", "#f3f3f3", "#696969", "#8d8d8d",
"#808080", "#ffffff", "#808080", "#fdfcfa", "#d3d3d3", "#000000",
"#232323", "#808080", "#0000ff", "#644a9b", "#faf6ef", "#000000",
"#ffffdc", "#000000" };
QStringList inactive {
"#000000", "#d3d3d3", "#ffffff", "#f3f3f3", "#696969", "#8d8d8d",
"#000000", "#ffffff", "#000000", "#fdfcfa", "#d3d3d3", "#000000",
"#232323", "#ffffff", "#0000ff", "#644a9b", "#faf6ef", "#000000",
"#ffffdc", "#000000" };
QPalette *pal = new QPalette(Qt::black);
for (int i = 0; i < qMin(active.count(), int(QPalette::NColorRoles)); ++i)
{
QPalette::ColorRole colorRole = (QPalette::ColorRole)i;
pal->setColor(QPalette::Active, colorRole, QColor(active[i]));
pal->setColor(QPalette::Disabled, colorRole, QColor(disabled[i]));
pal->setColor(QPalette::Inactive, colorRole, QColor(inactive[i]));
}
return pal;
}
return d->baseTheme->palette(type);
}
const QFont* RTPTheme::font(Font type) const
{
Q_D(const RTPTheme);
return new QFont("Verdana",8);
}
QVariant RTPTheme::themeHint(ThemeHint hint) const
{
Q_D(const RTPTheme);
return d->baseTheme->themeHint(hint);
}
QPixmap RTPTheme::standardPixmap(StandardPixmap sp, const QSizeF &size) const
{
Q_D(const RTPTheme);
return d->baseTheme->standardPixmap(sp, size);
}
QIcon RTPTheme::fileIcon(const QFileInfo &fileInfo,
QPlatformTheme::IconOptions iconOptions) const
{
Q_D(const RTPTheme);
return d->baseTheme->fileIcon(fileInfo, iconOptions);
}
QIconEngine * RTPTheme::createIconEngine(const QString &iconName) const
{
Q_D(const RTPTheme);
return d->baseTheme->createIconEngine(iconName);
}
#if QT_CONFIG(shortcut)
QList<QKeySequence> RTPTheme::keyBindings(QKeySequence::StandardKey key) const
{
Q_D(const RTPTheme);
return d->baseTheme->keyBindings(key);
}
#endif
QString RTPTheme::standardButtonText(int button) const
{
Q_D(const RTPTheme);
return d->baseTheme->standardButtonText(button);
}
QT_END_NAMESPACE

53
rtptheme.h Normal file
View File

@ -0,0 +1,53 @@
#ifndef RTPTHEME_H
#define RTPTHEME_H
#include <qpa/qplatformtheme.h>
QT_BEGIN_NAMESPACE
class RTPThemePrivate;
class RTPTheme : public QPlatformTheme
{
Q_DECLARE_PRIVATE(RTPTheme)
public:
RTPTheme();
QPlatformMenuItem *createPlatformMenuItem() const override;
QPlatformMenu *createPlatformMenu() const override;
QPlatformMenuBar *createPlatformMenuBar() const override;
void showPlatformMenuBar() override;
bool usePlatformNativeDialog(DialogType type) const override;
QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const override;
#ifndef QT_NO_SYSTEMTRAYICON
QPlatformSystemTrayIcon *createPlatformSystemTrayIcon() const override;
#endif
const QPalette *palette(Palette type = SystemPalette) const override;
const QFont *font(Font type = SystemFont) const override;
QVariant themeHint(ThemeHint hint) const override;
QPixmap standardPixmap(StandardPixmap sp, const QSizeF &size) const override;
QIcon fileIcon(const QFileInfo &fileInfo,
QPlatformTheme::IconOptions iconOptions = nullptr) const override;
QIconEngine *createIconEngine(const QString &iconName) const override;
#if QT_CONFIG(shortcut)
QList<QKeySequence> keyBindings(QKeySequence::StandardKey key) const override;
#endif
QString standardButtonText(int button) const override;
private:
QScopedPointer<RTPThemePrivate> d_ptr;
Q_DISABLE_COPY_MOVE(RTPTheme)
};
QT_END_NAMESPACE
#endif // QXDGDESKTOPPORTALTHEME_H

3
rtptheme.json Normal file
View File

@ -0,0 +1,3 @@
{
"Keys": [ "rtptheme"]
}

16
rtptheme.pro Normal file
View File

@ -0,0 +1,16 @@
TARGET = rtptheme
CONFIG += plugin
TEMPLATE = lib
PLUGIN_TYPE = platformthemes
PLUGIN_EXTENDS = -
PLUGIN_CLASS_NAME = RTPThemePlugin
QT += gui-private
HEADERS += \
rtptheme.h
SOURCES += \
main.cpp \
rtptheme.cpp