Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
demo: update
Browse files Browse the repository at this point in the history
  • Loading branch information
wangwenx190 committed Oct 8, 2023
1 parent ad595c5 commit c8511ba
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 21 deletions.
4 changes: 2 additions & 2 deletions examples/dialog/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int main(int argc, char *argv[])

// Not necessary, but better call this function, before the construction
// of any Q(Core|Gui)Application instances.
FramelessHelper::Widgets::initialize();
FramelessHelperWidgetsInitialize();

#if 0
if (!qEnvironmentVariableIsSet("QT_WIDGETS_RHI")) {
Expand All @@ -54,7 +54,7 @@ int main(int argc, char *argv[])
// Must be called after QGuiApplication has been constructed, we are using
// some private functions from QPA which won't be available until there's
// a QGuiApplication instance.
FramelessHelper::Core::setApplicationOSThemeAware();
FramelessHelperEnableThemeAware();

FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow);
//FramelessConfig::instance()->set(Global::Option::DisableLazyInitializationForMicaMaterial);
Expand Down
4 changes: 2 additions & 2 deletions examples/mainwindow/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int main(int argc, char *argv[])

// Not necessary, but better call this function, before the construction
// of any Q(Core|Gui)Application instances.
FramelessHelper::Widgets::initialize();
FramelessHelperWidgetsInitialize();

#if 0
if (!qEnvironmentVariableIsSet("QT_WIDGETS_RHI")) {
Expand All @@ -54,7 +54,7 @@ int main(int argc, char *argv[])
// Must be called after QGuiApplication has been constructed, we are using
// some private functions from QPA which won't be available until there's
// a QGuiApplication instance.
FramelessHelper::Core::setApplicationOSThemeAware();
FramelessHelperEnableThemeAware();

FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow);
//FramelessConfig::instance()->set(Global::Option::DisableLazyInitializationForMicaMaterial);
Expand Down
6 changes: 3 additions & 3 deletions examples/quick/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ int main(int argc, char *argv[])

// Not necessary, but better call this function, before the construction
// of any Q(Core|Gui)Application instances.
FramelessHelper::Quick::initialize();
FramelessHelperQuickInitialize();

const auto application = std::make_unique<QGuiApplication>(argc, argv);

// Must be called after QGuiApplication has been constructed, we are using
// some private functions from QPA which won't be available until there's
// a QGuiApplication instance.
FramelessHelper::Core::setApplicationOSThemeAware();
FramelessHelperEnableThemeAware();

FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow);
//FramelessConfig::instance()->set(Global::Option::DisableLazyInitializationForMicaMaterial);
Expand Down Expand Up @@ -116,7 +116,7 @@ int main(int argc, char *argv[])

#if (((QT_VERSION < QT_VERSION_CHECK(6, 2, 0)) || defined(QUICK_USE_QMAKE)) && !QMLTC_ENABLED)
// Don't forget to register our own custom QML types!
FramelessHelper::Quick::registerTypes(engine.get());
FramelessHelperQuickRegisterTypes(engine.get());

