Add APP key button widget
This commit is contained in:
100
KeyBorad/KeyBorad/APP/AppKeyButton.cpp
Normal file
100
KeyBorad/KeyBorad/APP/AppKeyButton.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
#include "APP/AppKeyButton.h"
|
||||
|
||||
#include "APP/AppTheme.h"
|
||||
|
||||
namespace APP
|
||||
{
|
||||
|
||||
App_KeyButton::App_KeyButton(quint16 Usage, const QString& Text, QWidget* p_Parent)
|
||||
: QPushButton(Text, p_Parent),
|
||||
appUsage(Usage),
|
||||
appBaseText(Text)
|
||||
{
|
||||
setMinimumSize(88, 72);
|
||||
setCheckable(false);
|
||||
App_Func_RefreshText();
|
||||
App_Func_RefreshStyle();
|
||||
}
|
||||
|
||||
quint16 App_KeyButton::App_Func_GetUsage() const
|
||||
{
|
||||
return appUsage;
|
||||
}
|
||||
|
||||
void App_KeyButton::App_Func_SetPressedState(bool IsPressed)
|
||||
{
|
||||
if (appIsPressed == IsPressed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
appIsPressed = IsPressed;
|
||||
App_Func_RefreshStyle();
|
||||
}
|
||||
|
||||
void App_KeyButton::App_Func_SetLatchedState(bool IsLatched)
|
||||
{
|
||||
if (appIsLatched == IsLatched)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
appIsLatched = IsLatched;
|
||||
App_Func_RefreshStyle();
|
||||
}
|
||||
|
||||
void App_KeyButton::App_Func_SetFeatureText(const QString& Text)
|
||||
{
|
||||
if (appFeatureText == Text.trimmed())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
appFeatureText = Text.trimmed();
|
||||
App_Func_RefreshText();
|
||||
}
|
||||
|
||||
void App_KeyButton::App_Func_RefreshText()
|
||||
{
|
||||
if (appFeatureText.isEmpty())
|
||||
{
|
||||
setText(appBaseText);
|
||||
return;
|
||||
}
|
||||
|
||||
setText(QStringLiteral("%1\n%2").arg(appBaseText, appFeatureText));
|
||||
}
|
||||
|
||||
void App_KeyButton::App_Func_RefreshStyle()
|
||||
{
|
||||
const App_ThemePalette Palette = App_Theme_DefaultPalette();
|
||||
const QColor FillColor = appIsPressed
|
||||
? Palette.Accent
|
||||
: (appIsLatched ? Palette.AccentSoft : Palette.Surface);
|
||||
const QColor TextColor = appIsPressed
|
||||
? QColor(15, 23, 42)
|
||||
: Palette.TextPrimary;
|
||||
|
||||
setStyleSheet(QStringLiteral(
|
||||
"QPushButton {"
|
||||
" background:rgb(%1,%2,%3);"
|
||||
" color:rgb(%4,%5,%6);"
|
||||
" border:1px solid rgb(%7,%8,%9);"
|
||||
" border-radius:12px;"
|
||||
" font-size:16px;"
|
||||
" font-weight:600;"
|
||||
" padding:8px;"
|
||||
"}"
|
||||
)
|
||||
.arg(FillColor.red())
|
||||
.arg(FillColor.green())
|
||||
.arg(FillColor.blue())
|
||||
.arg(TextColor.red())
|
||||
.arg(TextColor.green())
|
||||
.arg(TextColor.blue())
|
||||
.arg(Palette.Border.red())
|
||||
.arg(Palette.Border.green())
|
||||
.arg(Palette.Border.blue()));
|
||||
}
|
||||
|
||||
} // namespace APP
|
||||
30
KeyBorad/KeyBorad/APP/AppKeyButton.h
Normal file
30
KeyBorad/KeyBorad/APP/AppKeyButton.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QtGlobal>
|
||||
#include <QtWidgets/QPushButton>
|
||||
|
||||
namespace APP
|
||||
{
|
||||
|
||||
class App_KeyButton : public QPushButton
|
||||
{
|
||||
public:
|
||||
explicit App_KeyButton(quint16 Usage, const QString& Text, QWidget* p_Parent = nullptr);
|
||||
|
||||
quint16 App_Func_GetUsage() const;
|
||||
void App_Func_SetPressedState(bool IsPressed);
|
||||
void App_Func_SetLatchedState(bool IsLatched);
|
||||
void App_Func_SetFeatureText(const QString& Text);
|
||||
|
||||
private:
|
||||
void App_Func_RefreshText();
|
||||
void App_Func_RefreshStyle();
|
||||
|
||||
quint16 appUsage = 0;
|
||||
bool appIsPressed = false;
|
||||
bool appIsLatched = false;
|
||||
QString appBaseText;
|
||||
QString appFeatureText;
|
||||
};
|
||||
|
||||
} // namespace APP
|
||||
Reference in New Issue
Block a user