qmlRegisterSingletonType<QuickSettings>("Demo", 1, 0, "Settings",
[](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
Expand Down
4 changes: 2 additions & 2 deletions examples/widget/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int main(int argc, char *argv[])

// Not necessary, but better call this function, before the construction
// of any Q(Core|Gui)Application instances.
FramelessHelper::Widgets::initialize();
FramelessHelperWidgetsInitialize();

#if 0
if (!qEnvironmentVariableIsSet("QT_WIDGETS_RHI")) {
Expand All @@ -54,7 +54,7 @@ int main(int argc, char *argv[])
// Must be called after QGuiApplication has been constructed, we are using
// some private functions from QPA which won't be available until there's
// a QGuiApplication instance.
FramelessHelper::Core::setApplicationOSThemeAware();
FramelessHelperEnableThemeAware();

FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow);
//FramelessConfig::instance()->set(Global::Option::DisableLazyInitializationForMicaMaterial);
Expand Down
59 changes: 47 additions & 12 deletions examples/widget/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "widget.h"
#include <QtCore/qdatetime.h>
#include <QtCore/qcoreevent.h>
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
# include <QtGui/qshortcut.h>
#else
Expand Down Expand Up @@ -54,7 +55,7 @@ FRAMELESSHELPER_STRING_CONSTANT(DevicePixelRatio)
Widget::Widget(QWidget *parent) : FramelessWidget(parent)
{
initialize();
startTimer(100);
m_timerId = startTimer(100);
connect(FramelessManager::instance(), &FramelessManager::systemThemeChanged, this, &Widget::updateStyleSheet);
}

Expand All @@ -63,7 +64,7 @@ Widget::~Widget() = default;
void Widget::timerEvent(QTimerEvent *event)
{
FramelessWidget::timerEvent(event);
if (m_clockLabel) {
if ((event->timerId() == m_timerId) && m_clockLabel) {
m_clockLabel->setText(QTime::currentTime().toString(FRAMELESSHELPER_STRING_LITERAL("hh:mm:ss")));
}
}
Expand All @@ -89,23 +90,55 @@ void Widget::initialize()
#endif
m_clockLabel = new QLabel(this);
m_clockLabel->setFrameShape(QFrame::NoFrame);
m_clockLabel->setAlignment(Qt::AlignCenter);
QFont clockFont = font();
clockFont.setBold(true);
clockFont.setPointSize(70);
m_clockLabel->setFont(clockFont);
const auto contentLayout = new QHBoxLayout;
contentLayout->setContentsMargins(0, 0, 0, 0);
contentLayout->setSpacing(0);
contentLayout->addStretch();
contentLayout->addWidget(m_clockLabel);
contentLayout->addStretch();
m_compilerInfoLabel = new QLabel(this);
m_compilerInfoLabel->setFrameShape(QFrame::NoFrame);
m_compilerInfoLabel->setAlignment(Qt::AlignCenter);
static const VersionInfo versionInfo = FramelessHelperVersion();
m_compilerInfoLabel->setText(
FRAMELESSHELPER_STRING_LITERAL("Compiler: %1 %2")
.arg(QString::fromUtf8(versionInfo.compiler.name),
QString::fromUtf8(versionInfo.compiler.version)));
m_commitInfoLabel = new QLabel(this);
m_commitInfoLabel->setFrameShape(QFrame::NoFrame);
m_commitInfoLabel->setAlignment(Qt::AlignCenter);
m_commitInfoLabel->setText(
FRAMELESSHELPER_STRING_LITERAL("Commit: %1 (%2)")
.arg(QString::fromUtf8(versionInfo.commit.hash),
QString::fromUtf8(versionInfo.commit.author)));
const auto clockLabelLayout = new QHBoxLayout;
clockLabelLayout->setContentsMargins(0, 0, 0, 0);
clockLabelLayout->setSpacing(0);
clockLabelLayout->addStretch();
clockLabelLayout->addWidget(m_clockLabel);
clockLabelLayout->addStretch();
const auto compilerInfoLabelLayout = new QHBoxLayout;
compilerInfoLabelLayout->setContentsMargins(0, 0, 0, 0);
compilerInfoLabelLayout->setSpacing(0);
compilerInfoLabelLayout->addStretch();
compilerInfoLabelLayout->addWidget(m_compilerInfoLabel);
compilerInfoLabelLayout->addStretch();
const auto commitInfoLabelLayout = new QHBoxLayout;
commitInfoLabelLayout->setContentsMargins(0, 0, 0, 0);
commitInfoLabelLayout->setSpacing(0);
commitInfoLabelLayout->addStretch();
commitInfoLabelLayout->addWidget(m_commitInfoLabel);
commitInfoLabelLayout->addStretch();
const auto mainLayout = new QVBoxLayout(this);
mainLayout->setSpacing(0);
mainLayout->setContentsMargins(0, 0, 0, 0);
#if FRAMELESSHELPER_CONFIG(titlebar)
mainLayout->addWidget(m_titleBar);
#endif
mainLayout->addLayout(contentLayout);
mainLayout->addStretch();
mainLayout->addLayout(clockLabelLayout);
mainLayout->addStretch();
mainLayout->addLayout(compilerInfoLabelLayout);
mainLayout->addLayout(commitInfoLabelLayout);
updateStyleSheet();

m_cancelShortcut = new QShortcut(this);
Expand Down Expand Up @@ -149,9 +182,11 @@ void Widget::initialize()
void Widget::updateStyleSheet()
{
const bool dark = (FramelessManager::instance()->systemTheme() == SystemTheme::Dark);
const QColor clockLabelTextColor = (dark ? kDefaultWhiteColor : kDefaultBlackColor);
m_clockLabel->setStyleSheet(FRAMELESSHELPER_STRING_LITERAL("background-color: transparent; color: %1;")
.arg(clockLabelTextColor.name()));
const QColor labelTextColor = (dark ? kDefaultWhiteColor : kDefaultBlackColor);
const QString labelStyleSheet = FRAMELESSHELPER_STRING_LITERAL("background-color: transparent; color: %1;").arg(labelTextColor.name());
m_clockLabel->setStyleSheet(labelStyleSheet);
m_compilerInfoLabel->setStyleSheet(labelStyleSheet);
m_commitInfoLabel->setStyleSheet(labelStyleSheet);
if (FramelessWidgetsHelper::get(this)->isBlurBehindWindowEnabled()) {
setStyleSheet(FRAMELESSHELPER_STRING_LITERAL("background-color: transparent;"));
} else {
Expand Down
3 changes: 3 additions & 0 deletions examples/widget/widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ private Q_SLOTS:
FRAMELESSHELPER_PREPEND_NAMESPACE(StandardTitleBar) *m_titleBar = nullptr;
#endif
QLabel *m_clockLabel = nullptr;
QLabel *m_compilerInfoLabel = nullptr;
QLabel *m_commitInfoLabel = nullptr;
QShortcut *m_fullScreenShortcut = nullptr;
QShortcut *m_cancelShortcut = nullptr;
int m_timerId = -1;
};

0 comments on commit c8511ba

Please sign in to comment.